diff --git a/.dev_scripts/benchmark_inference_fps.py b/.dev_scripts/benchmark_inference_fps.py index 5d46d52a8e3..81dcd6b1a1f 100644 --- a/.dev_scripts/benchmark_inference_fps.py +++ b/.dev_scripts/benchmark_inference_fps.py @@ -7,6 +7,7 @@ from mmcv import Config, DictAction from mmcv.runner import init_dist from terminaltables import GithubFlavoredMarkdownTable + from tools.analysis_tools.benchmark import repeat_measure_inference_speed diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 13e4cc406c4..8c21d42d8b0 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,12 +3,8 @@ repos: rev: 3.8.3 hooks: - id: flake8 - - repo: https://github.com/asottile/seed-isort-config - rev: v2.2.0 - hooks: - - id: seed-isort-config - - repo: https://github.com/timothycrosley/isort - rev: 4.3.21 + - repo: https://github.com/PyCQA/isort + rev: 5.10.1 hooks: - id: isort - repo: https://github.com/pre-commit/mirrors-yapf diff --git a/mmdet/core/bbox/assigners/assign_result.py b/mmdet/core/bbox/assigners/assign_result.py index eda0a01d56f..c1a2d5f371f 100644 --- a/mmdet/core/bbox/assigners/assign_result.py +++ b/mmdet/core/bbox/assigners/assign_result.py @@ -140,6 +140,7 @@ def random(cls, **kwargs): labels = None else: import numpy as np + # Create an overlap for each predicted box max_overlaps = torch.from_numpy(rng.rand(num_preds)) diff --git a/mmdet/core/bbox/samplers/sampling_result.py b/mmdet/core/bbox/samplers/sampling_result.py index 6c03c7bb4d7..7d106cbeffd 100644 --- a/mmdet/core/bbox/samplers/sampling_result.py +++ b/mmdet/core/bbox/samplers/sampling_result.py @@ -112,9 +112,9 @@ def random(cls, rng=None, **kwargs): >>> self = SamplingResult.random() >>> print(self.__dict__) """ - from mmdet.core.bbox.samplers.random_sampler import RandomSampler - from mmdet.core.bbox.assigners.assign_result import AssignResult from mmdet.core.bbox import demodata + from mmdet.core.bbox.assigners.assign_result import AssignResult + from mmdet.core.bbox.samplers.random_sampler import RandomSampler rng = demodata.ensure_rng(rng) # make probabalistic? diff --git a/mmdet/core/mask/structures.py b/mmdet/core/mask/structures.py index 8fd30680a67..285e9cc1e7e 100644 --- a/mmdet/core/mask/structures.py +++ b/mmdet/core/mask/structures.py @@ -960,6 +960,7 @@ def _gen_polygon(n, irregularity, spikeyness): a list of vertices, in CCW order. """ from scipy.stats import truncnorm + # Generate around the unit circle cx, cy = (0.0, 0.0) radius = 1 diff --git a/mmdet/datasets/api_wrappers/panoptic_evaluation.py b/mmdet/datasets/api_wrappers/panoptic_evaluation.py index 1a21fe8f098..9b34201e1c5 100644 --- a/mmdet/datasets/api_wrappers/panoptic_evaluation.py +++ b/mmdet/datasets/api_wrappers/panoptic_evaluation.py @@ -11,7 +11,7 @@ import numpy as np try: - from panopticapi.evaluation import PQStat, VOID, OFFSET + from panopticapi.evaluation import OFFSET, VOID, PQStat from panopticapi.utils import rgb2id except ImportError: PQStat = None diff --git a/mmdet/datasets/builder.py b/mmdet/datasets/builder.py index ab0d3a801b5..30e1ee91a05 100644 --- a/mmdet/datasets/builder.py +++ b/mmdet/datasets/builder.py @@ -56,8 +56,8 @@ def _concat_dataset(cfg, default_args=None): def build_dataset(cfg, default_args=None): - from .dataset_wrappers import (ConcatDataset, RepeatDataset, - ClassBalancedDataset, MultiImageMixDataset) + from .dataset_wrappers import (ClassBalancedDataset, ConcatDataset, + MultiImageMixDataset, RepeatDataset) if isinstance(cfg, (list, tuple)): dataset = ConcatDataset([build_dataset(c, default_args) for c in cfg]) elif cfg['type'] == 'ConcatDataset': diff --git a/mmdet/datasets/lvis.py b/mmdet/datasets/lvis.py index d91138effca..511e31aebec 100644 --- a/mmdet/datasets/lvis.py +++ b/mmdet/datasets/lvis.py @@ -343,7 +343,7 @@ def evaluate(self, warnings.warn( 'mmlvis is deprecated, please install official lvis-api by "pip install git+https://github.com/lvis-dataset/lvis-api.git"', # noqa: E501 UserWarning) - from lvis import LVISResults, LVISEval + from lvis import LVISEval, LVISResults except ImportError: raise ImportError( 'Package lvis is not installed. Please run "pip install git+https://github.com/lvis-dataset/lvis-api.git".' # noqa: E501 diff --git a/mmdet/models/backbones/pvt.py b/mmdet/models/backbones/pvt.py index 9443273a62e..8b7d5d5344a 100644 --- a/mmdet/models/backbones/pvt.py +++ b/mmdet/models/backbones/pvt.py @@ -158,7 +158,7 @@ def __init__(self, self.norm = build_norm_layer(norm_cfg, embed_dims)[1] # handle the BC-breaking from https://github.com/open-mmlab/mmcv/pull/1418 # noqa - from mmdet import mmcv_version, digit_version + from mmdet import digit_version, mmcv_version if mmcv_version < digit_version('1.3.17'): warnings.warn('The legacy version of forward function in' 'SpatialReductionAttention is deprecated in' diff --git a/setup.cfg b/setup.cfg index 18adf687165..c298a0e6e3b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [isort] line_length = 79 multi_line_output = 0 -known_standard_library = setuptools +extra_standard_library = setuptools known_first_party = mmdet known_third_party = PIL,asynctest,cityscapesscripts,cv2,gather_models,matplotlib,mmcv,numpy,onnx,onnxruntime,pycocotools,pytest,pytorch_sphinx_theme,requests,scipy,seaborn,six,terminaltables,torch,ts,yaml no_lines_before = STDLIB,LOCALFOLDER diff --git a/setup.py b/setup.py index e5cb8bea6fc..6bc78853ac1 100755 --- a/setup.py +++ b/setup.py @@ -67,9 +67,9 @@ def parse_requirements(fname='requirements.txt', with_version=True): CommandLine: python -c "import setup; print(setup.parse_requirements())" """ + import re import sys from os.path import exists - import re require_fpath = fname def parse_line(line): diff --git a/tests/test_data/test_pipelines/test_transform/test_img_augment.py b/tests/test_data/test_pipelines/test_transform/test_img_augment.py index 2a65fc2e81c..f28030e9689 100644 --- a/tests/test_data/test_pipelines/test_transform/test_img_augment.py +++ b/tests/test_data/test_pipelines/test_transform/test_img_augment.py @@ -45,7 +45,7 @@ def test_imequalize(nb_rand_test=100): def _imequalize(img): # equalize the image using PIL.ImageOps.equalize - from PIL import ImageOps, Image + from PIL import Image, ImageOps img = Image.fromarray(img) equalized_img = np.asarray(ImageOps.equalize(img)) return equalized_img @@ -81,8 +81,8 @@ def test_adjust_brightness(nb_rand_test=100): def _adjust_brightness(img, factor): # adjust the brightness of image using # PIL.ImageEnhance.Brightness - from PIL.ImageEnhance import Brightness from PIL import Image + from PIL.ImageEnhance import Brightness img = Image.fromarray(img) brightened_img = Brightness(img).enhance(factor) return np.asarray(brightened_img) @@ -124,8 +124,9 @@ def _adjust_brightness(img, factor): def test_adjust_contrast(nb_rand_test=100): def _adjust_contrast(img, factor): - from PIL.ImageEnhance import Contrast from PIL import Image + from PIL.ImageEnhance import Contrast + # Image.fromarray defaultly supports RGB, not BGR. # convert from BGR to RGB img = Image.fromarray(img[..., ::-1], mode='RGB') diff --git a/tests/test_models/test_forward.py b/tests/test_models/test_forward.py index 9e51c17176a..db75b2fd418 100644 --- a/tests/test_models/test_forward.py +++ b/tests/test_models/test_forward.py @@ -616,9 +616,10 @@ def test_detr_forward(): def test_inference_detector(): + from mmcv import ConfigDict + from mmdet.apis import inference_detector from mmdet.models import build_detector - from mmcv import ConfigDict # small RetinaNet num_class = 3 diff --git a/tests/test_models/test_roi_heads/test_bbox_head.py b/tests/test_models/test_roi_heads/test_bbox_head.py index 07753b83470..e839d0672c5 100644 --- a/tests/test_models/test_roi_heads/test_bbox_head.py +++ b/tests/test_models/test_roi_heads/test_bbox_head.py @@ -213,8 +213,8 @@ def _demodata_refine_boxes(n_roi, n_img, rng=0): """Create random test data for the ``mmdet.models.bbox_heads.bbox_head.BBoxHead.refine_boxes`` method.""" import numpy as np - from mmdet.core.bbox.demodata import random_boxes - from mmdet.core.bbox.demodata import ensure_rng + + from mmdet.core.bbox.demodata import ensure_rng, random_boxes try: import kwarray except ImportError: diff --git a/tests/test_models/test_roi_heads/test_mask_head.py b/tests/test_models/test_roi_heads/test_mask_head.py index 0aa20099a72..89a476dc7a1 100644 --- a/tests/test_models/test_roi_heads/test_mask_head.py +++ b/tests/test_models/test_roi_heads/test_mask_head.py @@ -30,6 +30,7 @@ def test_mask_head_loss(): # create dummy mask import numpy as np + from mmdet.core import BitmapMasks dummy_mask = np.random.randint(0, 2, (1, 160, 240), dtype=np.uint8) gt_masks = [BitmapMasks(dummy_mask, 160, 240)] diff --git a/tests/test_runtime/test_config.py b/tests/test_runtime/test_config.py index 2f9c33ba087..dce88f41bf4 100644 --- a/tests/test_runtime/test_config.py +++ b/tests/test_runtime/test_config.py @@ -115,6 +115,7 @@ def _check_roi_head(config, head): def _check_roi_extractor(config, roi_extractor, prev_roi_extractor=None): import torch.nn as nn + # Separate roi_extractor and prev_roi_extractor checks for flexibility if isinstance(roi_extractor, nn.ModuleList): roi_extractor = roi_extractor[0] @@ -259,9 +260,10 @@ def test_config_data_pipeline(config_rpath): xdoctest -m tests/test_runtime/ test_config.py test_config_build_data_pipeline """ + import numpy as np from mmcv import Config + from mmdet.datasets.pipelines import Compose - import numpy as np config_dpath = _get_config_directory() print(f'Found config_dpath = {config_dpath}') diff --git a/tests/test_utils/test_anchor.py b/tests/test_utils/test_anchor.py index 83a1befb290..a9aef721203 100644 --- a/tests/test_utils/test_anchor.py +++ b/tests/test_utils/test_anchor.py @@ -11,6 +11,7 @@ def test_standard_points_generator(): from mmdet.core.anchor import build_prior_generator + # teat init anchor_generator_cfg = dict( type='MlvlPointGenerator', strides=[4, 8], offset=0) @@ -286,6 +287,7 @@ def test_standard_anchor_generator(): def test_strides(): from mmdet.core import AnchorGenerator + # Square strides self = AnchorGenerator([10], [1.], [1.], [10]) anchors = self.grid_anchors([(2, 2)], device='cpu') diff --git a/tools/analysis_tools/test_robustness.py b/tools/analysis_tools/test_robustness.py index 29cb41da657..0c1ddbeec54 100644 --- a/tools/analysis_tools/test_robustness.py +++ b/tools/analysis_tools/test_robustness.py @@ -12,13 +12,13 @@ wrap_fp16_model) from pycocotools.coco import COCO from pycocotools.cocoeval import COCOeval -from tools.analysis_tools.robustness_eval import get_results from mmdet import datasets from mmdet.apis import multi_gpu_test, set_random_seed, single_gpu_test from mmdet.core import eval_map from mmdet.datasets import build_dataloader, build_dataset from mmdet.models import build_detector +from tools.analysis_tools.robustness_eval import get_results def coco_eval_with_return(result_files,