-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoffee_prediction.py
27 lines (22 loc) · 944 Bytes
/
coffee_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
#!/usr/bin/env python
# coding: utf-8
from tensorflow import keras
#from tensorflow.keras.preprocessing.image import load_img, img_to_array
import numpy as np
prediction_label = {0: "Healthy", 1: "Red Spider Mite", 2: "Rust"}
#def make_prediction(file_path, model):
# image = load_img(file_path, target_size=(224, 224))
# x = img_to_array(image)
# x = np.expand_dims(x, axis=0)
# images = np.vstack([x])
# pred_classes = model.predict(images, batch_size=10)
# classes = pred_classes.argmax(axis=-1)
# return prediction_label.get(classes[0], 'Not sure.')
def make_prediction(image, model):
image = image.resize((224, 224))
image_array = keras.preprocessing.image.img_to_array(image)
x = np.expand_dims(image_array, axis=0)
images = np.vstack([x])
pred_classes = model.predict(images, batch_size=10)
classes = pred_classes.argmax(axis=-1)
return prediction_label.get(classes[0], 'Not sure.')