pub struct PromptEncoder { /* private fields */ }Expand description
Encodes geometric prompts (points / boxes) into sparse embeddings and a coarse mask into a dense embedding.
Implementations§
Source§impl PromptEncoder
impl PromptEncoder
Sourcepub fn dense_positional_encoding(&self) -> Vec<f32>
pub fn dense_positional_encoding(&self) -> Vec<f32>
Image-grid positional encoding used by the decoder, (e, grid, grid).
Sourcepub fn encode_points(
&self,
coords: &[f32],
labels: &[i32],
) -> VisionResult<Vec<f32>>
pub fn encode_points( &self, coords: &[f32], labels: &[i32], ) -> VisionResult<Vec<f32>>
Encode point prompts.
coords is [n · 2] pixel coordinates; labels[i] is 1 for a
foreground point, 0 for background, and any negative value for a
padding (“not a point”) entry. Returns sparse embeddings [n · e].
§Errors
VisionError::DimensionMismatchifcoords.len() != 2·labels.len().
Sourcepub fn encode_box(&self, box4: &[f32]) -> VisionResult<Vec<f32>>
pub fn encode_box(&self, box4: &[f32]) -> VisionResult<Vec<f32>>
Encode a box prompt [x1, y1, x2, y2] (pixels) into two corner
embeddings [2 · e].
§Errors
VisionError::DimensionMismatchifbox4.len() != 4.
Sourcepub fn encode_mask(&self, mask: Option<&[f32]>) -> VisionResult<Vec<f32>>
pub fn encode_mask(&self, mask: Option<&[f32]>) -> VisionResult<Vec<f32>>
Encode a coarse mask [grid · grid] into a dense embedding
(e, grid, grid). When mask is None, the learned no_mask embedding
is broadcast over the grid.
§Errors
VisionError::DimensionMismatchifmaskisSomebut notgrid · gridlong.
Auto Trait Implementations§
impl Freeze for PromptEncoder
impl RefUnwindSafe for PromptEncoder
impl Send for PromptEncoder
impl Sync for PromptEncoder
impl Unpin for PromptEncoder
impl UnsafeUnpin for PromptEncoder
impl UnwindSafe for PromptEncoder
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
Mutably borrows from an owned value. Read more