Just follow the example to do the test
test image
Imnum=1; % image number
im=imread(testimds.Files{Imnum});
imshow(im)
imgSize = size(im) %% rgb :L*w*3
imgSize = imgSize(1:2); %got the width and height
show the activations
Investigate features by observing which areas in the convolutional layers activate on an image and comparing with the corresponding areas in the original images. Each layer of a convolutional neural network consists of many 2-D arrays called channels. Pass the image through the network and examine the output activations of the conv1 layer.
net=rcnn.Network
act1 = activations(net,im,'conv');
sz = size(act1)
act1 = reshape(act1,[sz(1) sz(2) 1 sz(3)]);
I = imtile(mat2gray(act1),'GridSize',[8 4]);
imshow(I)
Find the Strongest Activation Channel
You also can try to find interesting channels by programmatically investigating channels with large activations. Find the channel with the largest activation using the max
function, resize, and show the activations.
[maxValue,maxValueIndex] = max(max(max(act1))); act1chMax = act1(:,:,:,maxValueIndex); act1chMax = mat2gray(act1chMax); act1chMax = imresize(act1chMax,imgSize); I = imtile({im,act1chMax}); imshow(I)
Investigate a Deeper Layer
Most convolutional neural networks learn to detect features like color and edges in their first convolutional layer. In deeper convolutional layers, the network learns to detect more complicated features. Later layers build up their features by combining features of earlier layers. Investigate the conv5
layer in the same way as the conv1
layer. Calculate, reshape, and show the activations in a grid.
act5 = activations(net,im,'conv_1');
sz = size(act5);
act5 = reshape(act5,[sz(1) sz(2) 1 sz(3)]);
I = imtile(imresize(mat2gray(act5),[80 390 ]),'GridSize',[8 4]);
imshow(I)