-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy.py
27 lines (20 loc) · 882 Bytes
/
deploy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import matplotlib.pyplot as plt
import os, shutil, pathlib
import numpy as np
from tensorflow.keras.preprocessing import image
def predict_image_class(model, class_labels_map, category, id):
img_path = f"./{category}/{category}_{id}.JPG"
# img_path = "./readme_images/camouflaged_owl.jpg"
plt.figure()
image_matrix = plt.imread(img_path)
plt.imshow(image_matrix)
plt.axis("off")
img = image.load_img(img_path, target_size=(112, 112))
img_array = image.img_to_array(img)
x = np.expand_dims(img_array, axis=0)
img_preprocessed = np.vstack([x])
predictions = model.predict(img_preprocessed)
print("\nProbabilities : ", predictions)
max_index_probability = np.argmax(predictions)
print("\nPredicted : ", list(class_labels_map.keys())[list(class_labels_map.values()).index(max_index_probability)])
plt.show(block=False)