Objectness
File:
/src/nms.hppLines 76–110 /**
* @brief This function takes as input a tensor with box coordinates, objectness probability and class scores and
* returns a tensor of box coordinates and another tensor with class scores.
*
* @tparam numBoxes The number of boxes in the input tensor.
* @tparam numClasses The number of classes in the input tensor.
* @tparam InputShape the shape of the input tensor.
* @tparam InFracBits The number of fractional bits in the input type of the input tensor.
* @tparam OutputBoxShape The shape of the output box tensor.
* @tparam BoxFracBits The number of fractional bits in the type of the box tensor.
* @tparam OutputScoreShape The shape of the output score tensor.
* @tparam ScoreFracBits The number of fractional bits in the type of the output score tensor.
* @tparam numValidBoxes The maximum number of boxes selected after objectness filtering.
* @param nmsObj A structure of various constants associated with nms used this function.
* @param ocmRawInp Input tensor with box coordinates, objectness probability and class scores.
* @param ocmValidBoxes Tensor containing valid boxes that are not filtered by NMS.
* @param scores Scores of boxes that are deemed valid and are not filtered by NMS.
* @param confidenceThreshFP Confidence threshold below which bounding boxes will be filtered.
* @return nms_results An integer specifying the number of boxes and associated class scores selected from the input tensor.
*/
// clang-format on
template <std::int32_t numBoxes,
std::int32_t numClasses,
std::int32_t numValidBoxes,
typename InputShape,
FracRepType InFracBits,
typename OutputBoxShape,
FracRepType BoxFracBits,
typename OutputScoreShape,
FracRepType ScoreFracBits>
qVar_t<std::int32_t> nmsObjectness(NmsSpec& nmsObj,
InputShape& ocmRawInp,
OutputBoxShape& ocmValidBoxes,
OutputScoreShape& scores,
FixedPoint<std::int32_t, InFracBits>& confidenceThreshFP) {
Intersection-over-Union (IoU)
File:
/src/nms.hppLines 195–228 /**
* @brief Computes Non-Max Suppression (NMS) of Intersection-over-Union predictions.
*
* The box tensor has a list of boxes, The arrays qSortedR and qTScores are arrays of indices
* and scores (sorted by scores). These are qVars where each core has data for one class.
* The indices specify the box in the boxes tensor. The score is the score for a class for the box.
* A qvar (qValidBoxCount) specifies the number of boxes for each class with valid scores.
* overlapthreshFP is used to eleminate boxes with overlap greater than this threshold.
*
* @tparam BoxTensorShape Shape of the box tensor. It is a 2-dimensional tensor of 4 rows and validBoxSize columns. It has elements of type `FixedPoint<int32, numBoxFracBits>`.
* @tparam boxCacheSize The size of the box Cache array on the core
* @tparam numBoxFracBits The number of fractional bits for the boxes in the box tensor and core box variables
* @tparam numScoreFracBits The number of fractional bits for the scores in the qTScores array.
* @param boxes The input box tensor
* @param vmaxcount The count of valid boxes in the box tensor
* @param qBoxCache An array on the core that is used to cache boxes loaded into the core from OCM. it has a maximum size of boxCacheSize.
* @param qSortedR An array of indices. The index (column number in the box tensor) refers to box in the box tensor.
* @param qTScores An array of scores per class (on each core) of the box referenced by the indices
* @param qValidBoxCount The initial count of valid boxes (indices/scores) per class. These are usually boxes with scores above a scorethreshold
* @param overlapthreshFP The value of overlap threshold
* @return qValidBoxCount The number of valid bounding boxes, i.e. boxes not filtered out by NMS algorithm.
*/
// clang-format on
template <typename BoxTensorShape,
std::int16_t boxCacheSize,
std::uint8_t numBoxFracBits,
std::uint8_t numScoreFracBits>
qVar_t<std::int32_t> nmsIou(BoxTensorShape& boxes,
std::int32_t vmaxcount,
qVar_t<FixedPoint<std::int32_t, numBoxFracBits>> qBoxCache[boxCacheSize][4],
qVar_t<std::int16_t> qSortedR[],
qVar_t<FixedPoint<std::int16_t, numScoreFracBits>> qTScores[],
qVar_t<std::int16_t> qValidBoxCount,
FixedPoint<std::int32_t, numBoxFracBits> overlapthreshFP) {