- ‘activations’: www.mathworks.com/help/deeplearning/ref/seriesnetwork.activations.html
- 'minibatchpredict’: www.mathworks.com/help/deeplearning/ref/minibatchpredict.html
How to view the output of each and every hidden layer in a deep neural network
17 次查看(过去 30 天)
显示 更早的评论
I am using deep neural network with 10 hidden layers and I want to view the output of each and every hidden layer.
When I execute the model I can see only the final result but I am unable to see the output of each and every hidden layer.
could anyone help me to view the output of each hidden layer.
0 个评论
回答(1 个)
Shantanu Dixit
2024-7-17
Hi Prabha,
It is my understanding that you want to view the output of each and every hidden layer in the deep neural network. To view the output at every layer you can use ‘activations’ or ‘minibatchpredict’.
‘activations’ takes in three input arguments namely network (‘SeriesNetwork’), image, layername or number.
net = alexnet; % 'SeriesNetwork'
I = imread('peppers.png'); % Read the image
I = imresize(I, [227 227]);
plot(net)
actLayerPool1 = activations(net,I,"pool1"); %% output corresponding to pool1
disp(size(actLayerPool1));
actLayerConv1 = activations(net,I,"conv1"); %% output corresponding to layer 2 or conv1
disp(size(actLayerConv1));
Alternatively one can obtain the intermediate output maps using ‘minibatchpredict’. Here the network should be initialised be as a ‘dlnetwork’ and the input should include batch dimension (‘SSCB’)
% Define the layers of the network
layers = [
imageInputLayer([28 28 1], Normalization="none", Name="input")
convolution2dLayer(3, 8, Padding="same", Name="conv_1")
reluLayer(Name="relu_1")
fullyConnectedLayer(10, Name="fc")
softmaxLayer(Name="softmax")
];
net = dlnetwork(layers); %% dlnetwork
disp(net);
sampleInput = rand(28, 28, 1);
dlSampleInput = dlarray(sampleInput, 'SSCB');
activations_conv_layer = minibatchpredict(net,dlSampleInput,Outputs="conv_1"); %% corresponding to conv_1
activations_fc = minibatchpredict(net,dlSampleInput,Outputs="fc"); %% corresponding to fully connected layer
Refer to the following MathWorks documentation for better understanding
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!