Answers.Body: <p>It seems Alex has just used the Matlab function <code>mat2gray</code>, as described here: <a href="https://www.mathworks.com/help/vision/ug/image-category-classification-using-deep-learning.html" rel="nofollow noreferrer">https://www.mathworks.com/help/vision/ug/image-category-classification-using-deep-learning.html</a></p>
  <p>The visual outcome of the features is very similar. <code>mat2gray</code> will simply scale the weights between 0 and 1 (no clipping).</p>
  <p>Leaving the (slightly adapted) example code of Mathworks here for future reference:</p>
  <pre><code>layer1weights = mat2gray(layer1weights) ;
  layer1weights = imresize(layer1weights,5) ; 
  
  figure
  montage(layer1weights)
  title('First convolutional layer weights')
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-04-23T14:37:52.773Z
Answers.LastActivityDate: 2021-04-23T14:37:52.773Z
Answers.UserDisplayName: kapibarasama
Body: <p>I would like to show the RGB features learned in the first layer of a convolutional neural network similarly to this visualization of the same layer's features from AlexNet:</p>
  <p><a href="https://i.sstatic.net/X8Rwz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/X8Rwz.png" alt="AlexNet first layer weights" /></a></p>
  <p>My learned weights are in the range [-1.1,1.1]. When I use <code>imshow</code> in python or <code>imagesc</code> in Matlab, the weight values are clipped to [0,1], leaving only positive weights intact, everything else black (obviously).</p>
  <p>Negative weight values could be informative, so I don't want to clip them. Rescaling the weights to [0,1] works fine for grayscale features, but not for RGB features as it is unclear how negative values of a channel should be visualized. In the above picture 0 furthermore seems to map to the middle of the range (gray).</p>
  <p>How are such RGB features visualized so that they look similarly to above AlexNet visualization?</p>
  <p>(Sorry for the beginner's question.)</p>
  
Tags: <neural-networks><convolutional-neural-networks>
Title: Showing first layer RGB weights similarly to AlexNet
UserDisplayName: kapibarasama
ThreadText: # Showing first layer RGB weights similarly to AlexNet
  
  (Asked by: username_0 on 2021-04-13)
  
  I would like to show the RGB features learned in the first layer of a convolutional neural network similarly to this visualization of the same layer's features from AlexNet:
  
  [![AlexNet first layer weights](https://i.sstatic.net/X8Rwz.png)](https://i.sstatic.net/X8Rwz.png)
  
  My learned weights are in the range [-1.1,1.1]. When I use `imshow` in python or `imagesc` in Matlab, the weight values are clipped to [0,1], leaving only positive weights intact, everything else black (obviously).
  
  Negative weight values could be informative, so I don't want to clip them. Rescaling the weights to [0,1] works fine for grayscale features, but not for RGB features as it is unclear how negative values of a channel should be visualized. In the above picture 0 furthermore seems to map to the middle of the range (gray).
  
  How are such RGB features visualized so that they look similarly to above AlexNet visualization?
  
  (Sorry for the beginner's question.)
  
  **Tags:** neural-networks, convolutional-neural-networks
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2021-04-23. Score: 0
  
  It seems Alex has just used the Matlab function `mat2gray`, as described here: <https://www.mathworks.com/help/vision/ug/image-category-classification-using-deep-learning.html>
  
  The visual outcome of the features is very similar. `mat2gray` will simply scale the weights between 0 and 1 (no clipping).
  
  Leaving the (slightly adapted) example code of Mathworks here for future reference:
  
  ```
  layer1weights = mat2gray(layer1weights) ;
  layer1weights = imresize(layer1weights,5) ; 
  
  figure
  montage(layer1weights)
  title('First convolutional layer weights')
  
  ```
  
  
  ---
  
  