Unrecognized function or variable ‘invertResidualLayer’

Technical Source
2 min readMar 23, 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?

NOTE:-

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

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:

  • Import the ‘net’ in the Network Designer Application and export the ‘lgraph’ after replacing last 3 layers with your desired layer.
  • 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.

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet