Detect objects using SSD deep learning detector


The ssdObjectDetector detects objects from an image, using a single shot detector (SSD) object detector. To detect objects in an image, pass the trained detector to the detect function.


Create an ssdObjectDetector detector object by calling the trainSSDObjectDetector function with training data (requires Deep Learning Toolbox™).

detector = trainSSDObjectDetector(trainingData,...)

To detect objects in an image, pass the detector to the detect function.


expand all

This property is read-only.

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 trainSSDObjectDetector function. You can modify this name after creating your ssdObjectDetector object.

This property is read-only.

Trained SSD multibox object detection network, specified as a DAGNetwork object. This object stores the layers that define the convolutional neural network used within the SSD detector.

This property is read-only.

Size of anchor boxes, specified as a P-by-1 cell array for P number of feature extraction layers used for object detection in the SSD network. Each element of the array contains an M-by-2 matrix of anchor box sizes, in the format [height width]. Each cell can contain a different number of anchor boxes. This value is set during training.

This property is read-only.

Names of the object classes that the SSD detector was trained to find, specified as a cell array. This property is set by the trainingData input argument for the trainSSDObjectDetector function.

Object Functions

detectDetect objects using SSD multibox object detector


collapse all

Load a pretrained single shot detector (SSD) object to detect vehicles in an image. The detector is trained with images of cars on a highway scene.

vehicleDetector = load('ssdVehicleDetector.mat','detector');
detector = vehicleDetector.detector;

Read a test image into the workspace.

I = imread('highway.png');

Display the test image.


Run the pretrained SSD object detector by using the detect function. The output contains the bounding boxes, scores, and the labels for vehicles detected in the image. The labels are derived from the ClassNames property of the detector.

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

   147   120    42    44

scores = single
labels = categorical

Annotate the image with the detection results.

if ~isempty(bboxes)
    detectedI = insertObjectAnnotation(I,'rectangle',bboxes,cellstr(labels));
   detectedI = insertText(I,[10 10],'No Detections');

Extended Capabilities

Introduced in R2020a