Skip to content

pixano_inference.models.detection

Detection model base class.

The I/O types (:class:DetectionInput/:class:DetectionOutput) are the wire contract and live in :mod:pixano_inference.schemas.detection; they are re-exported here so from pixano_inference.models.detection import DetectionInput keeps working.

DetectionModel(config)

Bases: InferenceModel[DetectionInput, DetectionOutput]

Base class for detection and instance-segmentation models.

Subclasses implement predict which receives a :class:DetectionInput and returns a :class:DetectionOutput. The same pair of types covers both pure detection (no masks) and instance segmentation (with masks). The interface property, when overridden, returns a :class:DetectionInterface: whether the model detects the classes the request names or has its own class set, and what each detection carries.

Example
@register_model("my-detector")
class MyDetector(DetectionModel):
    def load_model(self):
        self.model = load_weights(self.config.model_params["path"])

    def predict(self, input: DetectionInput) -> DetectionOutput:
        boxes, scores, cls = self.model(input.image, input.classes)
        return DetectionOutput(boxes=boxes, scores=scores, classes=cls)
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