MATLAB Answers

Training a network using valudationData of pixelwise labeling

9 views (last 30 days)
Mattias Nilsson
Mattias Nilsson on 12 Dec 2017
Commented: LJ Zhou on 25 May 2019
Hi, I am trying to train SegNet, based on this guide: semantic segmentation , while monitoring the loss function etc. I would like to use the validationData option to see how fell the model fairs during the training. I am trying to construct my validation data according to the documentation, however it does not appear to accept it. Is it possible to use this kind of validation data?
This is how i create the validationData
% Construct validationData from image datastore.
validIm = readall(imdsValid);
validLabel = readall(pxdsValid);
validationData = cell(1,2);
validationData{1} = cat(4, validIm{:});
validationData{2} = cat(4, validLabel{:});
options = trainingOptions('sgdm', ...
'Momentum', 0.9, ...
'InitialLearnRate', 1e-3, ...
'L2Regularization', 0.0005, ...
'MaxEpochs', 200, ...
'MiniBatchSize', 128, ...
'Shuffle', 'every-epoch', ...
'VerboseFrequency', 1, ...
'Plots', 'training-progress', ...
'ValidationData', validationData, ...
'ValidationFrequency', 100);
% Specify the class weights using a |pixelClassificationLayer|.
pxLayer = pixelClassificationLayer('Name','labels','ClassNames', tbl.Name, 'ClassWeights', classWeights)
% Update the SegNet network with the new |pixelClassificationLayer| by
% removing the current |pixelClassificationLayer| and adding the new layer.
% The current |pixelClassificationLayer| is named 'pixelLabels'. Remove it
% using |removeLayers|, add the new one using|addLayers|, and connect the
% new layer to the rest of the network using |connectLayers|.
lgraph = removeLayers(lgraph, 'pixelLabels');
lgraph = addLayers(lgraph, pxLayer);
lgraph = connectLayers(lgraph, 'softmax' ,'labels');
% Data augmentation
augmenter = imageDataAugmenter('RandXTranslation', [-10 10], ...
'RandYTranslation',[-10 10]);
datasource = pixelLabelImageSource(imdsTrain,pxdsTrain, ...
[net, info] = trainNetwork(datasource, lgraph, options);


Show 1 older comment
Salma Ali
Salma Ali on 18 Dec 2017
Hi Chris,
Kindly, I am facing the same problem with the validation data. I have done the 'checkpointpath', but I do not know how to build the 'OutputFcn' and how to pass back the results of the validated data to the training to optimize the weights?
It will be helpful to give an example of using the 'OutputFcn' with the Semantic Segmentation? As you have not show such example on your site.
Sahar Zafari
Sahar Zafari on 22 Jan 2018
I am having same problem. Could you please make an example how to define validation data in trainingOption for semantic segmentation?.
Here is the error: "Invalid validation data. Y must be a vector of categorical responses."
Steve Scott
Steve Scott on 22 Mar 2018
Yes, I am having this problem too, Sahar.
Is the "vector of categorical responses" per-pixel or per-image? Can you get the "vector of categorical responses" from the pixel datastore?

Sign in to comment.

Answers (1)

Tony Mackenzie
Tony Mackenzie on 5 Feb 2018
This was not working for me on 2017b but I just downloaded 2018a and tested it out with my test data using:
enddatasourcetrain = pixelLabelImageSource( imdsTrain, pxdsTrain);
datasourcetest = pixelLabelImageSource( imdsTest, pxdsTest);
options = trainingOptions('sgdm', ...
'Momentum', .9, ...
'InitialLearnRate', 1e-2, ...
'MaxEpochs', 100, ...
'MiniBatchSize',8, ...
'Shuffle', 'every-epoch', ...
'VerboseFrequency', 2,...
'ValidationData', datasourcetest, ...
Now it is working.


Show 2 older comments
RIDVAN YAYLA on 6 May 2019
Hello I also have a problem with the same function and the same page.
There is no any code about helperDeeplabv3PlusResnet18.m file but it is said that it is attached at the bottom of the page as a supported file.
Where is the helperDeepLabv3PlusResnet18 m file???
Do you have any idea?
todd chelsea
todd chelsea on 8 May 2019
there is a same question?
Where is the helperDeepLabv3PlusResnet18 m file???
anybody could do me a favor and give the helperDeepLabv3PlusResnet18.m file.
LJ Zhou
LJ Zhou on 25 May 2019
Actually, this file has been already in your disk, you may try this path :

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!