Expand description
§EdgeFirst HAL - Decoders
This crate provides decoding utilities for YOLOobject detection and segmentation models, and ModelPack detection and segmentation models. It supports both floating-point and quantized model outputs, allowing for efficient processing on edge devices. The crate includes functions for efficient post-processing model outputs into usable detection boxes and segmentation masks, as well as utilities for dequantizing model outputs..
For general usage, use the Decoder struct which provides functions for decoding various model outputs based on the model configuration.
If you already know the model type and output formats, you can use the lower-level functions directly from the yolo and modelpack modules.
§Quick Example
// Create a decoder for a YOLOv8 model with quantized int8 output with 0.25 score threshold and 0.7 IOU threshold
let decoder = DecoderBuilder::new()
.with_config_yolo_det(configs::Detection {
anchors: None,
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.012345, 26)),
shape: vec![1, 84, 8400],
dshape: Vec::new(),
normalized: Some(true),
},
Some(DecoderVersion::Yolov8))
.with_score_threshold(0.25)
.with_iou_threshold(0.7)
.build()?;
// Get the model output from the model. Here we load it from a test data file for demonstration purposes.
let model_output: Vec<i8> = include_bytes!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../testdata/yolov8s_80_classes.bin"))
.iter()
.map(|b| *b as i8)
.collect();
let model_output_array = ndarray::Array3::from_shape_vec((1, 84, 8400), model_output)?;
// THe capacity is used to determine the maximum number of detections to decode.
let mut output_boxes: Vec<_> = Vec::with_capacity(10);
let mut output_masks: Vec<_> = Vec::with_capacity(10);
// Decode the quantized model output into detection boxes and segmentation masks
// Because this model is a detection-only model, the `output_masks` vector will remain empty.
decoder.decode_quantized(&[model_output_array.view().into()], &mut output_boxes, &mut output_masks)?;§Overview
The primary components of this crate are:
Decoder/DecoderBuilderstruct: Provides high-level functions to decode model outputs based on the model configuration.yolomodule: Contains functions specific to decoding YOLO model outputs.modelpackmodule: Contains functions specific to decoding ModelPack model outputs.
The Decoder supports both floating-point and quantized model outputs, allowing for efficient processing on edge devices.
It also supports mixed integer types for quantized outputs, such as when one output tensor is int8 and another is uint8.
When decoding quantized outputs, the appropriate quantization parameters must be provided for each output tensor.
If the integer types used in the model output is not supported by the decoder, the user can manually dequantize the model outputs using
the dequantize functions provided in this crate, and then use the floating-point decoding functions. However, it is recommended
to not dequantize the model outputs manually before passing them to the decoder, as the quantized decoder functions are optimized for performance.
The yolo and modelpack modules provide lower-level functions for decoding model outputs directly,
which can be used if the model type and output formats are known in advance.
Re-exports§
pub use error::DecoderError;pub use error::DecoderResult;
Modules§
Structs§
- Bounding
Box - A bounding box with f32 coordinates in XYXY format
- Config
Outputs - Used to represent the outputs in the model configuration.
- Decoder
- Decoder
Builder - Detect
Box - A detection box with f32 bbox and score
- Detect
BoxQuantized - A detection box with a f32 bbox and quantized score
- Proto
Data - Raw prototype data for fused decode+render pipelines.
- Quantization
- Describes the quantization parameters for a tensor
- Segmentation
- A segmentation result with a segmentation mask, and a normalized bounding box representing the area that the segmentation mask covers
- XYWH
- Converts XYWH bounding boxes to XYXY. The XY values are the center of the box
- XYXY
- Converts XYXY bounding boxes to XYXY
Enums§
- Array
ViewD Quantized - Config
Output - Config
Output Ref - Decoder
Version - Decoder version for Ultralytics models.
- Nms
- NMS (Non-Maximum Suppression) mode for filtering overlapping detections.
- Proto
Tensor - Prototype tensor variants for fused decode+render pipelines.
Traits§
- BBox
Type Trait - Trait to convert bounding box formats to XYXY float format
Functions§
- dequant_
detect_ box - Turns a DetectBoxQuantized into a DetectBox by dequantizing the score.
- dequantize_
cpu - Dequantizes a slice from quantized values to float values using the given quantization parameters
- dequantize_
cpu_ chunked - Dequantizes a slice from quantized values to float values using the given
quantization parameters, using chunked processing. This is around 5% faster
than
dequantize_cpufor large slices. - dequantize_
ndarray - Dequantizes an ndarray from quantized values to f32 values using the given quantization parameters
- segmentation_
to_ mask - Converts a segmentation tensor into a 2D mask If the last dimension of the segmentation tensor is 1, values equal or above 128 are considered objects. Otherwise the object is the argmax index