usama1355 commited on
Commit
b4c83b2
·
verified ·
1 Parent(s): a0413d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
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
- #Fix Added because Model was trained on leaf images with black background.
331
- # 1. Turn the image into a matrix of numbers
332
- #image_array = np.array(image)
333
-
334
- # 2. Find all pixels where Red, Green, and Blue are all very high (white)
335
- #white_mask = (image_array[:, :, 0] > 240) & \
336
- #(image_array[:, :, 1] > 240) & \
337
- #(image_array[:, :, 2] > 240)
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 / 127.5) - 1.0
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 ---