Instructions to use magichampz/lego-technic-sorting-model with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- TF-Keras
How to use magichampz/lego-technic-sorting-model with TF-Keras:
# Note: 'keras<3.x' or 'tf_keras' must be installed (legacy), and from_pretrained_keras was removed in huggingface_hub 1.0. # See https://github.com/keras-team/tf-keras for more details. # !pip install "huggingface_hub<1.0" tf_keras from huggingface_hub import from_pretrained_keras model = from_pretrained_keras("magichampz/lego-technic-sorting-model") - Notebooks
- Google Colab
- Kaggle
Download create-model/create_training_data_array.py from magichampz/lego-technic-sorting-model: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/magichampz/lego-technic-sorting-model/resolve/main/create-model/create_training_data_array.py
- Command line
-
hf download hf://magichampz/lego-technic-sorting-model/create-model/create_training_data_array.py
-
curl -L -o create_training_data_array.py https://huggingface.co/magichampz/lego-technic-sorting-model/resolve/main/create-model/create_training_data_array.py
1.3 kB
| # script to create training data npy file from the database of images | |
| # the npy file can then be uploaded to google drive and read in the jupyter notebook | |
| # can then create training_data for model training | |
| import os | |
| import cv2 | |
| import numpy as np | |
| # initialize target image size for the training and testing data | |
| img_height = 128 | |
| img_width = 128 | |
| categories = ["straight-liftarm", 'pins', 'bent-liftarm', 'gears-and-disc', 'special-connector', 'axles', 'axle-connectors-stoppers'] | |
| training_data = [] | |
| def get_category_images(list,path,label): | |
| #print("old:", str(len(training_data))) | |
| current = len(training_data) | |
| for i in range(len(list)): | |
| try: | |
| image = cv2.imread(os.path.join(path,list[i]), | |
| cv2.IMREAD_GRAYSCALE) | |
| image = cv2.resize(image, (128,128)) | |
| training_data.append([image, label]) | |
| except Exception: | |
| pass | |
| new = len(training_data) | |
| print(new - current) | |
| for cat in categories: | |
| cat_path = "RPI3_project/lego-test-data/database/" + cat | |
| cat_list = os.listdir(cat_path) | |
| cat_label = categories.index(cat) | |
| get_category_images(cat_list, cat_path, cat_label) | |
| print(len(training_data)) | |
| td_array = np.array(training_data) | |
| len(td_array) | |
| np.save('td_array_7cat', td_array) | |