主要内容

maskrcnn

使用蒙版R-CNN实例分段检测对象

描述

Themaskrcnnobject performs instance segmentation of objects in an image using a Mask R-CNN (regions with convolution neural networks) object detector. To detect objects in an image, pass the trained detector to thesegmentObjectsfunction.

Note

此功能需要蒙版R-CNN实例分割的计算机视觉工具箱™型号. You can install theComputer Vision Toolbox Model for Mask R-CNN Instance Segmentationfrom Add-On Explorer. For more information about installing add-ons, seeGet and Manage Add-Ons. To run this function, you will require the Deep Learning Toolbox™.

Creation

描述

example

detector = maskrcnn("resnet50-coco")loads a pretrained Mask R-CNN object detector trained on the COCO data set with a ResNet-50 network as the feature extractor.

detector = maskrcnn("resnet50-coco",classNames)creates a pretrained Mask R-CNN object detector and configures it to perform transfer learning using a specified set of object classes. TheclassNames参数设置ClassNames财产。为了获得最佳结果,请在执行检测之前对检测器进行训练。

detector = maskrcnn("resnet50-coco",classNames,anchorBoxes)creates a pretrained Mask R-CNN object detector and configures it to perform transfer learning using a specified set of object classes and anchor boxes. TheclassNames参数设置ClassNames财产。TheanchorBoxes参数设置AnchorBoxes财产。

detector = maskrcnn(___,Name=Value)使用名称值参数来指定ROI池大小或设置ModelName或者输入properties. Specify name-value arguments in addition to the input arguments from any of the previous syntaxes.

例如,maskrcnn("resnet50-coco",classNames,anchorBoxes,PoolSize=[11 11])specifies the ROI pooling size for the detection head as 11-by-11 pixels.

Input Arguments

expand all

Name-Value Arguments

将可选的参数对Name1=Value1,...,NameN=ValueN, whereNameis the argument name and价值是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

例子:maskrcnn("resnet50-coco",classNames,anchorBoxes,PoolSize=[11 11])specifies the ROI pooling size for the detection head as 11-by-11 pixels.

检测头的ROI合并大小,以格式指定为1 by-2矢量[height宽度]。

掩模分割头的ROI池大小,以该格式指定为1 by-2矢量[height宽度]。

Properties

expand all

训练有素的蒙版R-CNN对象检测网络的名称,指定为字符串标量或字符向量。

Size of anchor boxes, specified as anM-by-2矩阵,每行以格式[height宽度]。The default value consists of 15 anchor boxes defined by the MS-COCO data set. When you specify the anchor boxes, themaskrcnnobject reinitializes the final convolution layers in the region proposal subnetwork to the correct size based on the number of anchor boxes.

创建对象后,您无法修改此属性的值。

训练了蒙版R-CNN检测器的对象类的名称,以检测为单元格数。默认值由MS-Coco数据集中的80个对象类名称组成,例如“人”,“自行车”和“汽车”。指定类名时maskrcnnobject reinitializes the final convolution layers in the detection head and mask segmentation head to the correct size based on the number of classes.

创建对象后,您无法修改此属性的值。

Image size to use for detection, specified as a 1-by-3 vector of positive integers in the format [height宽度3]。检测器将输入图像调整为此大小,同时保持纵横比。默认值是网络输入大小。

创建对象后,您无法修改此属性的值。

Object Functions

向前 Run forward pass on Mask R-CNN network
segmentObjects Segment objects using Mask R-CNN instance segmentation

例子

collapse all

Load a pretrained Mask R-CNN object detector.

detector = maskrcnn(“ Resnet50-Coco”)
detector = maskrcnn with properties: ModelName: 'maskrcnn' ClassNames: {1×80 cell} InputSize: [800 1200 3] AnchorBoxes: [15×2 double]

Read a test image that includes objects that the network can detect, such as people.

I = imread("visionteam.jpg");

使用蒙版R-CNN对象检测器的对象实例。

[蒙版,标签,分数,盒子] = SementObjects(检测器,i,阈值= 0.95);

Overlay the detected object masks in blue on the test image. Display the bounding boxes in red and the object labels.

overlayedImage = insertObjectMask(I,masks); imshow(overlayedImage) showShape(“矩形”,盒子,标签=标签,linecolor = [1 0 0])

版本历史

Introduced in R2021b