Skip to content

Sam2

Sam2EmbeddingResponse

Bases: BaseModel

SAM embedding response.

Attributes:

Name Type Description
embeddings Union[List[List[List[List[float]]]], Any]

The SAM embedding.

time float

The time in seconds it took to produce the embeddings including preprocessing.

Source code in inference/core/entities/responses/sam2.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class Sam2EmbeddingResponse(BaseModel):
    """SAM embedding response.

    Attributes:
        embeddings (Union[List[List[List[List[float]]]], Any]): The SAM embedding.
        time (float): The time in seconds it took to produce the embeddings including preprocessing.
    """

    image_id: str = Field(description="Image id embeddings are cached to")
    time: float = Field(
        description="The time in seconds it took to produce the embeddings including preprocessing"
    )

Sam2SegmentationPrediction

Bases: BaseModel

SAM segmentation prediction.

Attributes:

Name Type Description
masks Union[List[List[List[int]]], Dict[str, Any], Any]

Mask data - either polygon coordinates or RLE encoding.

confidence float

Masks confidences.

format Optional[str]

Format of the mask data: 'polygon' or 'rle'.

Source code in inference/core/entities/responses/sam2.py
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Sam2SegmentationPrediction(BaseModel):
    """SAM segmentation prediction.

    Attributes:
        masks (Union[List[List[List[int]]], Dict[str, Any], Any]): Mask data - either polygon coordinates or RLE encoding.
        confidence (float): Masks confidences.
        format (Optional[str]): Format of the mask data: 'polygon' or 'rle'.
    """

    masks: Union[List[List[List[int]]], Dict[str, Any]] = Field(
        description="If polygon format, masks is a list of polygons, where each polygon is a list of points, where each point is a tuple containing the x,y pixel coordinates of the point. If rle format, masks is a dictionary with the keys 'size' and 'counts' containing the size and counts of the RLE encoding."
    )
    confidence: float = Field(description="Masks confidences")
    format: Optional[str] = Field(
        default="polygon", description="Format of the mask data: 'polygon' or 'rle'"
    )