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, and single shot detection (SSD).

Applications for object detection include:

  • Image classification

  • Scene understanding

  • Self-driving vehicles

  • Surveillance

Create Training Data for Object Detection

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 Detector and Evaluate Results

Use the trainFasterRCNNObjectDetector, trainYOLOv2ObjectDetector, trainSSDObjectDetector functions to train an object detector. Use the evaluateDetectionMissRate and evaluateDetectionPrecision functions to evaluate the training results.

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, 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 Objects Using Pretrained Object Detection Models

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 example:

For a list of all the latest MathWorks pretrained models and examples, see MATLAB Deep Learning (GitHub).

See Also

Apps

Related Topics