-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.py
30 lines (25 loc) · 849 Bytes
/
test.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
import numpy as np
import tensorflow as tf
from keras.models import load_model
from colored import fg, bg, attr
train_ds = tf.keras.utils.image_dataset_from_directory(
"./input/train",
validation_split=0.2,
subset="training",
seed=123,
image_size=(25, 25),
batch_size=32)
filepath = 'saved_model/my_model'
model = load_model(filepath, compile = True)
image = tf.keras.utils.load_img("input/test/pepsi/18.jpg",target_size=(25,25))
input_arr = tf.keras.utils.img_to_array(image)
input_arr = np.array([input_arr]) # Convert single image to a batch.
predictions = model.predict(input_arr)
print(train_ds.class_names)
print(predictions)
if predictions[0][0] > .5:
print(f'{fg(196)}{"cocacola"}{attr(0)}')
elif predictions[0][1] > .5:
print(f'{fg(12)}{"pepsi"}{attr(0)}')
else:
print("not sure!")