Dimensions of arrays not consistent error with image segmentation network

1 次查看(过去 30 天)
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-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 个评论
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