pub struct Decoder {
pub iou_threshold: f32,
pub score_threshold: f32,
pub nms: Option<Nms>,
/* private fields */
}Fields§
§iou_threshold: f32§score_threshold: f32§nms: Option<Nms>NMS mode: Some(mode) applies NMS, None bypasses NMS (for end-to-end models)
Implementations§
Source§impl Decoder
impl Decoder
Sourcepub fn model_type(&self) -> &ModelType
pub fn model_type(&self) -> &ModelType
This function returns the parsed model type of the decoder.
§Examples
let decoder = DecoderBuilder::default()
.with_config_yaml_str(config_yaml)
.build()?;
assert!(matches!(
decoder.model_type(),
ModelType::ModelPackDetSplit { .. }
));Sourcepub fn normalized_boxes(&self) -> Option<bool>
pub fn normalized_boxes(&self) -> Option<bool>
Returns the box coordinate format if known from the model config.
Some(true): Boxes are in normalized [0,1] coordinatesSome(false): Boxes are in pixel coordinates relative to model inputNone: Unknown, caller must infer (e.g., check if any coordinate > 1.0)
This is determined by the model config’s normalized field, not the NMS
mode. When coordinates are in pixels or unknown, the caller may need
to normalize using the model input dimensions.
§Examples
let decoder = DecoderBuilder::default()
.with_config_yaml_str(config_yaml)
.build()?;
// Config doesn't specify normalized, so it's None
assert!(decoder.normalized_boxes().is_none());Sourcepub fn decode_quantized(
&self,
outputs: &[ArrayViewDQuantized<'_>],
output_boxes: &mut Vec<DetectBox>,
output_masks: &mut Vec<Segmentation>,
) -> Result<(), DecoderError>
pub fn decode_quantized( &self, outputs: &[ArrayViewDQuantized<'_>], output_boxes: &mut Vec<DetectBox>, output_masks: &mut Vec<Segmentation>, ) -> Result<(), DecoderError>
This function decodes quantized model outputs into detection boxes and
segmentation masks. The quantized outputs can be of u8, i8, u16, i16,
u32, or i32 types. Up to output_boxes.capacity() boxes and masks
will be decoded. The function clears the provided output vectors
before populating them with the decoded results.
This function returns a DecoderError if the the provided outputs don’t
match the configuration provided by the user when building the decoder.
§Examples
let decoder = DecoderBuilder::default()
.with_config_yaml_str(include_str!("../../../testdata/modelpack_split.yaml").to_string())
.with_score_threshold(0.45)
.with_iou_threshold(0.45)
.build()?;
let mut output_boxes: Vec<_> = Vec::with_capacity(10);
let mut output_masks: Vec<_> = Vec::with_capacity(10);
decoder.decode_quantized(&model_output, &mut output_boxes, &mut output_masks)?;
assert!(output_boxes[0].equal_within_delta(
&DetectBox {
bbox: BoundingBox {
xmin: 0.43171933,
ymin: 0.68243736,
xmax: 0.5626645,
ymax: 0.808863,
},
score: 0.99240804,
label: 0
},
1e-6
));Sourcepub fn decode_float<T>(
&self,
outputs: &[ArrayViewD<'_, T>],
output_boxes: &mut Vec<DetectBox>,
output_masks: &mut Vec<Segmentation>,
) -> Result<(), DecoderError>
pub fn decode_float<T>( &self, outputs: &[ArrayViewD<'_, T>], output_boxes: &mut Vec<DetectBox>, output_masks: &mut Vec<Segmentation>, ) -> Result<(), DecoderError>
This function decodes floating point model outputs into detection boxes
and segmentation masks. Up to output_boxes.capacity() boxes and
masks will be decoded. The function clears the provided output
vectors before populating them with the decoded results.
This function returns an Error if the the provided outputs don’t
match the configuration provided by the user when building the decoder.
Any quantization information in the configuration will be ignored.
§Examples
let decoder = DecoderBuilder::default()
.with_config_yolo_det(configs::Detection {
decoder: DecoderType::Ultralytics,
quantization: None,
shape: vec![1, 84, 8400],
anchors: None,
dshape: Vec::new(),
normalized: Some(true),
},
Some(DecoderVersion::Yolo11))
.with_score_threshold(0.25)
.with_iou_threshold(0.7)
.build()?;
let mut output_boxes: Vec<_> = Vec::with_capacity(10);
let mut output_masks: Vec<_> = Vec::with_capacity(10);
let model_output_f64 = vec![model_output_f64.view().into()];
decoder.decode_float(&model_output_f64, &mut output_boxes, &mut output_masks)?;
assert!(output_boxes[0].equal_within_delta(
&DetectBox {
bbox: BoundingBox {
xmin: 0.5285137,
ymin: 0.05305544,
xmax: 0.87541467,
ymax: 0.9998909,
},
score: 0.5591227,
label: 0
},
1e-6
));
Sourcepub fn decode_quantized_proto(
&self,
outputs: &[ArrayViewDQuantized<'_>],
output_boxes: &mut Vec<DetectBox>,
) -> Result<Option<ProtoData>, DecoderError>
pub fn decode_quantized_proto( &self, outputs: &[ArrayViewDQuantized<'_>], output_boxes: &mut Vec<DetectBox>, ) -> Result<Option<ProtoData>, DecoderError>
Decodes quantized model outputs into detection boxes, returning raw
ProtoData for segmentation models instead of materialized masks.
Returns Ok(None) for detection-only and ModelPack models (use
decode_quantized for those). Returns Ok(Some(ProtoData)) for
YOLO segmentation models.
Sourcepub fn decode_float_proto<T>(
&self,
outputs: &[ArrayViewD<'_, T>],
output_boxes: &mut Vec<DetectBox>,
) -> Result<Option<ProtoData>, DecoderError>
pub fn decode_float_proto<T>( &self, outputs: &[ArrayViewD<'_, T>], output_boxes: &mut Vec<DetectBox>, ) -> Result<Option<ProtoData>, DecoderError>
Decodes floating-point model outputs into detection boxes, returning
raw ProtoData for segmentation models instead of materialized masks.
Returns Ok(None) for detection-only and ModelPack models. Returns
Ok(Some(ProtoData)) for YOLO segmentation models.
Trait Implementations§
impl StructuralPartialEq for Decoder
Auto Trait Implementations§
impl Freeze for Decoder
impl RefUnwindSafe for Decoder
impl Send for Decoder
impl Sync for Decoder
impl Unpin for Decoder
impl UnsafeUnpin for Decoder
impl UnwindSafe for Decoder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more