Testing a trained neural network using semantic segmentation (segnet layers)
1视图(最近30天)
Show older comments
I have built a semantic segmentation network using the segnet layers to identify circular and psuedo-circular objects in a series of grayscale images.
I have trained the model with the training dataset stored as an imageDatastore (imds), and would now like to test it with the testdata stored as an imds as well.
谁能告诉我我该怎么做?
1 Comment
Amanjit Dulai
2021年8月19日
You can do this with the
semanticseg
function. Because the prediction results for semantic segmentation can be very large, the
semanticseg
function will write the outputs to disk. Here is a short example.
% Load a pretrained segmentation network.
data = load('triangleSegmentationNetwork');
net = data.net;
% Specify the location of the test data and load the images.
datadir = fullfile(toolboxDir(工具箱)('vision'),'visiondata',“三角形图”);
testImageDir = fullfile(dataDir,“证词”);
Imds = imagedatastore(sentimagedir);
%预测the test data. The results are returned as a datastore with
% image files stored in a temporary directory.
pxdsresults = semanticseg(imds,net,...
'MiniBatchSize', 4,...
'WriteLocation', tempdir );
If you have a the ground truth labels as well, you can use
semanticseg
with
evaluateSemanticSegmentation
to compute metrics. For example, you can run this code after the previous code:
% Load the labels for the data. Note that class names and pixel labels
% depend on your data.
testLabelDir = fullfile(dataDir,'testLabels');
classNames = ["triangle" "background"];
pixelLabelID = [255 0];
pxdsTruth = pixelLabelDatastore(testLabelDir,classNames,pixelLabelID);
% Compute metrics on the predictions using the ground truth.
metrics = evaluateSemanticSegmentation(pxdsResults,pxdsTruth);
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
开始狩猎!