mistralrs_core/vision_models/
preprocessor_config.rsuse std::collections::HashMap;
use candle_core::Result;
use image::imageops::FilterType;
use serde::Deserialize;
#[derive(Deserialize, Debug, Clone)]
#[allow(dead_code)]
pub struct PreProcessorConfig {
pub(crate) do_convert_rgb: Option<bool>,
pub(crate) do_image_splitting: Option<bool>,
pub(crate) do_normalize: Option<bool>,
pub(crate) do_pad: Option<bool>,
pub(crate) do_rescale: Option<bool>,
pub(crate) do_resize: Option<bool>,
pub(crate) do_center_crop: Option<bool>,
pub(crate) image_mean: Option<[f64; 3]>,
pub(crate) image_std: Option<[f64; 3]>,
pub(crate) rescale_factor: Option<f64>,
pub(crate) resampling: Option<usize>,
pub(crate) max_image_size: Option<HashMap<String, u32>>,
pub(crate) size: Option<HashMap<String, u32>>,
pub(crate) crop_size: Option<HashMap<String, u32>>,
pub(crate) num_img_tokens: Option<usize>,
pub(crate) num_crops: Option<usize>,
pub(crate) max_image_tiles: Option<usize>,
pub(crate) min_pixels: Option<usize>,
pub(crate) max_pixels: Option<usize>,
pub(crate) patch_size: Option<usize>,
pub(crate) merge_size: Option<usize>,
pub(crate) temporal_patch_size: Option<usize>,
}
#[allow(dead_code)]
pub(crate) trait ToFilter {
fn to_filter(self) -> Result<FilterType>;
}
impl ToFilter for Option<usize> {
fn to_filter(self) -> Result<FilterType> {
match self {
Some(0) => Ok(FilterType::Nearest),
Some(1) => Ok(FilterType::Lanczos3),
Some(2) | None => Ok(FilterType::Triangle), Some(3) => Ok(FilterType::CatmullRom), Some(4) => Ok(FilterType::Nearest),
Some(x) => candle_core::bail!("Filter number {x} not supported"),
}
}
}