MCPcopy Create free account
hub / github.com/ml-explore/mlx-examples / __init__

Method __init__

segment_anything/segment_anything/sam.py:19–47  ·  view source on GitHub ↗

SAM predicts object masks from an image and input prompts. Args: vision_encoder (ImageEncoderViT): The backbone used to encode the image into image embeddings that allow for efficient mask prediction. prompt_encoder (PromptEncoder): Encodes v

(
        self,
        vision_encoder: ImageEncoderViT,
        prompt_encoder: PromptEncoder,
        mask_decoder: MaskDecoder,
        pixel_mean: List[float] = [123.675, 116.28, 103.53],
        pixel_std: List[float] = [58.395, 57.12, 57.375],
    )

Source from the content-addressed store, hash-verified

17 image_format: str = "RGB"
18
19 def __init__(
20 self,
21 vision_encoder: ImageEncoderViT,
22 prompt_encoder: PromptEncoder,
23 mask_decoder: MaskDecoder,
24 pixel_mean: List[float] = [123.675, 116.28, 103.53],
25 pixel_std: List[float] = [58.395, 57.12, 57.375],
26 ) -> None:
27 """
28 SAM predicts object masks from an image and input prompts.
29
30 Args:
31 vision_encoder (ImageEncoderViT): The backbone used to encode the
32 image into image embeddings that allow for efficient mask prediction.
33 prompt_encoder (PromptEncoder): Encodes various types of input prompts.
34 mask_decoder (MaskDecoder): Predicts masks from the image embeddings
35 and encoded prompts.
36 pixel_mean (list(float)): Mean values for normalizing pixels in the input image.
37 pixel_std (list(float)): Std values for normalizing pixels in the input image.
38 """
39 super().__init__()
40 self.vision_encoder = vision_encoder
41 self.prompt_encoder = prompt_encoder
42 self.mask_decoder = mask_decoder
43 self._pixel_mean = mx.array(pixel_mean).reshape(1, 1, -1)
44 self._pixel_std = mx.array(pixel_std).reshape(1, 1, -1)
45 self.shared_image_embedding = PositionEmbeddingRandom(
46 prompt_encoder.embed_dim // 2
47 )
48
49 def __call__(
50 self,

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected