Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code for heatmap in figure2 #3

Open
ximu1211 opened this issue May 18, 2021 · 7 comments
Open

Code for heatmap in figure2 #3

ximu1211 opened this issue May 18, 2021 · 7 comments

Comments

@ximu1211
Copy link

This type of heatmap has rarely been seen before. If possible, is there a code?

@haoyuc
Copy link
Owner

haoyuc commented Jun 3, 2021

For the heatmap, we first average a feature map in the channel dimension and then visualize it.

For example,

feature = torch.mean(feature,1)[0,:,:]

The "0" in [0,:,:] means we use the first image of a batch.

Then we can just use matplotlib to visualize it:

plt.matshow(feature)
plt.axis('off')

@haoyuc haoyuc closed this as completed Jun 17, 2021
@ximu1211
Copy link
Author

For the heatmap, we first average a feature map in the channel dimension and then visualize it.

For example,

feature = torch.mean(feature,1)[0,:,:]

The "0" in [0,:,:] means we use the first image of a batch.

Then we can just use matplotlib to visualize it:

plt.matshow(feature)
plt.axis('off')

Can the heatmap in the paper be realized in this way?
Usually this way is achieved as shown in the figure below.
image
I prefer to produce this result:
image

@haoyuc haoyuc reopened this Jun 17, 2021
@ximu1211
Copy link
Author

By using the above code, most of the generated is similar to the The third row.
image
I don’t know which module to add to the heat map can generate the first row or second row of results.

In addition, it seems that the picture is cropped into several blocks during the running of the program. Where is this part of the code? Can it be cropped?

@yuwei66
Copy link

yuwei66 commented Jul 9, 2021

Can the visualization code of feature map be published?

@haoyuc
Copy link
Owner

haoyuc commented Jul 11, 2021

As mentioned in the paper:

The white area in the feature map indicates zero values, the red area indicates positive values, and the blue area indicates negative values.

You can try this:

# feature [h, w]
max_ = float(feature.max())   # > 0
min_ = float(feature.min())   # < 0

# make white color represent 0 value
m = -max(abs(max_), abs(min_))
feature[0,0] = m

plt.matshow(feature, interpolation='nearest', cmap='seismic')
plt.colorbar()

@q760019473 @ximu1211

@nanmehta
Copy link

thnks sir! have 1 doubt, can you please let me know that why the feature maps are of green color.

@haoyuc
Copy link
Owner

haoyuc commented Jul 17, 2021

Because the default setting of plt.matshow is green, you can change the color by setting cmap=, like plt.matshow(feature, cmap='seismic') @nan-rock

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants