Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -53,7 +53,7 @@ app_ui = ui.page_fillable(
|
|
| 53 |
ui.input_switch("show_margins", "Show marginal plots", value=True),
|
| 54 |
),
|
| 55 |
ui.output_image("uploaded_image"), # display the uploaded TIFF sidewalk tile image
|
| 56 |
-
ui.
|
| 57 |
ui.output_ui("value_boxes"),
|
| 58 |
ui.output_plot("scatter", fill=True),
|
| 59 |
ui.help_text(
|
|
@@ -176,8 +176,6 @@ def server(input: Inputs, output: Outputs, session: Session):
|
|
| 176 |
""" Prepare Inputs """
|
| 177 |
# get input points prompt (grid of points)
|
| 178 |
input_points = generate_input_points(image)
|
| 179 |
-
print("INPUT POINTS SHAPE", np.array(input_points).shape)
|
| 180 |
-
print("IMAGE DIMENSIONS", image.width, image.height)
|
| 181 |
|
| 182 |
# prepare image and prompt for the model
|
| 183 |
inputs = processor(image, input_points=input_points, return_tensors="pt")
|
|
@@ -199,66 +197,53 @@ def server(input: Inputs, output: Outputs, session: Session):
|
|
| 199 |
prob = prob.cpu().numpy().squeeze()
|
| 200 |
prediction = (prob > 0.5).astype(np.uint8)
|
| 201 |
|
| 202 |
-
#
|
| 203 |
-
|
| 204 |
-
# # Extract the image data from the batch
|
| 205 |
-
# image_data = batch['image'].cpu().detach().numpy()[0] # Assuming batch size is 1
|
| 206 |
-
|
| 207 |
-
# # Plot the first image on the left
|
| 208 |
-
# axes[0].imshow(image_data)
|
| 209 |
-
# axes[0].set_title("Image")
|
| 210 |
-
|
| 211 |
-
# # Plot the second image on the right
|
| 212 |
-
# axes[1].imshow(prob)
|
| 213 |
-
# axes[1].set_title("Probability Map")
|
| 214 |
-
|
| 215 |
-
# # Plot the prediction image on the right
|
| 216 |
-
# axes[2].imshow(prediction)
|
| 217 |
-
# axes[2].set_title("Prediction")
|
| 218 |
-
|
| 219 |
-
# # Plot the predicted mask on the right
|
| 220 |
-
# axes[3].imshow(image_data)
|
| 221 |
-
# show_mask(prediction, axes[3])
|
| 222 |
-
# axes[3].set_title("Predicted Mask")
|
| 223 |
-
|
| 224 |
-
# # Extract the ground truth mask data from the batch
|
| 225 |
-
# ground_truth_mask_data = inputs['ground_truth_mask'].cpu().detach().numpy()[0] # Assuming batch size is 1
|
| 226 |
-
|
| 227 |
-
# # Plot the ground truth mask on the right
|
| 228 |
-
# axes[4].imshow(image_data)
|
| 229 |
-
# axes[4].imshow(ground_truth_mask_data)
|
| 230 |
-
# #show_mask(inputs['ground_truth_mask'], axes[4])
|
| 231 |
-
# axes[4].set_title("Ground Truth Mask")
|
| 232 |
-
|
| 233 |
-
# # Hide axis ticks and labels
|
| 234 |
-
# for ax in axes:
|
| 235 |
-
# ax.set_xticks([])
|
| 236 |
-
# ax.set_yticks([])
|
| 237 |
-
# ax.set_xticklabels([])
|
| 238 |
-
# ax.set_yticklabels([])
|
| 239 |
-
|
| 240 |
-
# # Display the images side by side
|
| 241 |
-
# plt.show()
|
| 242 |
-
|
| 243 |
-
# Evaluate the image with the model
|
| 244 |
-
# Example: predictions = model.predict(image_array)
|
| 245 |
-
|
| 246 |
-
# Return the processed result (replace 'result' with the actual processed result)
|
| 247 |
-
return "Processed result"
|
| 248 |
|
| 249 |
@reactive.Calc
|
| 250 |
-
def
|
| 251 |
-
"""Processes the image when uploaded"""
|
| 252 |
if input.tile_image() is not None:
|
| 253 |
return process_image()
|
| 254 |
else:
|
| 255 |
return None
|
| 256 |
|
| 257 |
@output
|
| 258 |
-
@render.
|
| 259 |
-
def
|
| 260 |
-
|
| 261 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 262 |
|
| 263 |
|
| 264 |
|
|
|
|
| 53 |
ui.input_switch("show_margins", "Show marginal plots", value=True),
|
| 54 |
),
|
| 55 |
ui.output_image("uploaded_image"), # display the uploaded TIFF sidewalk tile image
|
| 56 |
+
ui.output_plot("prediction_plots"),
|
| 57 |
ui.output_ui("value_boxes"),
|
| 58 |
ui.output_plot("scatter", fill=True),
|
| 59 |
ui.help_text(
|
|
|
|
| 176 |
""" Prepare Inputs """
|
| 177 |
# get input points prompt (grid of points)
|
| 178 |
input_points = generate_input_points(image)
|
|
|
|
|
|
|
| 179 |
|
| 180 |
# prepare image and prompt for the model
|
| 181 |
inputs = processor(image, input_points=input_points, return_tensors="pt")
|
|
|
|
| 197 |
prob = prob.cpu().numpy().squeeze()
|
| 198 |
prediction = (prob > 0.5).astype(np.uint8)
|
| 199 |
|
| 200 |
+
# Return the processed result
|
| 201 |
+
return image, prob, prediction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
|
| 203 |
@reactive.Calc
|
| 204 |
+
def get_predictions():
|
| 205 |
+
"""Processes the image when uploaded to get predictions"""
|
| 206 |
if input.tile_image() is not None:
|
| 207 |
return process_image()
|
| 208 |
else:
|
| 209 |
return None
|
| 210 |
|
| 211 |
@output
|
| 212 |
+
@render.plot
|
| 213 |
+
def prediction_plots():
|
| 214 |
+
# get prediction results when image is uploaded
|
| 215 |
+
image, prob, prediction = get_predictions()
|
| 216 |
+
|
| 217 |
+
fig, axes = plt.subplots(1, 4, figsize=(15, 5))
|
| 218 |
+
|
| 219 |
+
# Extract the image data
|
| 220 |
+
image_data = image.cpu().detach().numpy()
|
| 221 |
+
|
| 222 |
+
# Plot the first image on the left
|
| 223 |
+
axes[0].imshow(image_data)
|
| 224 |
+
axes[0].set_title("Image")
|
| 225 |
+
|
| 226 |
+
# Plot the probability map on the right
|
| 227 |
+
axes[1].imshow(prob)
|
| 228 |
+
axes[1].set_title("Probability Map")
|
| 229 |
+
|
| 230 |
+
# Plot the prediction image on the right
|
| 231 |
+
axes[2].imshow(prediction)
|
| 232 |
+
axes[2].set_title("Prediction")
|
| 233 |
+
|
| 234 |
+
# Plot the predicted mask on the right
|
| 235 |
+
axes[3].imshow(image_data)
|
| 236 |
+
show_mask(prediction, axes[3])
|
| 237 |
+
axes[3].set_title("Predicted Mask")
|
| 238 |
+
|
| 239 |
+
# Hide axis ticks and labels
|
| 240 |
+
for ax in axes:
|
| 241 |
+
ax.set_xticks([])
|
| 242 |
+
ax.set_yticks([])
|
| 243 |
+
ax.set_xticklabels([])
|
| 244 |
+
ax.set_yticklabels([])
|
| 245 |
+
|
| 246 |
+
return fig
|
| 247 |
|
| 248 |
|
| 249 |
|