Skip to main content

Sam3

Struct Sam3 

Source
pub struct Sam3 { /* private fields */ }

Implementations§

Source§

impl Sam3

Source

pub fn from_checkpoint( weights_path: &str, cfg: Sam3Config, ) -> Result<Sam3, Error>

Load a SAM3 checkpoint for native inference.

Load from .safetensors or .gguf (general.architecture = sam3).

For PyTorch checkpoints, convert with tests/sam3_parity_helpers/pt_to_safetensors.py or use community GGUF (e.g. rob-laz/sam3-gguf).

Source

pub fn from_checkpoint_on( weights_path: &str, cfg: Sam3Config, device: Device, ) -> Result<Sam3, Error>

Source

pub fn from_safetensors( weights_path: &str, cfg: Sam3Config, ) -> Result<Sam3, Error>

Source

pub fn from_safetensors_on( weights_path: &str, cfg: Sam3Config, device: Device, ) -> Result<Sam3, Error>

Source

pub fn compile_profile(&self) -> &CompileProfile

Tier-1 compile profile (sam.rlx.toml next to weights when present).

Source

pub fn config(&self) -> &Sam3Config

Source

pub fn tracker_weights(&self) -> &Sam3TrackerWeights

Returns the loaded tracker weights (used by the video basic test to confirm checkpoint coverage).

Source

pub fn encoder_weights(&self) -> &Sam3EncoderWeights

Source

pub fn decoder_weights(&self) -> &Sam3DecoderWeights

Source

pub fn device(&self) -> Device

Source

pub fn encode_image( &self, image_u8: &[u8], h_in: usize, w_in: usize, ) -> Result<Sam3EncodedImage, Error>

Source

pub fn predict_image_text( &mut self, image_u8: &[u8], h_in: usize, w_in: usize, tokens: &[u32], ) -> Result<Sam3ImagePrediction, Error>

Run the vision trunk + 4-scale neck and return per-level [channels, h, w] feature maps with matching sinusoidal positional encodings. Used by the detector and as a parity gate. End-to-end image inference with a pre-tokenized text prompt (tokens has length seq_len == decoder context length, usually 32). Returns the same 3-tuple the public Sam3Processor.set_text_ prompt exposes — without NMS / score thresholding, which we leave to callers so parity tests can compare raw model outputs.

Source

pub fn run_segmentation( &mut self, enc_memory_bf: &[f32], backbone_fpn: &[Vec<f32>], backbone_shapes: &[(usize, usize)], obj_queries_last_bf: &[f32], prompt_seq_first: &[f32], prompt_kpm: &[u8], batch: usize, enc_h: usize, enc_w: usize, num_queries: usize, seq_len: usize, ) -> Result<Sam3SegmentationOutput, Error>

Forward the segmentation head: cross-attend encoder memory to the text prompt, run the pixel decoder, and emit per-query mask logits plus the semantic mask.

Source

pub fn run_dot_prod_scoring( &self, hs_bf: &[f32], prompt_seq_first: &[f32], prompt_kpm: &[u8], num_layers: usize, batch: usize, num_queries: usize, seq_len: usize, ) -> Result<Vec<f32>, Error>

Compute per-query, per-layer scores via mean-pooled text + linear projections + dot product.

Source

pub fn run_decoder( &self, memory: &[f32], memory_pos: &[f32], memory_text: &[f32], text_attention_mask: &[u8], batch: usize, h: usize, w: usize, seq_len: usize, ) -> Result<Sam3DecoderOutput, Error>

Run the detector decoder. Inputs are the encoder memory in batch-first flat [batch, h*w, 256] plus matching positional encoding, and the text memory in seq-first [seq, batch, 256]. Returns intermediate layer outputs, refined boxes, and presence logits — the same triple the upstream model uses to derive scores and final box predictions.

Source

pub fn run_encoder( &self, src_bchw: &[f32], src_pos_bchw: &[f32], prompt_seq_first: &[f32], prompt_kpm: &[u8], batch: usize, src_h: usize, src_w: usize, prompt_len: usize, ) -> Result<Vec<f32>, Error>

Run the detector encoder fusion on a single FPN level + text prompt. Returns the encoded image memory in batch-first flat [batch, h*w, 256].

Source

pub fn encode_text_tokens( &self, tokens: &[u32], batch: usize, seq_len: usize, ) -> Result<Sam3TextEncoded, Error>

Run the text encoder on already-tokenized inputs. Returns the resized memory the detector consumes.

Source

pub fn predict_neck( &mut self, image_u8: &[u8], h_in: usize, w_in: usize, ) -> Result<Vec<Sam3FeatureLevel>, Error>

Source

pub fn patch_embed_image( &self, image_u8: &[u8], h_in: usize, w_in: usize, ) -> Result<Sam3EncodedImage, Error>

Source

pub fn predict_image( &mut self, image_u8: &[u8], h_in: usize, w_in: usize, text_prompt: Option<&str>, boxes: Option<&[f32]>, points: Option<(&[f32], &[f32])>, ) -> Result<Sam3ImagePrediction, Error>

Source

pub fn predict_video_frame( &mut self, state: &mut Sam3VideoState, image_u8: &[u8], h_in: usize, w_in: usize, text_prompt: Option<&str>, ) -> Result<Sam3VideoFramePrediction, Error>

Auto Trait Implementations§

§

impl !RefUnwindSafe for Sam3

§

impl !Sync for Sam3

§

impl !UnwindSafe for Sam3

§

impl Freeze for Sam3

§

impl Send for Sam3

§

impl Unpin for Sam3

§

impl UnsafeUnpin for Sam3

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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