Skip to content

Commit

Permalink
[Enhancement] Upgrade isort in pre-commit hook (#7130)
Browse files Browse the repository at this point in the history
* upgrade isort to v5.10.1

* replace known_standard_library with extra_standard_library

* upgrade isort to v5.10.1

replace known_standard_library with extra_standard_library

* imports order changes
  • Loading branch information
chhluo authored Feb 9, 2022
1 parent d09155f commit 9ad0682
Show file tree
Hide file tree
Showing 18 changed files with 29 additions and 23 deletions.
1 change: 1 addition & 0 deletions .dev_scripts/benchmark_inference_fps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions mmdet/core/bbox/assigners/assign_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 2 additions & 2 deletions mmdet/core/bbox/samplers/sampling_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
1 change: 1 addition & 0 deletions mmdet/core/mask/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mmdet/datasets/api_wrappers/panoptic_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions mmdet/datasets/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
2 changes: 1 addition & 1 deletion mmdet/datasets/lvis.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion mmdet/models/backbones/pvt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion tests/test_models/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/test_models/test_roi_heads/test_bbox_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions tests/test_models/test_roi_heads/test_mask_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_runtime/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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}')
Expand Down
2 changes: 2 additions & 0 deletions tests/test_utils/test_anchor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion tools/analysis_tools/test_robustness.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9ad0682

Please sign in to comment.