SI_InteligentnyWozekWidlowy/imageClasification/Classificator.py

23 lines
582 B
Python
Raw Normal View History

2022-06-02 11:13:21 +02:00
import numpy as np
import tensorflow as tf
from tensorflow import keras
# loaded_model = keras.models.load_model("my_model")
def image_classification(path, model):
class_names = ['door', 'refrigerator', 'shelf']
img = tf.keras.utils.load_img(
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])
2022-06-06 23:46:27 +02:00
# print(class_names[np.argmax(score)])
2022-06-02 11:13:21 +02:00
return class_names[np.argmax(score)]