ssdObjectDetector

Detect objects using SSD deep learning detector

Description

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.

Creation

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.

Properties

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 (Deep Learning Toolbox) 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

Examples

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.

imshow(I);

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 = 2×4

   139    78    96    81
    99    67   165   146

scores = 2x1 single column vector

    0.8349
    0.6302

labels = 1x2 categorical
     vehicle      vehicle 

Annotate the image with the detection results.

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

Extended Capabilities

Introduced in R2020a