From 8bb7fc1f325c49861897a29b7630ac040475245f Mon Sep 17 00:00:00 2001 From: Jaeguk Hyun Date: Mon, 25 Mar 2024 15:12:47 +0900 Subject: [PATCH] Modify detection docs and remove unused initial detectors (#3186) * Modify detection docs and remove unused initial detectors * Update unit tests --- .../object_detection/object_detection.rst | 6 - .../tutorials/base/how_to_train/detection.rst | 2 - src/otx/algo/detection/atss.py | 21 --- src/otx/algo/detection/rtmdet.py | 39 ----- src/otx/recipe/detection/atss_r50_fpn.yaml | 93 ----------- src/otx/recipe/detection/rtmdet_tiny.yaml | 146 ------------------ tests/unit/algo/detection/test_atss.py | 4 +- tests/unit/algo/detection/test_rtmdet.py | 20 --- 8 files changed, 1 insertion(+), 330 deletions(-) delete mode 100644 src/otx/algo/detection/rtmdet.py delete mode 100644 src/otx/recipe/detection/atss_r50_fpn.yaml delete mode 100644 src/otx/recipe/detection/rtmdet_tiny.yaml delete mode 100644 tests/unit/algo/detection/test_rtmdet.py diff --git a/docs/source/guide/explanation/algorithms/object_detection/object_detection.rst b/docs/source/guide/explanation/algorithms/object_detection/object_detection.rst index 64e926b8928..66c1a7fe1a8 100644 --- a/docs/source/guide/explanation/algorithms/object_detection/object_detection.rst +++ b/docs/source/guide/explanation/algorithms/object_detection/object_detection.rst @@ -111,12 +111,6 @@ We trained each model with a single Nvidia GeForce RTX3090. +----------------------------+------------------+-----------+-----------+-----------+-----------+--------------+ | ResNeXt101-ATSS | 45.1 (63.8) | 45.5 | 99.3 | 69.3 | 93.1 | 99.1 | +----------------------------+------------------+-----------+-----------+-----------+-----------+--------------+ -| ResNet50-Deformable-DETR | 44.3 (63.2) | 44.8 | 97.7 | 60.7 | 93.4 | 99.2 | -+----------------------------+------------------+-----------+-----------+-----------+-----------+--------------+ -| ResNet50-DINO | 49.0 (66.4) | 47.2 | 99.5 | 62.9 | 93.5 | 99.1 | -+----------------------------+------------------+-----------+-----------+-----------+-----------+--------------+ -| ResNet50-Lite-DINO | 48.1 (64.4) | 47.0 | 99.0 | 62.5 | 93.6 | 99.4 | -+----------------------------+------------------+-----------+-----------+-----------+-----------+--------------+ | YOLOX-S | 40.3 (59.1) | 37.1 | 93.6 | 54.8 | 92.7 | 98.8 | +----------------------------+------------------+-----------+-----------+-----------+-----------+--------------+ | YOLOX-L | 49.4 (67.1) | 44.5 | 94.6 | 55.8 | 91.8 | 99.0 | diff --git a/docs/source/guide/tutorials/base/how_to_train/detection.rst b/docs/source/guide/tutorials/base/how_to_train/detection.rst index 474dccd2f96..89c2a8b7cc4 100644 --- a/docs/source/guide/tutorials/base/how_to_train/detection.rst +++ b/docs/source/guide/tutorials/base/how_to_train/detection.rst @@ -136,7 +136,6 @@ The list of supported templates for object detection is available with the comma ┃ Task ┃ Model Name ┃ Recipe Path ┃ ┡━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ DETECTION │ atss_mobilenetv2_tile │ src/otx/recipe/detection/atss_mobilenetv2_tile.yaml │ - │ DETECTION │ atss_r50_fpn │ src/otx/recipe/detection/atss_r50_fpn.yaml │ │ DETECTION │ atss_resnext101 │ src/otx/recipe/detection/atss_resnext101.yaml │ │ DETECTION │ atss_mobilenetv2 │ src/otx/recipe/detection/atss_mobilenetv2.yaml │ └───────────┴───────────────────────┴────────────────────────────────────────────────────────────────┘ @@ -151,7 +150,6 @@ The list of supported templates for object detection is available with the comma print(model_lists) ''' [ - 'atss_r50_fpn', 'atss_mobilenetv2', 'atss_mobilenetv2_tile', 'atss_resnext101', diff --git a/src/otx/algo/detection/atss.py b/src/otx/algo/detection/atss.py index 58eb1631780..a502f98d4d4 100644 --- a/src/otx/algo/detection/atss.py +++ b/src/otx/algo/detection/atss.py @@ -37,24 +37,3 @@ def _export_parameters(self) -> dict[str, Any]: def load_from_otx_v1_ckpt(self, state_dict: dict, add_prefix: str = "model.model.") -> dict: """Load the previous OTX ckpt according to OTX2.0.""" return OTXv1Helper.load_det_ckpt(state_dict, add_prefix) - - -class ATSSR50FPN(ATSS): - """ATSSR50FPN Model.""" - - def __init__(self, num_classes: int) -> None: - super().__init__(num_classes=num_classes, variant="r50_fpn") - self.image_size = (1, 3, 800, 1333) - self.tile_image_size = self.image_size - - @property - def _export_parameters(self) -> dict[str, Any]: - """Parameters for an exporter.""" - export_params = super()._export_parameters - export_params["deploy_cfg"] = "otx.algo.detection.mmdeploy.atss_r50_fpn" - export_params["input_size"] = self.image_size - export_params["resize_mode"] = "standard" # [TODO](@Eunwoo): need to revert it to fit_to_window after resolving - export_params["pad_value"] = 0 - export_params["swap_rgb"] = False - - return export_params diff --git a/src/otx/algo/detection/rtmdet.py b/src/otx/algo/detection/rtmdet.py deleted file mode 100644 index f47be33127c..00000000000 --- a/src/otx/algo/detection/rtmdet.py +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright (C) 2023 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -# -"""RTMDetTiny model implementations.""" - -from __future__ import annotations - -from typing import Any, Literal - -from otx.algo.utils.mmconfig import read_mmconfig -from otx.algo.utils.support_otx_v1 import OTXv1Helper -from otx.core.model.entity.detection import MMDetCompatibleModel - - -class RTMDet(MMDetCompatibleModel): - """RTMDet Model.""" - - def __init__(self, num_classes: int, variant: Literal["tiny"]) -> None: - model_name = f"rtmdet_{variant}" - config = read_mmconfig(model_name=model_name) - super().__init__(num_classes=num_classes, config=config) - self.image_size = (1, 3, 640, 640) - self.tile_image_size = self.image_size - - @property - def _export_parameters(self) -> dict[str, Any]: - """Parameters for an exporter.""" - export_params = super()._export_parameters - export_params["deploy_cfg"] = "otx.algo.detection.mmdeploy.rtmdet" - export_params["input_size"] = self.image_size - export_params["resize_mode"] = "fit_to_window_letterbox" - export_params["pad_value"] = 114 - export_params["swap_rgb"] = False - - return export_params - - def load_from_otx_v1_ckpt(self, state_dict: dict, add_prefix: str = "model.model.") -> dict: - """Load the previous OTX ckpt according to OTX2.0.""" - return OTXv1Helper.load_det_ckpt(state_dict, add_prefix) diff --git a/src/otx/recipe/detection/atss_r50_fpn.yaml b/src/otx/recipe/detection/atss_r50_fpn.yaml deleted file mode 100644 index 4aa71b6d416..00000000000 --- a/src/otx/recipe/detection/atss_r50_fpn.yaml +++ /dev/null @@ -1,93 +0,0 @@ -model: - class_path: otx.algo.detection.atss.ATSSR50FPN - init_args: - num_classes: 1000 - -optimizer: - class_path: torch.optim.Adam - init_args: - lr: 1e-3 - weight_decay: 0.0 - -scheduler: - - class_path: otx.algo.schedulers.warmup_schedulers.LinearWarmupScheduler - init_args: - num_warmup_steps: 3 - - class_path: lightning.pytorch.cli.ReduceLROnPlateau - init_args: - mode: max - factor: 0.1 - patience: 4 - monitor: val/map_50 - -metric: - class_path: torchmetrics.detection.mean_ap.MeanAveragePrecision - init_args: - box_format: xyxy - iou_type: bbox - -engine: - task: DETECTION - device: auto - -callback_monitor: val/map_50 - -data: ../_base_/data/mmdet_base.yaml - -overrides: - gradient_clip_val: 35.0 - data: - config: - train_subset: - batch_size: 2 - transforms: - - backend_args: null - type: LoadImageFromFile - - type: LoadAnnotations - with_bbox: true - - keep_ratio: true - scale: - - 1333 - - 800 - type: Resize - - prob: 0.5 - type: RandomFlip - - type: PackDetInputs - val_subset: - batch_size: 1 - transforms: - - backend_args: null - type: LoadImageFromFile - - keep_ratio: true - scale: - - 1333 - - 800 - type: Resize - - type: LoadAnnotations - with_bbox: true - - meta_keys: - - img_id - - img_path - - ori_shape - - img_shape - - scale_factor - type: PackDetInputs - test_subset: - batch_size: 1 - transforms: - - backend_args: null - type: LoadImageFromFile - - keep_ratio: true - scale: - - 1333 - - 800 - type: Resize - - type: LoadAnnotations - with_bbox: true - - meta_keys: - - img_id - - img_path - - ori_shape - - img_shape - - scale_factor - type: PackDetInputs diff --git a/src/otx/recipe/detection/rtmdet_tiny.yaml b/src/otx/recipe/detection/rtmdet_tiny.yaml deleted file mode 100644 index ea62d8ca6cc..00000000000 --- a/src/otx/recipe/detection/rtmdet_tiny.yaml +++ /dev/null @@ -1,146 +0,0 @@ -model: - class_path: otx.algo.detection.rtmdet.RTMDet - init_args: - num_classes: 80 - variant: tiny - -optimizer: - class_path: torch.optim.Adam - init_args: - lr: 1e-3 - weight_decay: 0.0 - -scheduler: - class_path: lightning.pytorch.cli.ReduceLROnPlateau - init_args: - mode: min - factor: 0.1 - patience: 9 - monitor: train/loss - -metric: - class_path: torchmetrics.detection.mean_ap.MeanAveragePrecision - init_args: - box_format: xyxy - iou_type: bbox - -engine: - task: DETECTION - device: auto - -callback_monitor: val/map_50 - -data: ../_base_/data/mmdet_base.yaml -overrides: - precision: 32 - data: - config: - train_subset: - batch_size: 32 - transforms: - - backend_args: null - type: LoadImageFromFile - - type: LoadAnnotations - with_bbox: true - - img_scale: - - 640 - - 640 - max_cached_images: 20 - pad_val: 114.0 - random_pop: false - type: CachedMosaic - - keep_ratio: true - ratio_range: - - 0.5 - - 2.0 - scale: - - 1280 - - 1280 - type: RandomResize - - crop_size: - - 640 - - 640 - type: RandomCrop - - type: YOLOXHSVRandomAug - - prob: 0.5 - type: RandomFlip - - pad_val: - img: - - 114 - - 114 - - 114 - size: - - 640 - - 640 - type: Pad - - img_scale: - - 640 - - 640 - max_cached_images: 10 - pad_val: - - 114 - - 114 - - 114 - prob: 0.5 - random_pop: false - ratio_range: - - 1.0 - - 1.0 - type: CachedMixUp - - type: PackDetInputs - val_subset: - batch_size: 5 - transforms: - - backend_args: null - type: LoadImageFromFile - - keep_ratio: true - scale: - - 640 - - 640 - type: Resize - - pad_val: - img: - - 114 - - 114 - - 114 - size: - - 640 - - 640 - type: Pad - - type: LoadAnnotations - with_bbox: true - - meta_keys: - - img_id - - img_path - - ori_shape - - img_shape - - scale_factor - type: PackDetInputs - test_subset: - batch_size: 5 - transforms: - - backend_args: null - type: LoadImageFromFile - - keep_ratio: true - scale: - - 640 - - 640 - type: Resize - - pad_val: - img: - - 114 - - 114 - - 114 - size: - - 640 - - 640 - type: Pad - - type: LoadAnnotations - with_bbox: true - - meta_keys: - - img_id - - img_path - - ori_shape - - img_shape - - scale_factor - type: PackDetInputs diff --git a/tests/unit/algo/detection/test_atss.py b/tests/unit/algo/detection/test_atss.py index 787eb5cf5cb..1564a7bee15 100644 --- a/tests/unit/algo/detection/test_atss.py +++ b/tests/unit/algo/detection/test_atss.py @@ -3,7 +3,7 @@ """Test of OTX SSD architecture.""" import pytest -from otx.algo.detection.atss import ATSS, ATSSR50FPN +from otx.algo.detection.atss import ATSS from otx.algo.utils.support_otx_v1 import OTXv1Helper @@ -12,9 +12,7 @@ class TestATSS: "model", [ ATSS(num_classes=2, variant="mobilenetv2"), - ATSS(num_classes=2, variant="r50_fpn"), ATSS(num_classes=2, variant="resnext101"), - ATSSR50FPN(num_classes=2), ], ) def test(self, model, mocker) -> None: diff --git a/tests/unit/algo/detection/test_rtmdet.py b/tests/unit/algo/detection/test_rtmdet.py deleted file mode 100644 index 15949f76701..00000000000 --- a/tests/unit/algo/detection/test_rtmdet.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright (C) 2024 Intel Corporation -# SPDX-License-Identifier: Apache-2.0 -"""Test of OTX SSD architecture.""" - -import pytest -from otx.algo.detection.rtmdet import RTMDet -from otx.algo.utils.support_otx_v1 import OTXv1Helper - - -class TestRTMDet: - @pytest.fixture() - def fxt_model(self) -> RTMDet: - return RTMDet(num_classes=3, variant="tiny") - - def test(self, fxt_model, mocker) -> None: - mock_load_ckpt = mocker.patch.object(OTXv1Helper, "load_det_ckpt") - fxt_model.load_from_otx_v1_ckpt({}) - mock_load_ckpt.assert_called_once_with({}, "model.model.") - - assert isinstance(fxt_model._export_parameters, dict)