JohanBeytell commited on
Commit
eaab480
·
verified ·
1 Parent(s): efaf45d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -11,6 +11,25 @@ model = load_model('acres-ppdc-01.keras')
11
  class_labels = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
12
 
13
  def classify_potato_plant(img):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # Preprocess the image for the model
15
  img = img.resize((128, 128)) # Resize to the same size the model was trained on
16
  img = image.img_to_array(img)
 
11
  class_labels = ['Potato___Early_blight', 'Potato___Late_blight', 'Potato___healthy']
12
 
13
  def classify_potato_plant(img):
14
+ # Convert the image to a NumPy array for manipulation
15
+ img = np.array(img)
16
+
17
+ # Get the current width and height of the image
18
+ h, w, _ = img.shape
19
+
20
+ # Calculate the cropping coordinates to keep the center of the image
21
+ if h > w:
22
+ # If height is greater than width, crop the top and bottom
23
+ start = (h - w) // 2
24
+ img = img[start:start + w, :, :] # Crop to width
25
+ else:
26
+ # If width is greater than height, crop the left and right
27
+ start = (w - h) // 2
28
+ img = img[:, start:start + h, :] # Crop to height
29
+
30
+ # Convert back to PIL image after cropping
31
+ img = image.array_to_img(img)
32
+
33
  # Preprocess the image for the model
34
  img = img.resize((128, 128)) # Resize to the same size the model was trained on
35
  img = image.img_to_array(img)