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: usizeStage-0 embedding dimension. Doubles after each Q-pool.
num_heads: usizeStage-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: f64LayerNorm eps used throughout the encoder.
mlp_ratio: f64MLP expansion ratio (FFN hidden = mlp_ratio · embed_dim).
qkv_bias: boolQKV linear bias toggle (always true in published configs).
fpn_out_chans: usizeOutput channels per FPN level (256 for every published config).
Implementations§
Source§impl Sam2HieraConfig
impl Sam2HieraConfig
Sourcepub fn tiny() -> Sam2HieraConfig
pub fn tiny() -> Sam2HieraConfig
sam2_hiera_tiny — ~30 M params.
Sourcepub fn small() -> Sam2HieraConfig
pub fn small() -> Sam2HieraConfig
sam2_hiera_small — ~46 M params.
Sourcepub fn base_plus() -> Sam2HieraConfig
pub fn base_plus() -> Sam2HieraConfig
sam2_hiera_base_plus — ~80 M params, the recommended default.
Sourcepub fn large() -> Sam2HieraConfig
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+).
Sourcepub fn total_blocks(&self) -> usize
pub fn total_blocks(&self) -> usize
Total number of transformer blocks across all stages.
Sourcepub fn q_pool_block_indices(&self) -> Vec<usize>
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].
Sourcepub fn stage_of_block(&self, block_idx: usize) -> usize
pub fn stage_of_block(&self, block_idx: usize) -> usize
Stage index for the i-th flattened block.
Sourcepub fn embed_dim_at_stage(&self, s: usize) -> usize
pub fn embed_dim_at_stage(&self, s: usize) -> usize
Embedding dimension at stage s (doubles per Q-pool).
Sourcepub fn num_heads_at_stage(&self, s: usize) -> usize
pub fn num_heads_at_stage(&self, s: usize) -> usize
Number of heads at stage s (doubles per Q-pool).
Sourcepub fn window_size_at_stage(&self, s: usize) -> usize
pub fn window_size_at_stage(&self, s: usize) -> usize
Mask-unit window size at stage s.
Sourcepub fn grid_size_at_stage(&self, s: usize) -> usize
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
impl Clone for Sam2HieraConfig
Source§fn clone(&self) -> Sam2HieraConfig
fn clone(&self) -> Sam2HieraConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Sam2HieraConfig
impl Debug for Sam2HieraConfig
Source§impl<'de> Deserialize<'de> for Sam2HieraConfig
impl<'de> Deserialize<'de> for Sam2HieraConfig
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Sam2HieraConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Sam2HieraConfig, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for Sam2HieraConfig
impl RefUnwindSafe for Sam2HieraConfig
impl Send for Sam2HieraConfig
impl Sync for Sam2HieraConfig
impl Unpin for Sam2HieraConfig
impl UnsafeUnpin for Sam2HieraConfig
impl UnwindSafe for Sam2HieraConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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