Why "trainNetwork" function works with GoogLeNet but not with other pretrained networks. Why the other pretrained networks need the "trainnet" function

5 views (last 30 days)
When i try to train a modified pretrained GoogLeNet for binary classification, with the trainnet function as bellow:
[...] =trainnet(resizeTrainImgs,lgraph_1,"crossentropy",opts);
It does not work, It displays the following message:
"Error using trainnet (line 16)
Network must be a dlnetwork or an array of layers."

Answers (1)

Cris LaPierre
Cris LaPierre on 26 Feb 2025
Moved: Walter Roberson on 5 Mar 2025
It sounds like you are asking what is the difference between trainnet and trainnetwork. This answer might be helpful: https://www.mathworks.com/matlabcentral/answers/2060029-difference-between-trainnet-and-trainnetwork
A related question might be what is the difference between a dlnetwork and a DAGNetwork.
We would have to see the layers of your network to say for certain, but a big difference is that DAGNetworks returns a prediction while a dlnetwork returns scores. This is why different functions are needed to train them.
For example, the last layer in this example DAG network classifies the image
layers = [
imageInputLayer([28 28 1])
convolution2dLayer(5,16,'Padding','same')
batchNormalizationLayer
reluLayer('Name','relu_1')
convolution2dLayer(3,32,'Padding','same','Stride',2)
batchNormalizationLayer
reluLayer
convolution2dLayer(3,32,'Padding','same')
batchNormalizationLayer
reluLayer
additionLayer(2,'Name','add')
averagePooling2dLayer(2,'Stride',2)
fullyConnectedLayer(10)
softmaxLayer
classificationLayer];
while in this dlnetwork example, the last layer returns the scores. The actual predictions are made using minibatchpredict.
layers = [
imageInputLayer([28 28 1],Normalization="none")
convolution2dLayer(5,16,Padding="same")
batchNormalizationLayer
reluLayer(Name="relu_1")
convolution2dLayer(3,32,Padding="same",Stride=2)
batchNormalizationLayer
reluLayer
convolution2dLayer(3,32,Padding="same")
batchNormalizationLayer
reluLayer
additionLayer(2,Name="add")
fullyConnectedLayer(numClasses)
softmaxLayer(Name="softmax")];
Perhaps the flowchart on this doc page is helpful.
  4 Comments
Aristotle
Aristotle on 5 Mar 2025
Moved: Walter Roberson on 5 Mar 2025
Dear Cris LaPierre thank you for your prompt answer and suggetion.
I would like to ask:
1] what is the mathematical and data structure difference between a “LayerGraph” object that is produced by the older version (v1) of the Deep Learner Designer and a “dlnetwork” object that is produced by the later version of Deep Learner Designer. Why MATLAB decided this change?
2] whic Loss Function is used by the training function “trainNetwork”?
Cris LaPierre
Cris LaPierre on 5 Mar 2025
Moved: Cris LaPierre on 5 Mar 2025
For 1, see my original answer above. Perhaps this answer is also helpful. The notable difference is what the last layer is.
For 2, it depends on the type of model you are training. Perhaps this 2023b doc page is helpful. I got there from here.

Sign in to comment.

Categories

Find more on Image Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!