dyzy41 / ChangeCLIP

Apache License 2.0
74 stars 1 forks source link

Heat map visualization of ChangeCLIP #16

Open edwd38165 opened 2 months ago

edwd38165 commented 2 months ago

I noticed that in section 4.8 of the paper you mentioned Heat map visualization of change regions, but I didn't find a way to implement this in the code you provided, can you remind me how to implement this method? Thank you!

dyzy41 commented 2 months ago
def vis_features(self, xCat, x, img_metas):
    save_path = '/home/user/dsj_code/ChangeCLIP/feature_viswhucd0516'
    imgA_path = img_metas[0]['filenameA']
    imgB_path = img_metas[0]['filenameB']
    name = os.path.basename(imgA_path).split('.')[0]

    for i in range(4):
        cat = xCat[i]
        diff = x[i]

        cat = F.interpolate(cat, (256, 256), mode='bilinear', align_corners=True)
        catvis = torch.mean(cat, dim=1)
        catvis = catvis[0].detach().cpu()
        ax = sns.heatmap(catvis, cmap='jet')
        plt.savefig(os.path.join(save_path, 'cat/{}_{}.png'.format(name, i)))
        plt.cla()
        plt.clf()

        diff = F.interpolate(diff, (256, 256), mode='bilinear', align_corners=True)
        diffvis = torch.mean(diff, dim=1)
        diffvis = diffvis[0].detach().cpu()
        ax = sns.heatmap(diffvis, cmap='jet')
        plt.savefig(os.path.join(save_path, 'diff/{}_{}.png'.format(name, i)))
        plt.cla()
        plt.clf()
edwd38165 commented 2 months ago

Thank you for your quick response! but which specific code position should I put it in to make it work properly? Can you provide more hints?

dyzy41 commented 2 months ago

This is for visualizing the general feature maps, and it can be used wherever you need to visualize feature maps. You can read through the code to confirm what parameters should be input. When performing feature map visualization, it should be done during the testing phase, and you need to ensure that model.eval() is called.

edwd38165 commented 2 months ago

Ok, thank you very much for your reply!

This is for visualizing the general feature maps, and it can be used wherever you need to visualize feature maps. You can read through the code to confirm what parameters should be input. When performing feature map visualization, it should be done during the testing phase, and you need to ensure that model.eval() is called.