SI_InteligentnyWozekWidlowy/imageClasification/Classificator.py

24 lines
702 B
Python
Raw Permalink Normal View History

2022-06-02 01:56:52 +02:00
import numpy as np
import tensorflow as tf
def image_clasification(image_path, model):
# loaded_model = keras.models.load_model("my_model")
class_names = ['door', 'refrigerator', 'shelf']
img = tf.keras.utils.load_img(
image_path, target_size=(180, 180)
)
img_array = tf.keras.utils.img_to_array(img)
img_array = tf.expand_dims(img_array, 0) # Create a batch
predictions = model.predict(img_array)
score = tf.nn.softmax(predictions[0])
# print(
# "This image most likely belongs to {} with a {:.2f} percent confidence."
# .format(class_names[np.argmax(score)], 100 * np.max(score))
# )
return class_names[np.argmax(score)]