-
Notifications
You must be signed in to change notification settings - Fork 0
/
Prediction.py
32 lines (23 loc) · 1.18 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
import cv2
import tensorflow as tf
import pickle
import numpy as np
# will use this to convert prediction num to string value
CATEGORIES = ['apple_pie', 'beignets', 'bibimbap', 'breakfast_burrito',
'cheese_plate', 'chicken_wings', 'creme_brulee', 'deviled_eggs',
'dumplings', 'lobster_bisque', 'croque_madame', 'shrimp_and_grits',
'guacamole', 'tuna_tartare', 'peking_duck', 'macarons',
'paella', 'strawberry_shortcake', 'ramen', 'red_velvet_cake', 'samosa',
'cannoli', 'ceviche', 'baby_back_ribs']
img = 'redVelvet.jpg'
IMG_SIZE = 50
def prepare(filepath):
img_array = cv2.imread(filepath) # read in the image
new_array = cv2.resize(img_array, (IMG_SIZE, IMG_SIZE)) # resize image to match model's expected sizing
return new_array.reshape(-1, IMG_SIZE, IMG_SIZE, 3) # return the image with shaping that TF wants.
# model = tf.keras.models.load_model("food_prediction.model")
model = pickle.load(open("food_classifier.pickle", "rb"))
prediction = model.predict([prepare(img)]) # REMEMBER YOU'RE PASSING A LIST OF THINGS YOU WISH TO PREDICT
max_val = np.argmax(prediction)
answer = CATEGORIES[max_val]
print(answer)