sanket09 commited on
Commit
8bc1126
·
verified ·
1 Parent(s): daf8559

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -67,7 +67,7 @@ def train_random_forest_model():
67
  B2_resized = cv2.resize(B2_image, target_size, interpolation=cv2.INTER_NEAREST)
68
  return B2_resized.reshape(-1, 1)
69
 
70
- data_dir = 'Data' # Update to your local directory containing TIFF files
71
  X_list = []
72
  y_list = []
73
 
@@ -164,19 +164,24 @@ def predict_deep_learning(model_name, file):
164
  predictions = model.predict(preprocessed_patches)
165
  predictions = predictions.reshape((n_patches_y, n_patches_x))
166
 
167
- threshold = np.percentile(predictions, 90)
 
168
 
 
169
  overlay = np.zeros_like(img_data, dtype=np.float32)
170
  for i in range(n_patches_y):
171
  for j in range(n_patches_x):
172
  if predictions[i, j] > threshold:
173
  overlay[i*patch_size:(i+1)*patch_size, j*patch_size:(j+1)*patch_size] = predictions[i, j]
174
 
 
175
  plt.figure(figsize=(10, 10))
176
  plt.imshow(img_data, cmap='gray', alpha=0.5)
177
  plt.imshow(overlay, cmap='jet', alpha=0.5)
178
  plt.title('Crop Yield Prediction Overlay')
179
  plt.colorbar()
 
 
180
  plt.savefig('/tmp/dl_prediction_overlay.png')
181
 
182
  return '/tmp/dl_prediction_overlay.png'
 
67
  B2_resized = cv2.resize(B2_image, target_size, interpolation=cv2.INTER_NEAREST)
68
  return B2_resized.reshape(-1, 1)
69
 
70
+ data_dir = 'Data'
71
  X_list = []
72
  y_list = []
73
 
 
164
  predictions = model.predict(preprocessed_patches)
165
  predictions = predictions.reshape((n_patches_y, n_patches_x))
166
 
167
+ # Set a threshold to highlight areas with higher predicted yields
168
+ threshold = np.percentile(predictions, 90) # Adjust the percentile as needed
169
 
170
+ # Create an overlay image to visualize predictions
171
  overlay = np.zeros_like(img_data, dtype=np.float32)
172
  for i in range(n_patches_y):
173
  for j in range(n_patches_x):
174
  if predictions[i, j] > threshold:
175
  overlay[i*patch_size:(i+1)*patch_size, j*patch_size:(j+1)*patch_size] = predictions[i, j]
176
 
177
+ # Plot the overlay on the original image
178
  plt.figure(figsize=(10, 10))
179
  plt.imshow(img_data, cmap='gray', alpha=0.5)
180
  plt.imshow(overlay, cmap='jet', alpha=0.5)
181
  plt.title('Crop Yield Prediction Overlay')
182
  plt.colorbar()
183
+
184
+ # Save the plot to a file
185
  plt.savefig('/tmp/dl_prediction_overlay.png')
186
 
187
  return '/tmp/dl_prediction_overlay.png'