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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -59,7 +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 = cam / np.max(cam)
64
  return np.uint8(255 * cam)
65
 
@@ -75,25 +76,25 @@ def classify_image(inp):
75
  # modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
76
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
77
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
78
- cam0 = np.uint8(255 * modulator) # show_cam_on_image(img_d, modulator, use_rgb=True)
79
 
80
  modulator = model.layers[0].blocks[8].modulation.modulator.norm(2, 1, keepdim=True)
81
  # modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
82
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
83
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
84
- cam1 = np.uint8(255 * modulator) # show_cam_on_image(img_d, modulator, use_rgb=True)
85
 
86
  modulator = model.layers[0].blocks[5].modulation.modulator.norm(2, 1, keepdim=True)
87
  # modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
88
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
89
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
90
- cam2 = np.uint8(255 * modulator) # show_cam_on_image(img_d, modulator, use_rgb=True)
91
 
92
  modulator = model.layers[0].blocks[2].modulation.modulator.norm(2, 1, keepdim=True)
93
  # modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
94
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
95
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
96
- cam3 = np.uint8(255 * modulator) # show_cam_on_image(img_d, modulator, use_rgb=True)
97
 
98
  return {labels[i]: float(prediction[i]) for i in range(1000)}, Image.fromarray(cam0), Image.fromarray(cam1), Image.fromarray(cam2), Image.fromarray(cam3)
99
 
 
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
 
 
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)
92
 
93
  modulator = model.layers[0].blocks[2].modulation.modulator.norm(2, 1, keepdim=True)
94
  # modulator = nn.Upsample(size=img_t.shape[1:], mode='bilinear')(modulator)
95
  modulator = modulator.squeeze(1).detach().permute(1, 2, 0).numpy()
96
  modulator = (modulator - modulator.min()) / (modulator.max() - modulator.min())
97
+ cam3 = show_cam_on_image(img_d, modulator, use_rgb=True)
98
 
99
  return {labels[i]: float(prediction[i]) for i in range(1000)}, Image.fromarray(cam0), Image.fromarray(cam1), Image.fromarray(cam2), Image.fromarray(cam3)
100