Skip to main content

PreProcessorConfig

Struct PreProcessorConfig 

Source
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

Source

pub const CLIP_MEAN: [f64; 3]

Source

pub const CLIP_STD: [f64; 3]

Source

pub const IMAGENET_MEAN: [f64; 3]

Source

pub const IMAGENET_STD: [f64; 3]

Source

pub const SIGLIP_MEAN: [f64; 3]

Source

pub const SIGLIP_STD: [f64; 3]

Source

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.

Source

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.

Source

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.

Source

pub fn get_image_mean(&self) -> [f64; 3]

Get image mean as fixed array, with fallback to CLIP defaults.

Source

pub fn get_image_std(&self) -> [f64; 3]

Get image std as fixed array, with fallback to CLIP defaults.

Source

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).

Source

pub fn get_crop_size(&self) -> Option<(u32, u32)>

Get crop size.

Returns (height, width).

Source

pub fn get_filter(&self) -> FilterType

Get the interpolation filter for resizing.

Source

pub fn should_normalize(&self) -> bool

Check if normalization should be applied.

Source

pub fn should_rescale(&self) -> bool

Check if rescaling should be applied.

Source

pub fn should_resize(&self) -> bool

Check if resizing should be applied.

Source

pub fn should_center_crop(&self) -> bool

Check if center cropping should be applied.

Source

pub fn get_rescale_factor(&self) -> f64

Get rescale factor with default.

Source

pub fn get_extra<T: DeserializeOwned>(&self, key: &str) -> Option<T>

Get a typed extra field.

Trait Implementations§

Source§

impl Clone for PreProcessorConfig

Source§

fn clone(&self) -> PreProcessorConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PreProcessorConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for PreProcessorConfig

Source§

fn default() -> PreProcessorConfig

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for PreProcessorConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more