From 6e8681966dad94f2f5abda6463c1a0d7af7f7995 Mon Sep 17 00:00:00 2001 From: "Cho, Sungman" Date: Thu, 29 Dec 2022 02:12:16 +0900 Subject: [PATCH] Resolve some flake8 issues --- .pre-commit-config.yaml | 2 +- otx/mpa/cls/explainer.py | 1 - otx/mpa/cls/exporter.py | 2 +- otx/mpa/cls/stage.py | 1 + otx/mpa/cls/trainer.py | 1 + otx/mpa/det/inferrer.py | 1 + otx/mpa/det/semisl/__init__.py | 2 -- otx/mpa/det/trainer.py | 2 -- otx/mpa/modules/datasets/seg_incr_voc_dataset.py | 1 - otx/mpa/modules/hooks/model_ema_v2_hook.py | 1 - otx/mpa/modules/ov/graph/graph.py | 3 ++- otx/mpa/modules/ov/models/__init__.py | 2 -- otx/mpa/seg/inferrer.py | 1 - 13 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5ffae63f1c6..50e8dc50f3e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: name: "flake8" files: '^(otx|tests)/.*\.py' args: ["--config", ".flake8", "--max-complexity", "20"] - exclude: "^(.*/protobuf|tests/ote_cli)" + exclude: "^(.*/protobuf|tests/ote_cli)|otx/mpa|otx/recipes" # yaml formatting - repo: https://github.com/pre-commit/mirrors-prettier diff --git a/otx/mpa/cls/explainer.py b/otx/mpa/cls/explainer.py index 79bd8589076..fc9b7c00e06 100644 --- a/otx/mpa/cls/explainer.py +++ b/otx/mpa/cls/explainer.py @@ -8,7 +8,6 @@ import torch from mmcls.datasets import build_dataloader, build_dataset from mmcls.models import build_classifier -from mmcv.parallel import MMDataParallel from mmcv.runner import load_checkpoint, wrap_fp16_model from otx.mpa.cls.stage import ClsStage diff --git a/otx/mpa/cls/exporter.py b/otx/mpa/cls/exporter.py index aa509bed836..907e82cdecc 100644 --- a/otx/mpa/cls/exporter.py +++ b/otx/mpa/cls/exporter.py @@ -10,7 +10,7 @@ import torch.onnx from mmcls.datasets.pipelines import Compose from mmcls.models import build_classifier -from mmcv.runner import load_checkpoint, wrap_fp16_model +from mmcv.runner import load_checkpoint from otx.mpa.registry import STAGES from otx.mpa.utils import mo_wrapper diff --git a/otx/mpa/cls/stage.py b/otx/mpa/cls/stage.py index 812dc538b01..0924c7e6364 100644 --- a/otx/mpa/cls/stage.py +++ b/otx/mpa/cls/stage.py @@ -161,6 +161,7 @@ def configure_model(cfg, training, **kwargs): # checking task incremental model configurations + # noqa: C901 @staticmethod def configure_task(cfg, training, model_meta=None, **kwargs): """Configure for Task Adaptation Task""" diff --git a/otx/mpa/cls/trainer.py b/otx/mpa/cls/trainer.py index 6105906af92..c7faa5e9ec9 100644 --- a/otx/mpa/cls/trainer.py +++ b/otx/mpa/cls/trainer.py @@ -35,6 +35,7 @@ @STAGES.register_module() class ClsTrainer(ClsStage): + # noqa: C901 def run(self, model_cfg, model_ckpt, data_cfg, **kwargs): """Run training stage""" self._init_logger() diff --git a/otx/mpa/det/inferrer.py b/otx/mpa/det/inferrer.py index 736d42d1cb3..d93bc38eccd 100644 --- a/otx/mpa/det/inferrer.py +++ b/otx/mpa/det/inferrer.py @@ -78,6 +78,7 @@ def default(self, obj): print(json_dump) """ + # noqa: C901 def infer(self, cfg, eval=False, dump_features=False, dump_saliency_map=False): samples_per_gpu = cfg.data.test.pop("samples_per_gpu", 1) if samples_per_gpu > 1: diff --git a/otx/mpa/det/semisl/__init__.py b/otx/mpa/det/semisl/__init__.py index f4ac9934e7e..1e19f1159d9 100644 --- a/otx/mpa/det/semisl/__init__.py +++ b/otx/mpa/det/semisl/__init__.py @@ -1,5 +1,3 @@ # Copyright (C) 2022 Intel Corporation # SPDX-License-Identifier: Apache-2.0 # - -from . import inferrer, trainer diff --git a/otx/mpa/det/trainer.py b/otx/mpa/det/trainer.py index 1de9cbc7a2c..396af530fc5 100644 --- a/otx/mpa/det/trainer.py +++ b/otx/mpa/det/trainer.py @@ -19,8 +19,6 @@ from otx.mpa.registry import STAGES from otx.mpa.utils.logger import get_logger -from .stage import DetectionStage - # TODO[JAEGUK]: Remove import detection_tasks # from detection_tasks.apis.detection.config_utils import cluster_anchors diff --git a/otx/mpa/modules/datasets/seg_incr_voc_dataset.py b/otx/mpa/modules/datasets/seg_incr_voc_dataset.py index 37acba567cd..3f41fe9410f 100644 --- a/otx/mpa/modules/datasets/seg_incr_voc_dataset.py +++ b/otx/mpa/modules/datasets/seg_incr_voc_dataset.py @@ -8,7 +8,6 @@ from mmseg.datasets import DATASETS, CustomDataset from otx.mpa.modules.utils.task_adapt import map_class_names -from otx.mpa.utils import logger @DATASETS.register_module() diff --git a/otx/mpa/modules/hooks/model_ema_v2_hook.py b/otx/mpa/modules/hooks/model_ema_v2_hook.py index cb737aed6a0..b98c646dee1 100644 --- a/otx/mpa/modules/hooks/model_ema_v2_hook.py +++ b/otx/mpa/modules/hooks/model_ema_v2_hook.py @@ -6,7 +6,6 @@ import torch import torch.nn as nn -from mmcv.parallel import is_module_wrapper from mmcv.runner import HOOKS, Hook from otx.mpa.utils.logger import get_logger diff --git a/otx/mpa/modules/ov/graph/graph.py b/otx/mpa/modules/ov/graph/graph.py index 967a75a3cc9..f5a8b2b702e 100644 --- a/otx/mpa/modules/ov/graph/graph.py +++ b/otx/mpa/modules/ov/graph/graph.py @@ -343,7 +343,7 @@ def get_nodes_by_types(self, types: List[str]) -> List[Operation]: def bfs( self, node: Operation, reverse: bool = False, depth_limit: Optional[int] = None - ) -> Generator[Union[Tuple[Operation, Operation], Tuple[Operation, Tuple[Operation]]], None, None,]: + ) -> Generator[Union[Tuple[Operation, Operation], Tuple[Operation, Tuple[Operation]]], None, None]: if reverse: for s, t in nx.bfs_edges(self, node, reverse=True, depth_limit=depth_limit): yield (t, s) @@ -406,6 +406,7 @@ def get_nodes_by_type_pattern(self, pattern: List[str], start_node: Optional[Ope start_nodes = [found[-1] for found in founds] return founds + # noqa: C901 def _freeze_normalize_nodes(self): invariant_types = ["Transpose", "Convert"] diff --git a/otx/mpa/modules/ov/models/__init__.py b/otx/mpa/modules/ov/models/__init__.py index 01a8b587443..c9aec6105c1 100644 --- a/otx/mpa/modules/ov/models/__init__.py +++ b/otx/mpa/modules/ov/models/__init__.py @@ -26,5 +26,3 @@ # pass # else: # from . import mmseg - -from .ov_model import OVModel diff --git a/otx/mpa/seg/inferrer.py b/otx/mpa/seg/inferrer.py index 07b9d6ac629..7f5acb841ab 100644 --- a/otx/mpa/seg/inferrer.py +++ b/otx/mpa/seg/inferrer.py @@ -2,7 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 # -import os import os.path as osp from contextlib import nullcontext