SUST-reynole / USSFC-Net

37 stars 4 forks source link

Heat map issues #3

Open is8xia opened 1 year ago

is8xia commented 1 year ago

hello Thanks for sharing your source code! On my side, I would like to ask you how the heat map in your Figure 7 is realized?

XinzheGeng commented 1 year ago

@is8xia Please refer to this repo: https://github.com/jacobgil/pytorch-grad-cam tutorial: https://jacobgil.github.io/pytorch-gradcam-book/Class%20Activation%20Maps%20for%20Semantic%20Segmentation.html#tutorial-class-activation-maps-for-semantic-segmentation

is8xia commented 1 year ago

@XinzheGeng Thank you for your reply. But there is a problem, in change detection the input image is two, how do you go about getting the heat map via grad_cam? Can you provide an idea or source code?

XinzheGeng commented 1 year ago

@is8xia You can try to modify the code of the network: Merge the bitemporal images into the network, and modify the code of forward() as follow. x1, x2 = torch.unsqueeze(x1[0], dim=0), torch.unsqueeze(x1[1], dim=0)

is8xia commented 1 year ago

@XinzheGeng Thank you, I have achieved it

bobo59 commented 10 months ago

谢谢你,我做到了

你好,请问是否可以分享你完成的代码。

adleess commented 8 months ago

hello When i using grad-cam, there will be an error:' grad can be implicitly created only for scalar outputs', I don't know if you have encountered this problem when using it, and I would like to ask you how to realize the visualization.

is8xia commented 8 months ago

@bobo59 Change the input to the grad source code. Change the input to a splice of two images and separate the spliced images in the network. input_tensor = [torch.unsqueeze(imgA_tensor, dim=0), torch.unsqueeze(imgB_tensor, dim=0)]

is8xia commented 8 months ago

Check if the output of your network is a tensor or a tuple, the output of the network needed for grad_cam should be a single tensor.

你好, 当我使用grad-cam时,会出现错误:'grad can beimplicitly create only for scalaroutputs',不知道你在使用的时候是否遇到过这个问题,想请教一下你如何解决实现可视化。

adleess commented 8 months ago

Check if the output of your network is a tensor or a tuple, the output of the network needed for grad_cam should be a single tensor.

你好, 当我使用grad-cam时,会出现错误:'grad can beimplicitly create only for scalaroutputs',不知道你在使用的时候是否遇到过这个问题,想请教一下你如何解决实现可视化。

Thank you for your help, I've solved the problem

henuJackSon commented 1 week ago

@bobo59 Change the input to the grad source code. Change the input to a splice of two images and separate the spliced images in the network. input_tensor = [torch.unsqueeze(imgA_tensor, dim=0), torch.unsqueeze(imgB_tensor, dim=0)]

Hello, I added this line of code to Grad-Cam according to your method, and changed the forward in the network structure from (x1,x2) to (MyList), but it still gave an error and couldn't get the heat map. For example, in 'input_tensor = input_tensor.cuda()', 'AttributeError: 'list' object has no attribute 'to''. Can you share your code and solution? Looking forward to your reply

henuJackSon commented 1 week ago

An exception occurred in CAM with block: <class 'IndexError'>. Message: index 1 is out of bounds for dimension 0 with size 1

@is8xia You can try to modify the code of the network: Merge the bitemporal images into the network, and modify the code of forward() as follow. x1, x2 = torch.unsqueeze(x1[0], dim=0), torch.unsqueeze(x1[1], dim=0)

How do you store x1, x2, and convert the two variables in the forward function into one variable for input? I tried to store two images in a list and kept getting errors. AttributeError: 'list' object has no attribute 'to' Looking forward to your reply

code: list1 = [] list1.append(img1) list1.append(img2)

model: def forward(self,list1): x1,x2=list1[0],list[1]

Grad-CAM: grayscale_cam = cam(input_tensor=input_tensor, targets=targets)[0, :] print("代码运行到了cam之后") cam_image = show_cam_on_image(rgb_img1, grayscale_cam, use_rgb=True)