How to draw attention weight in ROIGather
Thanks for your work, can you please tell me how to draw figure 5 in the paper. How to draw attention weight on the original figure ? I would appreciate it if you could respond in a timely manner.
I tried to implement an attention visualization function myself, but it didn't seem to be effective. Did you solve it?
I tried to implement an attention visualization function myself, but it didn't seem to be effective. Did you solve it?
Then I tried adjusting the code again, and now it seems to work better. You can add code starting from line 221, /libs/models/layers/attentions.py:(please ignore my code quality)
# add 'layer_index' parameter passing on line 148
if layer_index == 2:
import numpy as np
from torchvision import transforms
import cv2
B, Np = sim_map.shape[:2]
# cancel the code 'x=F.interpolate(x,self.size)' on line 262
att_map = sim_map.reshape(B, Np, 40, 100).mean(dim=1).unsqueeze(1)
max_val = att_map.reshape(B, 1, -1).max(dim=-1).values
min_val = att_map.reshape(B, 1, -1).min(dim=-1).values
att_map = torch.div(att_map - min_val, max_val - min_val)
trans = transforms.Resize([540, 960])
att_map = trans(att_map).squeeze(0).permute(1,2,0) * 255
att_map = np.uint8(np.array(att_map.cpu()))
att_map = cv2.applyColorMap(att_map, cv2.COLORMAP_JET)
cv2.imwrite('attention_map.png', att_map)
import pdb; pdb.set_trace()
I tried to implement an attention visualization function myself, but it didn't seem to be effective. Did you solve it?
Then I tried adjusting the code again, and now it seems to work better. You can add code starting from line 221, /libs/models/layers/attentions.py:(please ignore my code quality)
# add 'layer_index' parameter passing on line 148 if layer_index == 2: import numpy as np from torchvision import transforms import cv2 B, Np = sim_map.shape[:2] # cancel the code 'x=F.interpolate(x,self.size)' on line 262 att_map = sim_map.reshape(B, Np, 40, 100).mean(dim=1).unsqueeze(1) max_val = att_map.reshape(B, 1, -1).max(dim=-1).values min_val = att_map.reshape(B, 1, -1).min(dim=-1).values att_map = torch.div(att_map - min_val, max_val - min_val) trans = transforms.Resize([540, 960]) att_map = trans(att_map).squeeze(0).permute(1,2,0) * 255 att_map = np.uint8(np.array(att_map.cpu())) att_map = cv2.applyColorMap(att_map, cv2.COLORMAP_JET) cv2.imwrite('attention_map.png', att_map) import pdb; pdb.set_trace()
Can you tell me more details? I would be very grateful.Extremely urgent. My contact information is [email protected].
I tried to implement an attention visualization function myself, but it didn't seem to be effective. Did you solve it?
Then I tried adjusting the code again, and now it seems to work better. You can add code starting from line 221, /libs/models/layers/attentions.py:(please ignore my code quality)
# add 'layer_index' parameter passing on line 148 if layer_index == 2: import numpy as np from torchvision import transforms import cv2 B, Np = sim_map.shape[:2] # cancel the code 'x=F.interpolate(x,self.size)' on line 262 att_map = sim_map.reshape(B, Np, 40, 100).mean(dim=1).unsqueeze(1) max_val = att_map.reshape(B, 1, -1).max(dim=-1).values min_val = att_map.reshape(B, 1, -1).min(dim=-1).values att_map = torch.div(att_map - min_val, max_val - min_val) trans = transforms.Resize([540, 960]) att_map = trans(att_map).squeeze(0).permute(1,2,0) * 255 att_map = np.uint8(np.array(att_map.cpu())) att_map = cv2.applyColorMap(att_map, cv2.COLORMAP_JET) cv2.imwrite('attention_map.png', att_map) import pdb; pdb.set_trace()Can you tell me more details? I would be very grateful.Extremely urgent. My contact information is [email protected].
That is all the details.