필터 지우기
필터 지우기

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

조회 수: 11 (최근 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