Errors in transfer learning using resnet101

I would like to use resnet101 to do transfer learning.
When I build the network and use the trainNetwork function as shown below, I get the following error. What is the cause?
Layer 'res2a': unconnected input. The input of each layer must be coupled with the output of another layer.
An unconnected input was detected:
net = resnet101;
layers = net.Layers;
layers = [
layers(1:344)
fullyConnectedLayer(Numberofclasses)
layers(346)
classificationLayer];
options = trainingOptions('sgdm',...
'MiniBatchSize',16,...
'InitialLearnRate', 0.0001, ...
...)
trainNetwork(TrainImage,TrainData,layers,options);

 Respuesta aceptada

Akira Agata
Akira Agata el 18 de Mzo. de 2021
Since ResNet-101 is imported as a DAGNetwork object, the following steps will be needed (more details can be found in this Link)
  1. Convert DAGNetwork object to LayerGraph object
  2. Replace the last few layers
  3. Freeze bias/weight of initial layers (optional)
  4. Re-connect all the layers in the original order by using the support function createLgraphUsingConnections
So the MATLAB code will be like this.
net = resnet101;
% 1. Convert DAGNetwork object to LayerGraph object
lgraph = layerGraph(net);
% 2. Replace the last few layers
lgraph = replaceLayer(lgraph,'fc1000',...
fullyConnectedLayer(Numberofclasses,'Name','fcNew'));
lgraph = replaceLayer(lgraph,'ClassificationLayer_predictions',...
classificationLayer('Name','ClassificationNew'));
% 4. Re-connect all the layers in the original order
% by using the support function createLgraphUsingConnections
layers = lgraph.Layers;
connections = lgraph.Connections;
lgraph = createLgraphUsingConnections(layers,connections);
% Train the network
options = trainingOptions('sgdm',...
'MiniBatchSize',16,...
'InitialLearnRate', 0.0001, ...
...)
net = trainNetwork(imdsTrain,lgraph,options);

3 comentarios

Sushma TV
Sushma TV el 15 de Nov. de 2021
Hello Sir,
I am doing transfer learning using Googlenet for binary classification of images. I was getting the same error and made the changes as suggested above. The earlier error is resolved. However I am getting the error with createLgraphUsingConnections.
The error I am getting is
'createLgraphUsingConnections' is used in Train Deep Learning Network to Classify New Images.
It is not executing further after this. Should this function be written explicitly.
Kindly assist on how to overcome this error and procced.
baby
baby el 18 de Feb. de 2022
I dont think its an error, its a warning but somehow it appears in red. You can ignore this and proceed with the training procedure, and to make sure you can use command:
analyzeNetwor(lgraph)
if found no error, the traning will process very nicely. ( I hope).
Tan
Tan el 14 de Mayo de 2023
hi although using the command
layers = lgraph.Layers;
connections = lgraph.Connections;
lgraph = createLgraphUsingConnections(layers,connections);
it also show the same error:
trainedNet = trainNetwork(augmentedTrainingSet,lgraph,options);
Error using trainNetwork
Invalid network.
Caused by:
Layer 'inception_3a-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_3b-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4a-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4b-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4c-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4d-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_4e-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_5a-output': Unconnected input. Each layer input must be connected to the output of another
layer.
Layer 'inception_5b-output': Unconnected input. Each layer input must be connected to the output of another
layer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Deep Learning Toolbox en Centro de ayuda y File Exchange.

Productos

Versión

R2020a

Etiquetas

Preguntada:

el 15 de Mzo. de 2021

Comentada:

Tan
el 14 de Mayo de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by