pub struct DecoderBuilder { /* private fields */ }Implementations§
Source§impl DecoderBuilder
impl DecoderBuilder
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a default DecoderBuilder with no configuration and 0.5 score threshold and 0.5 IoU threshold.
A valid configuration must be provided before building the Decoder.
§Examples
let decoder = DecoderBuilder::new()
.with_config_yaml_str(config_yaml)
.build()?;
assert_eq!(decoder.score_threshold, 0.5);
assert_eq!(decoder.iou_threshold, 0.5);
Sourcepub fn with_config_yaml_str(self, yaml_str: String) -> Self
pub fn with_config_yaml_str(self, yaml_str: String) -> Self
Loads a model configuration in YAML format. Does not check if the string
is a correct configuration file. Use DecoderBuilder.build() to
deserialize the YAML and parse the model configuration.
§Examples
let config_yaml = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../testdata/modelpack_split.yaml")).to_string();
let decoder = DecoderBuilder::new()
.with_config_yaml_str(config_yaml)
.build()?;
Sourcepub fn with_config_json_str(self, json_str: String) -> Self
pub fn with_config_json_str(self, json_str: String) -> Self
Loads a model configuration in JSON format. Does not check if the string
is a correct configuration file. Use DecoderBuilder.build() to
deserialize the JSON and parse the model configuration.
§Examples
let config_json = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../testdata/modelpack_split.json")).to_string();
let decoder = DecoderBuilder::new()
.with_config_json_str(config_json)
.build()?;
Sourcepub fn with_config(self, config: ConfigOutputs) -> Self
pub fn with_config(self, config: ConfigOutputs) -> Self
Loads a model configuration. Does not check if the configuration is
correct. Intended to be used when the user needs control over the
deserialize of the configuration information. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let config_json = include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/../../testdata/modelpack_split.json"));
let config = serde_json::from_str(config_json)?;
let decoder = DecoderBuilder::new().with_config(config).build()?;
Sourcepub fn with_config_yolo_det(
self,
boxes: Detection,
version: Option<DecoderVersion>,
) -> Self
pub fn with_config_yolo_det( self, boxes: Detection, version: Option<DecoderVersion>, ) -> Self
Loads a YOLO detection model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
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),
},
None,
)
.build()?;
Sourcepub fn with_config_yolo_split_det(self, boxes: Boxes, scores: Scores) -> Self
pub fn with_config_yolo_split_det(self, boxes: Boxes, scores: Scores) -> Self
Loads a YOLO split detection model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let boxes_config = configs::Boxes {
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.012345, 26)),
shape: vec![1, 4, 8400],
dshape: Vec::new(),
normalized: Some(true),
};
let scores_config = configs::Scores {
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 80, 8400],
dshape: Vec::new(),
};
let decoder = DecoderBuilder::new()
.with_config_yolo_split_det(boxes_config, scores_config)
.build()?;Sourcepub fn with_config_yolo_segdet(
self,
boxes: Detection,
protos: Protos,
version: Option<DecoderVersion>,
) -> Self
pub fn with_config_yolo_segdet( self, boxes: Detection, protos: Protos, version: Option<DecoderVersion>, ) -> Self
Loads a YOLO segmentation model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let seg_config = configs::Detection {
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.012345, 26)),
shape: vec![1, 116, 8400],
anchors: None,
dshape: Vec::new(),
normalized: Some(true),
};
let protos_config = configs::Protos {
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 160, 160, 32],
dshape: Vec::new(),
};
let decoder = DecoderBuilder::new()
.with_config_yolo_segdet(
seg_config,
protos_config,
Some(configs::DecoderVersion::Yolov8),
)
.build()?;Sourcepub fn with_config_yolo_split_segdet(
self,
boxes: Boxes,
scores: Scores,
mask_coefficients: MaskCoefficients,
protos: Protos,
) -> Self
pub fn with_config_yolo_split_segdet( self, boxes: Boxes, scores: Scores, mask_coefficients: MaskCoefficients, protos: Protos, ) -> Self
Loads a YOLO split segmentation model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let boxes_config = configs::Boxes {
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.012345, 26)),
shape: vec![1, 4, 8400],
dshape: Vec::new(),
normalized: Some(true),
};
let scores_config = configs::Scores {
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.012345, 14)),
shape: vec![1, 80, 8400],
dshape: Vec::new(),
};
let mask_config = configs::MaskCoefficients {
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.0064123, 125)),
shape: vec![1, 32, 8400],
dshape: Vec::new(),
};
let protos_config = configs::Protos {
decoder: configs::DecoderType::Ultralytics,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 160, 160, 32],
dshape: Vec::new(),
};
let decoder = DecoderBuilder::new()
.with_config_yolo_split_segdet(boxes_config, scores_config, mask_config, protos_config)
.build()?;Sourcepub fn with_config_modelpack_det(self, boxes: Boxes, scores: Scores) -> Self
pub fn with_config_modelpack_det(self, boxes: Boxes, scores: Scores) -> Self
Loads a ModelPack detection model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let boxes_config = configs::Boxes {
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.012345, 26)),
shape: vec![1, 8400, 1, 4],
dshape: Vec::new(),
normalized: Some(true),
};
let scores_config = configs::Scores {
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 8400, 3],
dshape: Vec::new(),
};
let decoder = DecoderBuilder::new()
.with_config_modelpack_det(boxes_config, scores_config)
.build()?;Sourcepub fn with_config_modelpack_det_split(self, boxes: Vec<Detection>) -> Self
pub fn with_config_modelpack_det_split(self, boxes: Vec<Detection>) -> Self
Loads a ModelPack split detection model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let config0 = configs::Detection {
anchors: Some(vec![
[0.13750000298023224, 0.2074074000120163],
[0.2541666626930237, 0.21481481194496155],
[0.23125000298023224, 0.35185185074806213],
]),
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.012345, 26)),
shape: vec![1, 17, 30, 18],
dshape: Vec::new(),
normalized: Some(true),
};
let config1 = configs::Detection {
anchors: Some(vec![
[0.36666667461395264, 0.31481480598449707],
[0.38749998807907104, 0.4740740656852722],
[0.5333333611488342, 0.644444465637207],
]),
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 9, 15, 18],
dshape: Vec::new(),
normalized: Some(true),
};
let decoder = DecoderBuilder::new()
.with_config_modelpack_det_split(vec![config0, config1])
.build()?;Sourcepub fn with_config_modelpack_segdet(
self,
boxes: Boxes,
scores: Scores,
segmentation: Segmentation,
) -> Self
pub fn with_config_modelpack_segdet( self, boxes: Boxes, scores: Scores, segmentation: Segmentation, ) -> Self
Loads a ModelPack segmentation detection model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let boxes_config = configs::Boxes {
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.012345, 26)),
shape: vec![1, 8400, 1, 4],
dshape: Vec::new(),
normalized: Some(true),
};
let scores_config = configs::Scores {
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 8400, 2],
dshape: Vec::new(),
};
let seg_config = configs::Segmentation {
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 640, 640, 3],
dshape: Vec::new(),
};
let decoder = DecoderBuilder::new()
.with_config_modelpack_segdet(boxes_config, scores_config, seg_config)
.build()?;Sourcepub fn with_config_modelpack_segdet_split(
self,
boxes: Vec<Detection>,
segmentation: Segmentation,
) -> Self
pub fn with_config_modelpack_segdet_split( self, boxes: Vec<Detection>, segmentation: Segmentation, ) -> Self
Loads a ModelPack segmentation split detection model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let config0 = configs::Detection {
anchors: Some(vec![
[0.36666667461395264, 0.31481480598449707],
[0.38749998807907104, 0.4740740656852722],
[0.5333333611488342, 0.644444465637207],
]),
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.08547406643629074, 174)),
shape: vec![1, 9, 15, 18],
dshape: Vec::new(),
normalized: Some(true),
};
let config1 = configs::Detection {
anchors: Some(vec![
[0.13750000298023224, 0.2074074000120163],
[0.2541666626930237, 0.21481481194496155],
[0.23125000298023224, 0.35185185074806213],
]),
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.09929127991199493, 183)),
shape: vec![1, 17, 30, 18],
dshape: Vec::new(),
normalized: Some(true),
};
let seg_config = configs::Segmentation {
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 640, 640, 2],
dshape: Vec::new(),
};
let decoder = DecoderBuilder::new()
.with_config_modelpack_segdet_split(vec![config0, config1], seg_config)
.build()?;Sourcepub fn with_config_modelpack_seg(self, segmentation: Segmentation) -> Self
pub fn with_config_modelpack_seg(self, segmentation: Segmentation) -> Self
Loads a ModelPack segmentation model configuration. Use
DecoderBuilder.build() to parse the model configuration.
§Examples
let seg_config = configs::Segmentation {
decoder: configs::DecoderType::ModelPack,
quantization: Some(configs::QuantTuple(0.0064123, -31)),
shape: vec![1, 640, 640, 3],
dshape: Vec::new(),
};
let decoder = DecoderBuilder::new()
.with_config_modelpack_seg(seg_config)
.build()?;Sourcepub fn add_output(self, output: ConfigOutput) -> Self
pub fn add_output(self, output: ConfigOutput) -> Self
Add an output to the decoder configuration.
Incrementally builds the model configuration by adding outputs one at
a time. The decoder resolves the model type from the combination of
outputs during build().
If dshape is non-empty on the output, shape is automatically
derived from it (the size component of each named dimension). This
prevents conflicts between shape and dshape.
This uses the programmatic config path. Calling this after
with_config_json_str() or with_config_yaml_str() replaces the
string-based config source.
§Examples
let decoder = DecoderBuilder::new()
.add_output(ConfigOutput::Scores(configs::Scores {
decoder: configs::DecoderType::Ultralytics,
dshape: vec![
(configs::DimName::Batch, 1),
(configs::DimName::NumClasses, 80),
(configs::DimName::NumBoxes, 8400),
],
..Default::default()
}))
.add_output(ConfigOutput::Boxes(configs::Boxes {
decoder: configs::DecoderType::Ultralytics,
dshape: vec![
(configs::DimName::Batch, 1),
(configs::DimName::BoxCoords, 4),
(configs::DimName::NumBoxes, 8400),
],
..Default::default()
}))
.build()?;Sourcepub fn with_decoder_version(self, version: DecoderVersion) -> Self
pub fn with_decoder_version(self, version: DecoderVersion) -> Self
Sets the decoder version for Ultralytics models.
This is used with add_output() to specify the YOLO architecture
version when it cannot be inferred from the output shapes alone.
Yolov5,Yolov8,Yolo11: Traditional models requiring external NMSYolo26: End-to-end models with NMS embedded in the model graph
§Examples
let decoder = DecoderBuilder::new()
.add_output(ConfigOutput::Detection(configs::Detection {
decoder: configs::DecoderType::Ultralytics,
dshape: vec![
(configs::DimName::Batch, 1),
(configs::DimName::NumBoxes, 100),
(configs::DimName::NumFeatures, 6),
],
..Default::default()
}))
.with_decoder_version(configs::DecoderVersion::Yolo26)
.build()?;Sourcepub fn with_score_threshold(self, score_threshold: f32) -> Self
pub fn with_score_threshold(self, score_threshold: f32) -> Self
Sets the scores threshold of the decoder
§Examples
let decoder = DecoderBuilder::new()
.with_config_json_str(config_json)
.with_score_threshold(0.654)
.build()?;
assert_eq!(decoder.score_threshold, 0.654);Sourcepub fn with_iou_threshold(self, iou_threshold: f32) -> Self
pub fn with_iou_threshold(self, iou_threshold: f32) -> Self
Sets the IOU threshold of the decoder. Has no effect when NMS is set to
None
§Examples
let decoder = DecoderBuilder::new()
.with_config_json_str(config_json)
.with_iou_threshold(0.654)
.build()?;
assert_eq!(decoder.iou_threshold, 0.654);Sourcepub fn with_nms(self, nms: Option<Nms>) -> Self
pub fn with_nms(self, nms: Option<Nms>) -> Self
Sets the NMS mode for the decoder.
Some(Nms::ClassAgnostic)— class-agnostic NMS (default): suppress overlapping boxes regardless of class labelSome(Nms::ClassAware)— class-aware NMS: only suppress boxes that share the same class label AND overlap above the IoU thresholdNone— bypass NMS entirely (for end-to-end models with embedded NMS)
§Examples
let decoder = DecoderBuilder::new()
.with_config_json_str(config_json)
.with_nms(Some(Nms::ClassAware))
.build()?;
assert_eq!(decoder.nms, Some(Nms::ClassAware));Sourcepub fn build(self) -> Result<Decoder, DecoderError>
pub fn build(self) -> Result<Decoder, DecoderError>
Builds the decoder with the given settings. If the config is a JSON or YAML string, this will deserialize the JSON or YAML and then parse the configuration information.
§Examples
let decoder = DecoderBuilder::new()
.with_config_json_str(config_json)
.with_score_threshold(0.654)
.build()?;Trait Implementations§
Source§impl Clone for DecoderBuilder
impl Clone for DecoderBuilder
Source§fn clone(&self) -> DecoderBuilder
fn clone(&self) -> DecoderBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for DecoderBuilder
impl Debug for DecoderBuilder
Source§impl Default for DecoderBuilder
impl Default for DecoderBuilder
Source§fn default() -> Self
fn default() -> Self
Creates a default DecoderBuilder with no configuration and 0.5 score threshold and 0.5 IoU threshold.
A valid configuration must be provided before building the Decoder.
§Examples
let decoder = DecoderBuilder::default()
.with_config_yaml_str(config_yaml)
.build()?;
assert_eq!(decoder.score_threshold, 0.5);
assert_eq!(decoder.iou_threshold, 0.5);
Source§impl PartialEq for DecoderBuilder
impl PartialEq for DecoderBuilder
impl StructuralPartialEq for DecoderBuilder
Auto Trait Implementations§
impl Freeze for DecoderBuilder
impl RefUnwindSafe for DecoderBuilder
impl Send for DecoderBuilder
impl Sync for DecoderBuilder
impl Unpin for DecoderBuilder
impl UnsafeUnpin for DecoderBuilder
impl UnwindSafe for DecoderBuilder
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