Dimensions of arrays not consistent error with image segmentation network
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Jacob Heiss
el 14 de Jun. de 2023
Respondida: Jacob Heiss
el 21 de Jun. de 2023
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 comentarios
Respuesta aceptada
Más respuestas (1)
Vinayak Agrawal
el 19 de Jun. de 2023
Editada: Vinayak Agrawal
el 19 de Jun. de 2023
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1414324/image.png)
Hope it helps!
Please accept the answer if it is working so that others can get benefitted.
3 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!