Deep learning using trainnet for resnet18 : old trainnetwork –> new trainnet
Hi,
I copied a matlab example for semantic image segmentation using MATLAB 2022, and the example used ‘trainNetwork’ and ‘deeplabv3plusLayers’ for resnet18, and the results were excellent for my images which have 9 labels (background + 8)
However, now the documentation for trainNetwork recommends moving the training command to be ‘trainnet’, and the documentation for ‘deeplabv3plusLayers’ recommends moving to ‘ deeplabv3plus’. When I follow the provided example (e.g https://www.mathworks.com/help/vision/ug/semantic-segmentation-using-deep-learning.html), my segmentation results are noticibly worse:
…especially for my primary ROIs of interest: ROI1, ROI2, and ROI3.
My program which calls trainnet uses the following options. The function call is also shown here:
options = trainingOptions(‘sgdm’,…
‘InitialLearnRate’,0.1, …
‘Momentum’,0.9,…
‘L2Regularization’,0.0001,…
‘MaxEpochs’,80,…
‘MiniBatchSize’,128,…
‘LearnRateSchedule’,’piecewise’,…
‘Shuffle’,’every-epoch’,…
‘GradientThresholdMethod’,’l2norm’,…
‘GradientThreshold’,0.05, …
‘Plots’,’training-progress’, …
‘VerboseFrequency’,10,…
‘ExecutionEnvironment’,’multi-gpu’,…
‘ValidationData’,dsValid,…
‘ValidationFrequency’,30,…
‘ValidationPatience’,15,…
‘InputDataFormats’, {‘SSCB’});
[ROISegNet,info] = trainnet(dsTrain,network,@(Y,T) modelLoss(Y,T,classWeights),options);
where the modelLoss subroutine is as provided by MATLAB:
function loss = modelLoss(Y,T,classWeights)
weights = dlarray(classWeights,"C");
mask = ~isnan(T);
T(isnan(T)) = 0;
loss = crossentropy(Y,T,weights,Mask=mask,NormalizationFactor="mask-included");
end
As a novice learning how to do this, can anyone offer suggestions on how to handle trainnet such that the results generated are closer to the old version?
Thank you for your help!Hi,
I copied a matlab example for semantic image segmentation using MATLAB 2022, and the example used ‘trainNetwork’ and ‘deeplabv3plusLayers’ for resnet18, and the results were excellent for my images which have 9 labels (background + 8)
However, now the documentation for trainNetwork recommends moving the training command to be ‘trainnet’, and the documentation for ‘deeplabv3plusLayers’ recommends moving to ‘ deeplabv3plus’. When I follow the provided example (e.g https://www.mathworks.com/help/vision/ug/semantic-segmentation-using-deep-learning.html), my segmentation results are noticibly worse:
…especially for my primary ROIs of interest: ROI1, ROI2, and ROI3.
My program which calls trainnet uses the following options. The function call is also shown here:
options = trainingOptions(‘sgdm’,…
‘InitialLearnRate’,0.1, …
‘Momentum’,0.9,…
‘L2Regularization’,0.0001,…
‘MaxEpochs’,80,…
‘MiniBatchSize’,128,…
‘LearnRateSchedule’,’piecewise’,…
‘Shuffle’,’every-epoch’,…
‘GradientThresholdMethod’,’l2norm’,…
‘GradientThreshold’,0.05, …
‘Plots’,’training-progress’, …
‘VerboseFrequency’,10,…
‘ExecutionEnvironment’,’multi-gpu’,…
‘ValidationData’,dsValid,…
‘ValidationFrequency’,30,…
‘ValidationPatience’,15,…
‘InputDataFormats’, {‘SSCB’});
[ROISegNet,info] = trainnet(dsTrain,network,@(Y,T) modelLoss(Y,T,classWeights),options);
where the modelLoss subroutine is as provided by MATLAB:
function loss = modelLoss(Y,T,classWeights)
weights = dlarray(classWeights,"C");
mask = ~isnan(T);
T(isnan(T)) = 0;
loss = crossentropy(Y,T,weights,Mask=mask,NormalizationFactor="mask-included");
end
As a novice learning how to do this, can anyone offer suggestions on how to handle trainnet such that the results generated are closer to the old version?
Thank you for your help! Hi,
I copied a matlab example for semantic image segmentation using MATLAB 2022, and the example used ‘trainNetwork’ and ‘deeplabv3plusLayers’ for resnet18, and the results were excellent for my images which have 9 labels (background + 8)
However, now the documentation for trainNetwork recommends moving the training command to be ‘trainnet’, and the documentation for ‘deeplabv3plusLayers’ recommends moving to ‘ deeplabv3plus’. When I follow the provided example (e.g https://www.mathworks.com/help/vision/ug/semantic-segmentation-using-deep-learning.html), my segmentation results are noticibly worse:
…especially for my primary ROIs of interest: ROI1, ROI2, and ROI3.
My program which calls trainnet uses the following options. The function call is also shown here:
options = trainingOptions(‘sgdm’,…
‘InitialLearnRate’,0.1, …
‘Momentum’,0.9,…
‘L2Regularization’,0.0001,…
‘MaxEpochs’,80,…
‘MiniBatchSize’,128,…
‘LearnRateSchedule’,’piecewise’,…
‘Shuffle’,’every-epoch’,…
‘GradientThresholdMethod’,’l2norm’,…
‘GradientThreshold’,0.05, …
‘Plots’,’training-progress’, …
‘VerboseFrequency’,10,…
‘ExecutionEnvironment’,’multi-gpu’,…
‘ValidationData’,dsValid,…
‘ValidationFrequency’,30,…
‘ValidationPatience’,15,…
‘InputDataFormats’, {‘SSCB’});
[ROISegNet,info] = trainnet(dsTrain,network,@(Y,T) modelLoss(Y,T,classWeights),options);
where the modelLoss subroutine is as provided by MATLAB:
function loss = modelLoss(Y,T,classWeights)
weights = dlarray(classWeights,"C");
mask = ~isnan(T);
T(isnan(T)) = 0;
loss = crossentropy(Y,T,weights,Mask=mask,NormalizationFactor="mask-included");
end
As a novice learning how to do this, can anyone offer suggestions on how to handle trainnet such that the results generated are closer to the old version?
Thank you for your help! deep learning, semantic segmentation, resnet18, trainnet MATLAB Answers — New Questions