pub struct PreProcessorConfig {Show 29 fields
pub image_processor_type: Option<String>,
pub do_convert_rgb: Option<bool>,
pub do_normalize: Option<bool>,
pub do_pad: Option<bool>,
pub do_rescale: Option<bool>,
pub do_resize: Option<bool>,
pub do_center_crop: Option<bool>,
pub image_mean: Option<Vec<f64>>,
pub image_std: Option<Vec<f64>>,
pub rescale_factor: Option<f64>,
pub resampling: Option<usize>,
pub size: Option<HashMap<String, u32>>,
pub crop_size: Option<HashMap<String, u32>>,
pub patch_size: Option<PatchSize>,
pub merge_size: Option<usize>,
pub min_pixels: Option<usize>,
pub max_pixels: Option<usize>,
pub temporal_patch_size: Option<usize>,
pub num_crops: Option<usize>,
pub dynamic_hd: Option<usize>,
pub max_image_tiles: Option<usize>,
pub num_img_tokens: Option<usize>,
pub im_start_token: Option<String>,
pub im_end_token: Option<String>,
pub slice_start_token: Option<String>,
pub slice_end_token: Option<String>,
pub vision_start_token: Option<String>,
pub vision_end_token: Option<String>,
pub extra: HashMap<String, Value>,
}Expand description
HuggingFace preprocessor_config.json structure.
This struct captures the common fields across different vision model processors.
Model-specific fields are accessed via the flexible extra field.
Fields§
§image_processor_type: Option<String>Processor class name (e.g., “CLIPImageProcessor”, “Qwen2VLImageProcessor”)
do_convert_rgb: Option<bool>Whether to convert to RGB
do_normalize: Option<bool>Whether to normalize with mean/std
do_pad: Option<bool>Whether to pad images
do_rescale: Option<bool>Whether to rescale pixel values (typically by 1/255)
do_resize: Option<bool>Whether to resize images
do_center_crop: Option<bool>Whether to center crop after resizing
image_mean: Option<Vec<f64>>Per-channel normalization mean
image_std: Option<Vec<f64>>Per-channel normalization std
rescale_factor: Option<f64>Rescale factor (typically 1/255 = 0.00392156862745098)
resampling: Option<usize>PIL resampling filter enum (0=Nearest, 1=Lanczos, 2=Bilinear, 3=Bicubic)
size: Option<HashMap<String, u32>>Target size for resizing Can be {“height”: H, “width”: W} or {“shortest_edge”: S}
crop_size: Option<HashMap<String, u32>>Target size for center cropping
patch_size: Option<PatchSize>Vision encoder patch size (typically 14 or 16) Can be an integer or a dict {“height”: x, “width”: y}
merge_size: Option<usize>Qwen-VL: merge size for token reduction
min_pixels: Option<usize>Qwen-VL: minimum total pixels
max_pixels: Option<usize>Qwen-VL: maximum total pixels
temporal_patch_size: Option<usize>Qwen-VL: temporal patch size for video
num_crops: Option<usize>Phi3-Vision: number of image crops
dynamic_hd: Option<usize>Phi4-Vision: dynamic HD max crops
max_image_tiles: Option<usize>LLaMA-Vision: maximum image tiles
num_img_tokens: Option<usize>Fixed number of image tokens (some models use this)
im_start_token: Option<String>Image start token
im_end_token: Option<String>Image end token
slice_start_token: Option<String>Slice start token (for multi-crop)
slice_end_token: Option<String>Slice end token
vision_start_token: Option<String>Vision start token (alternative naming)
vision_end_token: Option<String>Vision end token
extra: HashMap<String, Value>Catch-all for model-specific fields not explicitly defined
Implementations§
Source§impl PreProcessorConfig
impl PreProcessorConfig
pub const CLIP_MEAN: [f64; 3]
pub const CLIP_STD: [f64; 3]
pub const IMAGENET_MEAN: [f64; 3]
pub const IMAGENET_STD: [f64; 3]
pub const SIGLIP_MEAN: [f64; 3]
pub const SIGLIP_STD: [f64; 3]
Sourcepub fn from_json(json: &str) -> Result<Self, Error>
pub fn from_json(json: &str) -> Result<Self, Error>
Parse from JSON string.
Handles both standard HuggingFace format (top-level fields) and Kimi-K2.5’s
nested format where values are under media_proc_cfg.
Sourcepub fn from_value(value: Value) -> Result<Self, Error>
pub fn from_value(value: Value) -> Result<Self, Error>
Parse from JSON value.
Handles both standard HuggingFace format (top-level fields) and Kimi-K2.5’s
nested format where values are under media_proc_cfg.
Sourcepub fn get_patch_size(&self, default: usize) -> usize
pub fn get_patch_size(&self, default: usize) -> usize
Get patch size as a simple usize.
Returns the height value from PatchSize if available, falling back to provided default.
Sourcepub fn get_image_mean(&self) -> [f64; 3]
pub fn get_image_mean(&self) -> [f64; 3]
Get image mean as fixed array, with fallback to CLIP defaults.
Sourcepub fn get_image_std(&self) -> [f64; 3]
pub fn get_image_std(&self) -> [f64; 3]
Get image std as fixed array, with fallback to CLIP defaults.
Sourcepub fn get_target_size(&self) -> Option<(u32, u32)>
pub fn get_target_size(&self) -> Option<(u32, u32)>
Get target size from various config formats.
Handles both {"height": H, "width": W} and {"shortest_edge": S} formats.
Returns (height, width).
Sourcepub fn get_crop_size(&self) -> Option<(u32, u32)>
pub fn get_crop_size(&self) -> Option<(u32, u32)>
Get crop size.
Returns (height, width).
Sourcepub fn get_filter(&self) -> FilterType
pub fn get_filter(&self) -> FilterType
Get the interpolation filter for resizing.
Sourcepub fn should_normalize(&self) -> bool
pub fn should_normalize(&self) -> bool
Check if normalization should be applied.
Sourcepub fn should_rescale(&self) -> bool
pub fn should_rescale(&self) -> bool
Check if rescaling should be applied.
Sourcepub fn should_resize(&self) -> bool
pub fn should_resize(&self) -> bool
Check if resizing should be applied.
Sourcepub fn should_center_crop(&self) -> bool
pub fn should_center_crop(&self) -> bool
Check if center cropping should be applied.
Sourcepub fn get_rescale_factor(&self) -> f64
pub fn get_rescale_factor(&self) -> f64
Get rescale factor with default.
Sourcepub fn get_extra<T: DeserializeOwned>(&self, key: &str) -> Option<T>
pub fn get_extra<T: DeserializeOwned>(&self, key: &str) -> Option<T>
Get a typed extra field.
Trait Implementations§
Source§impl Clone for PreProcessorConfig
impl Clone for PreProcessorConfig
Source§fn clone(&self) -> PreProcessorConfig
fn clone(&self) -> PreProcessorConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for PreProcessorConfig
impl Debug for PreProcessorConfig
Source§impl Default for PreProcessorConfig
impl Default for PreProcessorConfig
Source§fn default() -> PreProcessorConfig
fn default() -> PreProcessorConfig
Source§impl<'de> Deserialize<'de> for PreProcessorConfig
impl<'de> Deserialize<'de> for PreProcessorConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for PreProcessorConfig
impl RefUnwindSafe for PreProcessorConfig
impl Send for PreProcessorConfig
impl Sync for PreProcessorConfig
impl Unpin for PreProcessorConfig
impl UnsafeUnpin for PreProcessorConfig
impl UnwindSafe for PreProcessorConfig
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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