Explanation Alexnet in deep learning ?
3 次查看(过去 30 天)
显示 更早的评论
i need someone to explain me the following question:
this is a part of my code, my question is:
1. coluld you please write some explanation comment only for the following part of code only for (emoveLayers ,inputLayer, replaceLayer , addLayers and connectLayers.
2. i think this code is the same work when we modify AlexNet in (deepNetworkDesigner) am i right or not? or is there any different between 2 ways (manually/deepNetworkDesigner and coding) as below code?
lgraph = layerGraph(net.Layers);
lgraph = removeLayers(lgraph, 'fc8'); %please comment here for explanation ???
lgraph = removeLayers(lgraph, 'prob');
lgraph = removeLayers(lgraph, 'output');
% create and add layers
inputLayer = imageInputLayer([imageSize 1], 'Name', net.Layers(1).Name,... %please comment here
'DataAugmentation', net.Layers(1).DataAugmentation, ...
'Normalization', net.Layers(1).Normalization);
lgraph = replaceLayer(lgraph,net.Layers(1).Name,inputLayer);
newConv1_Weights = net.Layers(2).Weights;
newConv1_Weights = mean(newConv1_Weights(:,:,1:3,:), 3); % taking the mean of kernal channels
newConv1 = convolution2dLayer(net.Layers(2).FilterSize(1), net.Layers(2).NumFilters,...
'Name', net.Layers(2).Name,...
'NumChannels', inputLayer.InputSize(3),...
'Stride', net.Layers(2).Stride,...
'DilationFactor', net.Layers(2).DilationFactor,...
'Padding', net.Layers(2).PaddingSize,...
'Weights', newConv1_Weights,...BiasLearnRateFactor
'Bias', net.Layers(2).Bias,...
'BiasLearnRateFactor', net.Layers(2).BiasLearnRateFactor);
lgraph = replaceLayer(lgraph,net.Layers(2).Name,newConv1); %please comment here for explanation ?
lgraph = addLayers(lgraph, fullyConnectedLayer(numClasses,'Name', 'fc2'));
lgraph = addLayers(lgraph, softmaxLayer('Name', 'softmax'));%please comment here for explanation ?
lgraph = addLayers(lgraph, classificationLayer('Name','output'));
lgraph = connectLayers(lgraph, 'drop7', 'fc2');%please comment here for explanation ???
lgraph = connectLayers(lgraph, 'fc2', 'softmax');
lgraph = connectLayers(lgraph, 'softmax', 'output');
% -------------------------------------------------------------------------
0 个评论
采纳的回答
Mohammad Sami
2020-9-7
This code is for transfer learning. That is when you already have a pretrained model that you wish to use for another purpose. The process is explained in detail in MATLAB's documentation.
Using Deep Network Designer:
Usign Manual Method:
Since the network was trained with different classes then your current purpose, you have to remove the final few layers at least from the last fully connected layer onwards. This is because the final fully connected layer needs to have the same output size as the number of classess in your data.
You then have to have to create new layers for the layers that you removed. The new fully connected layer has the output size which matches the number of classes in your data. Finally you can add these newly connected layers to complete your network.
3 个评论
Mohammad Sami
2020-10-2
Deep network designer is a convenient app to help you design / edit a network. Once you have edited to your satisfaction you can export it as code. You can always do the same directly in code.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!