semanticSegmentationMetrics - Semantic segmentation quality metrics - MATLAB (original) (raw)

Semantic segmentation quality metrics

Description

A semanticSegmentationMetrics object encapsulates semantic segmentation quality metrics for a set of images.

Properties

expand all

This property is read-only.

Confusion matrix, specified as a table with C rows and columns, where C is the number of classes in the semantic segmentation. Each table element (i,j) is the count of pixels known to belong to class i but predicted to belong to class j.

This property is read-only.

Normalized confusion matrix, specified as a table with_C_ rows and columns, where C is the number of classes in the semantic segmentation. TheNormalizedConfusionMatrx represents a confusion matrix normalized by the number of pixels known to belong to each class. Each table element (i,j) is the count of pixels known to belong to class i but predicted to belong to class j, divided by the total number of pixels predicted in class i. Elements are in the range [0, 1].

This property is read-only.

Semantic segmentation metrics aggregated over the data set, specified as a table with one row. DataSetMetrics has up to five columns, corresponding to the metrics that were specified by the'Metrics' name-value pair used with evaluateSemanticSegmentation:

Note

A value of NaN in the dataset, class, or image metrics, indicates that one or more classes were missing during the computation of the metrics when using the evaluateSemanticSegmentation function. In this case, the software was unable to accurately compute the metrics.

The missing classes can be found by looking at theClassMetrics property, which provides the metrics for each class. To more accurately evaluate your network, augment your ground truth with more data that includes the missing classes.

This property is read-only.

Semantic segmentation metrics for each class, specified as a table with_C_ rows, where C is the number of classes in the semantic segmentation. ClassMetrics has up to three columns, corresponding to the metrics that were specified by the'Metrics' name-value pair used with evaluateSemanticSegmentation:

This property is read-only.

Semantic segmentation metrics for each image in the data set, specified as a table with N rows, where N is the number of images in the data set. ImageMetrics has up to five columns, corresponding to the metrics that were specified by the'Metrics' name-value pair used with evaluateSemanticSegmentation:

Each image metric returns a vector, with one element for each image in the data set. The order of the rows matches the order of the images defined by the input PixelLabelDatastore objects representing the data set.

Examples

collapse all

The triangleImages data set has 100 test images with ground truth labels. Define the location of the data set.

dataSetDir = fullfile(toolboxdir("vision"),"visiondata","triangleImages");

Define the location of the test images and ground truth labels.

testImagesDir = fullfile(dataSetDir,"testImages"); testLabelsDir = fullfile(dataSetDir,"testLabels");

Create an imageDatastore holding the test images.

imds = imageDatastore(testImagesDir);

Define the class names and their associated label IDs.

classNames = ["triangle" "background"]; labelIDs = [255 0];

Create a pixelLabelDatastore holding the ground truth pixel labels for the test images.

pxdsTruth = pixelLabelDatastore(testLabelsDir,classNames,labelIDs);

Load a semantic segmentation network that has been trained on the training images of triangleImages.

net = load("triangleSegmentationNetwork"); net = net.net;

Run the network on the test images. Predicted labels are written to disk in a temporary directory and returned as a pixelLabelDatastore.

pxdsResults = semanticseg(imds,net,Classes=classNames,WriteLocation=tempdir);

Running semantic segmentation network

Evaluate the prediction results against the ground truth.

metrics = evaluateSemanticSegmentation(pxdsResults,pxdsTruth);

Evaluating semantic segmentation results

Display the properties of the semanticSegmentationMetrics object.

metrics = semanticSegmentationMetrics with properties:

          ConfusionMatrix: [2×2 table]
NormalizedConfusionMatrix: [2×2 table]
           DataSetMetrics: [1×5 table]
             ClassMetrics: [2×3 table]
             ImageMetrics: [100×5 table]

Display the classification accuracy, the intersection over union, and the boundary F-1 score for each class. These values are stored in the ClassMetrics property.

ans=2×3 table Accuracy IoU MeanBFScore ________ _______ ___________

triangle      0.99302     0.83206      0.67208  
background    0.99063      0.9903      0.93918  

Display the normalized confusion matrix that is stored in the NormalizedConfusionMatrix property.

ans=2×2 table triangle background ________ __________

triangle        4697           33   
background       915        96755   

Version History

Introduced in R2017b