Skip to main content

VisionProcessor

Struct VisionProcessor 

Source
pub struct VisionProcessor {
    pub patch: usize,
    pub pool_k: usize,
    pub image_budget: usize,
    pub video_budget: usize,
    pub video_fps: f64,
    pub max_frames: usize,
    pub overflow_truncate: bool,
}
Expand description

The processor settings (processor_config.json).

Fields§

§patch: usize§pool_k: usize§image_budget: usize

soft tokens per image (image_processor.max_soft_tokens)

§video_budget: usize

soft tokens per video frame (video_processor.max_soft_tokens)

§video_fps: f64

frames sampled per second of video

§max_frames: usize

sampled frames are cut to this many, evenly (overflow_strategy)

§overflow_truncate: bool

uniform (default) or truncate

Implementations§

Source§

impl VisionProcessor

Source

pub fn from_config(cfg: &Value) -> Self

From processor_config.json (missing fields keep the defaults).

Source

pub fn check_budget(budget: usize) -> Result<usize, String>

budget checked against the five the model was trained for.

Source§

impl VisionProcessor

Source

pub fn resized_size( &self, w: usize, h: usize, budget: usize, ) -> Result<(usize, usize), String>

The size an image of w × h is resized to at budget soft tokens.

Source

pub fn prepare_image( &self, img: &RgbFrame, budget: usize, ) -> Result<VisionInput, String>

Resize (when the size changes) and patchify one image.

Source

pub fn prepare_frames( &self, frames: &[RgbFrame], budget: usize, ) -> Result<Vec<VisionInput>, String>

Video frames (already sampled, one size): each resized to the size frame 0 takes at budget, then patchified.

Source

pub fn sample_indices(&self, total: usize, src_fps: Option<f64>) -> Vec<usize>

The frames of a total-frame video at src_fps the processor keeps: int(i · src_fps / fps) for i < max(1, int(total / src_fps · fps)), then cut to max_frames (evenly, np.linspace(..., dtype=int), or the first ones under truncate). src_fps = None (frames with no rate) keeps every frame and applies only the cap.

Trait Implementations§

Source§

impl Clone for VisionProcessor

Source§

fn clone(&self) -> Self

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 VisionProcessor

Source§

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

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

impl Default for VisionProcessor

Source§

fn default() -> Self

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

impl PartialEq for VisionProcessor

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for VisionProcessor

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<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> 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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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