Training a network using valudationData of pixelwise labeling

1 次查看(过去 30 天)
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 个评论
Sahar Zafari
Sahar Zafari 2018-1-22
编辑:Sahar Zafari 2018-1-22
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
Steve Scott 2018-3-22
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?

请先登录,再进行评论。

回答(1 个)

Tony Mackenzie
Tony Mackenzie 2018-2-5
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 个评论
todd chelsea
todd chelsea 2019-5-8
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 2019-5-25
Actually, this file has been already in your disk, you may try this path :
C:\Users\Administrator\Documents\MATLAB\Examples\R2019a\deeplearning_shared\SemanticSegmentationUsingDeepLearningExample

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by