sanjam99 commited on
Commit
97a4c7d
·
1 Parent(s): 9deb136

this is pushing mew visual model to resnet50

Browse files
Files changed (1) hide show
  1. app.py +23 -2
app.py CHANGED
@@ -12,6 +12,7 @@ from tensorflow.keras.layers import GlobalAveragePooling2D, Dense, Input
12
  from tensorflow.keras.optimizers import Adam
13
  from PIL import Image
14
  import rasterio
 
15
  from tensorflow.keras.applications import ResNet50
16
  from tensorflow.keras.models import Model
17
 
@@ -104,7 +105,27 @@ def predict_deep_learning(model_name, file):
104
  predictions = model.predict(preprocessed_patches)
105
  predictions = predictions.reshape((n_patches_y, n_patches_x))
106
 
107
- return predictions
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  else:
109
  return "No file uploaded"
110
  else:
@@ -123,7 +144,7 @@ inputs_deep_learning = [
123
  gr.Dropdown(choices=list(deep_learning_models.keys()), label='Model'),
124
  gr.File(label='Upload TIFF File')
125
  ]
126
- outputs_deep_learning = gr.Textbox(label='Predictions')
127
 
128
  with gr.Blocks() as demo:
129
  with gr.Tab("Traditional ML Models"):
 
12
  from tensorflow.keras.optimizers import Adam
13
  from PIL import Image
14
  import rasterio
15
+ import matplotlib.pyplot as plt
16
  from tensorflow.keras.applications import ResNet50
17
  from tensorflow.keras.models import Model
18
 
 
105
  predictions = model.predict(preprocessed_patches)
106
  predictions = predictions.reshape((n_patches_y, n_patches_x))
107
 
108
+ # Set a threshold to highlight areas with higher predicted yields
109
+ threshold = np.percentile(predictions, 90) # Adjust the percentile as needed
110
+
111
+ # Create an overlay image to visualize predictions
112
+ overlay = np.zeros_like(img_data, dtype=np.float32)
113
+ for i in range(n_patches_y):
114
+ for j in range(n_patches_x):
115
+ if predictions[i, j] > threshold:
116
+ overlay[i*patch_size:(i+1)*patch_size, j*patch_size:(j+1)*patch_size] = predictions[i, j]
117
+
118
+ # Plot the overlay on the original image
119
+ plt.figure(figsize=(10, 10))
120
+ plt.imshow(img_data, cmap='gray', alpha=0.5)
121
+ plt.imshow(overlay, cmap='jet', alpha=0.5)
122
+ plt.title('Crop Yield Prediction Overlay')
123
+ plt.colorbar()
124
+
125
+ # Save the plot to a file
126
+ plt.savefig('/tmp/prediction_overlay.png')
127
+
128
+ return '/tmp/prediction_overlay.png'
129
  else:
130
  return "No file uploaded"
131
  else:
 
144
  gr.Dropdown(choices=list(deep_learning_models.keys()), label='Model'),
145
  gr.File(label='Upload TIFF File')
146
  ]
147
+ outputs_deep_learning = gr.Image(label='Prediction Overlay')
148
 
149
  with gr.Blocks() as demo:
150
  with gr.Tab("Traditional ML Models"):