Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade the version of isort #1705

Merged
merged 2 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,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
3 changes: 2 additions & 1 deletion mmcv/cnn/bricks/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@

# Avoid BC-breaking of importing MultiScaleDeformableAttention from this file
try:
from mmcv.ops.multi_scale_deform_attn import MultiScaleDeformableAttention # noqa F401
from mmcv.ops.multi_scale_deform_attn import \
MultiScaleDeformableAttention # noqa F401
zhouzaida marked this conversation as resolved.
Show resolved Hide resolved
warnings.warn(
ImportWarning(
'``MultiScaleDeformableAttention`` has been moved to '
Expand Down
3 changes: 2 additions & 1 deletion mmcv/fileio/handlers/yaml_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import yaml

try:
from yaml import CLoader as Loader, CDumper as Dumper
from yaml import CDumper as Dumper
from yaml import CLoader as Loader
except ImportError:
from yaml import Loader, Dumper

Expand Down
2 changes: 1 addition & 1 deletion mmcv/onnx/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,8 +409,8 @@ def cummin(g, input, dim):

@parse_args('v', 'v', 'is')
def roll(g, input, shifts, dims):
from torch.onnx.symbolic_opset9 import squeeze
from packaging import version
from torch.onnx.symbolic_opset9 import squeeze
input_shape = g.op('Shape', input)

need_flatten = len(dims) == 0
Expand Down
1 change: 1 addition & 0 deletions mmcv/ops/nms.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def symbolic(g, bboxes, scores, iou_threshold, offset, score_threshold,
offset_i=int(offset))
else:
from torch.onnx.symbolic_opset9 import select, squeeze, unsqueeze

from ..onnx.onnx_utils.symbolic_helper import _size_helper

boxes = unsqueeze(g, bboxes, 0)
Expand Down
5 changes: 3 additions & 2 deletions mmcv/ops/roi_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ def symbolic(g, input, rois, output_size, spatial_scale, sampling_ratio,
mode_s=pool_mode,
aligned_i=aligned)
else:
from torch.onnx.symbolic_opset9 import sub, squeeze
from torch.onnx.symbolic_helper import _slice_helper
from torch.onnx import TensorProtoDataType
from torch.onnx.symbolic_helper import _slice_helper
from torch.onnx.symbolic_opset9 import squeeze, sub

# batch_indices = rois[:, 0].long()
batch_indices = _slice_helper(
g, rois, axes=[1], starts=[0], ends=[1])
Expand Down
16 changes: 10 additions & 6 deletions mmcv/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@
]
else:
from .env import collect_env
from .hub import load_url
from .logging import get_logger, print_log
from .parrots_jit import jit, skip_no_elena
from .parrots_wrapper import (
TORCH_VERSION, BuildExtension, CppExtension, CUDAExtension, DataLoader,
PoolDataLoader, SyncBatchNorm, _AdaptiveAvgPoolNd, _AdaptiveMaxPoolNd,
_AvgPoolNd, _BatchNorm, _ConvNd, _ConvTransposeMixin, _InstanceNorm,
_MaxPoolNd, get_build_config, is_rocm_pytorch, _get_cuda_home)
# yapf: disable
from .parrots_wrapper import (TORCH_VERSION, BuildExtension, CppExtension,
CUDAExtension, DataLoader, PoolDataLoader,
SyncBatchNorm, _AdaptiveAvgPoolNd,
_AdaptiveMaxPoolNd, _AvgPoolNd, _BatchNorm,
_ConvNd, _ConvTransposeMixin, _get_cuda_home,
_InstanceNorm, _MaxPoolNd, get_build_config,
is_rocm_pytorch)
# yapf: enable
from .registry import Registry, build_from_cfg
from .trace import is_jit_tracing
from .hub import load_url
__all__ = [
'Config', 'ConfigDict', 'DictAction', 'collect_env', 'get_logger',
'print_log', 'is_str', 'iter_cast', 'list_cast', 'tuple_cast',
Expand Down
9 changes: 5 additions & 4 deletions mmcv/utils/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
'1.7.0'):
# Modified from https://github.com/pytorch/pytorch/blob/master/torch/hub.py
import os
import torch
import warnings
from urllib.parse import urlparse
import sys
import warnings
import zipfile
from torch.hub import download_url_to_file, _get_torch_home, HASH_REGEX
from urllib.parse import urlparse

import torch
from torch.hub import HASH_REGEX, _get_torch_home, download_url_to_file

# Hub used to support automatically extracts from zipfile manually
# compressed by users. The legacy zip format expects only one file from
Expand Down
2 changes: 1 addition & 1 deletion mmcv/utils/parrots_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ def _get_norm():
from parrots.nn.modules.batchnorm import _BatchNorm, _InstanceNorm
SyncBatchNorm_ = torch.nn.SyncBatchNorm2d
else:
from torch.nn.modules.instancenorm import _InstanceNorm
from torch.nn.modules.batchnorm import _BatchNorm
from torch.nn.modules.instancenorm import _InstanceNorm
SyncBatchNorm_ = torch.nn.SyncBatchNorm
return _BatchNorm, _InstanceNorm, SyncBatchNorm_

Expand Down
3 changes: 2 additions & 1 deletion mmcv/utils/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,9 @@ def assert_is_norm_layer(module) -> bool:
Returns:
bool: Whether the module is a norm layer.
"""
from .parrots_wrapper import _BatchNorm, _InstanceNorm
from torch.nn import GroupNorm, LayerNorm

from .parrots_wrapper import _BatchNorm, _InstanceNorm
norm_layer_candidates = (_BatchNorm, _InstanceNorm, GroupNorm, LayerNorm)
return isinstance(module, norm_layer_candidates)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ split_before_expression_after_opening_paren = true
[isort]
line_length = 79
multi_line_output = 0
known_standard_library = pkg_resources,setuptools,logging,os,warnings,abc
extra_standard_library = pkg_resources,setuptools,logging,os,warnings,abc
known_first_party = mmcv
known_third_party = addict,cv2,numpy,onnx,onnxruntime,packaging,pytest,pytorch_sphinx_theme,scipy,sphinx,tensorrt,torch,torchvision,yaml,yapf
no_lines_before = STDLIB,LOCALFOLDER
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def get_extensions():
if EXT_TYPE == 'parrots':
ext_name = 'mmcv._ext'
from parrots.utils.build_extension import Extension

# new parrots op impl do not use MMCV_USE_PARROTS
# define_macros = [('MMCV_USE_PARROTS', None)]
define_macros = []
Expand Down Expand Up @@ -314,8 +315,8 @@ def get_extensions():

if EXT_TYPE == 'pytorch' and os.getenv('MMCV_WITH_ORT', '0') != '0':
ext_name = 'mmcv._ext_ort'
from torch.utils.cpp_extension import library_paths, include_paths
import onnxruntime
from torch.utils.cpp_extension import include_paths, library_paths
library_dirs = []
libraries = []
include_dirs = []
Expand Down
12 changes: 7 additions & 5 deletions tests/test_image/test_photometric.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def test_imequalize(self, 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 @@ -141,8 +141,8 @@ def test_adjust_brightness(self, 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 All @@ -169,8 +169,9 @@ def _adjust_brightness(img, factor):
def test_adjust_contrast(self, 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 Expand Up @@ -204,8 +205,9 @@ def _adjust_contrast(img, factor):
def test_auto_contrast(self, nb_rand_test=100):

def _auto_contrast(img, cutoff=0):
from PIL.ImageOps import autocontrast
from PIL import Image
from PIL.ImageOps import autocontrast

# Image.fromarray defaultly supports RGB, not BGR.
# convert from BGR to RGB
img = Image.fromarray(img[..., ::-1], mode='RGB')
Expand Down Expand Up @@ -250,8 +252,8 @@ def test_adjust_sharpness(self, nb_rand_test=100):
def _adjust_sharpness(img, factor):
# adjust the sharpness of image using
# PIL.ImageEnhance.Sharpness
from PIL.ImageEnhance import Sharpness
from PIL import Image
from PIL.ImageEnhance import Sharpness
img = Image.fromarray(img)
sharpened_img = Sharpness(img).enhance(factor)
return np.asarray(sharpened_img)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_ops/test_border_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _test_border_align_allclose(device, dtype, pool_size):
if not torch.cuda.is_available() and device == 'cuda':
pytest.skip('test requires GPU')
try:
from mmcv.ops import border_align, BorderAlign
from mmcv.ops import BorderAlign, border_align
except ModuleNotFoundError:
pytest.skip('BorderAlign op is not successfully compiled')

Expand Down
4 changes: 3 additions & 1 deletion tests/test_runner/test_basemodule.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ def __init__(self,
def test_initilization_info_logger():
# 'override' has higher priority

import os

import torch.nn as nn

from mmcv.utils.logging import get_logger
import os

class OverloadInitConv(nn.Conv2d, BaseModule):

Expand Down
4 changes: 0 additions & 4 deletions tests/test_runner/test_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ def __init__(self):

def test_load_checkpoint():
import os

import re
import tempfile

Expand Down Expand Up @@ -230,7 +229,6 @@ def __init__(self):

def test_load_checkpoint_metadata():
import os

import tempfile

from mmcv.runner import load_checkpoint, save_checkpoint
Expand Down Expand Up @@ -301,7 +299,6 @@ def _load_from_state_dict(self, state_dict, prefix, local_metadata,

def test_load_classes_name():
import os

import tempfile

from mmcv.runner import load_checkpoint, save_checkpoint
Expand Down Expand Up @@ -335,7 +332,6 @@ def test_load_classes_name():

def test_checkpoint_loader():
import os

import tempfile

from mmcv.runner import CheckpointLoader, _load_checkpoint, save_checkpoint
Expand Down
1 change: 0 additions & 1 deletion tests/test_utils/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ def func_c():
def test_import_modules_from_strings():
# multiple imports
import os.path as osp_

import sys as sys_
osp, sys = mmcv.import_modules_from_strings(['os.path', 'sys'])
assert osp == osp_
Expand Down