projekt_widzenie/model_pred/check_model_on_cpu/check.py

28 lines
765 B
Python
Raw Normal View History

2023-01-21 16:28:59 +01:00
import numpy as np
import tensorflow as tf
from tensorflow import keras
2023-01-22 17:22:30 +01:00
model = keras.models.load_model('../sign_char_detection_model')
2023-01-21 16:28:59 +01:00
class_names = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'del', 'nothing', 'space']
2023-01-22 14:43:02 +01:00
path_to_img = 'A_test_rect.png'
2023-01-21 16:28:59 +01:00
def pred_sign_char(path_to_img: str):
pred = []
test_image = tf.keras.utils.load_img(path_to_img, target_size = (256, 256))
test_image = tf.keras.utils.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = model.predict(test_image)
print(result)
pred.append(class_names[np.argmax(result)])
print(pred)
return pred[0]
2023-01-22 17:22:30 +01:00
pred_sign_char(path_to_img)