Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -327,28 +327,22 @@ async def predict_tomato(file: UploadFile = File(...)):
|
|
| 327 |
"message": "Please upload a clear image of a PLANT leaf."
|
| 328 |
})
|
| 329 |
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
# 3. Change all those specific pixels to [0, 0, 0] (Pure Black)
|
| 340 |
-
#image_array[white_mask] = [0, 0, 0]
|
| 341 |
-
|
| 342 |
-
# 4. Turn the matrix back into an image so the rest of the code can use it
|
| 343 |
-
#image = Image.fromarray(image_array)
|
| 344 |
-
|
| 345 |
|
| 346 |
# 1. Standard Resize
|
| 347 |
image = image.resize((224, 224))
|
| 348 |
|
| 349 |
# 2. Custom Normalization: Converting [0, 255] to [-1.0, 1.0]
|
| 350 |
input_data = np.array(image).astype(np.float32)
|
| 351 |
-
input_data = (input_data
|
| 352 |
input_data = np.expand_dims(input_data, axis=0)
|
| 353 |
|
| 354 |
# --- RUN INFERENCE ---
|
|
|
|
| 327 |
"message": "Please upload a clear image of a PLANT leaf."
|
| 328 |
})
|
| 329 |
|
| 330 |
+
image_array = np.array(image)
|
| 331 |
+
white_mask = (
|
| 332 |
+
(image_array[:, :, 0] > 240) &
|
| 333 |
+
(image_array[:, :, 1] > 240) &
|
| 334 |
+
(image_array[:, :, 2] > 240)
|
| 335 |
+
)
|
| 336 |
+
image_array[white_mask] = [0, 0, 0]
|
| 337 |
+
image = Image.fromarray(image_array)
|
| 338 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
|
| 340 |
# 1. Standard Resize
|
| 341 |
image = image.resize((224, 224))
|
| 342 |
|
| 343 |
# 2. Custom Normalization: Converting [0, 255] to [-1.0, 1.0]
|
| 344 |
input_data = np.array(image).astype(np.float32)
|
| 345 |
+
input_data = efficientnet_preprocess(input_data)
|
| 346 |
input_data = np.expand_dims(input_data, axis=0)
|
| 347 |
|
| 348 |
# --- RUN INFERENCE ---
|