Spaces:
Sleeping
Sleeping
Describe what you changed
Browse files
model.py
CHANGED
|
@@ -1,23 +1,18 @@
|
|
| 1 |
-
from tensorflow.keras.
|
| 2 |
-
from
|
| 3 |
-
from tensorflow.keras.models import Model
|
| 4 |
-
|
| 5 |
-
import tensorflow as tf
|
| 6 |
import numpy as np
|
| 7 |
-
from PIL import Image # <-- Add this import
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
def build_model(num_classes):
|
| 11 |
-
base_model = MobileNetV2(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
|
| 12 |
-
base_model.trainable = False
|
| 13 |
-
|
| 14 |
-
x = base_model.output
|
| 15 |
-
x = GlobalAveragePooling2D()(x)
|
| 16 |
-
x = Dense(128, activation='relu')(x)
|
| 17 |
-
output = Dense(num_classes, activation='softmax')(x)
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def predict(image: Image.Image):
|
| 23 |
"""
|
|
|
|
| 1 |
+
from tensorflow.keras.models import load_model
|
| 2 |
+
from PIL import Image
|
|
|
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
# ✅ Define your class names in the exact training order
|
| 6 |
+
class_names = [
|
| 7 |
+
"Pepper__bell___Bacterial_spot",
|
| 8 |
+
"Pepper__bell___healthy",
|
| 9 |
+
"Potato___healthy",
|
| 10 |
+
"Potato___Early_blight"
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
# ✅ Load your trained model
|
| 14 |
+
# Make sure this file is in the same folder as model.py
|
| 15 |
+
model = load_model("final_plantvillage_model.keras")
|
| 16 |
|
| 17 |
def predict(image: Image.Image):
|
| 18 |
"""
|