aagoluoglu commited on
Commit
6a56578
·
verified ·
1 Parent(s): 1c151cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -94,14 +94,14 @@ def load_model():
94
 
95
  return model, processor, device
96
 
97
- def show_mask(mask, ax, random_color=False):
98
  if random_color:
99
  color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
100
  else:
101
  color = np.array([30/255, 144/255, 255/255, 0.6])
102
  h, w = mask.shape[-2:]
103
  mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1)
104
- ax.imshow(mask_image)
105
 
106
  ### SERVER ###
107
  def server(input: Inputs, output: Outputs, session: Session):
@@ -238,22 +238,25 @@ def server(input: Inputs, output: Outputs, session: Session):
238
 
239
  # Extract the image data
240
  #image_data = image.cpu().detach().numpy()
 
 
 
241
 
242
  # Plot the first image on the left
243
  axes[0].imshow(image)
244
  axes[0].set_title("Image")
245
 
246
  # Plot the probability map on the right
247
- axes[1].imshow(prob)
248
  axes[1].set_title("Probability Map")
249
 
250
  # Plot the prediction image on the right
251
- axes[2].imshow(prediction)
252
  axes[2].set_title("Prediction")
253
 
254
  # Plot the predicted mask on the right
255
  axes[3].imshow(image)
256
- show_mask(prediction, axes[3])
257
  axes[3].set_title("Predicted Mask")
258
 
259
  # Hide axis ticks and labels
 
94
 
95
  return model, processor, device
96
 
97
+ def show_mask(mask, ax, width, height, random_color=False):
98
  if random_color:
99
  color = np.concatenate([np.random.random(3), np.array([0.6])], axis=0)
100
  else:
101
  color = np.array([30/255, 144/255, 255/255, 0.6])
102
  h, w = mask.shape[-2:]
103
  mask_image = mask.reshape(h, w, 1) * color.reshape(1, 1, -1)
104
+ ax.imshow(mask_image, extent=(0, width, height, 0)) # Setting extent to match original image dimensions
105
 
106
  ### SERVER ###
107
  def server(input: Inputs, output: Outputs, session: Session):
 
238
 
239
  # Extract the image data
240
  #image_data = image.cpu().detach().numpy()
241
+
242
+ # Get the dimensions of the original image
243
+ height, width = image.shape[:2]
244
 
245
  # Plot the first image on the left
246
  axes[0].imshow(image)
247
  axes[0].set_title("Image")
248
 
249
  # Plot the probability map on the right
250
+ axes[1].imshow(prob, extent=(0, width, height, 0)) # Setting extent to match original image dimensions
251
  axes[1].set_title("Probability Map")
252
 
253
  # Plot the prediction image on the right
254
+ axes[2].imshow(prediction, extent=(0, width, height, 0)) # Setting extent to match original image dimensions
255
  axes[2].set_title("Prediction")
256
 
257
  # Plot the predicted mask on the right
258
  axes[3].imshow(image)
259
+ show_mask(prediction, axes[3], width, height)
260
  axes[3].set_title("Predicted Mask")
261
 
262
  # Hide axis ticks and labels