Main Content

yolov2OutputLayer

(To be removed) Create output layer for YOLO v2 object detection network

yolov2OutputLayer will be removed in a future release. Create a YOLO v2 object detection network using the yolov2ObjectDetector object instead. For more information, see Version History.

Description

The yolov2OutputLayer function creates a YOLOv2OutputLayer object, which represents the output layer for you only look once version 2 (YOLO v2) object detection network. The output layer provides the refined bounding box locations of the target objects.

Creation

Description

layer = yolov2OutputLayer(anchorBoxes) creates a YOLOv2OutputLayer object, layer, which represents the output layer for YOLO v2 object detection network. The layer outputs the refined bounding box locations that are predicted using a predefined set of anchor boxes specified at the input.

example

layer = yolov2OutputLayer(anchorBoxes,Name,Value) sets the additional properties using name-value pairs and the input from the preceding syntax. Enclose each property name in single quotes. For example, yolov2OutputLayer('Name','yolo_Out') creates an output layer with the name 'yolo_Out'.

example

Input Arguments

expand all

Set of anchor boxes, specified as an M-by-2 matrix, where each row is of the form [height width]. The matrix defines the height and the width of M number of anchor boxes. This input sets the AnchorBoxes property of the output layer. You can use the clustering approach for estimating anchor boxes from the training data. For more information, see Estimate Anchor Boxes From Training Data.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Properties

expand all

Layer name, specified as a character vector or string scalar. For Layer array input, the trainnet (Deep Learning Toolbox) and dlnetwork (Deep Learning Toolbox) functions automatically assign names to layers with the name "".

The yolov2OutputLayer object stores this property as a character vector.

Data Types: char | string

This property is read-only.

Loss function, set as 'mean-squared-error'. For more information about the loss function, see Loss Function for Bounding Box Refinement.

This property is read-only.

Set of anchor boxes used for training, specified as a M-by-2 matrix defining the width and the height of M number of anchor boxes. This property is set by the input anchorBoxes.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

This property is read-only.

Weights in the loss function, specified as a 1-by-4 vector of form [K1 K2 K3 K4]. Weights increase the stability of the network model by penalizing incorrect bounding box predictions and false classifications. For more information about the weights in loss the function, see Loss Function for Bounding Box Refinement.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Classes of the output layer, specified as a categorical vector, string array, cell array of character vectors, or 'auto'. Use this name-value pair to specify the names of the object classes in the input training data.

If the value is set to 'auto', then the software automatically sets the classes at training time. If you specify the string array or cell array of character vectors str, then the software sets the classes of the output layer to categorical(str). The default value is 'auto'.

Data Types: char | string | cell | categorical

This property is read-only.

Number of inputs to the layer, returned as 1. This layer accepts a single input only.

Data Types: double

This property is read-only.

Input names, returned as {'in'}. This layer accepts a single input only.

Data Types: cell

Examples

collapse all

Create a YOLO v2 output layer with two anchor boxes.

Define the height and the width of the anchor boxes.

anchorBoxes = [16 16;32 32];

Specify the names of the object classes in the training data.

classNames = {'Vehicle','Person'};

Generate a YOLO v2 output layer with the name "yolo_Out".

layer = yolov2OutputLayer(anchorBoxes,'Name','yolo_Out','Classes',classNames);

Inspect the properties of the YOLO v2 output layer.

layer
layer = 
  YOLOv2OutputLayer with properties:

            Name: 'yolo_Out'

   Hyperparameters
         Classes: [2x1 categorical]
    LossFunction: 'mean-squared-error'
     AnchorBoxes: [2x2 double]
     LossFactors: [5 1 1 1]

You can read the values for Classes property by using dot notation layer.Classes. The function stores the class names as a categorical array.

layer.Classes
ans = 2x1 categorical
     Vehicle 
     Person 

More About

expand all

Tips

To improve prediction accuracy, you can:

  • Train the network with more number of images. You can expand the training dataset through data augmentation. For information on how to apply data augmentation for training dataset, see Preprocess Images for Deep Learning (Deep Learning Toolbox).

  • Perform multiscale training by using the trainYOLOv2ObjectDetector function. To do so, specify the TrainingImageSize argument of trainYOLOv2ObjectDetector function for training the network.

  • Choose anchor boxes appropriate to the dataset for training the network. You can use the estimateAnchorBoxes function to compute anchor boxes directly from the training data.

References

[1] Joseph. R, S. K. Divvala, R. B. Girshick, and F. Ali. "You Only Look Once: Unified, Real-Time Object Detection." In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 779–788. Las Vegas, NV: CVPR, 2016.

[2] Joseph. R and F. Ali. "YOLO 9000: Better, Faster, Stronger." In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition (CVPR), pp. 6517–6525. Honolulu, HI: CVPR, 2017.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2019a

collapse all

R2024b: To be removed

The yolov2OutputLayer object will be removed in a future release. Create a YOLO v2 object detection network using the yolov2ObjectDetector object instead, using these steps:

  • Define your network as a dlnetwork (Deep Learning Toolbox) object. You can use functions such as addLayers (Deep Learning Toolbox) and connectLayers (Deep Learning Toolbox) to build the network. Do not include output layers in the network.

  • Create a yolov2ObjectDetector using the dlnetwork as the custom network. You can specify the anchor boxes, class names, and loss factors using the AnchorBoxes, ClassNames, and LossFactors name-value arguments, respectively.