Main Content

Getting Started with Object Detection Using Deep Learning

Object detection using deep learning provides a fast and accurate means to predict the location of an object in an image. Deep learning is a powerful machine learning technique in which the object detector automatically learns image features required for detection tasks. Several techniques for object detection using deep learning are available such as Faster R-CNN, you only look once (YOLO) v2, YOLO v3, YOLO v4, YOLOX, and single shot detection (SSD).

Applications for object detection include:

  • Image classification

  • Scene understanding

  • Self-driving vehicles

  • Surveillance

Create Training Data

Use a labeling app to interactively label ground truth data in a video, image sequence, image collection, or custom data source. You can label object detection ground truth using rectangle labels, which define the position and size of the object in the image.

Augment and Preprocess Data

Using data augmentation provides a way to use limited data sets for training. Minor changes, such as translation, cropping, or transforming an image, provide, new, distinct, and unique images that you can use to train a robust detector. Datastores are a convenient way to read and augment collections of data. Use imageDatastore and the boxLabelDatastore to create datastores for images and labeled bounding box data.

For more information about augmenting training data using datastores, see Datastores for Deep Learning (Deep Learning Toolbox), and Perform Additional Image Processing Operations Using Built-In Datastores (Deep Learning Toolbox).

Create Object Detection Network

Each object detector contains a unique network architecture. For example, the Faster R-CNN detector uses a two-stage network for detection, whereas the YOLO v2 detector uses a single stage. Use functions like fasterRCNNLayers or yolov2Layers to create a network. You can also design a network layer by layer using the Deep Network Designer (Deep Learning Toolbox).

Train Object Detector and Evaluate Results

For object detection, use training functions such as the trainFasterRCNNObjectDetector, trainYOLOv2ObjectDetector, trainYOLOv3ObjectDetector, trainYOLOv4ObjectDetector, and trainSSDObjectDetector functions to train an object detector. Use the evaluateObjectDetection function to evaluate the training results with a comprehensive set of metrics.

Detect Objects Using Deep Learning Detectors

Detect objects in an image using the trained detector. For example, the partial code shown below uses the trained detector on an image I. Use the detect object function on fasterRCNNObjectDetector, yolov2ObjectDetector, yolov3ObjectDetector, yolov4ObjectDetector, or ssdObjectDetector objects to return bounding boxes, detection scores, and categorical labels assigned to the bounding boxes.

I = imread(input_image)
[bboxes,scores,labels] = detect(detector,I)

Detect and Segment Objects Using Pretrained Models

Computer Vision Toolbox™ provides pretrained object detection models to use for performing out-of-the-box inference.

To use a pretrained object detection model

  1. Download a pretrained model. The pretrained models are shipped as support packages that you can download and install using either the visionSupportPackages function or the Add-On Explorer.

  2. Use an object detector in the Computer Vision Toolbox to load the pretrained model and detect objects in a test image.

For example, to use the darknet19-coco pretrained YOLO v2 model described in the Pretrained Models for Object Detection section, load the model by using the yolov2ObjectDetector object. You can then use the detect function of yolov2ObjectDetector object to detect objects in an unknown image.

detector = yolov2ObjectDetector("darknet19-coco");
testImage = imread("highway.png");
[bboxes,scores,labels] = detect(detector,testImage);

Pretrained Models for Object Detection

The table lists the names of the pretrained models for object detection, names of the corresponding support packages, and the object detectors in Computer Vision Toolbox.

Name of Pretrained ModelDescriptionName of Support PackageObject Detection Model
darknet19-cocoA pretrained YOLO v2 deep learning network created using DarkNet-19 as the base network and trained on COCO dataset.Computer Vision Toolbox Model for YOLO v2 Object Detectionyolov2ObjectDetector
tiny-yolov2-cocoA pretrained YOLO v2 deep learning network created using a small base network and trained on COCO dataset.
darknet53-cocoA pretrained YOLO v3 deep learning network created using DarkNet-53 as the base network and trained on COCO dataset.Computer Vision Toolbox Model for YOLO v3 Object Detectionyolov3ObjectDetector
tiny-yolov3-cocoA pretrained YOLO v3 deep learning network created using a small base network and trained on COCO dataset.
csp-darknet53-cocoA pretrained YOLO v4 deep learning network created using CSP-DarkNet-53 as the base network and trained on COCO dataset.Computer Vision Toolbox Model for YOLO v4 Object Detectionyolov4ObjectDetector
tiny-yolov4-cocoA pretrained YOLO v4 deep learning network created using a small base network and trained on COCO dataset.
small-cocoA pretrained YOLOX deep learning network created using CSP-DarkNet-53 as the base network and trained on COCO dataset.

Computer Vision Toolbox Automated Visual Inspection Library

yoloxObjectDetector
tiny-cocoA pretrained YOLOX deep learning network created using CSP-DarkNet-53 as a base network with fewer filters and trained on COCO dataset.

Computer Vision Toolbox Automated Visual Inspection Library

MathWorks GitHub

MathWorks® GitHub repository provides implementations of the latest pretrained object detection deep learning networks to download and use for performing out-of-the-box inference. The pretrained object detection networks are already trained on standard data sets such as the COCO and Pascal VOC data sets. You can use these pretrained models directly to detect different objects in a test image.

For a list of all the latest MathWorks pretrained object detectors, see MATLAB Deep Learning (GitHub).

See Also

Apps

Related Topics