datumaro.plugins.sam_transforms.interpreters.sam_decoder_for_bbox#

Classes

SAMDecoderForBboxInterpreter()

class datumaro.plugins.sam_transforms.interpreters.sam_decoder_for_bbox.SAMDecoderForBboxInterpreter[source]#

Bases: IModelInterpreter

h_model = 1024#
w_model = 1024#
onnx_mask_input = array([[[[0., 0., 0., ..., 0., 0., 0.],          [0., 0., 0., ..., 0., 0., 0.],          [0., 0., 0., ..., 0., 0., 0.],          ...,          [0., 0., 0., ..., 0., 0., 0.],          [0., 0., 0., ..., 0., 0., 0.],          [0., 0., 0., ..., 0., 0., 0.]]]], dtype=float32)#
onnx_has_mask_input = array([0.], dtype=float32)#
mask_threshold = 0.0#
preprocess(inp: DatasetItem) Tuple[ndarray | Dict[str, ndarray], PrepInfo][source]#

Preprocessing an dataset item input.

Parameters:

img – DatasetItem input

Returns:

It returns a tuple of preprocessed input and preprocessing information. The preprocessing information will be used in the postprocessing step. One use case for this would be an affine transformation of the output bounding box obtained by object detection models. Input images for those models are usually resized to fit the model input dimensions. As a result, the postprocessing step should refine the model output bounding box to match the original input image size.

postprocess(pred: Dict[str, ndarray] | List[Dict[str, ndarray]], info: PrepInfo) List[Annotation][source]#

Postprocesses the outputs of the SAM decoder to generate masks associated with bounding boxes.

Parameters:
  • pred – List of dictionaries containing model predictions. Each dictionary should have the ‘masks’ key corresponding to the predicted mask of which shape is (1, H, W).

  • info – List of associated bounding boxes obtained from the preprocessing step.

Returns:

List of Mask`s associated with the input bounding boxes. Each Mask object contains the generated mask along with metadata from the corresponding `Bbox: id, group, object_id, label, z_order and attributes.

get_categories()[source]#

It should be implemented if the model generate a new categories