Generating coloured feature maps

WeiQin-C: <p>Hi all,</p>
<p>May I ask for help in regards to how to extract and plot heatmaps for features like the one shown in the image included in this post?</p>
<p>Thank you <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/3X/e/b/ebbe9a5f40d81bef6e58c2ae19c0bf5571e8863f.jpeg" data-download-href="https://discuss.pytorch.org/uploads/default/ebbe9a5f40d81bef6e58c2ae19c0bf5571e8863f" title="image"><img src="https://discuss.pytorch.org/uploads/default/optimized/3X/e/b/ebbe9a5f40d81bef6e58c2ae19c0bf5571e8863f_2_690x261.jpeg" alt="image" data-base62-sha1="xDuznw1mwLMQykKIGBbLelBRdkH" width="690" height="261" srcset="https://discuss.pytorch.org/uploads/default/optimized/3X/e/b/ebbe9a5f40d81bef6e58c2ae19c0bf5571e8863f_2_690x261.jpeg, https://discuss.pytorch.org/uploads/default/original/3X/e/b/ebbe9a5f40d81bef6e58c2ae19c0bf5571e8863f.jpeg 1.5x, https://discuss.pytorch.org/uploads/default/original/3X/e/b/ebbe9a5f40d81bef6e58c2ae19c0bf5571e8863f.jpeg 2x" data-dominant-color="9BB2B9"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">image</span><span class="informations">968×367 119 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>

nitaifingerhut: <p>convert your tensor to Numpy first using .detach().cpu().numpy()</p>
<p>And use matplotlib imshow with cmap argument. I think in the case you sent it’s cmap=‘jet’</p>

WeiQin-C: <p><a class="mention" href="/u/nitaifingerhut">@nitaifingerhut</a> Hi Thanks for your reply. Do you know if any pre-processing step is usually applied to these features before plotting them? In many research papers, I only see them visualising one feature map where in practice we often have few hundred (32, 64, 128 or even 256) of these features in one layer.</p>

nitaifingerhut: <p>well it depends on what you want to plot…<br>
I think you are referring to papers which visualize the network learnable parameters, and the plots aims to make sense in what your model is learning.<br>
In other cases you may only plot the model’s output to understand how it is doing in relate to ground truth / whatever you are trying it will learn.</p>

WeiQin-C: <p>I am trying to understand like what exactly the network is “seeing” when it is predicting a car or a sky, etc…</p>

AlperEkmekci: <p>You are searching for <code>saliency map</code> which is the color map image that involves most feature when the prediction is happening.</p>
<p>You can refer this <a href="https://github.com/utkuozbulak/pytorch-cnn-visualizations" rel="noopener nofollow ugc">link</a> for these.</p>

nitaifingerhut: <p>you need to provide a wider context of your data, model and objective and explain exactly what you want to see<br>
nevertheless, the way to plot tensors is as I mentioned, by converting to numpy and plotting it</p>

WeiQin-C: <p>Thank you for the suggestion! I will look into it <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>

WeiQin-C: <p>I am working on a stereo matching network and I want to visualise the differences in features extracted in different network architectures. I am hoping by visualising these features from different networks will help me to understand the pros and cons provided by each network.</p>
<p>I hope this make sense <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=9" title=":slight_smile:" class="emoji" alt=":slight_smile:"></p>