YoloV5Decode#
Enumerations#
- PVAYoloV5DecodeInputLayout
Raw YOLOv5 head tensor layout.
Functions#
- NVCVStatus pvaYoloV5DecodeCreate(NVCVOperatorHandle *handle, NVCVTensorRequirements const *inPredReqs, NVCVTensorRequirements const *inAnchorReqs, NVCVTensorRequirements const *outBoxesReqs, NVCVTensorRequirements const *outScoresReqs, NVCVTensorRequirements const *outClassesReqs, NVCVTensorRequirements const *outCountReqs, int numClasses, float confThreshold, int imgHeight, int imgWidth, PVAYoloV5DecodeInputLayout inputLayout)
Constructs an instance of the YOLOv5 decode operator.
- NVCVStatus pvaYoloV5DecodeSubmit(NVCVOperatorHandle handle, cupvaStream_t stream, NVCVTensorHandle predictions, NVCVTensorHandle anchors, NVCVTensorHandle boxes, NVCVTensorHandle scores, NVCVTensorHandle classes, NVCVTensorHandle count)
Submits the YOLOv5 decode operator to a cuPVA stream.
- NVCVStatus pvaYoloV5DecodeSubmit(NVCVOperatorHandle handle, cudaStream_t stream, NVCVTensorHandle predictions, NVCVTensorHandle anchors, NVCVTensorHandle boxes, NVCVTensorHandle scores, NVCVTensorHandle classes, NVCVTensorHandle count)
Submits the YOLOv5 decode operator to a CUDA stream.
Enumerations#
Functions#
- NVCVStatus pvaYoloV5DecodeCreate(
- NVCVOperatorHandle *handle,
- NVCVTensorRequirements const *inPredReqs,
- NVCVTensorRequirements const *inAnchorReqs,
- NVCVTensorRequirements const *outBoxesReqs,
- NVCVTensorRequirements const *outScoresReqs,
- NVCVTensorRequirements const *outClassesReqs,
- NVCVTensorRequirements const *outCountReqs,
- int numClasses,
- float confThreshold,
- int imgHeight,
- int imgWidth,
- PVAYoloV5DecodeInputLayout inputLayout,
Constructs an instance of the YOLOv5 decode operator.
The operator decodes the raw output of one YOLOv5 detection head (one scale) into boxes, scores and class identifiers, keeping the detections whose score is above a confidence threshold.
Semantics:
The prediction tensor holds 3 anchors x (numClasses + 5) values per grid cell. For anchor a of cell (x, y) the values are, in order: tx, ty, tw, th, obj and one logit cls[c] per class. In CHW layout value k of anchor a is channel a * (numClasses + 5) + k; in HWC layout it is element a * (numClasses + 5) + k of the cell. The anchor row of anchor a of cell (x, y) is i = (y * W + x) * 3 + a, and row i of the anchors tensor holds [grid_x, grid_y, anchor_w, anchor_h, stride] for it, with anchor_w, anchor_h and stride in pixels. With sigmoid(v) = 1 / (1 + exp(-v)):
One detection is emitted for every class c with score > confThreshold (strictly greater), so an anchor can produce several detections that share the same box. The box is written ascx = (2 * sigmoid(tx) - 0.5 + grid_x) * stride cy = (2 * sigmoid(ty) - 0.5 + grid_y) * stride w = (2 * sigmoid(tw))^2 * anchor_w h = (2 * sigmoid(th))^2 * anchor_h score = sigmoid(obj) * sigmoid(cls[c])
the score is stored as FP16 and the class as its index c. Detections are written in ascending anchor row order and, within one anchor row, in ascending class order, starting at the position given by the count tensor. Once maxOutputBoxes detections are stored the remaining detections are dropped without an error and the count stays at maxOutputBoxes.left = max(cx - w / 2, 0) top = max(cy - h / 2, 0) right = min(cx + w / 2, imgWidth) bottom = min(cy + h / 2, imgHeight)
The count tensor is an in/out append cursor, so the outputs can be shared by the operators of all scales of a model: initialize it to zero before the first scale and submit the scales in order. An incoming count outside [0, maxOutputBoxes] is clamped to that range.
Limitations:
Exactly 80 classes and three anchors per grid cell are supported.
The prediction and anchors tensors must be tightly packed.
The rows of the boxes tensor may be padded (strides[0] >= maxOutputBoxes * sizeof(float)); its elements, and those of the scores, classes and count tensors, must be contiguous.
maxOutputBoxes must not exceed 5120.
The layout fields of the tensor requirements are not checked; the layout of the prediction tensor is selected by inputLayout.
Input Tensors:
Tensor Name
dtype
rank
layout
shape
predictions
NVCV_DATA_TYPE_F32
3
CHW or HWC
[255, H, W] or [H, W, 255]
anchors
NVCV_DATA_TYPE_F32
2
HW
[H * W * 3, 5]
Output Tensors:
Tensor Name
dtype
rank
layout
shape
boxes
NVCV_DATA_TYPE_F32
2
HW
[4, maxOutputBoxes]
scores
NVCV_DATA_TYPE_F16
1
W
[maxOutputBoxes]
classes
NVCV_DATA_TYPE_S16
1
W
[maxOutputBoxes]
count
NVCV_DATA_TYPE_S32
1
W
[1]
The boxes tensor uses structure-of-arrays storage: row 0 holds left, row 1 top, row 2 right and row 3 bottom.
- Parameters:
handle – [out] Where the operator instance handle will be written to.
Must not be NULL.
inPredReqs – [in] Pointer to the NVCVTensorRequirements of the predictions tensor.
Must not be NULL.
inAnchorReqs – [in] Pointer to the NVCVTensorRequirements of the anchors tensor.
Must not be NULL.
outBoxesReqs – [in] Pointer to the NVCVTensorRequirements of the boxes tensor.
Must not be NULL.
outScoresReqs – [in] Pointer to the NVCVTensorRequirements of the scores tensor.
Must not be NULL.
outClassesReqs – [in] Pointer to the NVCVTensorRequirements of the classes tensor.
Must not be NULL.
outCountReqs – [in] Pointer to the NVCVTensorRequirements of the count tensor.
Must not be NULL.
numClasses – [in] Number of object classes. Must be 80.
confThreshold – [in] Confidence threshold for filtering detections (e.g., 0.25).
Must be in the range (0, 1), exclusive.
imgHeight – [in] Network input height in pixels. Must be positive.
imgWidth – [in] Network input width in pixels. Must be positive.
inputLayout – [in] Layout of the prediction tensor.
- Return values:
NVCV_ERROR_INVALID_ARGUMENT – The possible cases might be the following: 1) handle or a tensor requirements pointer is NULL. 2) numClasses is not 80. 3) confThreshold is not in (0, 1), or imgHeight or imgWidth is not positive. 4) inputLayout is not a PVAYoloV5DecodeInputLayout value. 5) A tensor has the wrong rank, data type or shape, or violates a documented limitation above.
NVCV_ERROR_OUT_OF_MEMORY – Not enough memory to create the operator.
NVCV_ERROR_INTERNAL – Internal error in the operator.
NVCV_SUCCESS – Operator created successfully.
- NVCVStatus pvaYoloV5DecodeSubmit(
- NVCVOperatorHandle handle,
- cupvaStream_t stream,
- NVCVTensorHandle predictions,
- NVCVTensorHandle anchors,
- NVCVTensorHandle boxes,
- NVCVTensorHandle scores,
- NVCVTensorHandle classes,
- NVCVTensorHandle count,
Submits the YOLOv5 decode operator to a cuPVA stream.
- Parameters:
handle – [in] Handle to the operator.
Must not be NULL.
stream – [in] Handle to a valid cuPVA stream.
predictions – [in] Raw prediction tensor for one YOLOv5 scale.
Must not be NULL.
anchors – [in] Anchors tensor for the same scale.
Must not be NULL.
boxes – [out] Decoded boxes tensor, shared by all scales.
Must not be NULL.
scores – [out] Decoded scores tensor, shared by all scales.
Must not be NULL.
classes – [out] Decoded class identifiers tensor, shared by all scales.
Must not be NULL.
count – [inout] Append cursor. Initialize it to zero before the first scale.
Must not be NULL.
- Return values:
NVCV_ERROR_INVALID_ARGUMENT – The possible cases might be the following: 1) handle or a tensor handle is NULL, or points to an invalid address. 2) A tensor does not meet the requirements used to create the operator handle.
NVCV_ERROR_INTERNAL – Internal error in the operator.
NVCV_SUCCESS – Operation submitted successfully.
- NVCVStatus pvaYoloV5DecodeSubmit(
- NVCVOperatorHandle handle,
- cudaStream_t stream,
- NVCVTensorHandle predictions,
- NVCVTensorHandle anchors,
- NVCVTensorHandle boxes,
- NVCVTensorHandle scores,
- NVCVTensorHandle classes,
- NVCVTensorHandle count,
Submits the YOLOv5 decode operator to a CUDA stream.
Note
CUDA stream support requirements:
PVA SDK 2.7.0 or later
Jetpack 7 or later
DriveOS 7 or later
x86 Emulator is not supported
- Parameters:
handle – [in] Handle to the operator.
stream – [in] Handle to a valid CUDA stream.
predictions – [in] Raw prediction tensor for one YOLOv5 scale.
anchors – [in] Anchors tensor for the same scale.
boxes – [out] Decoded boxes tensor, shared by all scales.
scores – [out] Decoded scores tensor, shared by all scales.
classes – [out] Decoded class identifiers tensor, shared by all scales.
count – [inout] Append cursor. Initialize it to zero before the first scale.
- Return values:
NVCV_ERROR_NOT_IMPLEMENTED – CUDA stream submission is not supported on this platform.
NVCV_ERROR_INVALID_ARGUMENT – The possible cases might be the following: 1) handle or a tensor handle is NULL, or points to an invalid address. 2) A tensor does not meet the requirements used to create the operator handle.
NVCV_ERROR_INTERNAL – Internal error in the operator.
NVCV_SUCCESS – Operation submitted successfully.