I want to go deep to see the feature of the trained model rcnn ,which was transfered from cifar10net
test to visualize the feature of CNN
rcnn.Network.Layers
ans = 15x1 Layer array with layers: 1 'imageinput' Image Input 32x32x3 images with 'zerocenter' normalization 2 'conv' Convolution 32 5x5x3 convolutions with stride [1 1] and padding [2 2 2 2] 3 'relu' ReLU ReLU 4 'maxpool' Max Pooling 3x3 max pooling with stride [2 2] and padding [0 0 0 0] 5 'conv_1' Convolution 32 5x5x32 convolutions with stride [1 1] and padding [2 2 2 2] 6 'relu_1' ReLU ReLU 7 'maxpool_1' Max Pooling 3x3 max pooling with stride [2 2] and padding [0 0 0 0] 8 'conv_2' Convolution 64 5x5x32 convolutions with stride [1 1] and padding [2 2 2 2] 9 'relu_2' ReLU ReLU 10 'maxpool_2' Max Pooling 3x3 max pooling with stride [2 2] and padding [0 0 0 0] 11 'fc' Fully Connected 64 fully connected layer 12 'relu_3' ReLU ReLU 13 'rcnnFC' Fully Connected 2 fully connected layer 14 'rcnnSoftmax' Softmax softmax 15 'rcnnClassification' Classification Output crossentropyex with classes 'rebar' and 'Background'
corresponding function to see the feature
% I = deepDreamImage(net,layer,channels)
% I = deepDreamImage(net,layer,channels,Name,Value)
% Set layer to be the first convolutional layer. This layer is the second layer in the network and is named 'conv '.
layerN=2;
name=rcnn.Network.Layers(layerN).Name
%% Visualize the first 32 features learned by this layer using deepDreamImage by setting channels to be the vector of indices 1:56. Set 'PyramidLevels' to 1 so that the images are not scaled. To display the images together, you can use imtile.
%% deepDreamImage uses a compatible GPU, by default, if available. Otherwise it uses the CPU. A CUDA® enabled NVIDIA® GPU with compute capability 3.0 or higher is required for training on a GPU.
channels = 1:rcnn.Network.Layers(2, 1).NumFilters;
I = deepDreamImage(rcnn.Network,layerN,channels,'PyramidLevels',1);
|==============================================| | Iteration | Activation | Pyramid Level | | | Strength | | |==============================================| | 1 | 18.01 | 1 | | 2 | 11.76 | 1 | | 3 | 5.50 | 1 | | 4 | 0.75 | 1 | | 5 | 7.00 | 1 | | 6 | 13.26 | 1 | | 7 | 19.51 | 1 | | 8 | 25.77 | 1 | | 9 | 32.02 | 1 | | 10 | 38.27 | 1 | |==============================================|
figure
I = imtile(I,'ThumbnailSize',[64 64]);
imshow(I)
title(['Layer ',name,' Features'])
These images mostly contain edges and colors, which indicates that the filters at layer 'conv1'
are edge detectors and color filters. The edge detectors are at different angles, which allows the network to construct more complex features in the later layers. howver, I can't understand from the above figure.
I = imtile(I,'ThumbnailSize',[64 64],'GridSize', [4 8]);
layerN=5;
name=rcnn.Network.Layers(layerN).Name
I = deepDreamImage(rcnn.Network,layerN,channels,'PyramidLevels',1);
figure
I = imtile(I,'ThumbnailSize',[64 64],'GridSize', [4 8]);
% I = imtile(I,'GridSize', [4 8]); % if you don't specify the ThumbnaiSize,
% the image will be very small
imshow(I)
title(['Layer ',name,' Features'])
|==============================================| | Iteration | Activation | Pyramid Level | | | Strength | | |==============================================| | 1 | 33.87 | 1 | | 2 | 32.53 | 1 | | 3 | 31.35 | 1 | | 4 | 30.27 | 1 | | 5 | 29.08 | 1 | | 6 | 27.90 | 1 | | 7 | 26.71 | 1 | | 8 | 25.51 | 1 | | 9 | 24.32 | 1 | | 10 | 23.12 | 1 | |==============================================|
%% show all the conv layer
all the conv layer
layers = [2 5 8];
channels = 1:32;
for layer = layers
I = deepDreamImage(rcnn.Network,layer,channels, ...
'Verbose',false, ...
'PyramidLevels',1);
figure
I = imtile(I,'ThumbnailSize',[128 128],'GridSize', [4 8]);
imshow(I)
name = rcnn.Network.Layers(layer).Name;
title(['Layer ',name,' Features'])
end
Visualize Fully Connected Layers
layers = [11 13];
channels = 1:2;
for layer = layers
% channels=rcnn.Network.Layers(layers).OutputSize
if layer==11
channels=3;
else
channels=2;
end
I = deepDreamImage(rcnn.Network,layer,channels, ...
'Verbose',false, ...
'NumIterations',50);
figure
I = imtile(I,'ThumbnailSize',[128 128]);
imshow(I)
name = rcnn.Network.Layers(layer).Name;
title(['Layer ',name,' Features'])
end
%% The classes are stored in the Classes property of the output layer (the last layer). You can view the names of the selected classes by selecting the entries in channels.
layer = 15;
channels = [1];
rcnn.Network.Layers(end).Classes(channels)
ans =
categorical
rebar
layer = 14;
channels = [1];
rcnn.Network.Layers(end).Classes(channels)
I = deepDreamImage(rcnn.Network,layer,channels,...
'Verbose',false, ...
'NumIterations',50,...
'PyramidLevels',1);
figure
I = imtile(I,'ThumbnailSize',[128 128]);
imshow(I)
name = rcnn.Network.Layers(layer).Name;
title(['Layer ',name,' Features'])
ans = categorical rebar
I can view the feautre from layer 2 to 14, but I don't know how many channels are in the specifi layer?