iris.nodes.segmentation package

Submodules

iris.nodes.segmentation.multilabel_segmentation_interface module

class iris.nodes.segmentation.multilabel_segmentation_interface.MultilabelSemanticSegmentationInterface(**kwargs: Any)[source]

Bases: Algorithm

Interface of a model semantic segmentation prediction trained with multilabel labels.

CLASSES_MAPPING = {0: 'eyeball', 1: 'iris', 2: 'pupil', 3: 'eyelashes'}
HUGGING_FACE_REPO_ID = 'Worldcoin/iris-semantic-segmentation'
MODEL_CACHE_DIR = '/home/wiktor.lazarski/iris_conciliation/open-iris/src/iris/nodes/segmentation/assets'
classmethod create_from_hugging_face() MultilabelSemanticSegmentationInterface[source]

Abstract function just to make sure all subclasses implement it.

Raises:

RuntimeError – Raised if subclass doesn’t implement that class method.

Returns:

MultilabelSemanticSegmentationInterface subclass object.

Return type:

MultilabelSemanticSegmentationInterface

postprocess_segmap(segmap: ndarray, original_image_resolution: Tuple[int, int]) ndarray[source]

Postprocess segmentation map.

Parameters:
  • segmap (np.ndarray) – Predicted segmentation map.

  • original_image_resolution (Tuple[int, int]) – Original input image resolution (width, height).

Returns:

Postprocessed segmentation map.

Return type:

np.ndarray

preprocess(image: ndarray, input_resolution: Tuple[int, int], nn_input_channels: int) ndarray[source]

Preprocess image before running a model inference.

Parameters:
  • image (np.ndarray) – Image to preprocess.

  • input_resolution (Tuple[int, int]) – A model input resolution.

  • nn_input_channels (int) – A model input channels.

Returns:

Preprocessed image.

Return type:

np.ndarray

iris.nodes.segmentation.onnx_multilabel_segmentation module

class iris.nodes.segmentation.onnx_multilabel_segmentation.ONNXMultilabelSegmentation(model_path: str, input_resolution: Tuple[PositiveInt, PositiveInt] = (640, 480), input_num_channels: Literal[1, 3] = 3, callbacks: List[Callback] = [])[source]

Bases: MultilabelSemanticSegmentationInterface

Implementation of class which uses ONNX model to perform semantic segmentation maps prediction.

For more detailed model description check model card available in SEMSEG_MODEL_CARD.md file.

class Parameters(*, session: InferenceSession, input_resolution: Tuple[PositiveInt, PositiveInt], input_num_channels: Literal[1, 3])[source]

Bases: Parameters

Parameters class for ONNXMultilabelSegmentation objects.

input_num_channels: Literal[1, 3]
input_resolution: Tuple[PositiveInt, PositiveInt]
session: InferenceSession
classmethod create_from_hugging_face(model_name: str = 'iris_semseg_upp_scse_mobilenetv2.onnx', input_resolution: Tuple[PositiveInt, PositiveInt] = (640, 480), input_num_channels: Literal[1, 3] = 3, callbacks: List[Callback] = []) ONNXMultilabelSegmentation[source]

Create ONNXMultilabelSegmentation object with by downloading model from HuggingFace repository MultilabelSemanticSegmentationInterface.HUGGING_FACE_REPO_ID.

Parameters:
  • model_name (str, optional) – Name of the ONNX model stored in HuggingFace repo. Defaults to “iris_semseg_upp_scse_mobilenetv2.onnx”.

  • input_resolution (Tuple[PositiveInt, PositiveInt], optional) – Neural Network input image resolution. Defaults to (640, 480).

  • input_num_channels (Literal[1, 3], optional) – Neural Network input image number of channels. Defaults to 3.

  • callbacks (List[Callback], optional) – List of algorithm callbacks. Defaults to [].

Returns:

ONNXMultilabelSegmentation object.

Return type:

ONNXMultilabelSegmentation

run(image: IRImage) SegmentationMap[source]

Perform semantic segmentation prediction on an image.

Parameters:

image (IRImage) – Infrared image object.

Returns:

Postprocessed model predictions.

Return type:

SegmentationMap

iris.nodes.segmentation.tensorrt_multilabel_segmentation module

Module contents