Spaces:
Sleeping
Sleeping
Commit
·
5acffdb
1
Parent(s):
7cc0fbb
model4 init
Browse files- efficientnetb3-Plant-leaves-merge-v2-0.96.h5 +3 -0
- main.py +85 -5
efficientnetb3-Plant-leaves-merge-v2-0.96.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d9bc8334814370c0ee60ce848e2d9c64adc3f59a15fe7b294c06ec217200fd73
|
| 3 |
+
size 134980088
|
main.py
CHANGED
|
@@ -52,6 +52,8 @@ model_27 = load_model("efficientnetb3-Botanical-Garden-v1-98.88.h5")
|
|
| 52 |
|
| 53 |
model_plant_leaves = load_model("efficientnetb3-Plant-leaves-v1-0.97.h5")
|
| 54 |
|
|
|
|
|
|
|
| 55 |
# Define class labels
|
| 56 |
class_labels = {
|
| 57 |
0: "Apple___Apple_scab",
|
|
@@ -149,6 +151,35 @@ class_plant_leaves = {
|
|
| 149 |
21: "Pongamia Pinnata healthy (P7a)",
|
| 150 |
}
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
|
| 153 |
# Define a route to accept single image uploads and make predictions
|
| 154 |
@app.post("/predict/")
|
|
@@ -228,10 +259,12 @@ async def predict_single_image_self(file: UploadFile):
|
|
| 228 |
except Exception as e:
|
| 229 |
return {"error": str(e)}
|
| 230 |
|
|
|
|
| 231 |
def h():
|
| 232 |
return "Hello World"
|
| 233 |
|
| 234 |
-
|
|
|
|
| 235 |
async def predict_single_image_self(file: UploadFile):
|
| 236 |
try:
|
| 237 |
# Read the uploaded image
|
|
@@ -262,19 +295,66 @@ async def predict_single_image_self(file: UploadFile):
|
|
| 262 |
if not matched_rows.empty:
|
| 263 |
matched_rows_json = matched_rows.to_json(orient="records")
|
| 264 |
|
| 265 |
-
|
| 266 |
result = {
|
| 267 |
"predicted_class": predicted_class_label,
|
| 268 |
"class_probabilities": predictions.tolist(),
|
| 269 |
"details": matched_rows_json,
|
| 270 |
}
|
| 271 |
else:
|
| 272 |
-
|
| 273 |
result = {
|
| 274 |
-
|
| 275 |
-
|
| 276 |
}
|
| 277 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 278 |
|
| 279 |
return result
|
| 280 |
|
|
|
|
| 52 |
|
| 53 |
model_plant_leaves = load_model("efficientnetb3-Plant-leaves-v1-0.97.h5")
|
| 54 |
|
| 55 |
+
model_merge_plant_leaves = load_model("efficientnetb3-Plant-leaves-merge-v2-0.96.h5")
|
| 56 |
+
|
| 57 |
# Define class labels
|
| 58 |
class_labels = {
|
| 59 |
0: "Apple___Apple_scab",
|
|
|
|
| 151 |
21: "Pongamia Pinnata healthy (P7a)",
|
| 152 |
}
|
| 153 |
|
| 154 |
+
class_plant_leaves_merged = {
|
| 155 |
+
0: "Kola Jamun",
|
| 156 |
+
1: "Alstonia Scholaris healthy (P2b)",
|
| 157 |
+
2: "Pomegranate healthy (P9a)",
|
| 158 |
+
3: "Pongamia Pinnata healthy (P7a)",
|
| 159 |
+
4: "Jamun diseased (P5b)",
|
| 160 |
+
5: "Gauva healthy (P3a)",
|
| 161 |
+
6: "Shewali",
|
| 162 |
+
7: "Mango healthy (P0a)",
|
| 163 |
+
8: "Bael diseased (P4b)",
|
| 164 |
+
9: "Alstonia Scholaris diseased (P2a)",
|
| 165 |
+
10: "Pomegranate diseased (P9b)",
|
| 166 |
+
11: "Jatropha healthy (P6a)",
|
| 167 |
+
12: "Jamun healthy (P5a)",
|
| 168 |
+
13: "Gauva diseased (P3b)",
|
| 169 |
+
14: "Chinar healthy (P11a)",
|
| 170 |
+
15: "Lemon diseased (P10b)",
|
| 171 |
+
16: "Arjun diseased (P1a)",
|
| 172 |
+
17: "Pongamia Pinnata diseased (P7b)",
|
| 173 |
+
18: "Curry Patta",
|
| 174 |
+
19: "Basil healthy (P8)",
|
| 175 |
+
20: "Lemon healthy (P10a)",
|
| 176 |
+
21: "Jatropha diseased (P6b)",
|
| 177 |
+
22: "Arjun healthy (P1b)",
|
| 178 |
+
23: "Lemon",
|
| 179 |
+
24: "Chinar diseased (P11b)",
|
| 180 |
+
25: "Mango diseased (P0b)",
|
| 181 |
+
}
|
| 182 |
+
|
| 183 |
|
| 184 |
# Define a route to accept single image uploads and make predictions
|
| 185 |
@app.post("/predict/")
|
|
|
|
| 259 |
except Exception as e:
|
| 260 |
return {"error": str(e)}
|
| 261 |
|
| 262 |
+
|
| 263 |
def h():
|
| 264 |
return "Hello World"
|
| 265 |
|
| 266 |
+
|
| 267 |
+
@app.post("/predict-plant-dataset-merge-25/")
|
| 268 |
async def predict_single_image_self(file: UploadFile):
|
| 269 |
try:
|
| 270 |
# Read the uploaded image
|
|
|
|
| 295 |
if not matched_rows.empty:
|
| 296 |
matched_rows_json = matched_rows.to_json(orient="records")
|
| 297 |
|
|
|
|
| 298 |
result = {
|
| 299 |
"predicted_class": predicted_class_label,
|
| 300 |
"class_probabilities": predictions.tolist(),
|
| 301 |
"details": matched_rows_json,
|
| 302 |
}
|
| 303 |
else:
|
|
|
|
| 304 |
result = {
|
| 305 |
+
"predicted_class": predicted_class_label,
|
| 306 |
+
"class_probabilities": predictions.tolist(),
|
| 307 |
}
|
| 308 |
|
| 309 |
+
return result
|
| 310 |
+
|
| 311 |
+
except Exception as e:
|
| 312 |
+
return {"error": str(e)}
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
@app.post("/predict-plant-dataset-22/")
|
| 316 |
+
async def predict_single_image_self(file: UploadFile):
|
| 317 |
+
try:
|
| 318 |
+
# Read the uploaded image
|
| 319 |
+
image = await file.read()
|
| 320 |
+
img = Image.open(io.BytesIO(image))
|
| 321 |
+
|
| 322 |
+
# Model Params
|
| 323 |
+
img_size = (224, 224)
|
| 324 |
+
channels = 3 # either BGR or Grayscale
|
| 325 |
+
color = "rgb"
|
| 326 |
+
img_shape = (img_size[0], img_size[1], channels)
|
| 327 |
+
|
| 328 |
+
# Preprocess the image to match the input requirements of your model
|
| 329 |
+
img = img.resize((224, 224)) # Adjust the size as needed
|
| 330 |
+
img = np.asarray(img)
|
| 331 |
+
img = preprocess_input(img)
|
| 332 |
+
|
| 333 |
+
# Make a prediction using your pre-trained model
|
| 334 |
+
predictions = model_merge_plant_leaves.predict(np.expand_dims(img, axis=0))
|
| 335 |
+
|
| 336 |
+
# Convert prediction indices to class labels
|
| 337 |
+
predicted_class_index = np.argmax(predictions)
|
| 338 |
+
predicted_class_label = class_plant_leaves_merged.get(
|
| 339 |
+
predicted_class_index, "Unknown"
|
| 340 |
+
)
|
| 341 |
+
|
| 342 |
+
matched_rows = df[df["id"] == predicted_class_index]
|
| 343 |
+
matched_rows_json = matched_rows.to_json(orient="records")
|
| 344 |
+
|
| 345 |
+
if not matched_rows.empty:
|
| 346 |
+
matched_rows_json = matched_rows.to_json(orient="records")
|
| 347 |
+
|
| 348 |
+
result = {
|
| 349 |
+
"predicted_class": predicted_class_label,
|
| 350 |
+
"class_probabilities": predictions.tolist(),
|
| 351 |
+
"details": matched_rows_json,
|
| 352 |
+
}
|
| 353 |
+
else:
|
| 354 |
+
result = {
|
| 355 |
+
"predicted_class": predicted_class_label,
|
| 356 |
+
"class_probabilities": predictions.tolist(),
|
| 357 |
+
}
|
| 358 |
|
| 359 |
return result
|
| 360 |
|