show the feature of CNN model(continual )

ref:https://www.mathworks.com/help/deeplearning/examples/visualize-activations-of-a-convolutional-neural-network.html

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)

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

做一个码农都是奢望

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值