How to fix error from evaluatese​manticsegm​entation function?

1 view (last 30 days)
I used the code for evaluation semantic segmentation in
as shown below:
clc
clear all
dataSetDir = fullfile(toolboxdir('vision'),'visiondata','triangleImages');
testImagesDir = fullfile(dataSetDir,'testImages');
testLabelsDir = fullfile(dataSetDir,'testLabels');
imds = imageDatastore(testImagesDir);
classNames = ["crack","background"];
labelIDs = [255 0];
pxdsTruth = pixelLabelDatastore(testLabelsDir,classNames,labelIDs);
data = load('triangleSegmentationNetwork');
net = data.net
net =
SeriesNetwork with properties: Layers: [10×1 nnet.cnn.layer.Layer] InputNames: {'imageinput'} OutputNames: {'classoutput'}
pxdsResults = semanticseg(imds,net,"WriteLocation",tempdir);
Running semantic segmentation network ------------------------------------- * Processed 100 images.
metrics = evaluateSemanticSegmentation(pxdsResults,pxdsTruth)
Evaluating semantic segmentation results ---------------------------------------- * Selected metrics: global accuracy, class accuracy, IoU, weighted IoU, BF score. * Processed 0 images.
Error using semanticSegmentationMetrics>iAssertCategoricalsHaveSameCategories
The categorical data returned by dsResults and dsTruth must have the same categories.

Error in semanticSegmentationMetrics/processImages (line 589)
iAssertCategoricalsHaveSameCategories(act,exp,obj.ClassNames);

Error in semanticSegmentationMetrics/processImagesSerial (line 663)
m = processImages(obj,data);

Error in semanticSegmentationMetrics/computeMetrics (line 389)
metrics = processImagesSerial(obj);

Error in semanticSegmentationMetrics (line 195)
[obj, blockMetrics] = obj.computeMetrics();

Error in semanticSegmentationMetrics.compute (line 174)
[obj, blockMetrics] = semanticSegmentationMetrics(varargin{:});

Error in evaluateSemanticSegmentation (line 205)
[metrics, blockMetrics, canComputeBlockMetrics] = semanticSegmentationMetrics.compute(varargin{:});
I got the following error:
Error using semanticSegmentationMetrics>iAssertCategoricalsHaveSameCategories (line 1226)
The categorical data returned by dsResults and dsTruth must have the same categories.
Error in semanticSegmentationMetrics/processImages (line 589)
iAssertCategoricalsHaveSameCategories(act,exp,obj.ClassNames);
Error in semanticSegmentationMetrics/processImagesSerial (line 663)
m = processImages(obj,data);
Error in semanticSegmentationMetrics/computeMetrics (line 389)
metrics = processImagesSerial(obj);
Error in semanticSegmentationMetrics (line 195)
[obj, blockMetrics] = obj.computeMetrics();
Error in semanticSegmentationMetrics.compute (line 174)
[obj, blockMetrics] = semanticSegmentationMetrics(varargin{:});
Error in evaluateSemanticSegmentation (line 205)
[metrics, blockMetrics, canComputeBlockMetrics] = semanticSegmentationMetrics.compute(varargin{:});
Error in Gtruth2 (line 13)
metrics = evaluateSemanticSegmentation(pxdsResults,pxdsTruth)
I noted that I have different categories between Result and Truth, but I don’t know how to fix it. I named the attached file same as mentioned in the code on Evaluate semantic segmentation data set against ground truth - MATLAB evaluateSemanticSegmentation (mathworks.com) (triangleImages)
the attached (R7001-60.png) is from testImages folder , the attached (gT7001_60.png) is from testLables folder , both folders in (triangleImages) folder.
How to fix it?
  2 Comments
Walter Roberson
Walter Roberson on 14 Dec 2023
The stored images from data = load('triangleSegmentationNetwork'); are class "triangle" and "background" not "crack" and "background"

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!