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/testing-tflite-model-com.py from magichampz/lego-technic-sorting-model: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/magichampz/lego-technic-sorting-model/resolve/main/create-model/testing-tflite-model-com.py
- Command line
-
hf download hf://magichampz/lego-technic-sorting-model/create-model/testing-tflite-model-com.py
-
curl -L -o testing-tflite-model-com.py https://huggingface.co/magichampz/lego-technic-sorting-model/resolve/main/create-model/testing-tflite-model-com.py
1.29 kB
| # to test tflite model on individual images | |
| # run on your own computer as raspberry pi can't install tensorflow, and we need the img_to_array function | |
| import numpy as np | |
| import tensorflow as tf | |
| from tensorflow.keras.preprocessing.image import load_img | |
| from tensorflow.keras.preprocessing.image import img_to_array | |
| from PIL import Image, ImageOps | |
| # Load TFLite model and allocate tensors. | |
| interpreter = tf.lite.Interpreter(model_path="OGmodel.tflite") | |
| interpreter.allocate_tensors() | |
| # Get input and output tensors. | |
| input_details = interpreter.get_input_details() | |
| output_details = interpreter.get_output_details() | |
| # Test model on random input data. | |
| input_shape = input_details[0]['shape'] | |
| input_image = Image.open('lego-testing/testing/12image.jpg') | |
| input_image = ImageOps.grayscale(input_image) | |
| input_image = input_image.resize((28,28)) | |
| input_data = img_to_array(input_image) | |
| input_data.resize(1,28,28,1) | |
| #input_data = np.array(np.random.random_sample(input_shape), dtype=np.float32) | |
| interpreter.set_tensor(input_details[0]['index'], input_data) | |
| interpreter.invoke() | |
| # The function `get_tensor()` returns a copy of the tensor data. | |
| # Use `tensor()` in order to get a pointer to the tensor. | |
| output_data = interpreter.get_tensor(output_details[0]['index']) | |
| print(np.argmax(output_data[0])) |