Unrecognized function or variable 'invertResidualLayer'

조회 수: 1 (최근 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 CenterFile Exchange에서 Image Data Workflows에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by