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
45fa3e44
Unverified
Commit
45fa3e44
authored
May 18, 2022
by
Zaida Zhou
Committed by
GitHub
May 18, 2022
Browse files
Add pyupgrade pre-commit hook (#1937)
* add pyupgrade * add options for pyupgrade * minor refinement
parent
c561264d
Changes
110
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
31 additions
and
32 deletions
+31
-32
tests/test_ops/test_box_iou_rotated.py
tests/test_ops/test_box_iou_rotated.py
+1
-1
tests/test_ops/test_carafe.py
tests/test_ops/test_carafe.py
+1
-1
tests/test_ops/test_cc_attention.py
tests/test_ops/test_cc_attention.py
+1
-1
tests/test_ops/test_deform_conv.py
tests/test_ops/test_deform_conv.py
+1
-1
tests/test_ops/test_deform_roi_pool.py
tests/test_ops/test_deform_roi_pool.py
+1
-1
tests/test_ops/test_focal_loss.py
tests/test_ops/test_focal_loss.py
+1
-1
tests/test_ops/test_fused_bias_leakyrelu.py
tests/test_ops/test_fused_bias_leakyrelu.py
+1
-1
tests/test_ops/test_info.py
tests/test_ops/test_info.py
+1
-1
tests/test_ops/test_masked_conv2d.py
tests/test_ops/test_masked_conv2d.py
+1
-1
tests/test_ops/test_modulated_deform_conv.py
tests/test_ops/test_modulated_deform_conv.py
+1
-1
tests/test_ops/test_ms_deformable_attn.py
tests/test_ops/test_ms_deformable_attn.py
+4
-4
tests/test_ops/test_nms.py
tests/test_ops/test_nms.py
+2
-3
tests/test_ops/test_onnx.py
tests/test_ops/test_onnx.py
+2
-2
tests/test_ops/test_psa_mask.py
tests/test_ops/test_psa_mask.py
+1
-1
tests/test_ops/test_roi_pool.py
tests/test_ops/test_roi_pool.py
+1
-1
tests/test_ops/test_syncbn.py
tests/test_ops/test_syncbn.py
+1
-1
tests/test_ops/test_tensorrt.py
tests/test_ops/test_tensorrt.py
+3
-3
tests/test_ops/test_upfirdn2d.py
tests/test_ops/test_upfirdn2d.py
+1
-1
tests/test_ops/test_voxelization.py
tests/test_ops/test_voxelization.py
+5
-5
tests/test_parallel.py
tests/test_parallel.py
+1
-1
No files found.
tests/test_ops/test_box_iou_rotated.py
View file @
45fa3e44
...
...
@@ -4,7 +4,7 @@ import pytest
import
torch
class
TestBoxIoURotated
(
object
)
:
class
TestBoxIoURotated
:
def
test_box_iou_rotated_cpu
(
self
):
from
mmcv.ops
import
box_iou_rotated
...
...
tests/test_ops/test_carafe.py
View file @
45fa3e44
...
...
@@ -3,7 +3,7 @@ import torch
from
torch.autograd
import
gradcheck
class
TestCarafe
(
object
)
:
class
TestCarafe
:
def
test_carafe_naive_gradcheck
(
self
):
if
not
torch
.
cuda
.
is_available
():
...
...
tests/test_ops/test_cc_attention.py
View file @
45fa3e44
...
...
@@ -15,7 +15,7 @@ class Loss(nn.Module):
return
torch
.
mean
(
input
-
target
)
class
TestCrissCrossAttention
(
object
)
:
class
TestCrissCrossAttention
:
def
test_cc_attention
(
self
):
device
=
torch
.
device
(
'cuda:0'
if
torch
.
cuda
.
is_available
()
else
'cpu'
)
...
...
tests/test_ops/test_deform_conv.py
View file @
45fa3e44
...
...
@@ -35,7 +35,7 @@ gt_offset_bias_grad = [1.44, -0.72, 0., 0., -0.10, -0.08, -0.54, -0.54],
gt_deform_weight_grad
=
[[[[
3.62
,
0.
],
[
0.40
,
0.18
]]]]
class
TestDeformconv
(
object
)
:
class
TestDeformconv
:
def
_test_deformconv
(
self
,
dtype
=
torch
.
float
,
...
...
tests/test_ops/test_deform_roi_pool.py
View file @
45fa3e44
...
...
@@ -35,7 +35,7 @@ outputs = [([[[[1, 1.25], [1.5, 1.75]]]], [[[[3.0625, 0.4375],
0.00390625
]]]])]
class
TestDeformRoIPool
(
object
)
:
class
TestDeformRoIPool
:
def
test_deform_roi_pool_gradcheck
(
self
):
if
not
torch
.
cuda
.
is_available
():
...
...
tests/test_ops/test_focal_loss.py
View file @
45fa3e44
...
...
@@ -37,7 +37,7 @@ sigmoid_outputs = [(0.13562961, [[-0.00657264, 0.11185755],
[
-
0.02462499
,
0.08277918
,
0.18050370
]])]
class
Testfocalloss
(
object
)
:
class
Testfocalloss
:
def
_test_softmax
(
self
,
dtype
=
torch
.
float
):
if
not
torch
.
cuda
.
is_available
():
...
...
tests/test_ops/test_fused_bias_leakyrelu.py
View file @
45fa3e44
...
...
@@ -10,7 +10,7 @@ except ImportError:
_USING_PARROTS
=
False
class
TestFusedBiasLeakyReLU
(
object
)
:
class
TestFusedBiasLeakyReLU
:
@
classmethod
def
setup_class
(
cls
):
...
...
tests/test_ops/test_info.py
View file @
45fa3e44
...
...
@@ -2,7 +2,7 @@
import
torch
class
TestInfo
(
object
)
:
class
TestInfo
:
def
test_info
(
self
):
if
not
torch
.
cuda
.
is_available
():
...
...
tests/test_ops/test_masked_conv2d.py
View file @
45fa3e44
...
...
@@ -2,7 +2,7 @@
import
torch
class
TestMaskedConv2d
(
object
)
:
class
TestMaskedConv2d
:
def
test_masked_conv2d
(
self
):
if
not
torch
.
cuda
.
is_available
():
...
...
tests/test_ops/test_modulated_deform_conv.py
View file @
45fa3e44
...
...
@@ -37,7 +37,7 @@ dcn_offset_b_grad = [
]
class
TestMdconv
(
object
)
:
class
TestMdconv
:
def
_test_mdconv
(
self
,
dtype
=
torch
.
float
,
device
=
'cuda'
):
if
not
torch
.
cuda
.
is_available
()
and
device
==
'cuda'
:
...
...
tests/test_ops/test_ms_deformable_attn.py
View file @
45fa3e44
...
...
@@ -55,7 +55,7 @@ def test_forward_multi_scale_deformable_attn_pytorch():
N
,
M
,
D
=
1
,
2
,
2
Lq
,
L
,
P
=
2
,
2
,
2
shapes
=
torch
.
as_tensor
([(
6
,
4
),
(
3
,
2
)],
dtype
=
torch
.
long
)
S
=
sum
(
[
(
H
*
W
).
item
()
for
H
,
W
in
shapes
]
)
S
=
sum
((
H
*
W
).
item
()
for
H
,
W
in
shapes
)
torch
.
manual_seed
(
3
)
value
=
torch
.
rand
(
N
,
S
,
M
,
D
)
*
0.01
...
...
@@ -78,7 +78,7 @@ def test_forward_equal_with_pytorch_double():
shapes
=
torch
.
as_tensor
([(
6
,
4
),
(
3
,
2
)],
dtype
=
torch
.
long
).
cuda
()
level_start_index
=
torch
.
cat
((
shapes
.
new_zeros
(
(
1
,
)),
shapes
.
prod
(
1
).
cumsum
(
0
)[:
-
1
]))
S
=
sum
(
[
(
H
*
W
).
item
()
for
H
,
W
in
shapes
]
)
S
=
sum
((
H
*
W
).
item
()
for
H
,
W
in
shapes
)
torch
.
manual_seed
(
3
)
value
=
torch
.
rand
(
N
,
S
,
M
,
D
).
cuda
()
*
0.01
...
...
@@ -111,7 +111,7 @@ def test_forward_equal_with_pytorch_float():
shapes
=
torch
.
as_tensor
([(
6
,
4
),
(
3
,
2
)],
dtype
=
torch
.
long
).
cuda
()
level_start_index
=
torch
.
cat
((
shapes
.
new_zeros
(
(
1
,
)),
shapes
.
prod
(
1
).
cumsum
(
0
)[:
-
1
]))
S
=
sum
(
[
(
H
*
W
).
item
()
for
H
,
W
in
shapes
]
)
S
=
sum
((
H
*
W
).
item
()
for
H
,
W
in
shapes
)
torch
.
manual_seed
(
3
)
value
=
torch
.
rand
(
N
,
S
,
M
,
D
).
cuda
()
*
0.01
...
...
@@ -155,7 +155,7 @@ def test_gradient_numerical(channels,
shapes
=
torch
.
as_tensor
([(
3
,
2
),
(
2
,
1
)],
dtype
=
torch
.
long
).
cuda
()
level_start_index
=
torch
.
cat
((
shapes
.
new_zeros
(
(
1
,
)),
shapes
.
prod
(
1
).
cumsum
(
0
)[:
-
1
]))
S
=
sum
(
[
(
H
*
W
).
item
()
for
H
,
W
in
shapes
]
)
S
=
sum
((
H
*
W
).
item
()
for
H
,
W
in
shapes
)
value
=
torch
.
rand
(
N
,
S
,
M
,
channels
).
cuda
()
*
0.01
sampling_locations
=
torch
.
rand
(
N
,
Lq
,
M
,
L
,
P
,
2
).
cuda
()
...
...
tests/test_ops/test_nms.py
View file @
45fa3e44
...
...
@@ -6,7 +6,7 @@ import torch
from
mmcv.utils
import
IS_CUDA_AVAILABLE
,
IS_MLU_AVAILABLE
class
Testnms
(
object
)
:
class
Testnms
:
@
pytest
.
mark
.
parametrize
(
'device'
,
[
pytest
.
param
(
...
...
@@ -129,8 +129,7 @@ class Testnms(object):
scores
=
tensor_dets
[:,
4
]
nms_keep_inds
=
nms
(
boxes
.
contiguous
(),
scores
.
contiguous
(),
iou_thr
)[
1
]
assert
set
([
g
[
0
].
item
()
for
g
in
np_groups
])
==
set
(
nms_keep_inds
.
tolist
())
assert
{
g
[
0
].
item
()
for
g
in
np_groups
}
==
set
(
nms_keep_inds
.
tolist
())
# non empty tensor input
tensor_dets
=
torch
.
from_numpy
(
np_dets
)
...
...
tests/test_ops/test_onnx.py
View file @
45fa3e44
...
...
@@ -33,7 +33,7 @@ def run_before_and_after_test():
class
WrapFunction
(
nn
.
Module
):
def
__init__
(
self
,
wrapped_function
):
super
(
WrapFunction
,
self
).
__init__
()
super
().
__init__
()
self
.
wrapped_function
=
wrapped_function
def
forward
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -662,7 +662,7 @@ def test_cummax_cummin(key, opset=11):
input_list
=
[
# arbitrary shape, e.g. 1-D, 2-D, 3-D, ...
torch
.
rand
((
2
,
3
,
4
,
1
,
5
)),
torch
.
rand
(
(
1
)
),
torch
.
rand
(
1
),
torch
.
rand
((
2
,
0
,
1
)),
# tensor.numel() is 0
torch
.
FloatTensor
(),
# empty tensor
]
...
...
tests/test_ops/test_psa_mask.py
View file @
45fa3e44
...
...
@@ -15,7 +15,7 @@ class Loss(nn.Module):
return
torch
.
mean
(
input
-
target
)
class
TestPSAMask
(
object
)
:
class
TestPSAMask
:
def
test_psa_mask_collect
(
self
):
if
not
torch
.
cuda
.
is_available
():
...
...
tests/test_ops/test_roi_pool.py
View file @
45fa3e44
...
...
@@ -29,7 +29,7 @@ outputs = [([[[[1., 2.], [3., 4.]]]], [[[[1., 1.], [1., 1.]]]]),
1.
]]]])]
class
TestRoiPool
(
object
)
:
class
TestRoiPool
:
def
test_roipool_gradcheck
(
self
):
if
not
torch
.
cuda
.
is_available
():
...
...
tests/test_ops/test_syncbn.py
View file @
45fa3e44
...
...
@@ -14,7 +14,7 @@ else:
import
re
class
TestSyncBN
(
object
)
:
class
TestSyncBN
:
def
dist_init
(
self
):
rank
=
int
(
os
.
environ
[
'SLURM_PROCID'
])
...
...
tests/test_ops/test_tensorrt.py
View file @
45fa3e44
...
...
@@ -30,7 +30,7 @@ if not is_tensorrt_plugin_loaded():
class
WrapFunction
(
nn
.
Module
):
def
__init__
(
self
,
wrapped_function
):
super
(
WrapFunction
,
self
).
__init__
()
super
().
__init__
()
self
.
wrapped_function
=
wrapped_function
def
forward
(
self
,
*
args
,
**
kwargs
):
...
...
@@ -576,7 +576,7 @@ def test_cummin_cummax(func: Callable):
input_list
=
[
# arbitrary shape, e.g. 1-D, 2-D, 3-D, ...
torch
.
rand
((
2
,
3
,
4
,
1
,
5
)).
cuda
(),
torch
.
rand
(
(
1
)
).
cuda
()
torch
.
rand
(
1
).
cuda
()
]
input_names
=
[
'input'
]
...
...
@@ -756,7 +756,7 @@ def test_corner_pool(mode):
class
CornerPoolWrapper
(
CornerPool
):
def
__init__
(
self
,
mode
):
super
(
CornerPoolWrapper
,
self
).
__init__
(
mode
)
super
().
__init__
(
mode
)
def
forward
(
self
,
x
):
# no use `torch.cummax`, instead `corner_pool` is used
...
...
tests/test_ops/test_upfirdn2d.py
View file @
45fa3e44
...
...
@@ -10,7 +10,7 @@ except ImportError:
_USING_PARROTS
=
False
class
TestUpFirDn2d
(
object
)
:
class
TestUpFirDn2d
:
"""Unit test for UpFirDn2d.
Here, we just test the basic case of upsample version. More gerneal tests
...
...
tests/test_ops/test_voxelization.py
View file @
45fa3e44
...
...
@@ -96,8 +96,8 @@ def test_voxelization_nondeterministic():
coors_all
=
dynamic_voxelization
.
forward
(
points
)
coors_all
=
coors_all
.
cpu
().
detach
().
numpy
().
tolist
()
coors_set
=
set
([
tuple
(
c
)
for
c
in
coors
])
coors_all_set
=
set
([
tuple
(
c
)
for
c
in
coors_all
])
coors_set
=
{
tuple
(
c
)
for
c
in
coors
}
coors_all_set
=
{
tuple
(
c
)
for
c
in
coors_all
}
assert
len
(
coors_set
)
==
len
(
coors
)
assert
len
(
coors_set
-
coors_all_set
)
==
0
...
...
@@ -112,7 +112,7 @@ def test_voxelization_nondeterministic():
for
c
,
ps
,
n
in
zip
(
coors
,
voxels
,
num_points_per_voxel
):
ideal_voxel_points_set
=
coors_points_dict
[
tuple
(
c
)]
voxel_points_set
=
set
([
tuple
(
p
)
for
p
in
ps
[:
n
]
])
voxel_points_set
=
{
tuple
(
p
)
for
p
in
ps
[:
n
]
}
assert
len
(
voxel_points_set
)
==
n
if
n
<
max_num_points
:
assert
voxel_points_set
==
ideal_voxel_points_set
...
...
@@ -133,7 +133,7 @@ def test_voxelization_nondeterministic():
voxels
,
coors
,
num_points_per_voxel
=
hard_voxelization
.
forward
(
points
)
coors
=
coors
.
cpu
().
detach
().
numpy
().
tolist
()
coors_set
=
set
([
tuple
(
c
)
for
c
in
coors
])
coors_all_set
=
set
([
tuple
(
c
)
for
c
in
coors_all
])
coors_set
=
{
tuple
(
c
)
for
c
in
coors
}
coors_all_set
=
{
tuple
(
c
)
for
c
in
coors_all
}
assert
len
(
coors_set
)
==
len
(
coors
)
==
len
(
coors_all_set
)
tests/test_parallel.py
View file @
45fa3e44
...
...
@@ -63,7 +63,7 @@ def test_is_module_wrapper():
# test module wrapper registry
@
MODULE_WRAPPERS
.
register_module
()
class
ModuleWrapper
(
object
)
:
class
ModuleWrapper
:
def
__init__
(
self
,
module
):
self
.
module
=
module
...
...
Prev
1
2
3
4
5
6
Next
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