|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
interpreter = tf.lite.Interpreter(model_path="OGmodel.tflite") |
|
interpreter.allocate_tensors() |
|
|
|
|
|
input_details = interpreter.get_input_details() |
|
output_details = interpreter.get_output_details() |
|
|
|
|
|
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) |
|
|
|
interpreter.set_tensor(input_details[0]['index'], input_data) |
|
|
|
interpreter.invoke() |
|
|
|
|
|
|
|
output_data = interpreter.get_tensor(output_details[0]['index']) |
|
print(np.argmax(output_data[0])) |