Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
MMCV
Commits
dd82ab14
Unverified
Commit
dd82ab14
authored
Feb 09, 2022
by
Zaida Zhou
Committed by
GitHub
Feb 09, 2022
Browse files
Upgrade the version of isort (#1705)
* Upgrade the version of isort * sort the order of importing modules
parent
b0b30d0c
Changes
17
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
43 additions
and
37 deletions
+43
-37
.pre-commit-config.yaml
.pre-commit-config.yaml
+2
-6
mmcv/cnn/bricks/transformer.py
mmcv/cnn/bricks/transformer.py
+2
-1
mmcv/fileio/handlers/yaml_handler.py
mmcv/fileio/handlers/yaml_handler.py
+2
-1
mmcv/onnx/symbolic.py
mmcv/onnx/symbolic.py
+1
-1
mmcv/ops/nms.py
mmcv/ops/nms.py
+1
-0
mmcv/ops/roi_align.py
mmcv/ops/roi_align.py
+3
-2
mmcv/utils/__init__.py
mmcv/utils/__init__.py
+10
-6
mmcv/utils/hub.py
mmcv/utils/hub.py
+5
-4
mmcv/utils/parrots_wrapper.py
mmcv/utils/parrots_wrapper.py
+1
-1
mmcv/utils/testing.py
mmcv/utils/testing.py
+2
-1
setup.cfg
setup.cfg
+1
-1
setup.py
setup.py
+2
-1
tests/test_image/test_photometric.py
tests/test_image/test_photometric.py
+7
-5
tests/test_ops/test_border_align.py
tests/test_ops/test_border_align.py
+1
-1
tests/test_runner/test_basemodule.py
tests/test_runner/test_basemodule.py
+3
-1
tests/test_runner/test_checkpoint.py
tests/test_runner/test_checkpoint.py
+0
-4
tests/test_utils/test_misc.py
tests/test_utils/test_misc.py
+0
-1
No files found.
.pre-commit-config.yaml
View file @
dd82ab14
...
@@ -4,12 +4,8 @@ repos:
...
@@ -4,12 +4,8 @@ repos:
rev
:
3.8.3
rev
:
3.8.3
hooks
:
hooks
:
-
id
:
flake8
-
id
:
flake8
-
repo
:
https://github.com/asottile/seed-isort-config
-
repo
:
https://github.com/PyCQA/isort
rev
:
v2.2.0
rev
:
5.10.1
hooks
:
-
id
:
seed-isort-config
-
repo
:
https://github.com/timothycrosley/isort
rev
:
4.3.21
hooks
:
hooks
:
-
id
:
isort
-
id
:
isort
-
repo
:
https://github.com/pre-commit/mirrors-yapf
-
repo
:
https://github.com/pre-commit/mirrors-yapf
...
...
mmcv/cnn/bricks/transformer.py
View file @
dd82ab14
...
@@ -19,7 +19,8 @@ from .registry import (ATTENTION, FEEDFORWARD_NETWORK, POSITIONAL_ENCODING,
...
@@ -19,7 +19,8 @@ from .registry import (ATTENTION, FEEDFORWARD_NETWORK, POSITIONAL_ENCODING,
# Avoid BC-breaking of importing MultiScaleDeformableAttention from this file
# Avoid BC-breaking of importing MultiScaleDeformableAttention from this file
try
:
try
:
from
mmcv.ops.multi_scale_deform_attn
import
MultiScaleDeformableAttention
# noqa F401
from
mmcv.ops.multi_scale_deform_attn
import
\
MultiScaleDeformableAttention
# noqa F401
warnings
.
warn
(
warnings
.
warn
(
ImportWarning
(
ImportWarning
(
'``MultiScaleDeformableAttention`` has been moved to '
'``MultiScaleDeformableAttention`` has been moved to '
...
...
mmcv/fileio/handlers/yaml_handler.py
View file @
dd82ab14
...
@@ -2,7 +2,8 @@
...
@@ -2,7 +2,8 @@
import
yaml
import
yaml
try
:
try
:
from
yaml
import
CLoader
as
Loader
,
CDumper
as
Dumper
from
yaml
import
CDumper
as
Dumper
from
yaml
import
CLoader
as
Loader
except
ImportError
:
except
ImportError
:
from
yaml
import
Loader
,
Dumper
from
yaml
import
Loader
,
Dumper
...
...
mmcv/onnx/symbolic.py
View file @
dd82ab14
...
@@ -409,8 +409,8 @@ def cummin(g, input, dim):
...
@@ -409,8 +409,8 @@ def cummin(g, input, dim):
@
parse_args
(
'v'
,
'v'
,
'is'
)
@
parse_args
(
'v'
,
'v'
,
'is'
)
def
roll
(
g
,
input
,
shifts
,
dims
):
def
roll
(
g
,
input
,
shifts
,
dims
):
from
torch.onnx.symbolic_opset9
import
squeeze
from
packaging
import
version
from
packaging
import
version
from
torch.onnx.symbolic_opset9
import
squeeze
input_shape
=
g
.
op
(
'Shape'
,
input
)
input_shape
=
g
.
op
(
'Shape'
,
input
)
need_flatten
=
len
(
dims
)
==
0
need_flatten
=
len
(
dims
)
==
0
...
...
mmcv/ops/nms.py
View file @
dd82ab14
...
@@ -48,6 +48,7 @@ class NMSop(torch.autograd.Function):
...
@@ -48,6 +48,7 @@ class NMSop(torch.autograd.Function):
offset_i
=
int
(
offset
))
offset_i
=
int
(
offset
))
else
:
else
:
from
torch.onnx.symbolic_opset9
import
select
,
squeeze
,
unsqueeze
from
torch.onnx.symbolic_opset9
import
select
,
squeeze
,
unsqueeze
from
..onnx.onnx_utils.symbolic_helper
import
_size_helper
from
..onnx.onnx_utils.symbolic_helper
import
_size_helper
boxes
=
unsqueeze
(
g
,
bboxes
,
0
)
boxes
=
unsqueeze
(
g
,
bboxes
,
0
)
...
...
mmcv/ops/roi_align.py
View file @
dd82ab14
...
@@ -30,9 +30,10 @@ class RoIAlignFunction(Function):
...
@@ -30,9 +30,10 @@ class RoIAlignFunction(Function):
mode_s
=
pool_mode
,
mode_s
=
pool_mode
,
aligned_i
=
aligned
)
aligned_i
=
aligned
)
else
:
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
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 = rois[:, 0].long()
batch_indices
=
_slice_helper
(
batch_indices
=
_slice_helper
(
g
,
rois
,
axes
=
[
1
],
starts
=
[
0
],
ends
=
[
1
])
g
,
rois
,
axes
=
[
1
],
starts
=
[
0
],
ends
=
[
1
])
...
...
mmcv/utils/__init__.py
View file @
dd82ab14
...
@@ -37,16 +37,20 @@ except ImportError:
...
@@ -37,16 +37,20 @@ except ImportError:
]
]
else
:
else
:
from
.env
import
collect_env
from
.env
import
collect_env
from
.hub
import
load_url
from
.logging
import
get_logger
,
print_log
from
.logging
import
get_logger
,
print_log
from
.parrots_jit
import
jit
,
skip_no_elena
from
.parrots_jit
import
jit
,
skip_no_elena
from
.parrots_wrapper
import
(
# yapf: disable
TORCH_VERSION
,
BuildExtension
,
CppExtension
,
CUDAExtension
,
DataLoader
,
from
.parrots_wrapper
import
(
TORCH_VERSION
,
BuildExtension
,
CppExtension
,
PoolDataLoader
,
SyncBatchNorm
,
_AdaptiveAvgPoolNd
,
_AdaptiveMaxPoolNd
,
CUDAExtension
,
DataLoader
,
PoolDataLoader
,
_AvgPoolNd
,
_BatchNorm
,
_ConvNd
,
_ConvTransposeMixin
,
_InstanceNorm
,
SyncBatchNorm
,
_AdaptiveAvgPoolNd
,
_MaxPoolNd
,
get_build_config
,
is_rocm_pytorch
,
_get_cuda_home
)
_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
.registry
import
Registry
,
build_from_cfg
from
.trace
import
is_jit_tracing
from
.trace
import
is_jit_tracing
from
.hub
import
load_url
__all__
=
[
__all__
=
[
'Config'
,
'ConfigDict'
,
'DictAction'
,
'collect_env'
,
'get_logger'
,
'Config'
,
'ConfigDict'
,
'DictAction'
,
'collect_env'
,
'get_logger'
,
'print_log'
,
'is_str'
,
'iter_cast'
,
'list_cast'
,
'tuple_cast'
,
'print_log'
,
'is_str'
,
'iter_cast'
,
'list_cast'
,
'tuple_cast'
,
...
...
mmcv/utils/hub.py
View file @
dd82ab14
...
@@ -10,12 +10,13 @@ if TORCH_VERSION != 'parrots' and digit_version(TORCH_VERSION) < digit_version(
...
@@ -10,12 +10,13 @@ if TORCH_VERSION != 'parrots' and digit_version(TORCH_VERSION) < digit_version(
'1.7.0'
):
'1.7.0'
):
# Modified from https://github.com/pytorch/pytorch/blob/master/torch/hub.py
# Modified from https://github.com/pytorch/pytorch/blob/master/torch/hub.py
import
os
import
os
import
torch
import
warnings
from
urllib.parse
import
urlparse
import
sys
import
sys
import
warnings
import
zipfile
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
# Hub used to support automatically extracts from zipfile manually
# compressed by users. The legacy zip format expects only one file from
# compressed by users. The legacy zip format expects only one file from
...
...
mmcv/utils/parrots_wrapper.py
View file @
dd82ab14
...
@@ -83,8 +83,8 @@ def _get_norm():
...
@@ -83,8 +83,8 @@ def _get_norm():
from
parrots.nn.modules.batchnorm
import
_BatchNorm
,
_InstanceNorm
from
parrots.nn.modules.batchnorm
import
_BatchNorm
,
_InstanceNorm
SyncBatchNorm_
=
torch
.
nn
.
SyncBatchNorm2d
SyncBatchNorm_
=
torch
.
nn
.
SyncBatchNorm2d
else
:
else
:
from
torch.nn.modules.instancenorm
import
_InstanceNorm
from
torch.nn.modules.batchnorm
import
_BatchNorm
from
torch.nn.modules.batchnorm
import
_BatchNorm
from
torch.nn.modules.instancenorm
import
_InstanceNorm
SyncBatchNorm_
=
torch
.
nn
.
SyncBatchNorm
SyncBatchNorm_
=
torch
.
nn
.
SyncBatchNorm
return
_BatchNorm
,
_InstanceNorm
,
SyncBatchNorm_
return
_BatchNorm
,
_InstanceNorm
,
SyncBatchNorm_
...
...
mmcv/utils/testing.py
View file @
dd82ab14
...
@@ -111,8 +111,9 @@ def assert_is_norm_layer(module) -> bool:
...
@@ -111,8 +111,9 @@ def assert_is_norm_layer(module) -> bool:
Returns:
Returns:
bool: Whether the module is a norm layer.
bool: Whether the module is a norm layer.
"""
"""
from
.parrots_wrapper
import
_BatchNorm
,
_InstanceNorm
from
torch.nn
import
GroupNorm
,
LayerNorm
from
torch.nn
import
GroupNorm
,
LayerNorm
from
.parrots_wrapper
import
_BatchNorm
,
_InstanceNorm
norm_layer_candidates
=
(
_BatchNorm
,
_InstanceNorm
,
GroupNorm
,
LayerNorm
)
norm_layer_candidates
=
(
_BatchNorm
,
_InstanceNorm
,
GroupNorm
,
LayerNorm
)
return
isinstance
(
module
,
norm_layer_candidates
)
return
isinstance
(
module
,
norm_layer_candidates
)
...
...
setup.cfg
View file @
dd82ab14
...
@@ -12,7 +12,7 @@ split_before_expression_after_opening_paren = true
...
@@ -12,7 +12,7 @@ split_before_expression_after_opening_paren = true
[isort]
[isort]
line_length = 79
line_length = 79
multi_line_output = 0
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_first_party = mmcv
known_third_party = addict,cv2,numpy,onnx,onnxruntime,packaging,pytest,pytorch_sphinx_theme,scipy,sphinx,tensorrt,torch,torchvision,yaml,yapf
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
no_lines_before = STDLIB,LOCALFOLDER
...
...
setup.py
View file @
dd82ab14
...
@@ -184,6 +184,7 @@ def get_extensions():
...
@@ -184,6 +184,7 @@ def get_extensions():
if
EXT_TYPE
==
'parrots'
:
if
EXT_TYPE
==
'parrots'
:
ext_name
=
'mmcv._ext'
ext_name
=
'mmcv._ext'
from
parrots.utils.build_extension
import
Extension
from
parrots.utils.build_extension
import
Extension
# new parrots op impl do not use MMCV_USE_PARROTS
# new parrots op impl do not use MMCV_USE_PARROTS
# define_macros = [('MMCV_USE_PARROTS', None)]
# define_macros = [('MMCV_USE_PARROTS', None)]
define_macros
=
[]
define_macros
=
[]
...
@@ -314,8 +315,8 @@ def get_extensions():
...
@@ -314,8 +315,8 @@ def get_extensions():
if
EXT_TYPE
==
'pytorch'
and
os
.
getenv
(
'MMCV_WITH_ORT'
,
'0'
)
!=
'0'
:
if
EXT_TYPE
==
'pytorch'
and
os
.
getenv
(
'MMCV_WITH_ORT'
,
'0'
)
!=
'0'
:
ext_name
=
'mmcv._ext_ort'
ext_name
=
'mmcv._ext_ort'
from
torch.utils.cpp_extension
import
library_paths
,
include_paths
import
onnxruntime
import
onnxruntime
from
torch.utils.cpp_extension
import
include_paths
,
library_paths
library_dirs
=
[]
library_dirs
=
[]
libraries
=
[]
libraries
=
[]
include_dirs
=
[]
include_dirs
=
[]
...
...
tests/test_image/test_photometric.py
View file @
dd82ab14
...
@@ -112,7 +112,7 @@ class TestPhotometric:
...
@@ -112,7 +112,7 @@ class TestPhotometric:
def
_imequalize
(
img
):
def
_imequalize
(
img
):
# equalize the image using PIL.ImageOps.equalize
# equalize the image using PIL.ImageOps.equalize
from
PIL
import
Image
Ops
,
Image
from
PIL
import
Image
,
Image
Ops
img
=
Image
.
fromarray
(
img
)
img
=
Image
.
fromarray
(
img
)
equalized_img
=
np
.
asarray
(
ImageOps
.
equalize
(
img
))
equalized_img
=
np
.
asarray
(
ImageOps
.
equalize
(
img
))
return
equalized_img
return
equalized_img
...
@@ -141,8 +141,8 @@ class TestPhotometric:
...
@@ -141,8 +141,8 @@ class TestPhotometric:
def
_adjust_brightness
(
img
,
factor
):
def
_adjust_brightness
(
img
,
factor
):
# adjust the brightness of image using
# adjust the brightness of image using
# PIL.ImageEnhance.Brightness
# PIL.ImageEnhance.Brightness
from
PIL.ImageEnhance
import
Brightness
from
PIL
import
Image
from
PIL
import
Image
from
PIL.ImageEnhance
import
Brightness
img
=
Image
.
fromarray
(
img
)
img
=
Image
.
fromarray
(
img
)
brightened_img
=
Brightness
(
img
).
enhance
(
factor
)
brightened_img
=
Brightness
(
img
).
enhance
(
factor
)
return
np
.
asarray
(
brightened_img
)
return
np
.
asarray
(
brightened_img
)
...
@@ -169,8 +169,9 @@ class TestPhotometric:
...
@@ -169,8 +169,9 @@ class TestPhotometric:
def
test_adjust_contrast
(
self
,
nb_rand_test
=
100
):
def
test_adjust_contrast
(
self
,
nb_rand_test
=
100
):
def
_adjust_contrast
(
img
,
factor
):
def
_adjust_contrast
(
img
,
factor
):
from
PIL.ImageEnhance
import
Contrast
from
PIL
import
Image
from
PIL
import
Image
from
PIL.ImageEnhance
import
Contrast
# Image.fromarray defaultly supports RGB, not BGR.
# Image.fromarray defaultly supports RGB, not BGR.
# convert from BGR to RGB
# convert from BGR to RGB
img
=
Image
.
fromarray
(
img
[...,
::
-
1
],
mode
=
'RGB'
)
img
=
Image
.
fromarray
(
img
[...,
::
-
1
],
mode
=
'RGB'
)
...
@@ -204,8 +205,9 @@ class TestPhotometric:
...
@@ -204,8 +205,9 @@ class TestPhotometric:
def
test_auto_contrast
(
self
,
nb_rand_test
=
100
):
def
test_auto_contrast
(
self
,
nb_rand_test
=
100
):
def
_auto_contrast
(
img
,
cutoff
=
0
):
def
_auto_contrast
(
img
,
cutoff
=
0
):
from
PIL.ImageOps
import
autocontrast
from
PIL
import
Image
from
PIL
import
Image
from
PIL.ImageOps
import
autocontrast
# Image.fromarray defaultly supports RGB, not BGR.
# Image.fromarray defaultly supports RGB, not BGR.
# convert from BGR to RGB
# convert from BGR to RGB
img
=
Image
.
fromarray
(
img
[...,
::
-
1
],
mode
=
'RGB'
)
img
=
Image
.
fromarray
(
img
[...,
::
-
1
],
mode
=
'RGB'
)
...
@@ -250,8 +252,8 @@ class TestPhotometric:
...
@@ -250,8 +252,8 @@ class TestPhotometric:
def
_adjust_sharpness
(
img
,
factor
):
def
_adjust_sharpness
(
img
,
factor
):
# adjust the sharpness of image using
# adjust the sharpness of image using
# PIL.ImageEnhance.Sharpness
# PIL.ImageEnhance.Sharpness
from
PIL.ImageEnhance
import
Sharpness
from
PIL
import
Image
from
PIL
import
Image
from
PIL.ImageEnhance
import
Sharpness
img
=
Image
.
fromarray
(
img
)
img
=
Image
.
fromarray
(
img
)
sharpened_img
=
Sharpness
(
img
).
enhance
(
factor
)
sharpened_img
=
Sharpness
(
img
).
enhance
(
factor
)
return
np
.
asarray
(
sharpened_img
)
return
np
.
asarray
(
sharpened_img
)
...
...
tests/test_ops/test_border_align.py
View file @
dd82ab14
...
@@ -51,7 +51,7 @@ def _test_border_align_allclose(device, dtype, pool_size):
...
@@ -51,7 +51,7 @@ def _test_border_align_allclose(device, dtype, pool_size):
if
not
torch
.
cuda
.
is_available
()
and
device
==
'cuda'
:
if
not
torch
.
cuda
.
is_available
()
and
device
==
'cuda'
:
pytest
.
skip
(
'test requires GPU'
)
pytest
.
skip
(
'test requires GPU'
)
try
:
try
:
from
mmcv.ops
import
b
order
_a
lign
,
B
order
A
lign
from
mmcv.ops
import
B
order
A
lign
,
b
order
_a
lign
except
ModuleNotFoundError
:
except
ModuleNotFoundError
:
pytest
.
skip
(
'BorderAlign op is not successfully compiled'
)
pytest
.
skip
(
'BorderAlign op is not successfully compiled'
)
...
...
tests/test_runner/test_basemodule.py
View file @
dd82ab14
...
@@ -88,9 +88,11 @@ class FooModel(BaseModule):
...
@@ -88,9 +88,11 @@ class FooModel(BaseModule):
def
test_initilization_info_logger
():
def
test_initilization_info_logger
():
# 'override' has higher priority
# 'override' has higher priority
import
os
import
torch.nn
as
nn
import
torch.nn
as
nn
from
mmcv.utils.logging
import
get_logger
from
mmcv.utils.logging
import
get_logger
import
os
class
OverloadInitConv
(
nn
.
Conv2d
,
BaseModule
):
class
OverloadInitConv
(
nn
.
Conv2d
,
BaseModule
):
...
...
tests/test_runner/test_checkpoint.py
View file @
dd82ab14
...
@@ -197,7 +197,6 @@ def test_load_checkpoint_with_prefix():
...
@@ -197,7 +197,6 @@ def test_load_checkpoint_with_prefix():
def
test_load_checkpoint
():
def
test_load_checkpoint
():
import
os
import
os
import
re
import
re
import
tempfile
import
tempfile
...
@@ -230,7 +229,6 @@ def test_load_checkpoint():
...
@@ -230,7 +229,6 @@ def test_load_checkpoint():
def
test_load_checkpoint_metadata
():
def
test_load_checkpoint_metadata
():
import
os
import
os
import
tempfile
import
tempfile
from
mmcv.runner
import
load_checkpoint
,
save_checkpoint
from
mmcv.runner
import
load_checkpoint
,
save_checkpoint
...
@@ -301,7 +299,6 @@ def test_load_checkpoint_metadata():
...
@@ -301,7 +299,6 @@ def test_load_checkpoint_metadata():
def
test_load_classes_name
():
def
test_load_classes_name
():
import
os
import
os
import
tempfile
import
tempfile
from
mmcv.runner
import
load_checkpoint
,
save_checkpoint
from
mmcv.runner
import
load_checkpoint
,
save_checkpoint
...
@@ -335,7 +332,6 @@ def test_load_classes_name():
...
@@ -335,7 +332,6 @@ def test_load_classes_name():
def
test_checkpoint_loader
():
def
test_checkpoint_loader
():
import
os
import
os
import
tempfile
import
tempfile
from
mmcv.runner
import
CheckpointLoader
,
_load_checkpoint
,
save_checkpoint
from
mmcv.runner
import
CheckpointLoader
,
_load_checkpoint
,
save_checkpoint
...
...
tests/test_utils/test_misc.py
View file @
dd82ab14
...
@@ -132,7 +132,6 @@ def test_requires_executable(capsys):
...
@@ -132,7 +132,6 @@ def test_requires_executable(capsys):
def
test_import_modules_from_strings
():
def
test_import_modules_from_strings
():
# multiple imports
# multiple imports
import
os.path
as
osp_
import
os.path
as
osp_
import
sys
as
sys_
import
sys
as
sys_
osp
,
sys
=
mmcv
.
import_modules_from_strings
([
'os.path'
,
'sys'
])
osp
,
sys
=
mmcv
.
import_modules_from_strings
([
'os.path'
,
'sys'
])
assert
osp
==
osp_
assert
osp
==
osp_
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment