# yolov2OutputLayer

Create output layer for YOLO v2 object detection network

## 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

### Syntax

``layer = yolov2OutputLayer(anchorBoxes)``
``layer = yolov2OutputLayer(anchorBoxes,Name,Value)``

### Description

example

````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'.```

### 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 a string scalar. For `Layer` array input, the `trainNetwork`, `assembleNetwork`, `layerGraph`, and `dlnetwork` functions automatically assign names to layers with `Name` set to `''`.

Data Types: `char` | `string`

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

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`

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`

Number of inputs of the layer. This layer accepts a single input only.

Data Types: `double`

Input names of the layer. 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 ```

expand all

## Tips

To improve prediction accuracy, you can:

## 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

Introduced in R2019a