Unrecognized function or variable 'invertResidualLayer'

1 vue (au cours des 30 derniers jours)
NoYeah
NoYeah le 17 Mar 2023
Commenté : NoYeah le 20 Mar 2023
I have installed add-on
'Deep Learning Toolbox' and 'Deep Learning Toolbox model for mobilenetv2'
and used the below code
net = mobilenetv2; % Load pretrained MobileNet model
numClasses = numel(classNames);
layers = [
net.Layers(1:end-3)
fullyConnectedLayer(numClasses,'Name','fc')
softmaxLayer('Name','softmax')
classificationLayer('Name','classoutput')];
options = trainingOptions('adam', ...
'MaxEpochs',10, ...
'MiniBatchSize',32, ...
'ValidationData',imdsValidation, ...
'ValidationFrequency',5, ...
'InitialLearnRate',1e-4, ...
'LearnRateSchedule','piecewise', ...
'LearnRateDropFactor',0.1, ...
'LearnRateDropPeriod',5, ...
'L2Regularization',0.01, ...
'Plots','training-progress');
% Train the network
net = trainNetwork(imdsTrain,layers,options);
and I got the error message below
Error using trainNetwork
invalid network.
caused by:
Layer 'block_11_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_12_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_14_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_15_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_2_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_4_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_5_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_7_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_8_add' Unconnected input. Each layer input must be connected to the output of
another layer.
Layer 'block_9_add' Unconnected input. Each layer input must be connected to the output of
another layer.
I don`t know why this error happens...
maybe using pretrained model intrigue error depends on the data?
How to solve this error?

Réponse acceptée

Pratham Shah
Pratham Shah le 17 Mar 2023
Hi,
I have struggled with this issue a lot and I know the reason behind it.
The problem is while you are calling 'net.Layers(1:end-3)' it will only have information of layers, not the connections and the problem is occuring in addition layer as it requires 2 inputs but the layer graph is skipping one connection in net.Layer.
I don't have any permenent solution to that but you can try 2 things:
  1. Import the 'net' in the Network Designer Application and export the 'lgraph' after replacing last 3 layers with your desired layer.
  2. You can use 'connectLayer' manually for all the unconnected layers like this,
lgraph = layerGraph(layers);
lgraph = connectLayers(lgraph,'input','add/in2');
but this process will take lot of time.
But by looking at you code I think you can just use the 'replaceLayer' in last layer(to match the number of classes) because mobilenetv2 already have fc and softmax function.
P.S. : Hope this helps :)
  1 commentaire
NoYeah
NoYeah le 20 Mar 2023
this helped me a lot but I won`t use MATLAB for deep learning

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Image Data Workflows dans Help Center et File Exchange

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by