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

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.)


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) ; 

title('First convolutional layer weights')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.