pixano_inference.models.segmentation
Segmentation model base class and I/O types.
SegmentationInput(**data)
Bases: BaseModel
Input for image segmentation.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
str | Path | bytes
|
Image for segmentation (path, URL, or base64). |
image_embedding |
NDArrayFloat | None
|
Pre-computed image embedding. |
high_resolution_features |
list[NDArrayFloat] | None
|
High resolution features. |
mask_input |
NDArrayFloat | None
|
Low-resolution mask logits from a previous refinement round. |
reset_predictor |
bool
|
True (default) for a new image. If False, keep current predictor. |
points |
list[list[list[int]]] | None
|
Point prompts [num_prompts, num_points, 2]. |
labels |
list[list[int]] | None
|
Labels for points [num_prompts, num_points]. |
boxes |
list[list[int]] | None
|
Box prompts [num_prompts, 4]. |
num_multimask_outputs |
int
|
Number of masks to generate per prediction. |
multimask_output |
bool
|
Whether to generate multiple masks per prediction. |
return_image_embedding |
bool
|
Whether to return the image embeddings. |
return_logits |
bool
|
Whether to return low-resolution logits for iterative refinement. |
Source code in pydantic/main.py
SegmentationModel(config)
Bases: InferenceModel
Base class for image segmentation models.
Example
@register_model("my-segmenter")
class MySegmenter(SegmentationModel):
def load_model(self):
self.model = load_weights(self.config.model_params["path"])
def predict(self, input: SegmentationInput) -> SegmentationOutput:
masks, scores = self.model(input.image, input.points, input.labels, input.boxes)
return SegmentationOutput(masks=masks, scores=scores)
Source code in pixano_inference/models/base.py
predict(input)
abstractmethod
Run image segmentation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input
|
SegmentationInput
|
Segmentation input with image, prompts, and options. |
required |
Returns:
| Type | Description |
|---|---|
SegmentationOutput
|
Segmentation output with masks, scores, and optionally embeddings. |
Source code in pixano_inference/models/segmentation.py
SegmentationOutput(**data)
Bases: BaseModel
Output for image segmentation.
Attributes:
| Name | Type | Description |
|---|---|---|
masks |
list[list[CompressedRLE]]
|
Generated masks [num_predictions, num_masks_per_prediction]. |
scores |
NDArrayFloat
|
Scores of the masks. |
image_embedding |
NDArrayFloat | None
|
Image embeddings (optional). |
high_resolution_features |
list[NDArrayFloat] | None
|
High resolution features (optional). |
mask_logits |
NDArrayFloat | None
|
Low-resolution logits for iterative refinement (optional). |