mmdetection#

OTX Adapters - mmdet.

class otx.algorithms.detection.adapters.mmdet.OTXDetDataset(otx_dataset: DatasetEntity, labels: List[LabelEntity], pipeline: Sequence[dict], domain: Domain, test_mode: bool = False, **kwargs)#

Wrapper that allows using a OTX dataset to train mmdetection models.

This wrapper is not based on the filesystem, but instead loads the items here directly from the OTX DatasetEntity object.

The wrapper overwrites some methods of the CustomDataset class: prepare_train_img, prepare_test_img and prepipeline Naming of certain attributes might seem a bit peculiar but this is due to the conventions set in CustomDataset. For instance, CustomDatasets expects the dataset items to be stored in the attribute data_infos, which is why it is named like that and not dataset_items.

evaluate(results, metric='mAP', logger=None, proposal_nums=(100, 300, 1000), iou_thr=0.5, scale_ranges=None)#

Evaluate the dataset.

Args:

results (list): Testing results of the dataset. metric (str | list[str]): Metrics to be evaluated. logger (logging.Logger | None | str): Logger used for printing

related information during evaluation. Default: None.

proposal_nums (Sequence[int]): Proposal number used for evaluating

recalls, such as recall@100, recall@1000. Default: (100, 300, 1000).

iou_thr (float | list[float]): IoU threshold. Default: 0.5. scale_ranges (list[tuple] | None): Scale ranges for evaluating mAP.

Default: None.

get_ann_info(idx: int)#

This method is used for evaluation of predictions.

The CustomDataset class implements a method CustomDataset.evaluate, which uses the class method get_ann_info to retrieve annotations.

Parameters:

idx – index of the dataset item for which to get the annotations

Return ann_info:

dict that contains the coordinates of the bboxes and their corresponding labels

static pre_pipeline(results: Dict[str, Any])#

Prepare results dict for pipeline. Add expected keys to the dict.

prepare_test_img(idx: int) dict#

Get testing data after pipeline.

Parameters:

idx – int, Index of data.

Return dict:

Testing data after pipeline with new keys introduced by pipeline.

prepare_train_img(idx: int) dict#

Get training data and annotations after pipeline.

Parameters:

idx – int, Index of data.

Return dict:

Training data and annotation after pipeline with new keys introduced by pipeline.

Initalization OTX Detection with MMDET.

Export task for OTX Detection with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.exporter.DetectionExporter(name, mode, config, common_cfg=None, index=0, **kwargs)#

Export class for object detection.

static naive_export(output_dir, model_builder, precision, cfg, model_name='model')#

Export using pytorch backend.

run(model_cfg, model_ckpt, data_cfg, **kwargs)#

Run exporter stage.

Inference task for OTX Detection with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.inferrer.DetectionInferrer(**kwargs)#

Class for object detection inference.

infer(cfg, model_builder=None, do_eval=False, dump_features=False, dump_saliency_map=False)#

Main inference function.

run(model_cfg, model_ckpt, data_cfg, **kwargs)#

Run inference stage for detection.

  • Configuration

  • Environment setup

  • Run inference via MMDetection -> MMCV

Base stage for OTX Detection with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.stage.DetectionStage(name, mode, config, common_cfg=None, index=0, **kwargs)#

Patch config to support otx train.

MODEL_BUILDER(train_cfg: Optional[Union[Config, ConfigDict]] = None, test_cfg: Optional[Union[Config, ConfigDict]] = None, checkpoint: Optional[str] = None, device: Union[str, device] = 'cpu', cfg_options: Optional[Union[Config, ConfigDict]] = None, from_scratch: bool = False) Module#

A builder function for mmdet model.

Creates a model, based on the configuration in config. Note that this function updates ‘load_from’ attribute of ‘config’.

static add_yolox_hooks(cfg)#

Add YOLOX related hooks.

configure(model_cfg, model_ckpt, data_cfg, training=True, **kwargs)#

Create MMCV-consumable config from given inputs.

configure_anchor(cfg)#

Patch anchor which are generated from dataset.

configure_bbox_head(cfg)#

Patch bbox head in detector for class incremental learning.

Most of patching are related with hyper-params in focal loss

configure_classes(cfg)#

Patch classes for model and dataset.

configure_data(cfg, training, data_cfg)#

Patch cfg.data.

Merge cfg and data_cfg Match cfg.data.train.type to super_type Patch for unlabeled data path ==> This may be moved to SemiDetectionStage

static configure_ema(cfg)#

Patch ema settings.

configure_hyperparams(cfg, **kwargs)#

Patch optimization hyparms such as batch size, learning rate.

configure_model(cfg, model_cfg, **kwargs)#

Patch config’s model.

Replace cfg.model to model_cfg Change model type to super type Patch for OMZ backbones

configure_regularization(cfg, training)#

Patch regularization parameters.

configure_task(cfg, training)#

Patch config to support training algorithm.

configure_task_data_pipeline(cfg)#

Trying to alter class indices of training data according to model class order.

Base trainer for OTX Object Detection with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.trainer.DetectionTrainer(**kwargs)#

Trainer class for MMDET.

run(model_cfg, model_ckpt, data_cfg, **kwargs)#

Run training stage for detection.

  • Configuration

  • Environment setup

  • Run training via MMDetection -> MMCV

Initialize incremental learning for OTX Detection.

class otx.algorithms.detection.adapters.mmdet.tasks.incremental.IncrDetectionInferrer(**kwargs)#

Inferencer for OTX Detection incremental learngin with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.incremental.IncrDetectionTrainer(**kwargs)#

Train class for incremental object detection.

Inference Incremental learning model of OTX detection.

class otx.algorithms.detection.adapters.mmdet.tasks.incremental.inferrer.IncrDetectionInferrer(**kwargs)#

Inferencer for OTX Detection incremental learngin with MMDET.

Stage for incremental object detection.

class otx.algorithms.detection.adapters.mmdet.tasks.incremental.stage.IncrDetectionStage(**kwargs)#

Patch config to support incremental learning for object detection.

configure_task(cfg, training, **kwargs)#

Patch config to support incremental learning.

configure_task_adapt_hook(cfg)#

Add TaskAdaptHook for sampler.

Train task for Incremental Learning for OTX Detection with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.incremental.trainer.IncrDetectionTrainer(**kwargs)#

Train class for incremental object detection.

Initialization of Semi-SL Object Detection with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.semisl.SemiSLDetectionExporter(**kwargs)#

Exporter class for Semi-SL Object detection.

class otx.algorithms.detection.adapters.mmdet.tasks.semisl.SemiSLDetectionInferrer(**kwargs)#

Class for semi-sl detection.

class otx.algorithms.detection.adapters.mmdet.tasks.semisl.SemiSLDetectionStage(**kwargs)#

Patch config to support semi supervised learning for object detection.

configure_data(cfg, training, data_cfg)#

Patch cfg.data.

configure_task(cfg, training)#

Patch config to support training algorithm.

class otx.algorithms.detection.adapters.mmdet.tasks.semisl.SemiSLDetectionTrainer(**kwargs)#

Train class for semi-sl object detection.

Inference task for Semi-SL OTX Detection with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.semisl.inferrer.SemiSLDetectionInferrer(**kwargs)#

Class for semi-sl detection.

Stage for Semi-SL training with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.semisl.stage.SemiSLDetectionStage(**kwargs)#

Patch config to support semi supervised learning for object detection.

configure_data(cfg, training, data_cfg)#

Patch cfg.data.

configure_task(cfg, training)#

Patch config to support training algorithm.

Semi-SL Object detection Task with MMDET.

class otx.algorithms.detection.adapters.mmdet.tasks.semisl.trainer.SemiSLDetectionTrainer(**kwargs)#

Train class for semi-sl object detection.