Bases: BaseModel
Unified prompt that can contain text and/or geometry.
Absolute pixel coordinates are used for boxes. Labels accept 0/1 or booleans.
Source code in inference/core/entities/requests/sam3.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73 | class Sam3Prompt(BaseModel):
"""Unified prompt that can contain text and/or geometry.
Absolute pixel coordinates are used for boxes. Labels accept 0/1 or booleans.
"""
type: Optional[str] = Field(
default=None, description="Optional hint: 'text' or 'visual'"
)
text: Optional[str] = Field(default=None)
output_prob_thresh: Optional[float] = Field(
default=None,
description="Score threshold for this prompt's outputs. Overrides request-level threshold if set.",
)
# Absolute-coordinate boxes (preferred) in pixels.
# XYWH absolute pixels
class Box(BaseModel):
x: float
y: float
width: float
height: float
# XYXY absolute pixels
class BoxXYXY(BaseModel):
x0: float
y0: float
x1: float
y1: float
# Single unified boxes field; each entry can be XYWH or XYXY
boxes: Optional[List[Union[Box, BoxXYXY]]] = Field(
default=None,
description="Absolute pixel boxes as either XYWH or XYXY entries",
)
box_labels: Optional[List[Union[int, bool]]] = Field(
default=None, description="List of 0/1 or booleans for boxes"
)
@validator("boxes", always=True)
def _validate_visual_boxes(cls, boxes, values):
prompt_type = values.get("type")
if prompt_type == "visual":
if not boxes or len(boxes) == 0:
raise ValueError("Visual prompt requires at least one box")
return boxes
@validator("box_labels", always=True)
def _validate_box_labels(cls, labels, values):
boxes = values.get("boxes")
if labels is None:
return labels
if boxes is None or len(labels) != len(boxes):
raise ValueError("box_labels must match boxes length when provided")
return labels
@validator("output_prob_thresh")
def _validate_output_prob_thresh(cls, v):
if v is not None and (v < 0.0 or v > 1.0):
raise ValueError("output_prob_thresh must be between 0.0 and 1.0")
return v
|