Dimensions of arrays not consistent error with image segmentation network

1 回表示 (過去 30 日間)
Jacob Heiss
Jacob Heiss 2023 年 6 月 14 日
回答済み: Jacob Heiss 2023 年 6 月 21 日
I am getting an error on line 80 of my code (when I try to train the network) where it says that the dimensions of the arrays being concatenated are not consistent. After looking into the problem a bit I double checked and all of my input images are 1024x1024 so I'm not sure where the problem is coming from.
clear all;
clc;
dataSetDir = 'C:\Users\jacob\Documents\School\Image Segmentation Training Data';
imageDir = fullfile(dataSetDir, 'Cores');
labelDir = fullfile(dataSetDir,'Labels Despeckeled');
imds = imageDatastore(imageDir);
classNames = ["background","core"];
labelIDs = [255 0];
pxds = pixelLabelDatastore(labelDir,classNames,labelIDs);
% I = read(imds);
% C = read(pxds);
%
% I = imresize(I,5);
% L = imresize(uint8(C{1}),5);
% imshowpair(I,L,'montage')
numFilters = 64;
filterSize = 3;
numClasses = 2;
inputSize = [1024,1024,3];
imgLayer = imageInputLayer(inputSize);
conv = convolution2dLayer(filterSize,numFilters,'Padding',1);
relu = reluLayer();
poolSize = 2;
maxPoolDownsample2x = maxPooling2dLayer(poolSize,'Stride',2);
downsamplingLayers = [
conv
relu
maxPoolDownsample2x
conv
relu
maxPoolDownsample2x
conv
relu
maxPoolDownsample2x
];
filterSize = 4;
transposedConvUpsample2x = transposedConv2dLayer(4,numFilters,'Stride',2,'Cropping',1);
upsamplingLayers = [
transposedConvUpsample2x
relu
transposedConvUpsample2x
relu
transposedConvUpsample2x
relu
];
conv1x1 = convolution2dLayer(1,numClasses);
finalLayers = [
conv1x1
softmaxLayer()
pixelClassificationLayer()
];
layers = [
imgLayer
downsamplingLayers
upsamplingLayers
finalLayers
];
opts = trainingOptions('sgdm', ...
'InitialLearnRate',1e-3, ...
'MaxEpochs',15, ...
'MiniBatchSize',64, ...
Plots="training-progress");
trainingData = combine(imds,pxds);
net = trainNetwork(trainingData,layers,opts);
testImage = imread('C:\Users\jacob\Documents\School\Image Segmentation Training Data\Cores\00.1nM Dox 231-001.png');
imshow(testImage)
C = semanticseg(testImage,net);
B = labeloverlay(testImage,C);
imshow(B)
  5 件のコメント
Jacob Heiss
Jacob Heiss 2023 年 6 月 19 日
Here is a screenshot of the error. Thanks.
Jacob Heiss
Jacob Heiss 2023 年 6 月 19 日
Here is also an example of an image and its label

サインインしてコメントする。

採用された回答

Jacob Heiss
Jacob Heiss 2023 年 6 月 21 日
I figured out the issue, the pixel label images had an invert LUT on them which was causing the problem.

その他の回答 (1 件)

Vinayak Agrawal
Vinayak Agrawal 2023 年 6 月 19 日
編集済み: Vinayak Agrawal 2023 年 6 月 19 日
Hi Jacob,
Based on the code snippet you provided, to fix this error, you should do following change
'Plots','training-progress');
By changing this, MATLAB should be able to correctly generate the desired training progress plots during the training process.
You can see this way of generating plots from this documentation(Train deep learning neural network - MATLAB trainNetwork - MathWorks India)
Here is the screenshot from the same document from where the changes are taken
Hope it helps!
Please accept the answer if it is working so that others can get benefitted.
  3 件のコメント
Vinayak Agrawal
Vinayak Agrawal 2023 年 6 月 21 日
try changing it to lowercase
'plots','training progress');
Jacob Heiss
Jacob Heiss 2023 年 6 月 21 日
I don't think that the issue is with the syntax of that part. The code still has the error even when that part is completely removed.

サインインしてコメントする。

Community Treasure Hunt

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

Start Hunting!

Translated by