use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ShapeCompatibilityStrategy {
Exact,
AspectRatio {
tolerance: f32,
},
MaxDimension {
bucket_size: u32,
},
Custom {
targets: Vec<(u32, u32)>,
tolerance: f32,
},
}
impl Default for ShapeCompatibilityStrategy {
fn default() -> Self {
Self::AspectRatio { tolerance: 0.1 }
}
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PaddingStrategy {
Zero,
Center {
fill_color: [u8; 3],
},
Edge,
Smart,
}
impl Default for PaddingStrategy {
fn default() -> Self {
Self::Center {
fill_color: [0, 0, 0],
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DynamicBatchConfig {
pub max_detection_batch_size: usize,
pub max_recognition_batch_size: usize,
pub min_batch_size: usize,
pub shape_compatibility: ShapeCompatibilityStrategy,
pub padding_strategy: PaddingStrategy,
}
impl Default for DynamicBatchConfig {
fn default() -> Self {
Self {
max_detection_batch_size: 8,
max_recognition_batch_size: 16,
min_batch_size: 2,
shape_compatibility: ShapeCompatibilityStrategy::default(),
padding_strategy: PaddingStrategy::default(),
}
}
}
impl DynamicBatchConfig {
pub fn new() -> Self {
Self::default()
}
pub fn with_max_detection_batch_size(mut self, size: usize) -> Self {
self.max_detection_batch_size = size;
self
}
pub fn with_max_recognition_batch_size(mut self, size: usize) -> Self {
self.max_recognition_batch_size = size;
self
}
pub fn with_min_batch_size(mut self, size: usize) -> Self {
self.min_batch_size = size;
self
}
pub fn with_shape_compatibility(mut self, strategy: ShapeCompatibilityStrategy) -> Self {
self.shape_compatibility = strategy;
self
}
pub fn with_padding_strategy(mut self, strategy: PaddingStrategy) -> Self {
self.padding_strategy = strategy;
self
}
}