How to solve the error: The spatial dimension sizes [313 316 3] of the input images to layer 'imageinput' must be greater than or equal to the corresponding minimum input dime
2 次查看(过去 30 天)
显示 更早的评论
I tried to use evaluatesemanticsegmentation function as follow:
destinationTestLabels = "D:\Matlab pics\matlab practices21\Phd analysis\trial meyhods\GroundTruth\crack\testLabels";
destinationTestImages = "D:\Matlab pics\matlab practices21\Phd analysis\trial meyhods\GroundTruth\crack\testImages";
testImagesDir = fullfile(destinationTestImages,'testImages');
testLabelsDir = fullfile(destinationTestLabels,'testLabels');
pixelLabelID = [1 0];
classNames = ["crack" "background"];
imds = imageDatastore(destinationTestImages);
pxdstest11 = pixelLabelDatastore(destinationTestLabels,classNames,pixelLabelID,"FileExtensions",".png");
data = load('triangleSegmentationNetwork');
net = data.net
pxdsResults = semanticseg(imds,net,"WriteLocation",tempdir);
I got the following error:
Error using SeriesNetwork/activations (line 817)
The spatial dimension sizes [313 316 3] of the input images to layer 'imageinput' must be greater than
or equal to the corresponding minimum input dimension sizes of the layer [32 32 1].
Error in semanticseg>iPredictDAGSeriesNetwork (line 609)
allScores = activations(net, X, layerName, ...
Error in semanticseg>iClassifyImagePixels (line 556)
allScores = iPredictDAGSeriesNetwork(X, net, params);
Error in semanticseg>iProcessImageDatastoreSerially (line 938)
L = iClassifyImagePixels(X{i}, net, params);
Error in semanticseg (line 265)
filenames = iProcessImageDatastoreSerially(ds, net, params);
Error in Gtruth3 (line 11)
pxdsResults = semanticseg(imds,net,"WriteLocation",tempdir);
I followed the same steps mentioned in:
www.mathworks.com/help/vision/ref/evaluatesemanticsegmentation.html
The files mentioned has the same two attached images, can anyone help me to fix this erro to calculate IoU?
6 个评论
Matt J
2023-10-8
编辑:Matt J
2023-10-8
Please stop re-iterating your original post and goals. We all understand you have a bigger task than the simplified code, but the simplified code contains key parts of the original code which you should be checking first. If it runs fine for you, then the problem is somewhere in your imds, because it is then obvious that the network fails only for particular images in the data store.
回答(1 个)
Gayathri
2025-6-12
The error is occuring because the network ("triangleSegmentationNetwork") expects grayscale images with an input size of [32 32 1], but the images in the Datastore are RGB images with dimensions [313 316 3].
The MATLAB example works because it uses grayscale images that match the network’s input requirements.
Now, as I see in the comments section, where one image was passed to the "semanticseg" function and it worked without throwing any errors. This is because when a single image is passed the underlying code converts the RGB image to a grayscale image as expected by the network. I am explaining with reference to the code below.
A=imread('gT7001_60.png');
net = load('triangleSegmentationNetwork').net;
out=semanticseg(A,net);
whos A out
However, when using an imageDatastore with multiple images, "semanticseg" function does not automatically perform this preprocessing, leading to the dimension mismatch error.
To resolve this, we need to preprocess the images in the imageDatastore by converting them to grayscale and resizing them to [32 32] before passing them to semanticseg. Alternatively, you can use a different network trained to accept RGB images (e.g., with input size [32 32 3] or larger).
Hope this helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Deep Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!