otx.algorithms.detection.adapters.mmdet.models.detectors#

Initial file for mmdetection detectors.

Classes

CustomATSS(*args[, task_adapt])

SAM optimizer & L2SP regularizer enabled custom ATSS.

CustomDeformableDETR(*args[, task_adapt])

Custom Deformable DETR with task adapt.

CustomLiteDINO(*args[, task_adapt])

Custom Lite-DINO <https://arxiv.org/pdf/2303.07335.pdf> for object detection.

CustomDINO(*args[, task_adapt])

Custom DINO detector.

CustomMaskRCNN(*args[, task_adapt])

CustomMaskRCNN Class for mmdetection detectors.

CustomSingleStageDetector(*args[, task_adapt])

SAM optimizer & L2SP regularizer enabled custom SSD.

CustomTwoStageDetector(*args[, task_adapt])

SAM optimizer & L2SP regularizer enabled custom 2-stage detector.

CustomVFNet(*args[, task_adapt])

SAM optimizer & L2SP regularizer enabled custom VFNet.

CustomYOLOX(*args[, task_adapt])

SAM optimizer & L2SP regularizer enabled custom YOLOX.

L2SPDetectorMixin([l2sp_ckpt, l2sp_weight])

L2SP-enabled detector mix-in.

SAMDetectorMixin()

SAM-enabled BaseDetector mix-in.

CustomMaskRCNNTileOptimized(*args, **kwargs)

Custom MaskRCNN detector with tile classifier.

MeanTeacher(arch_type[, ...])

Mean teacher framework for detection and instance segmentation.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomATSS(*args, task_adapt=None, **kwargs)[source]#

Bases: SAMDetectorMixin, DetLossDynamicsTrackingMixin, L2SPDetectorMixin, ATSS

SAM optimizer & L2SP regularizer enabled custom ATSS.

static load_state_dict_pre_hook(model, model_classes, chkpt_classes, chkpt_dict, prefix, *args, **kwargs)[source]#

Modify input state_dict according to class name matching before weight loading.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomDINO(*args, task_adapt=None, **kwargs)[source]#

Bases: CustomDeformableDETR

Custom DINO detector.

Initialize BaseModule, inherited from torch.nn.Module

load_state_dict_pre_hook(model_classes, ckpt_classes, ckpt_dict, *args, **kwargs)[source]#

Modify mmdet3.x version’s weights before weight loading.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomDeformableDETR(*args, task_adapt=None, **kwargs)[source]#

Bases: DeformableDETR

Custom Deformable DETR with task adapt.

Deformable DETR does not support task adapt, so it just take task_adpat argument.

Initialize BaseModule, inherited from torch.nn.Module

load_state_dict_pre_hook(model_classes, ckpt_classes, ckpt_dict, *args, **kwargs)[source]#

Modify input state_dict according to class name matching before weight loading.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomLiteDINO(*args, task_adapt=None, **kwargs)[source]#

Bases: CustomDINO

Custom Lite-DINO <https://arxiv.org/pdf/2303.07335.pdf> for object detection.

Initialize BaseModule, inherited from torch.nn.Module

load_state_dict_pre_hook(model_classes, ckpt_classes, ckpt_dict, *args, **kwargs)[source]#

Modify official lite dino version’s weights before weight loading.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomMaskRCNN(*args, task_adapt=None, **kwargs)[source]#

Bases: SAMDetectorMixin, L2SPDetectorMixin, MaskRCNN

CustomMaskRCNN Class for mmdetection detectors.

static load_state_dict_pre_hook(model, model_classes, chkpt_classes, chkpt_dict, prefix, *args, **kwargs)[source]#

Modify input state_dict according to class name matching before weight loading.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomMaskRCNNTileOptimized(*args, **kwargs)[source]#

Bases: CustomMaskRCNN

Custom MaskRCNN detector with tile classifier.

Parameters:
  • *args – args

  • **kwargs – kwargs

forward_train(img, img_metas, gt_bboxes, gt_labels, gt_bboxes_ignore=None, gt_masks=None, proposals=None, **kwargs)[source]#

Forward pass during training.

Joint training of tile classifier and MaskRCNN.

Parameters:
  • img (torch.Tensor) – input image

  • img_metas (list) – image meta data

  • gt_bboxes (list) – ground truth bounding boxes

  • gt_labels (list) – ground truth labels

  • gt_bboxes_ignore (list, optional) – ground truth bounding boxes to be ignored. Defaults to None.

  • gt_masks (list, optional) – ground truth masks. Defaults to None.

  • proposals (list, optional) – proposals. Defaults to None.

  • kwargs – kwargs

static make_fake_results(num_classes)[source]#

Make fake results.

Returns:

MaskRCNN output

Return type:

tuple

simple_test(img, img_metas, proposals=None, rescale=False, full_res_image=False)[source]#

Simple test.

Tile classifier is used to filter out images without any objects. If no objects are present, empty results are returned. Otherwise, MaskRCNN is used to detect objects.

Parameters:
  • img (torch.Tensor) – input image

  • img_metas (list) – image meta data

  • proposals (list, optional) – proposals. Defaults to None.

  • rescale (bool, optional) – rescale. Defaults to False.

  • full_res_image (bool, optional) – if the image is full resolution or not. Defaults to False.

Returns:

MaskRCNN output

Return type:

tuple

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomSingleStageDetector(*args, task_adapt=None, **kwargs)[source]#

Bases: SAMDetectorMixin, DetLossDynamicsTrackingMixin, L2SPDetectorMixin, SingleStageDetector

SAM optimizer & L2SP regularizer enabled custom SSD.

forward_train(img, img_metas, gt_bboxes, gt_labels, gt_bboxes_ignore=None, **kwargs)[source]#

Forward function for CustomSSD.

Parameters:
  • img (Tensor) – Input images of shape (N, C, H, W). Typically these should be mean centered and std scaled.

  • img_metas (list[dict]) – A List of image info dict where each dict has: ‘img_shape’, ‘scale_factor’, ‘flip’, and may also contain ‘filename’, ‘ori_shape’, ‘pad_shape’, and ‘img_norm_cfg’. For details on the values of these keys see mmdet.datasets.pipelines.Collect.

  • gt_bboxes (list[Tensor]) – Each item are the truth boxes for each image in [tl_x, tl_y, br_x, br_y] format.

  • gt_labels (list[Tensor]) – Class indices corresponding to each box

  • gt_bboxes_ignore (None | list[Tensor]) – Specify which bounding boxes can be ignored when computing the loss.

  • **kwargs (Any) – Addition keyword arguments.

Returns:

A dictionary of loss components.

Return type:

dict[str, Tensor]

static load_state_dict_pre_hook(model, model_classes, chkpt_classes, chkpt_dict, prefix, *args, **kwargs)[source]#

Modify input state_dict according to class name matching before weight loading.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomTwoStageDetector(*args, task_adapt=None, **kwargs)[source]#

Bases: SAMDetectorMixin, L2SPDetectorMixin, TwoStageDetector

SAM optimizer & L2SP regularizer enabled custom 2-stage detector.

forward_train(img, img_metas, gt_bboxes, gt_labels, gt_bboxes_ignore=None, **kwargs)[source]#

Forward function for CustomTwoStageDetector.

static load_state_dict_pre_hook(model, model_classes, chkpt_classes, chkpt_dict, prefix, *args, **kwargs)[source]#

Modify input state_dict according to class name matching before weight loading.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomVFNet(*args, task_adapt=None, **kwargs)[source]#

Bases: SAMDetectorMixin, DetLossDynamicsTrackingMixin, L2SPDetectorMixin, VFNet

SAM optimizer & L2SP regularizer enabled custom VFNet.

forward_train(img, img_metas, gt_bboxes, gt_labels, gt_bboxes_ignore=None, **kwargs)[source]#

Forward function for CustomVFNet.

static load_state_dict_pre_hook(model, model_classes, chkpt_classes, chkpt_dict, prefix, *args, **kwargs)[source]#

Modify input state_dict according to class name matching before weight loading.

class otx.algorithms.detection.adapters.mmdet.models.detectors.CustomYOLOX(*args, task_adapt=None, **kwargs)[source]#

Bases: SAMDetectorMixin, DetLossDynamicsTrackingMixin, L2SPDetectorMixin, YOLOX

SAM optimizer & L2SP regularizer enabled custom YOLOX.

extract_feat(img)[source]#

Directly extract features from the backbone+neck.

forward_train(img, img_metas, gt_bboxes, gt_labels, gt_bboxes_ignore=None, **kwargs)[source]#

Forward function for CustomYOLOX.

static load_state_dict_pre_hook(model, model_classes, chkpt_classes, chkpt_dict, prefix, *args, **kwargs)[source]#

Modify input state_dict according to class name matching before weight loading.

onnx_export(img, img_metas)[source]#

Test function without test time augmentation.

Parameters:
  • img (torch.Tensor) – input images.

  • img_metas (list[dict]) – List of image information.

Returns:

dets of shape [N, num_det, 5]

and class labels of shape [N, num_det].

Return type:

tuple[Tensor, Tensor]

class otx.algorithms.detection.adapters.mmdet.models.detectors.L2SPDetectorMixin(l2sp_ckpt=None, l2sp_weight=None, **kwargs)[source]#

Bases: object

L2SP-enabled detector mix-in.

forward_train(*args, **kwargs)[source]#

Forward function for L2SPDetectorMixin.

class otx.algorithms.detection.adapters.mmdet.models.detectors.MeanTeacher(arch_type, unlabeled_loss_weights={'bbox': 1.0, 'cls': 1.0, 'mask': 1.0}, pseudo_conf_thresh=0.7, bg_loss_weight=-1.0, min_pseudo_label_ratio=0.0, visualize=False, filter_empty_annotations=False, **kwargs)[source]#

Bases: SAMDetectorMixin, BaseDetector

Mean teacher framework for detection and instance segmentation.

aug_test(imgs, img_metas, **kwargs)[source]#

Aug Test from img with UnbiasedTeacher.

enable_unlabeled_loss(mode=True)[source]#

Enable function for UnbiasedTeacher unlabeled loss.

extract_feat(imgs)[source]#

Extract features for UnbiasedTeacher.

forward_dummy(img, **kwargs)[source]#

Dummy forward function for UnbiasedTeacher.

forward_teacher(img, img_metas)[source]#

Method to extract predictions (pseudo labeles) from teacher.

forward_train(img, img_metas, img0=None, gt_bboxes=None, gt_labels=None, gt_masks=None, gt_bboxes_ignore=None, **kwargs)[source]#

Forward function for UnbiasedTeacher.

generate_pseudo_labels(teacher_outputs, img_meta, **kwargs)[source]#

Generate pseudo label for UnbiasedTeacher.

static load_state_dict_pre_hook(module, state_dict, *args, **kwargs)[source]#

Redirect input state_dict to teacher model.

simple_test(img, img_metas, **kwargs)[source]#

Test from img with UnbiasedTeacher.

static state_dict_hook(module, state_dict, prefix, *args, **kwargs)[source]#

Redirect student model as output state_dict (teacher as auxilliary).

class otx.algorithms.detection.adapters.mmdet.models.detectors.SAMDetectorMixin[source]#

Bases: object

SAM-enabled BaseDetector mix-in.

train_step(data, optimizer, **kwargs)[source]#

Saving current batch data to compute SAM gradient.