Skip to content

Commit

Permalink
Update preprocessor config
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler committed Jul 15, 2024
1 parent ae43fbf commit 860073a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions mistralrs-core/src/vision_models/preprocessor_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,26 @@ use candle_core::Result;
use image::imageops::FilterType;
use serde::Deserialize;

#[derive(Deserialize, Debug, Clone)]
pub(crate) struct VisionCropParams {
pub(crate) output_size: Vec<usize>,

Check warning on line 9 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (macOS-latest, stable)

field `output_size` is never read

Check failure on line 9 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Clippy

field `output_size` is never read

Check warning on line 9 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

field `output_size` is never read

Check warning on line 9 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Docs

field `output_size` is never read

Check warning on line 9 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

field `output_size` is never read

Check warning on line 9 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

field `output_size` is never read

Check warning on line 9 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

field `output_size` is never read
}

#[derive(Deserialize, Debug, Clone)]
pub(crate) struct VisionNormalizeParams {
pub(crate) inplace: bool,

Check warning on line 14 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (macOS-latest, stable)

fields `inplace`, `mean`, and `std` are never read

Check failure on line 14 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Clippy

fields `inplace`, `mean`, and `std` are never read

Check warning on line 14 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

fields `inplace`, `mean`, and `std` are never read

Check warning on line 14 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Docs

fields `inplace`, `mean`, and `std` are never read

Check warning on line 14 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

fields `inplace`, `mean`, and `std` are never read

Check warning on line 14 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

fields `inplace`, `mean`, and `std` are never read

Check warning on line 14 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

fields `inplace`, `mean`, and `std` are never read
pub(crate) mean: Option<[f64; 3]>,
pub(crate) std: Option<[f64; 3]>,
}

#[derive(Deserialize, Debug, Clone)]
pub(crate) struct VisionResizeParams {
pub(crate) antialias: bool,

Check warning on line 21 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (macOS-latest, stable)

fields `antialias`, `interpolation`, `max_size`, and `size` are never read

Check failure on line 21 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Clippy

fields `antialias`, `interpolation`, `max_size`, and `size` are never read

Check warning on line 21 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (ubuntu-latest, stable)

fields `antialias`, `interpolation`, `max_size`, and `size` are never read

Check warning on line 21 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Docs

fields `antialias`, `interpolation`, `max_size`, and `size` are never read

Check warning on line 21 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Check (windows-latest, stable)

fields `antialias`, `interpolation`, `max_size`, and `size` are never read

Check warning on line 21 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Test Suite (ubuntu-latest, stable)

fields `antialias`, `interpolation`, `max_size`, and `size` are never read

Check warning on line 21 in mistralrs-core/src/vision_models/preprocessor_config.rs

View workflow job for this annotation

GitHub Actions / Test Suite (macOS-latest, stable)

fields `antialias`, `interpolation`, `max_size`, and `size` are never read
pub(crate) interpolation: usize,
pub(crate) max_size: Option<usize>,
pub(crate) size: (usize, usize),
}

#[derive(Deserialize, Debug, Clone)]
#[allow(dead_code)]
pub struct PreProcessorConfig {
Expand All @@ -22,6 +42,17 @@ pub struct PreProcessorConfig {
pub(crate) crop_size: Option<HashMap<String, u32>>,
pub(crate) num_img_tokens: Option<usize>,
pub(crate) num_crops: Option<usize>,
// OpenVLA
pub(crate) means: Option<Vec<[f64; 3]>>,
pub(crate) stds: Option<Vec<[f64; 3]>>,
pub(crate) input_sizes: Option<Vec<[usize; 3]>>,
pub(crate) tvf_crop_params: Option<Vec<VisionCropParams>>,
pub(crate) tvf_do_letterbox: Option<bool>,
pub(crate) tvf_letterbox_fill: Option<(usize, usize, usize)>,
pub(crate) tvf_normalize_params: Option<Vec<VisionNormalizeParams>>,
pub(crate) tvf_resize_params: Option<Vec<VisionResizeParams>>,
pub(crate) use_fused_vision_backbone: Option<bool>,
pub(crate) interpolations: Option<Vec<String>>,
}

#[allow(dead_code)]
Expand All @@ -43,3 +74,17 @@ impl ToFilter for Option<usize> {
}
}
}

impl ToFilter for String {
// https://github.com/python-pillow/Pillow/blob/4b68563e8a818fb9c528fa159ddf3f4eaefa35e6/src/PIL/Image.py#L164-L170
// Default: https://github.com/huggingface/transformers/blob/0df888ffb72ea370555efdef45985378d3cc7b2b/src/transformers/models/idefics2/image_processing_idefics2.py#L226
fn to_filter(self) -> Result<FilterType> {
match self.to_lowercase().as_str() {
"nearest" => Ok(FilterType::Nearest),
"lanczos" => Ok(FilterType::Lanczos3),
"bilinear" => Ok(FilterType::Triangle), // BiLinear
"bicubic" => Ok(FilterType::CatmullRom), // BiCubic
x => candle_core::bail!("Filter {x} not supported"),
}
}
}

0 comments on commit 860073a

Please sign in to comment.