Testing a trained neural network using semantic segmentation (segnet layers)

1 回表示 (過去 30 日間)
Atreya Danturthi
Atreya Danturthi 2021 年 8 月 9 日
コメント済み: Amanjit Dulai 2021 年 8 月 19 日
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.
Could anyone tell me how do I do that?
  1 件のコメント
Amanjit Dulai
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','triangleImages');
testImageDir = fullfile(dataDir,'testImages');
imds = imageDatastore(testImageDir);
% Predict on 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);

サインインしてコメントする。

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by