haoyuc / A2N

PyTorch code for our paper "Attention in Attention Network for Image Super-Resolution"
85 stars 18 forks source link

Code for heatmap in figure2 #3

Open ximu1211 opened 3 years ago

ximu1211 commented 3 years ago

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

haoyuc commented 3 years ago

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')
ximu1211 commented 3 years ago

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

ximu1211 commented 3 years ago

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 commented 3 years ago

Can the visualization code of feature map be published?

haoyuc commented 3 years ago

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 commented 3 years ago

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

haoyuc commented 3 years ago

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