Training a network using valudationData of pixelwise labeling
Show older comments
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, ...
'LearnRateSchedule','piecewise',...
'LearnRateDropFactor',0.2,...
'LearnRateDropPeriod',5,...
'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, ...
'DataAugmentation',augmenter);
[net, info] = trainNetwork(datasource, lgraph, options);
4 Comments
Chris Perkins
on 14 Dec 2017
Hi Mattias,
What exactly do you mean by 'does not appear to accept it'? Does "trainingOptions" return an error message (if so, what error) or does "trainNetwork" not perform as you expect?
In addition, can you provide your 'validationData' cell array? You should be able to attach it as a MEX file (If the file is too large, you could remove most of the data and post it with less data, just to show the full structure).
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.
https://uk.mathworks.com/help/vision/examples/semantic-segmentation-using-deep-learning.html
Regards,
Sahar Zafari
on 22 Jan 2018
Edited: Sahar Zafari
on 22 Jan 2018
Hi,
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."
Thanks
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?
Answers (1)
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,...
'Plots','training-progress',...
'LearnRateDropFactor',0.1,...
'ValidationData', datasourcetest, ...
'LearnRateDropPeriod',100);
Now it is working.
5 Comments
nasaruddin shaikh
on 21 Apr 2018
In example of Semantic Segmentation Using FCN-AlexNet on link https://www.mathworks.com/examples/matlab/community/32056-fcnalexnetexample#1 they have written that training on single GPU is done .I have COU then how to do Single GPU training ? what addition settings and softwares needed? what extra commands needed? please help me? I am working on project named automatic shadow detection using CNN .then how to do it with semantic segmenetation ? please reply
dinthisrang daimary
on 26 Mar 2019
hi. somebody please help me i am facing problem showing that
Error using helperDeeplabv3PlusResnet18
Too many input arguments.
Error in resnnet (line 57)
lgraph = helperDeeplabv3PlusResnet18(imageSize, numClasses);
link i have attached here
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
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
on 25 May 2019
Actually, this file has been already in your disk, you may try this path :
C:\Users\Administrator\Documents\MATLAB\Examples\R2019a\deeplearning_shared\SemanticSegmentationUsingDeepLearningExample
Categories
Find more on Parallel and Cloud 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!