Nguyen Thai Thao Uyen commited on
Commit
8e17922
·
1 Parent(s): 990d0b6
Files changed (2) hide show
  1. app.py +5 -6
  2. run.py +4 -2
app.py CHANGED
@@ -62,18 +62,17 @@ def server(input: Inputs, output: Outputs, session: Session):
62
 
63
  pred_prob, pred_prediction = run.pred(new_image)
64
 
65
- fig, axes = plt.subplots(1, 3, figsize=(15, 5))
 
66
 
67
- axes[0].imshow(new_image, cmap='gray')
68
- axes[0].set_title("Image")
 
69
 
70
  im = axes[1].imshow(pred_prob)
71
  axes[1].set_title("Probability Map")
72
  cbar = fig.colorbar(im, ax=axes[1])
73
 
74
- axes[2].imshow(pred_prediction, cmap='gray')
75
- axes[2].set_title("Prediction")
76
-
77
  for ax in axes:
78
  ax.set_xticks([])
79
  ax.set_yticks([])
 
62
 
63
  pred_prob, pred_prediction = run.pred(new_image)
64
 
65
+ print("plotting...")
66
+ fig, axes = plt.subplots(1, 2, figsize=(15, 5))
67
 
68
+
69
+ axes[0].imshow(pred_prediction, cmap='gray')
70
+ axes[0].set_title("Prediction")
71
 
72
  im = axes[1].imshow(pred_prob)
73
  axes[1].set_title("Probability Map")
74
  cbar = fig.colorbar(im, ax=axes[1])
75
 
 
 
 
76
  for ax in axes:
77
  ax.set_xticks([])
78
  ax.set_yticks([])
run.py CHANGED
@@ -29,17 +29,20 @@ def pred(src):
29
  image = Image.open(src)
30
  rgbim = image.convert("RGB")
31
  new_image = np.array(rgbim)
32
- print("Shape:",new_image.shape)
 
33
 
34
  inputs = processor(new_image, return_tensors="pt")
35
  model.eval()
36
 
37
  # forward pass
 
38
  with torch.no_grad():
39
  outputs = model(pixel_values=inputs["pixel_values"],
40
  multimask_output=False)
41
 
42
  # apply sigmoid
 
43
  pred_prob = torch.sigmoid(outputs.pred_masks.squeeze(1))
44
 
45
  # convert soft mask to hard mask
@@ -47,5 +50,4 @@ def pred(src):
47
  pred_prob = pred_prob.cpu().numpy().squeeze()
48
  pred_prediction = (pred_prob > PROBABILITY_THRES).astype(np.uint8)
49
 
50
- x=1
51
  return pred_prob, pred_prediction
 
29
  image = Image.open(src)
30
  rgbim = image.convert("RGB")
31
  new_image = np.array(rgbim)
32
+ print()
33
+ print("image shape:",new_image.shape)
34
 
35
  inputs = processor(new_image, return_tensors="pt")
36
  model.eval()
37
 
38
  # forward pass
39
+ print("predicting...")
40
  with torch.no_grad():
41
  outputs = model(pixel_values=inputs["pixel_values"],
42
  multimask_output=False)
43
 
44
  # apply sigmoid
45
+ print("apply sigmoid...")
46
  pred_prob = torch.sigmoid(outputs.pred_masks.squeeze(1))
47
 
48
  # convert soft mask to hard mask
 
50
  pred_prob = pred_prob.cpu().numpy().squeeze()
51
  pred_prediction = (pred_prob > PROBABILITY_THRES).astype(np.uint8)
52
 
 
53
  return pred_prob, pred_prediction