Semantic segmentation network - different behaviour on different systems

2 ビュー (過去 30 日間)
snipsnap333
snipsnap333 2023 年 3 月 6 日
回答済み: snipsnap333 2023 年 5 月 12 日
Hello,
i'm trying to train a semantic segmentation network to recognize certain areas in an image. So i labeled some images as train data and save them in 'gTruth.mat' and trained the network succesfully.
This works very fine when training the network on my laptop with Matlab 2022a without any error.
When I try the same code on my workstation where I have Matlab 2022b and 2018b installed, I get the following error message:
"Error using trainNetwork Invalid training data. The output size ([500 500 2]) of the last layer does not match the response size ([538 679 2])."
Why do I get different output sizes with the same code on two different systems? Or is this a special 2022a issue?
load('gTruth.mat');
classNames = {gTruth.LabelDefinitions.Name{1}, gTruth.LabelDefinitions.Name{2}};
[imdsTrain,pxdsTrain] = pixelLabelTrainingData(gTruth);
pximdsTrain = pixelLabelImageDatastore(imdsTrain,pxdsTrain);
tbl = countEachLabel(pxdsTrain);
numberPixels = sum(tbl.PixelCount);
frequency = tbl.PixelCount / numberPixels;
classWeights = 1 ./ frequency;
inputSize = [500 500 1];
filterSize = 3;
numFilters = 32;
numClasses = numel(classNames);
layers = [
imageInputLayer(inputSize)
convolution2dLayer(filterSize,numFilters,'DilationFactor',1,'Padding','same')
batchNormalizationLayer
reluLayer
convolution2dLayer(filterSize,numFilters,'DilationFactor',2,'Padding','same')
batchNormalizationLayer
reluLayer
convolution2dLayer(filterSize,numFilters,'DilationFactor',4,'Padding','same')
batchNormalizationLayer
reluLayer
convolution2dLayer(1,numClasses)
softmaxLayer
pixelClassificationLayer('Classes',classNames,'ClassWeights',classWeights)];
options = trainingOptions('sgdm', ...
'MaxEpochs', 15, ...
'MiniBatchSize',64, ...
'InitialLearnRate', 1e-3,...
'ExecutionEnvironment','cpu');
net = trainNetwork(pximdsTrain,layers,options);
Thanks in advance for your help

採用された回答

Shubham
Shubham 2023 年 5 月 4 日
The error message you are receiving indicates that the output size of your network’s last layer does not match the size of the response. This could be because of differences in the size and dimensions of the input images between the two systems.
The input images you use on the workstation with Matlab 2022b and 2018b may have different sizes or dimensions than those you used on your laptop with Matlab 2022a. This can cause the output size of the last layer to be different, leading to the error you see.
To solve this issue, you can try resizing your input images to a fixed size before training the network. This can be done using the imresize() function in Matlab. You can also check the size and dimensions of your input images using the size() function to ensure they are consistent across all systems.

その他の回答 (1 件)

snipsnap333
snipsnap333 2023 年 5 月 12 日
Thanks for your help. I could solve the problem in the meantime on my own. On the workstation somehow one of the training images was corrupt, so it hat indeed something to do with the input. When I replaced the corrupted file I could train the network without problems.

カテゴリ

Help Center および File ExchangeImage Data Workflows についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by