Error using activations functions in matlab

10 visualizaciones (últimos 30 días)
Teo
Teo el 22 de Mzo. de 2022
Editada: Teo el 24 de Mzo. de 2022
Hi,
I trying to replace the pre-trained CNN fully connected layer with mine 'new_fc'.
imds = imageDatastore('MerchData', 'IncludeSubfolders',true, 'LabelSource','foldernames');
[imdsTrain,imdsValidation] = splitEachLabel(imds,0.7);
testnet = resnet18
inputSize = testnet.Layers(1).InputSize
augimdsTrain = augmentedImageDatastore(inputSize(1:2),imdsTrain)
augimdsValidation = augmentedImageDatastore(inputSize(1:2),imdsValidation)
if isa(learnableLayer,'nnet.cnn.layer.FullyConnectedLayer')
newLearnableLayer = fullyConnectedLayer(7, ...
'Name','new_fc', ...
'WeightLearnRateFactor',10, ...
'BiasLearnRateFactor',10);
elseif isa(learnableLayer,'nnet.cnn.layer.Convolution2DLayer')
newLearnableLayer = convolution2dLayer(1,7, ...
'Name','new_conv', ...
'WeightLearnRateFactor',10, ...
'BiasLearnRateFactor',10);
end
lgraph = replaceLayer(lgraph,learnableLayer.Name,newLearnableLayer)
newClassLayer = classificationLayer('Name','new_classoutput')
lgraph = replaceLayer(lgraph,classLayer.Name,newClassLayer)
layer = 'new_fc';
activations(lgraph,augimdsTrain,layer,'OutputAs','rows')
The error message that i got is as below.
"check for incorrect argument data type or missing argument in call to function 'activations'.
Hope someone could help on this. Thank you in advance.

Respuesta aceptada

yanqi liu
yanqi liu el 23 de Mzo. de 2022
yes,sir,if modify net structure,may be need retrain it,then use activations to get feature
so,may be use
featuresTrain = activations(testnet,augimdsTrain,'fc1000','OutputAs','rows')
  2 comentarios
Teo
Teo el 23 de Mzo. de 2022
Thanks for the reply. May i comfirm with you again that i need to retrain it first using "trainNetwork" function then only use the following code?
featuresTrain = activations(lgraph,augimdsTrain,layer,'OutputAs','rows')
or i can directly use the followig code without retrain it as you already provide the solution as followed?
featuresTrain = activations(lgraph,augimdsTrain,'new_fc','OutputAs','rows')
Hope you are able to help on this?
Thank you
Teo
Teo el 23 de Mzo. de 2022
i managed to solve the problem. Thank you for your help.

Iniciar sesión para comentar.

Más respuestas (0)

Productos


Versión

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by