jw2yang commited on
Commit
bc3a9b9
1 Parent(s): db1ed1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -59,8 +59,8 @@ def show_cam_on_image(img: np.ndarray,
59
  raise Exception(
60
  "The input image should np.float32 in the range [0, 1]")
61
 
62
- # cam = 0.7*heatmap + 0.3*img
63
- cam = heatmap
64
  # cam = cam / np.max(cam)
65
  return np.uint8(255 * cam)
66
 
@@ -73,19 +73,19 @@ def classify_image(inp):
73
  prediction = model(img_t.unsqueeze(0)).softmax(-1).flatten()
74
 
75
  modulator = model.layers[0].blocks[11].modulation.modulator.norm(2, 1, keepdim=True)
76
- # modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
77
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
78
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
79
  cam0 = show_cam_on_image(img_d, modulator, use_rgb=True)
80
 
81
  modulator = model.layers[0].blocks[8].modulation.modulator.norm(2, 1, keepdim=True)
82
- # modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
83
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
84
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
85
  cam1 = show_cam_on_image(img_d, modulator, use_rgb=True)
86
 
87
  modulator = model.layers[0].blocks[5].modulation.modulator.norm(2, 1, keepdim=True)
88
- # modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
89
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
90
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
91
  cam2 = show_cam_on_image(img_d, modulator, use_rgb=True)
 
59
  raise Exception(
60
  "The input image should np.float32 in the range [0, 1]")
61
 
62
+ cam = 0.7*heatmap + 0.3*img
63
+ # cam = heatmap
64
  # cam = cam / np.max(cam)
65
  return np.uint8(255 * cam)
66
 
 
73
  prediction = model(img_t.unsqueeze(0)).softmax(-1).flatten()
74
 
75
  modulator = model.layers[0].blocks[11].modulation.modulator.norm(2, 1, keepdim=True)
76
+ modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
77
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
78
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
79
  cam0 = show_cam_on_image(img_d, modulator, use_rgb=True)
80
 
81
  modulator = model.layers[0].blocks[8].modulation.modulator.norm(2, 1, keepdim=True)
82
+ modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
83
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
84
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
85
  cam1 = show_cam_on_image(img_d, modulator, use_rgb=True)
86
 
87
  modulator = model.layers[0].blocks[5].modulation.modulator.norm(2, 1, keepdim=True)
88
+ modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
89
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
90
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
91
  cam2 = show_cam_on_image(img_d, modulator, use_rgb=True)