Main Content

solov2

Segment objects using SOLOv2 instance segmentation network

Since R2023b

Description

The solov2 object performs instance segmentation of objects in an image using a Segmenting Objects by LOcations version 2 (SOLOv2) instance segmentation network. To perform instance segmentation of objects in an image, pass the pretrained or trained network to the segmentObjects function.

Note

This functionality requires Deep Learning Toolbox™ and the Computer Vision Toolbox™ Model for SOLOv2 Instance Segmentation. You can install the Computer Vision Toolbox Model for SOLOv2 Instance Segmentation from Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

Creation

Description

example

detector = solov2(detectorName) creates a pretrained SOLOv2 instance segmentation network detectorName by using the specified SOLOv2 deep learning network trained on the COCO data set.

detector = solov2(detectorName,classNames) creates a pretrained SOLOv2 instance segmentation network and configures it to perform transfer learning on a specified set of object classes. The classNames argument sets the ClassNames property. For optimal results, train the network on new training images before performing segmentation.

detector = solov2(___,Name=Value) specifies the ModelName and InputSize properties using name-value arguments, in addition to any combination of input arguments from previous syntaxes.

For example, InputSize=[400 400 3] specifies the input image size as 400-by-400 pixels with 3 channels.

Input Arguments

expand all

Name of the pretrained SOLOv2 deep learning network, specified as one of these options:

  • "resnet50-coco" — A pretrained SOLOv2 deep learning network that uses ResNet-50 as the base network, trained on the COCO data set.

  • "light-resnet18-coco" — A pretrained SOLOv2 deep learning network that uses a version of ResNet-18 with a reduced number of features as a base network, trained on the COCO data set.

Data Types: char | string

Names of object classes for training the network, specified as a vector of strings, cell array of character vectors, or categorical vector. This argument sets the classNames property of the solov2 object.

Data Types: char | string | categorical

Properties

expand all

This property is read-only.

Name of the trained SOLOv2 instance segmentation network, specified as string scalar or character vector. The default ModelName is empty unless specified by detectorName.

To set the value of this property, you must specify it at object creation.

This property is read-only.

Object class names, stored as a string array. The default value consists of the 80 object class names in the MS-COCO data set, such as "person", "bicycle", and "car". When you specify the ClassNames argument, the solov2 object reinitializes the final convolution layers in the detection head and mask segmentation head to the correct size based on the number of classes you specify.

This property is read-only.

Image size to use during training and inference, specified as a 1-by-3 vector of positive integers of the form [height width channel]. The network resizes input images to this size while maintaining the aspect ratio.

To set the value of this property, you must specify it at object creation.

This property is read-only.

Grid sizes used at the five levels of the feature pyramid network in the SOLOv2 network detection head, returned as a 1-by-5 vector. Each level of the feature pyramid corresponds to a different spatial resolution, with higher stages corresponding to lower resolution and larger receptive fields. The model uses multiple grid sizes in the detection head to predict object masks at different scales and resolutions, which helps to improve the accuracy of the segmentation results.

Object Functions

segmentObjectsSegment objects using SOLOv2 instance segmentation

Examples

collapse all

Load a pretrained SOLOv2 instance segmentation network.

model = solov2("resnet50-coco")
model = 
  solov2 with properties:

     ModelName: "resnet50-coco"
    ClassNames: {1×80 cell}
     InputSize: [800 800 3]
     GridSizes: [12 16 24 36 40]

Read a test image that includes objects that the network is trained detect, such as people, into the workspace.

I = imread("visionteam.jpg");

Segment instances of objects in the image using the SOLOv2 instance segmentation model.

[masks,labels,scores] = segmentObjects(model,I,Threshold=0.6);

Overlay the detected object masks on the test image.

overlayedImage = insertObjectMask(I,masks);
figure
imshow(overlayedImage)

Figure contains an axes object. The axes object contains an object of type image.

Version History

Introduced in R2023b