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, and single shot detection (SSD).
Applications for object detection include:
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
to create datastores for images and labeled bounding box data.
Augment Bounding Boxes for Object Detection (Deep Learning Toolbox)
Preprocess Images for Deep Learning (Deep Learning Toolbox)
Preprocess Data for Domain-Specific Deep Learning Applications (Deep Learning Toolbox)
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
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
trainSSDObjectDetector functions to train an object detector. Use the
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
objects to return bounding boxes, detection scores, and categorical labels assigned to the
I = imread(input_image) [bboxes,scores,labels] = detect(detector,I)
Detect Objects Using Pretrained Object Detection 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
Download a pretrained model. The pretrained models are shipped as support packages that you can download and install using either the
visionSupportPackagesfunction or the Add-On Explorer.
Use an object detector in the Computer Vision Toolbox to load the pretrained model and detect objects in a test image.
The table lists the names of the pretrained models, names of the corresponding support packages, and the object detectors in Computer Vision Toolbox.
|Name of Pretrained Models||Description||Name of Support Package||Object Detector|
|A pretrained Mask R-CNN object detector trained on the COCO data set with a ResNet-50 network as the feature extractor.||Computer Vision Toolbox Model for Mask R-CNN Instance Segmentation|
|A 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 Detection|
|A pretrained YOLO v2 deep learning network created using a small base network and trained on COCO dataset.|
|A 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 Detection|
|A pretrained YOLO v3 deep learning network created using a small base network and trained on COCO dataset.|
|A 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 Detection|
|A pretrained YOLO v4 deep learning network created using a small base network and trained on COCO dataset.|
For example, to use the
darknet19-coco pretrained YOLO v2
model for object detection, load the model by using the
yolov2ObjectDetector object. You can then use the
yolov2ObjectDetector object to detect objects in an unknown
detector = yolov2ObjectDetector("darknet19-coco"); testImage = imread("highway.png"); [bboxes,scores,labels] = detect(detector,testImage);
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).