Skip to content

pixano_inference.models.segmentation

Segmentation model base class.

The I/O types (:class:SegmentationInput/:class:SegmentationOutput) are the wire contract and live in :mod:pixano_inference_client.segmentation; they are re-exported here so from pixano_inference.models.segmentation import SegmentationInput keeps working.

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
def __init__(self, config: ModelDeploymentConfig) -> None:
    """Initialize the model with deployment config.

    Args:
        config: Model deployment configuration.
    """
    self._config = config

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
@abstractmethod
def predict(self, input: SegmentationInput) -> SegmentationOutput:
    """Run image segmentation.

    Args:
        input: Segmentation input with image, prompts, and options.

    Returns:
        Segmentation output with masks, scores, and optionally embeddings.
    """