Skip to main content

Sam2HieraConfig

Struct Sam2HieraConfig 

Source
pub struct Sam2HieraConfig {
    pub embed_dim: usize,
    pub num_heads: usize,
    pub stages: Vec<usize>,
    pub global_att_blocks: Vec<usize>,
    pub window_pos_embed_bkg_spatial_size: [usize; 2],
    pub window_spec: [usize; 4],
    pub layer_norm_eps: f64,
    pub mlp_ratio: f64,
    pub qkv_bias: bool,
    pub fpn_out_chans: usize,
}
Expand description

Hiera image-encoder configuration — Tiny, Small, Base+ or Large.

Field names mirror Hiera’s Python kwargs so the values map 1:1 to the published checkpoints.

Fields§

§embed_dim: usize

Stage-0 embedding dimension. Doubles after each Q-pool.

§num_heads: usize

Stage-0 head count. Doubles after each Q-pool.

§stages: Vec<usize>

Number of blocks per stage. stages.len() == 4 for every published Hiera variant (Tiny/Small/Base+/Large).

§global_att_blocks: Vec<usize>

Indices (in the flattened block enumeration across stages) of blocks that use global attention rather than mask-unit (windowed) attention. Always exactly 3 entries in published configs.

§window_pos_embed_bkg_spatial_size: [usize; 2]

Background-pos-embed spatial size: [Ph, Pw] for the learned-pos table that gets bilinear-interpolated to the current grid each forward.

§window_spec: [usize; 4]

Mask-unit window size per stage (in units of post-Q-pool tokens at that stage). Always 4 entries, one per stage.

§layer_norm_eps: f64

LayerNorm eps used throughout the encoder.

§mlp_ratio: f64

MLP expansion ratio (FFN hidden = mlp_ratio · embed_dim).

§qkv_bias: bool

QKV linear bias toggle (always true in published configs).

§fpn_out_chans: usize

Output channels per FPN level (256 for every published config).

Implementations§

Source§

impl Sam2HieraConfig

Source

pub fn tiny() -> Sam2HieraConfig

sam2_hiera_tiny — ~30 M params.

Source

pub fn small() -> Sam2HieraConfig

sam2_hiera_small — ~46 M params.

Source

pub fn base_plus() -> Sam2HieraConfig

sam2_hiera_base_plus — ~80 M params, the recommended default.

Source

pub fn large() -> Sam2HieraConfig

sam2_hiera_large — ~224 M params. The YAML overrides window_pos_embed_bkg_spatial_size to [7, 7] (vs [14, 14] for base+).

Source

pub fn total_blocks(&self) -> usize

Total number of transformer blocks across all stages.

Source

pub fn q_pool_block_indices(&self) -> Vec<usize>

Indices (in the flattened block enumeration) where a Q-pool happens — at the first block of every stage after stage 0.

Reference: in Hiera.__init__ the Q-pool boundaries are cumulative_sum(stages)[:-1], i.e. [s0, s0+s1, s0+s1+s2].

Source

pub fn stage_of_block(&self, block_idx: usize) -> usize

Stage index for the i-th flattened block.

Source

pub fn embed_dim_at_stage(&self, s: usize) -> usize

Embedding dimension at stage s (doubles per Q-pool).

Source

pub fn num_heads_at_stage(&self, s: usize) -> usize

Number of heads at stage s (doubles per Q-pool).

Source

pub fn window_size_at_stage(&self, s: usize) -> usize

Mask-unit window size at stage s.

Source

pub fn grid_size_at_stage(&self, s: usize) -> usize

Per-axis spatial size of the token grid at stage s (before any Q-pool inside the stage — i.e. the size at the stage’s first post-Q-pool block, for s>0, or stage-0 patch grid for s=0).

Trait Implementations§

Source§

impl Clone for Sam2HieraConfig

Source§

fn clone(&self) -> Sam2HieraConfig

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 Sam2HieraConfig

Source§

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

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

impl<'de> Deserialize<'de> for Sam2HieraConfig

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Sam2HieraConfig, <__D as Deserializer<'de>>::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<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, 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> 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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,