I used the matlab documentation to evaluate my results from a previous trained networkbut I get this error, can someone fix it and get it to work and output results please.
What I specifically need is to evaluate segmentation results from the trained network and save the image results from segmentation to add to my report.
Here's the code I used
Evaluating semantic segmentation results
----------------------------------------
* Selected metrics: global accuracy, class accuracy, IoU, weighted IoU, BF score.
* Processed 0 [login to view URL] using semanticSegmentationMetrics>iAssertCategoricalsHaveSameCategories
The categorical data returned by dsResults and dsTruth must have the same
categories.
my code is below
dataSetDir = fullfile('LungTS','preprocessedDataset');
testImagesDir = fullfile(dataSetDir,'imagesTest');
imdReader = @(x) matRead(x);
imds = imageDatastore(testImagesDir, ...
'FileExtensions','.mat','ReadFcn',imdReader);
%imds = imageDatastore(testImagesDir);
classNames = ["nodule" "background"];
labelIDs = [255 0];
labelReader = @(x) matRead(x);
testLabelsDir = fullfile(dataSetDir,'labelsTest');
pxdsTruth = pixelLabelDatastore(testLabelsDir,classNames,labelIDs, ...
'FileExtensions','.mat','ReadFcn',labelReader);
net = load('[login to view URL]');
net = [login to view URL];
pxdsResults = semanticseg(imds,net,"WriteLocation",tempdir);
metrics = evaluateSemanticSegmentation(pxdsResults,pxdsTruth);
[login to view URL]
[login to view URL]
cm = confusionchart([login to view URL], ...
classNames, Normalization ='row-normalized');
[login to view URL] = 'Normalized Confusion Matrix (%)';
imageIoU = [login to view URL];
figure
histogram(imageIoU)
title('Image Mean IoU')
[minIoU, worstImageIndex] = min(imageIoU);
minIoU = minIoU(1);
worstImageIndex = worstImageIndex(1);
worstTestImage = readimage(imds,worstImageIndex);
worstTrueLabels = readimage(pxdsTruth,worstImageIndex);
worstPredictedLabels = readimage(pxdsResults,worstImageIndex);
worstTrueLabelImage = im2uint8(worstTrueLabels == classNames(1));
worstPredictedLabelImage = im2uint8(worstPredictedLabels == classNames(1));
worstMontage = cat(4,worstTestImage,worstTrueLabelImage,worstPredictedLabelImage);
worstMontage = imresize(worstMontage,4,"nearest");
figure
montage(worstMontage,'Size',[1 3])
title(['Test Image vs. Truth vs. Prediction. IoU = ' num2str(minIoU)])
[minIoU, worstImageIndex] = min(imageIoU);
minIoU = minIoU(1);
worstImageIndex = worstImageIndex(1);
worstTestImage = readimage(imds,worstImageIndex);
worstTrueLabels = readimage(pxdsTruth,worstImageIndex);
worstPredictedLabels = readimage(pxdsResults,worstImageIndex);
worstTrueLabelImage = im2uint8(worstTrueLabels == classNames(1));
worstPredictedLabelImage = im2uint8(worstPredictedLabels == classNames(1));
worstMontage = cat(4,worstTestImage,worstTrueLabelImage,worstPredictedLabelImage);
worstMontage = imresize(worstMontage,4,"nearest");
figure
montage(worstMontage,'Size',[1 3])
title(['Test Image vs. Truth vs. Prediction. IoU = ' num2str(minIoU)])
[maxIoU, bestImageIndex] = max(imageIoU);
maxIoU = maxIoU(1);
bestImageIndex = bestImageIndex(1);
bestTestImage = readimage(imds,bestImageIndex);
bestTrueLabels = readimage(pxdsTruth,bestImageIndex);
bestPredictedLabels = readimage(pxdsResults,bestImageIndex);
bestTrueLabelImage = im2uint8(bestTrueLabels == classNames(1));
bestPredictedLabelImage = im2uint8(bestPredictedLabels == classNames(1));
bestMontage = cat(4,bestTestImage,bestTrueLabelImage,bestPredictedLabelImage);
bestMontage = imresize(bestMontage,4,"nearest");
figure
montage(bestMontage,'Size',[1 3])
title(['Test Image vs. Truth vs. Prediction. IoU = ' num2str(maxIoU)])
evaluationMetrics = ["accuracy" "iou"];
metrics = evaluateSemanticSegmentation(pxdsResults,pxdsTruth,"Metrics",evaluationMetrics);
[login to view URL]