From 5053957c4d37928ac699c119a744e188946b5ba5 Mon Sep 17 00:00:00 2001 From: Songki Choi Date: Mon, 24 Jul 2023 10:18:14 +0900 Subject: [PATCH] Rename `SAMImageClassifier` -> `CustomImageClassifier` (#2384) * Rename SAMImageClassifier -> CustomImageClassifier Signed-off-by: Songki Choi * Fix module name sam_classifier -> custom_image_classifier Signed-off-by: Songki Choi * Fix pre-commit Signed-off-by: Songki Choi --------- Signed-off-by: Songki Choi --- .../adapters/mmcls/configurer.py | 2 +- .../adapters/mmcls/models/__init__.py | 18 ++++----------- .../mmcls/models/classifiers/__init__.py | 16 +++---------- ...assifier.py => custom_image_classifier.py} | 8 +++---- .../models/classifiers/semisl_classifier.py | 6 ++--- .../semisl_multilabel_classifier.py | 6 ++--- .../classification/configs/deit_tiny/model.py | 5 +++- .../configs/deit_tiny/model_hierarchical.py | 5 +++- .../configs/deit_tiny/model_multilabel.py | 5 +++- .../configs/efficientnet_b0_cls_incr/model.py | 5 +++- .../model_hierarchical.py | 5 +++- .../model_multilabel.py | 5 +++- .../efficientnet_v2_s_cls_incr/model.py | 5 +++- .../model_hierarchical.py | 5 +++- .../model_multilabel.py | 5 +++- .../mobilenet_v3_large_075_cls_incr/model.py | 5 +++- .../model_hierarchical.py | 5 +++- .../model_multilabel.py | 5 +++- .../mobilenet_v3_large_1_cls_incr/model.py | 5 +++- .../model_hierarchical.py | 5 +++- .../model_multilabel.py | 5 +++- .../mobilenet_v3_small_cls_incr/model.py | 5 +++- .../model_hierarchical.py | 5 +++- .../model_multilabel.py | 5 +++- ...ier.py => test_custom_image_classifier.py} | 23 +++++++++++-------- .../classifiers/test_semisl_classifier.py | 4 ++-- .../classifiers/test_semisl_mlc_classifier.py | 4 ++-- .../adapters/mmcls/test_task.py | 6 +++-- 28 files changed, 112 insertions(+), 71 deletions(-) rename src/otx/algorithms/classification/adapters/mmcls/models/classifiers/{sam_classifier.py => custom_image_classifier.py} (98%) rename tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/{test_sam_classifier.py => test_custom_image_classifier.py} (91%) diff --git a/src/otx/algorithms/classification/adapters/mmcls/configurer.py b/src/otx/algorithms/classification/adapters/mmcls/configurer.py index d0ecbfb4e2c..e9c380cdb5c 100644 --- a/src/otx/algorithms/classification/adapters/mmcls/configurer.py +++ b/src/otx/algorithms/classification/adapters/mmcls/configurer.py @@ -572,7 +572,7 @@ def _configure_dataloader(cfg): "MPAHierarchicalClsDataset", "ClsTVDataset", ] -WEIGHT_MIX_CLASSIFIER = ["SAMImageClassifier"] +WEIGHT_MIX_CLASSIFIER = ["CustomImageClassifier"] class IncrClassificationConfigurer(ClassificationConfigurer): diff --git a/src/otx/algorithms/classification/adapters/mmcls/models/__init__.py b/src/otx/algorithms/classification/adapters/mmcls/models/__init__.py index ee3c040a319..873e9fca15f 100644 --- a/src/otx/algorithms/classification/adapters/mmcls/models/__init__.py +++ b/src/otx/algorithms/classification/adapters/mmcls/models/__init__.py @@ -1,20 +1,10 @@ """OTX Algorithms - Classification Models.""" -# Copyright (C) 2022 Intel Corporation +# Copyright (C) 2022-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. -from .classifiers import BYOL, SAMImageClassifier, SemiSLClassifier, SupConClassifier +from .classifiers import BYOL, CustomImageClassifier, SemiSLClassifier, SupConClassifier from .heads import ( ClsHead, ConstrastiveHead, @@ -41,7 +31,7 @@ __all__ = [ "BYOL", - "SAMImageClassifier", + "CustomImageClassifier", "SemiSLClassifier", "SupConClassifier", "CustomLinearClsHead", diff --git a/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/__init__.py b/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/__init__.py index ff42c4f6085..432ff849ac1 100644 --- a/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/__init__.py +++ b/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/__init__.py @@ -1,23 +1,13 @@ """OTX Algorithms - Classification Classifiers.""" # Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 # -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions -# and limitations under the License. from .byol import BYOL -from .sam_classifier import SAMImageClassifier +from .custom_image_classifier import CustomImageClassifier from .semisl_classifier import SemiSLClassifier from .semisl_multilabel_classifier import SemiSLMultilabelClassifier from .supcon_classifier import SupConClassifier -__all__ = ["BYOL", "SAMImageClassifier", "SemiSLClassifier", "SemiSLMultilabelClassifier", "SupConClassifier"] +__all__ = ["BYOL", "CustomImageClassifier", "SemiSLClassifier", "SemiSLMultilabelClassifier", "SupConClassifier"] diff --git a/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/sam_classifier.py b/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/custom_image_classifier.py similarity index 98% rename from src/otx/algorithms/classification/adapters/mmcls/models/classifiers/sam_classifier.py rename to src/otx/algorithms/classification/adapters/mmcls/models/classifiers/custom_image_classifier.py index 68249a8f6be..6056b81e1b6 100644 --- a/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/sam_classifier.py +++ b/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/custom_image_classifier.py @@ -1,5 +1,5 @@ """Module for defining SAMClassifier for classification task.""" -# Copyright (C) 2022 Intel Corporation +# Copyright (C) 2022-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # from functools import partial @@ -17,7 +17,7 @@ @CLASSIFIERS.register_module() -class SAMImageClassifier(SAMClassifierMixin, ClsLossDynamicsTrackingMixin, ImageClassifier): +class CustomImageClassifier(SAMClassifierMixin, ClsLossDynamicsTrackingMixin, ImageClassifier): """SAM-enabled ImageClassifier.""" def __init__(self, task_adapt=None, **kwargs): @@ -283,7 +283,7 @@ def extract_feat(self, img): ) @FUNCTION_REWRITER.register_rewriter( - "otx.algorithms.classification.adapters.mmcls.models.classifiers.SAMImageClassifier.extract_feat" + "otx.algorithms.classification.adapters.mmcls.models.classifiers.CustomImageClassifier.extract_feat" ) def sam_image_classifier__extract_feat(ctx, self, img): # pylint: disable=unused-argument """Feature extraction function for SAMClassifier with mmdeploy.""" @@ -298,7 +298,7 @@ def sam_image_classifier__extract_feat(ctx, self, img): # pylint: disable=unuse return feat, backbone_feat @FUNCTION_REWRITER.register_rewriter( - "otx.algorithms.classification.adapters.mmcls.models.classifiers.SAMImageClassifier.simple_test" + "otx.algorithms.classification.adapters.mmcls.models.classifiers.CustomImageClassifier.simple_test" ) def sam_image_classifier__simple_test(ctx, self, img, img_metas): # pylint: disable=unused-argument """Simple test function used for inference for SAMClassifier with mmdeploy.""" diff --git a/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/semisl_classifier.py b/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/semisl_classifier.py index bd83c6fb449..33850bff708 100644 --- a/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/semisl_classifier.py +++ b/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/semisl_classifier.py @@ -1,5 +1,5 @@ """Module for defining a semi-supervised classifier using mmcls.""" -# Copyright (C) 2022 Intel Corporation +# Copyright (C) 2022-2023 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # @@ -8,13 +8,13 @@ from otx.algorithms.common.utils.logger import get_logger -from .sam_classifier import SAMImageClassifier +from .custom_image_classifier import CustomImageClassifier logger = get_logger() @CLASSIFIERS.register_module() -class SemiSLClassifier(SAMImageClassifier): +class SemiSLClassifier(CustomImageClassifier): """Semi-SL Classifier. This classifier supports unlabeled data by overriding forward_train diff --git a/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/semisl_multilabel_classifier.py b/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/semisl_multilabel_classifier.py index 6ab9a9edb39..1a773054384 100644 --- a/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/semisl_multilabel_classifier.py +++ b/src/otx/algorithms/classification/adapters/mmcls/models/classifiers/semisl_multilabel_classifier.py @@ -1,19 +1,19 @@ """Module for defining a semi-supervised multi-label classifier using mmcls.""" # Copyright (C) 2023 Intel Corporation -# # SPDX-License-Identifier: Apache-2.0 +# from mmcls.models.builder import CLASSIFIERS from otx.algorithms.common.utils.logger import get_logger -from .sam_classifier import SAMImageClassifier +from .custom_image_classifier import CustomImageClassifier logger = get_logger() @CLASSIFIERS.register_module() -class SemiSLMultilabelClassifier(SAMImageClassifier): +class SemiSLMultilabelClassifier(CustomImageClassifier): """Semi-SL Multilabel Classifier which supports unlabeled data by overriding forward_train.""" def forward_train(self, img, gt_label, **kwargs): diff --git a/src/otx/algorithms/classification/configs/deit_tiny/model.py b/src/otx/algorithms/classification/configs/deit_tiny/model.py index d250f7eef70..f69c8cdbbb6 100644 --- a/src/otx/algorithms/classification/configs/deit_tiny/model.py +++ b/src/otx/algorithms/classification/configs/deit_tiny/model.py @@ -1,4 +1,7 @@ """deit-tiny for multi-class config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name @@ -6,7 +9,7 @@ ckpt_url = "https://download.openmmlab.com/mmclassification/v0/deit/deit-tiny_pt-4xb256_in1k_20220218-13b382a0.pth" model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict(arch="deit-tiny", init_cfg=dict(type="Pretrained", checkpoint=ckpt_url, prefix="backbone")), ) diff --git a/src/otx/algorithms/classification/configs/deit_tiny/model_hierarchical.py b/src/otx/algorithms/classification/configs/deit_tiny/model_hierarchical.py index 7c824e42c0b..cfe90a9036e 100644 --- a/src/otx/algorithms/classification/configs/deit_tiny/model_hierarchical.py +++ b/src/otx/algorithms/classification/configs/deit_tiny/model_hierarchical.py @@ -1,4 +1,7 @@ """deit-tiny for hierarchical config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name @@ -6,7 +9,7 @@ ckpt_url = "https://download.openmmlab.com/mmclassification/v0/deit/deit-tiny_pt-4xb256_in1k_20220218-13b382a0.pth" model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict(arch="deit-tiny", init_cfg=dict(type="Pretrained", checkpoint=ckpt_url, prefix="backbone")), head=dict( diff --git a/src/otx/algorithms/classification/configs/deit_tiny/model_multilabel.py b/src/otx/algorithms/classification/configs/deit_tiny/model_multilabel.py index 9acb208ac36..3238948cace 100644 --- a/src/otx/algorithms/classification/configs/deit_tiny/model_multilabel.py +++ b/src/otx/algorithms/classification/configs/deit_tiny/model_multilabel.py @@ -1,4 +1,7 @@ """deit-tiny for multi-label config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name @@ -6,7 +9,7 @@ ckpt_url = "https://download.openmmlab.com/mmclassification/v0/deit/deit-tiny_pt-4xb256_in1k_20220218-13b382a0.pth" model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict(arch="deit-tiny", init_cfg=dict(type="Pretrained", checkpoint=ckpt_url, prefix="backbone")), head=dict( diff --git a/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model.py b/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model.py index f054d5d561f..4055b7ff90b 100644 --- a/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model.py +++ b/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model.py @@ -1,11 +1,14 @@ """EfficientNet-B0 for multi-class config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/efficientnet.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict( version="b0", diff --git a/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model_hierarchical.py b/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model_hierarchical.py index d74d4e55220..d022dab122a 100644 --- a/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model_hierarchical.py +++ b/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model_hierarchical.py @@ -1,11 +1,14 @@ """EfficientNet-B0 for hierarchical config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/efficientnet.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict( version="b0", diff --git a/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model_multilabel.py b/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model_multilabel.py index 6cfc08839d7..1dad67ed874 100644 --- a/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model_multilabel.py +++ b/src/otx/algorithms/classification/configs/efficientnet_b0_cls_incr/model_multilabel.py @@ -1,11 +1,14 @@ """EfficientNet-B0 for multi-label config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/multilabel/incremental.yaml", "../base/models/efficientnet.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict( version="b0", diff --git a/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model.py b/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model.py index 6337fe722bf..b0a278536cd 100644 --- a/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model.py +++ b/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model.py @@ -1,11 +1,14 @@ """EfficientNet-V2 for multi-class config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/efficientnet_v2.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict( version="s_21k", diff --git a/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model_hierarchical.py b/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model_hierarchical.py index 518845b4004..fbd590c9535 100644 --- a/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model_hierarchical.py +++ b/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model_hierarchical.py @@ -1,11 +1,14 @@ """EfficientNet-V2 for hierarchical config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/efficientnet_v2.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict(version="s_21k"), head=dict( diff --git a/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model_multilabel.py b/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model_multilabel.py index 3a3ab87ae84..b7c4743baf0 100644 --- a/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model_multilabel.py +++ b/src/otx/algorithms/classification/configs/efficientnet_v2_s_cls_incr/model_multilabel.py @@ -1,11 +1,14 @@ """EfficientNet-V2 for multi-label config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/multilabel/incremental.yaml", "../base/models/efficientnet_v2.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict( version="s_21k", diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model.py b/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model.py index e48bd28770a..36c0986b557 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model.py @@ -1,11 +1,14 @@ """MobileNet-V3-large-075 for multi-class config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict( mode="large", diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model_hierarchical.py b/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model_hierarchical.py index ead4c5c7271..1ac0b51bcd1 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model_hierarchical.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model_hierarchical.py @@ -1,11 +1,14 @@ """MobileNet-V3-large-075 for hierarchical config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict( mode="large", diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model_multilabel.py b/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model_multilabel.py index d5e0ec018e2..38c370e2af5 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model_multilabel.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_large_075_cls_incr/model_multilabel.py @@ -1,11 +1,14 @@ """MobileNet-V3-large-075 for multi-label config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/multilabel/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict( mode="large", diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model.py b/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model.py index 18e15ad7dd4..6441b503ee8 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model.py @@ -1,11 +1,14 @@ """MobileNet-V3-large-1 for multi-class config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict(mode="large"), head=dict( diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model_hierarchical.py b/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model_hierarchical.py index 1b43d67fdbb..8e5853da48c 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model_hierarchical.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model_hierarchical.py @@ -1,11 +1,14 @@ """MobileNet-V3-large-1 for hierarchical config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict(mode="large"), head=dict( diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model_multilabel.py b/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model_multilabel.py index 8bed4378322..e14c5479cff 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model_multilabel.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_large_1_cls_incr/model_multilabel.py @@ -1,11 +1,14 @@ """MobileNet-V3-large-1 for multi-label config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/multilabel/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", backbone=dict(mode="large"), head=dict( diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model.py b/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model.py index 613f8df63ab..2117d8a3014 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model.py @@ -1,10 +1,13 @@ """MobileNet-V3-Small for multi-class config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", ) diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model_hierarchical.py b/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model_hierarchical.py index 19d4a184a80..77f108deb3e 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model_hierarchical.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model_hierarchical.py @@ -1,11 +1,14 @@ """MobileNet-V3-Small for hierarchical config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", head=dict( type="CustomHierarchicalNonLinearClsHead", diff --git a/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model_multilabel.py b/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model_multilabel.py index 8d543455bcb..918699d51a0 100644 --- a/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model_multilabel.py +++ b/src/otx/algorithms/classification/configs/mobilenet_v3_small_cls_incr/model_multilabel.py @@ -1,11 +1,14 @@ """MobileNet-V3-Small for multi-label config.""" +# Copyright (C) 2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# # pylint: disable=invalid-name _base_ = ["../../../../recipes/stages/classification/multilabel/incremental.yaml", "../base/models/mobilenet_v3.py"] model = dict( - type="SAMImageClassifier", + type="CustomImageClassifier", task="classification", head=dict( type="CustomMultiLabelNonLinearClsHead", diff --git a/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_sam_classifier.py b/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_custom_image_classifier.py similarity index 91% rename from tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_sam_classifier.py rename to tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_custom_image_classifier.py index 1ec67d52c37..54b69219a56 100644 --- a/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_sam_classifier.py +++ b/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_custom_image_classifier.py @@ -1,3 +1,8 @@ +""" Tests for CustomImageClassifier.""" +# Copyright (C) 2022-2023 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 +# + import os.path as osp from copy import deepcopy from typing import Any, Dict @@ -6,9 +11,9 @@ import torch import datumaro as dm -from otx.algorithms.classification.adapters.mmcls.models.classifiers.sam_classifier import ( +from otx.algorithms.classification.adapters.mmcls.models.classifiers.custom_image_classifier import ( ImageClassifier, - SAMImageClassifier, + CustomImageClassifier, ) from otx.api.entities.datasets import DatasetEntity from tests.test_suite.e2e_test_system import e2e_pytest_unit @@ -58,13 +63,13 @@ def state_dict(self): return self._state_dict -class TestSAMImageClassifier: +class TestCustomImageClassifier: @pytest.fixture(autouse=True) def setup(self, mocker) -> None: mocker.patch.object(ImageClassifier, "__init__", return_value=None) - SAMImageClassifier._register_state_dict_hook = mocker.MagicMock() - SAMImageClassifier._register_load_state_dict_pre_hook = mocker.MagicMock() - self.classifier = SAMImageClassifier() + CustomImageClassifier._register_state_dict_hook = mocker.MagicMock() + CustomImageClassifier._register_load_state_dict_pre_hook = mocker.MagicMock() + self.classifier = CustomImageClassifier() @e2e_pytest_unit def test_forward_train(self, mocker): @@ -139,7 +144,7 @@ class TestLossDynamicsTrackingMixin: ] @pytest.fixture() - def classifier(self, request, mocker, fxt_multi_class_cls_dataset_entity: DatasetEntity) -> SAMImageClassifier: + def classifier(self, request, mocker, fxt_multi_class_cls_dataset_entity: DatasetEntity) -> CustomImageClassifier: head_type, loss_type = request.param n_data = len(fxt_multi_class_cls_dataset_entity) labels = fxt_multi_class_cls_dataset_entity.get_labels() @@ -166,7 +171,7 @@ def forward(self, *args, **kwargs): return torch.randn([n_data, 10]) mocker.patch("mmcls.models.classifiers.image.build_backbone", return_value=MockBackbone()) - classifier = SAMImageClassifier(track_loss_dynamics=True, **cfg) + classifier = CustomImageClassifier(track_loss_dynamics=True, **cfg) classifier.loss_dyns_tracker.init_with_otx_dataset(fxt_multi_class_cls_dataset_entity) return classifier @@ -196,7 +201,7 @@ def data(self, fxt_multi_class_cls_dataset_entity: DatasetEntity): @torch.no_grad() @pytest.mark.parametrize("classifier", TESTCASE, indirect=True, ids=lambda x: "-".join(x)) - def test_train_step(self, classifier: SAMImageClassifier, data: Dict[str, Any], tmp_dir_path: str): + def test_train_step(self, classifier: CustomImageClassifier, data: Dict[str, Any], tmp_dir_path: str): outputs = classifier.train_step(data) assert "loss_dyns" in outputs diff --git a/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_semisl_classifier.py b/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_semisl_classifier.py index a5886714d6f..ed0ba1c29a8 100644 --- a/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_semisl_classifier.py +++ b/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_semisl_classifier.py @@ -6,7 +6,7 @@ import torch from otx.algorithms.classification.adapters.mmcls.models.classifiers.semisl_classifier import ( - SAMImageClassifier, + CustomImageClassifier, SemiSLClassifier, ) from tests.test_suite.e2e_test_system import e2e_pytest_unit @@ -15,7 +15,7 @@ class TestSemiSLClassifier: @pytest.fixture(autouse=True) def setup(self, mocker) -> None: - mocker.patch.object(SAMImageClassifier, "__init__", return_value=None) + mocker.patch.object(CustomImageClassifier, "__init__", return_value=None) self.semisl_classifier = SemiSLClassifier() self.kwargs = dict() diff --git a/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_semisl_mlc_classifier.py b/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_semisl_mlc_classifier.py index 869ff4770ed..7ed1e00c6f3 100644 --- a/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_semisl_mlc_classifier.py +++ b/tests/unit/algorithms/classification/adapters/mmcls/models/classifiers/test_semisl_mlc_classifier.py @@ -6,7 +6,7 @@ import torch from otx.algorithms.classification.adapters.mmcls.models.classifiers.semisl_multilabel_classifier import ( - SAMImageClassifier, + CustomImageClassifier, SemiSLMultilabelClassifier, ) from tests.test_suite.e2e_test_system import e2e_pytest_unit @@ -15,7 +15,7 @@ class TestSemiSLMultilabelClassifier: @pytest.fixture(autouse=True) def setup(self, mocker) -> None: - mocker.patch.object(SAMImageClassifier, "__init__", return_value=None) + mocker.patch.object(CustomImageClassifier, "__init__", return_value=None) self.semisl_classifier = SemiSLMultilabelClassifier() self.kwargs = dict() diff --git a/tests/unit/algorithms/classification/adapters/mmcls/test_task.py b/tests/unit/algorithms/classification/adapters/mmcls/test_task.py index 31cdbaee923..ea41fe45404 100644 --- a/tests/unit/algorithms/classification/adapters/mmcls/test_task.py +++ b/tests/unit/algorithms/classification/adapters/mmcls/test_task.py @@ -19,7 +19,9 @@ from otx.algorithms.common.adapters.mmcv.utils import config_utils from otx.algorithms.common.adapters.mmcv.utils.config_utils import MPAConfig from otx.algorithms.classification.adapters.mmcls.task import MMClassificationTask -from otx.algorithms.classification.adapters.mmcls.models.classifiers.sam_classifier import SAMImageClassifier +from otx.algorithms.classification.adapters.mmcls.models.classifiers.custom_image_classifier import ( + CustomImageClassifier, +) from otx.algorithms.classification.configs.base import ClassificationConfig from otx.api.configuration import ConfigurableParameters from otx.api.configuration.helper import create @@ -161,7 +163,7 @@ def test_build_model(self, mocker) -> None: _mock_recipe_cfg.model.pop("task") _mock_recipe_cfg["channel_last"] = False model = self.mc_cls_task.build_model(_mock_recipe_cfg, True) - assert isinstance(model, SAMImageClassifier) + assert isinstance(model, CustomImageClassifier) _mock_recipe_cfg["channel_last"] = True new_model = self.mc_cls_task.build_model(_mock_recipe_cfg, True)