otx.core.model.segmentation#

Class definition for detection model entity used in OTX.

Classes

OTXSegmentationModel(label_info, input_size, ...)

Base class for the semantic segmentation models used in OTX.

OVSegmentationModel(model_name, model_type, ...)

Semantic segmentation model compatible for OpenVINO IR inference.

class otx.core.model.segmentation.OTXSegmentationModel(label_info: LabelInfoTypes, input_size: tuple[int, int] = (512, 512), optimizer: OptimizerCallable = <function _default_optimizer_callable>, scheduler: LRSchedulerCallable | LRSchedulerListCallable = <function _default_scheduler_callable>, metric: MetricCallable = <function _segm_callable>, torch_compile: bool = False, train_type: Literal[OTXTrainType.SUPERVISED, OTXTrainType.SEMI_SUPERVISED] = OTXTrainType.SUPERVISED, model_version: str | None = None, unsupervised_weight: float = 0.7, semisl_start_epoch: int = 2, drop_unreliable_pixels_percent: int = 20)[source]#

Bases: OTXModel[SegBatchDataEntity, SegBatchPredEntity]

Base class for the semantic segmentation models used in OTX.

Base semantic segmentation model.

Parameters:
  • label_info (LabelInfoTypes) – The label information for the segmentation model.

  • input_size (tuple[int, int]) – Model input size in the order of height and width.

  • optimizer (OptimizerCallable, optional) – The optimizer to use for training. Defaults to DefaultOptimizerCallable.

  • scheduler (LRSchedulerCallable | LRSchedulerListCallable, optional) – The scheduler to use for learning rate adjustment. Defaults to DefaultSchedulerCallable.

  • metric (MetricCallable, optional) – The metric to use for evaluation. Defaults to SegmCallable.

  • torch_compile (bool, optional) – Whether to compile the model using TorchScript. Defaults to False.

  • train_type (Literal[OTXTrainType.SUPERVISED, OTXTrainType.SEMI_SUPERVISED], optional) – The training type of the model. Defaults to OTXTrainType.SUPERVISED.

  • model_version (str | None, optional) – The version of the model. Defaults to None.

  • unsupervised_weight (float, optional) – The weight of the unsupervised loss. Only for semi-supervised learning. Defaults to 0.7.

  • semisl_start_epoch (int, optional) – The epoch at which the semi-supervised learning starts. Only for semi-supervised learning. Defaults to 2.

  • drop_unreliable_pixels_percent (int, optional) – The percentage of unreliable pixels to drop. Only for semi-supervised learning. Defaults to 20.

export(output_dir: Path, base_name: str, export_format: OTXExportFormatType, precision: OTXPrecisionType = OTXPrecisionType.FP32, to_exportable_code: bool = False) Path[source]#

Export this model to the specified output directory.

Parameters:
  • output_dir (Path) – directory for saving the exported model

  • base_name – (str): base name for the exported model file. Extension is defined by the target export format

  • export_format (OTXExportFormatType) – format of the output model

  • precision (OTXExportPrecisionType) – precision of the output model

  • to_exportable_code (bool) – flag to export model in exportable code with demo package

Returns:

path to the exported model.

Return type:

Path

forward_for_tracing(image: Tensor) Tensor | dict[str, Tensor][source]#

Model forward function used for the model tracing during model exportation.

get_dummy_input(batch_size: int = 1) SegBatchDataEntity[source]#

Returns a dummy input for semantic segmentation model.

class otx.core.model.segmentation.OVSegmentationModel(model_name: str, model_type: str = 'Segmentation', async_inference: bool = True, max_num_requests: int | None = None, use_throughput_mode: bool = True, model_api_configuration: dict[str, Any] | None = None, metric: MetricCallable = <function _segm_callable>, **kwargs)[source]#

Bases: OVModel[SegBatchDataEntity, SegBatchPredEntity]

Semantic segmentation model compatible for OpenVINO IR inference.

It can consume OpenVINO IR model path or model name from Intel OMZ repository and create the OTX segmentation model compatible for OTX testing pipeline.