Explanation Alexnet in deep learning ?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
shivan artosh
le 6 Sep 2020
Commenté : shivan artosh
le 2 Oct 2020
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 commentaires
Réponse acceptée
Mohammad Sami
le 7 Sep 2020
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 commentaires
Mohammad Sami
le 2 Oct 2020
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Data Workflows dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!