This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Detect objects using Fast R-CNN deep learning detector


The fastRCNNObjectDetector object detects objects from an image, using a Fast R-CNN (regions with convolution neural networks) object detector. To detect objects in an image, pass the trained detector to the detect function. To classify image regions, pass the detector to the classifyRegions function.

When using the detect or classifyRegions functions with fastRCNNObjectDetector, use of a CUDA® enabled NVIDIA® GPU with compute capability 3.0 or higher is highly recommended. The GPU reduces computation time significantly. Usage of the GPU requires Parallel Computing Toolbox™.


Create a fastRCNNObjectDetector object by calling the trainFastRCNNObjectDetector function with training data (requires Deep Learning Toolbox™).

detector = trainFastRCNNObjectDetector(trainingData,...)


expand all

Name of the classification model, specified as a character vector or string scalar. By default, the name is set to the heading of the second column of the trainingData table specified in the trainFastRCNNObjectDetector function. You can modify this name after creating your fastRCNNObjectDetector object.

Example: 'stopSign'

This property is read-only.

Trained Fast R-CNN detection network, specified as an object. This object stores the layers that define the convolutional neural network used within the Fast R-CNN detector. This network classifies region proposals produced by the RegionProposalFcn property.

Region proposal method, specified as a function handle.

This property is read-only.

Names of the object classes that the Fast R-CNN detector was trained to find, specified as a cell array. This property is set by the trainingData input argument for the trainFastRCNNObjectDetector function. Specify the class names as part of the trainingData table.

This property is read-only.

Minimum object size supported by the Fast R-CNN network, specified as a [height width] vector. The minimum size depends on the network architecture.

Object Functions

detectDetect objects using Fast R-CNN object detector
classifyRegionsClassify objects in image regions using Fast R-CNN object detector


collapse all

Detect vehicles within an image by using a Faster R-CNN object detector.

Load a Faster R-CNN object detector pretrained to detect vehicles.

data = load('fasterRCNNVehicleTrainingData.mat', 'detector');
detector = data.detector;

Read in a test image.

I = imread('highway.png');

Run the detector on the image and inspect the results. The labels come from the ClassNames property of the detector.

[bboxes,scores,labels] = detect(detector,I)
bboxes = 2×4

   150    86    80    72
    91    89    67    48

scores = 2x1 single column vector


labels = 2x1 categorical array

The detector has high confidence in the detections. Annotate the image with the bounding boxes for the detections and the corresponding detection scores.

  detectedI = insertObjectAnnotation(I,'Rectangle',bboxes,cellstr(labels));

Introduced in R2017a