Unrecognized function or variable 'invertResidualLayer'

4 ビュー (過去 30 日間)
NoYeah
NoYeah 2023 年 3 月 17 日
コメント済み: NoYeah 2023 年 3 月 20 日
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?

採用された回答

Pratham Shah
Pratham Shah 2023 年 3 月 17 日
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 件のコメント
NoYeah
NoYeah 2023 年 3 月 20 日
this helped me a lot but I won`t use MATLAB for deep learning

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDeep Learning Toolbox についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by