-
Notifications
You must be signed in to change notification settings - Fork 0
/
prediction.py
36 lines (29 loc) · 1.06 KB
/
prediction.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
28
29
30
31
32
33
34
35
36
from imports import tf, keras, PIL, plt, characters
from PIL import Image
def predict(new_model, choice):
choice_file = ""
if choice == 1:
choice_file = "new_luffy"
elif choice == 2:
choice_file = "new_sanji"
elif choice == 3:
choice_file = "new_law"
elif choice == 4:
choice_file = "new_chopper"
elif choice == 5:
return
new_img_path = f"Data/New_Data/{choice_file}.png"
img = Image.open(new_img_path).convert("RGB")
resized_img = img.resize((180, 180))
img_arr = keras.preprocessing.image.img_to_array(resized_img)
img_arr = tf.expand_dims(img_arr, 0)
img_arr_norm = img_arr / 255.0
prediction = new_model.predict(img_arr_norm)
predicted_character_tensor = tf.argmax(prediction, axis=1)
predicted_character_scalar = predicted_character_tensor.numpy()[0]
predicted_character = characters[predicted_character_scalar]
plt.imshow(resized_img)
plt.axis("off")
plt.text(0, -20, f"Prediction: {predicted_character}", fontsize=12)
plt.show()
return