Create prediction.py
Browse files- prediction.py +12 -0
prediction.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from tensorflow.keras.preprocessing import image
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
def predict_class(model, image_path):
|
| 5 |
+
img = image.load_img(image_path, target_size=(100, 100))
|
| 6 |
+
img_array = image.img_to_array(img)
|
| 7 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 8 |
+
predictions = model.predict(img_array)
|
| 9 |
+
predicted_index = np.argmax(predictions[0])
|
| 10 |
+
classes = ['Banano', 'Durazno', 'Fresa', 'Guanabana', 'Guayaba', 'Kiwi', 'Limon', 'Lulo', 'Mandarina', 'Mango', 'Manzana', 'Manzana Verde', 'Melon', 'Mora', 'Naranja']
|
| 11 |
+
predicted_class = classes[predicted_index]
|
| 12 |
+
return predicted_class
|