"docs/vscode:/vscode.git/clone" did not exist on "dbb16bedd54ffc2d7d2a2eac8d8064711f0c7286"
Unverified Commit fb486b96 authored by Jiazhen Wang's avatar Jiazhen Wang Committed by GitHub
Browse files

[Fix] Fix some warnings in unittest (#1522)

* [Fix] fix some warnings in unittest

* [Impl] standardize some warnings

* [Fix] fix warning type in test_deprecation

* [Fix] fix warning type

* [Fix] continue fixing

* [Fix] fix some details

* [Fix] fix docstring

* [Fix] del useless statement

* [Fix] keep compatibility for torch < 1.5.0
parent f367d621
import numpy as np import numpy as np
import torch import torch
import torch.nn as nn
import torch.nn.functional as F import torch.nn.functional as F
...@@ -15,7 +14,8 @@ class TestBilinearGridSample(object): ...@@ -15,7 +14,8 @@ class TestBilinearGridSample(object):
input = torch.rand(1, 1, 20, 20, dtype=dtype) input = torch.rand(1, 1, 20, 20, dtype=dtype)
grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]]) grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]])
grid = nn.functional.affine_grid(grid, (1, 1, 15, 15)).type_as(input) grid = F.affine_grid(
grid, (1, 1, 15, 15), align_corners=align_corners).type_as(input)
grid *= multiplier grid *= multiplier
out = bilinear_grid_sample(input, grid, align_corners=align_corners) out = bilinear_grid_sample(input, grid, align_corners=align_corners)
......
...@@ -8,6 +8,7 @@ import onnxruntime as rt ...@@ -8,6 +8,7 @@ import onnxruntime as rt
import pytest import pytest
import torch import torch
import torch.nn as nn import torch.nn as nn
import torch.nn.functional as F
from packaging import version from packaging import version
onnx_file = 'tmp.onnx' onnx_file = 'tmp.onnx'
...@@ -87,10 +88,11 @@ def test_grid_sample(mode, padding_mode, align_corners): ...@@ -87,10 +88,11 @@ def test_grid_sample(mode, padding_mode, align_corners):
input = torch.rand(1, 1, 10, 10) input = torch.rand(1, 1, 10, 10)
grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]]) grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]])
grid = nn.functional.affine_grid(grid, (1, 1, 15, 15)).type_as(input) grid = F.affine_grid(
grid, (1, 1, 15, 15), align_corners=align_corners).type_as(input)
def func(input, grid): def func(input, grid):
return nn.functional.grid_sample( return F.grid_sample(
input, input,
grid, grid,
mode=mode, mode=mode,
...@@ -110,7 +112,8 @@ def test_bilinear_grid_sample(align_corners): ...@@ -110,7 +112,8 @@ def test_bilinear_grid_sample(align_corners):
input = torch.rand(1, 1, 10, 10) input = torch.rand(1, 1, 10, 10)
grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]]) grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]])
grid = nn.functional.affine_grid(grid, (1, 1, 15, 15)).type_as(input) grid = F.affine_grid(
grid, (1, 1, 15, 15), align_corners=align_corners).type_as(input)
def func(input, grid): def func(input, grid):
return bilinear_grid_sample(input, grid, align_corners=align_corners) return bilinear_grid_sample(input, grid, align_corners=align_corners)
...@@ -462,7 +465,7 @@ def test_interpolate(): ...@@ -462,7 +465,7 @@ def test_interpolate():
register_extra_symbolics(opset_version) register_extra_symbolics(opset_version)
def func(feat, scale_factor=2): def func(feat, scale_factor=2):
out = nn.functional.interpolate(feat, scale_factor=scale_factor) out = F.interpolate(feat, scale_factor=scale_factor)
return out return out
net = WrapFunction(func) net = WrapFunction(func)
......
...@@ -7,6 +7,7 @@ import onnx ...@@ -7,6 +7,7 @@ import onnx
import pytest import pytest
import torch import torch
import torch.nn as nn import torch.nn as nn
import torch.nn.functional as F
try: try:
from mmcv.tensorrt import (TRTWrapper, is_tensorrt_plugin_loaded, onnx2trt, from mmcv.tensorrt import (TRTWrapper, is_tensorrt_plugin_loaded, onnx2trt,
...@@ -487,11 +488,10 @@ def test_grid_sample(mode, padding_mode, align_corners): ...@@ -487,11 +488,10 @@ def test_grid_sample(mode, padding_mode, align_corners):
input = torch.rand(1, 1, 10, 10).cuda() input = torch.rand(1, 1, 10, 10).cuda()
grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]]) grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]])
grid = nn.functional.affine_grid(grid, grid = F.affine_grid(grid, (1, 1, 15, 15)).type_as(input).cuda()
(1, 1, 15, 15)).type_as(input).cuda()
def func(input, grid): def func(input, grid):
return nn.functional.grid_sample( return F.grid_sample(
input, input,
grid, grid,
mode=mode, mode=mode,
......
...@@ -39,7 +39,7 @@ def test_voxelization(device_type): ...@@ -39,7 +39,7 @@ def test_voxelization(device_type):
device = torch.device(device_type) device = torch.device(device_type)
# test hard_voxelization on cpu/gpu # test hard_voxelization on cpu/gpu
points = torch.tensor(points).contiguous().to(device) points = points.contiguous().to(device)
coors, voxels, num_points_per_voxel = hard_voxelization.forward(points) coors, voxels, num_points_per_voxel = hard_voxelization.forward(points)
coors = coors.cpu().detach().numpy() coors = coors.cpu().detach().numpy()
voxels = voxels.cpu().detach().numpy() voxels = voxels.cpu().detach().numpy()
......
...@@ -57,7 +57,7 @@ def test_build_runner(): ...@@ -57,7 +57,7 @@ def test_build_runner():
@pytest.mark.parametrize('runner_class', RUNNERS.module_dict.values()) @pytest.mark.parametrize('runner_class', RUNNERS.module_dict.values())
def test_epoch_based_runner(runner_class): def test_epoch_based_runner(runner_class):
with pytest.warns(UserWarning): with pytest.warns(DeprecationWarning):
# batch_processor is deprecated # batch_processor is deprecated
model = OldStyleModel() model = OldStyleModel()
......
...@@ -533,6 +533,6 @@ def test_deprecation(): ...@@ -533,6 +533,6 @@ def test_deprecation():
] ]
for cfg_file in deprecated_cfg_files: for cfg_file in deprecated_cfg_files:
with pytest.warns(UserWarning): with pytest.warns(DeprecationWarning):
cfg = Config.fromfile(cfg_file) cfg = Config.fromfile(cfg_file)
assert cfg.item1 == 'expected' assert cfg.item1 == 'expected'
...@@ -96,15 +96,15 @@ def test_registry(): ...@@ -96,15 +96,15 @@ def test_registry():
pass pass
# begin: test old APIs # begin: test old APIs
with pytest.warns(UserWarning): with pytest.warns(DeprecationWarning):
CATS.register_module(SphynxCat) CATS.register_module(SphynxCat)
assert CATS.get('SphynxCat').__name__ == 'SphynxCat' assert CATS.get('SphynxCat').__name__ == 'SphynxCat'
with pytest.warns(UserWarning): with pytest.warns(DeprecationWarning):
CATS.register_module(SphynxCat, force=True) CATS.register_module(SphynxCat, force=True)
assert CATS.get('SphynxCat').__name__ == 'SphynxCat' assert CATS.get('SphynxCat').__name__ == 'SphynxCat'
with pytest.warns(UserWarning): with pytest.warns(DeprecationWarning):
@CATS.register_module @CATS.register_module
class NewCat: class NewCat:
...@@ -112,11 +112,11 @@ def test_registry(): ...@@ -112,11 +112,11 @@ def test_registry():
assert CATS.get('NewCat').__name__ == 'NewCat' assert CATS.get('NewCat').__name__ == 'NewCat'
with pytest.warns(UserWarning): with pytest.warns(DeprecationWarning):
CATS.deprecated_register_module(SphynxCat, force=True) CATS.deprecated_register_module(SphynxCat, force=True)
assert CATS.get('SphynxCat').__name__ == 'SphynxCat' assert CATS.get('SphynxCat').__name__ == 'SphynxCat'
with pytest.warns(UserWarning): with pytest.warns(DeprecationWarning):
@CATS.deprecated_register_module @CATS.deprecated_register_module
class CuteCat: class CuteCat:
...@@ -124,7 +124,7 @@ def test_registry(): ...@@ -124,7 +124,7 @@ def test_registry():
assert CATS.get('CuteCat').__name__ == 'CuteCat' assert CATS.get('CuteCat').__name__ == 'CuteCat'
with pytest.warns(UserWarning): with pytest.warns(DeprecationWarning):
@CATS.deprecated_register_module(force=True) @CATS.deprecated_register_module(force=True)
class NewCat2: class NewCat2:
......
...@@ -10,7 +10,7 @@ def test_color(): ...@@ -10,7 +10,7 @@ def test_color():
assert mmcv.color_val('green') == (0, 255, 0) assert mmcv.color_val('green') == (0, 255, 0)
assert mmcv.color_val((1, 2, 3)) == (1, 2, 3) assert mmcv.color_val((1, 2, 3)) == (1, 2, 3)
assert mmcv.color_val(100) == (100, 100, 100) assert mmcv.color_val(100) == (100, 100, 100)
assert mmcv.color_val(np.zeros(3, dtype=np.int)) == (0, 0, 0) assert mmcv.color_val(np.zeros(3, dtype=int)) == (0, 0, 0)
with pytest.raises(TypeError): with pytest.raises(TypeError):
mmcv.color_val([255, 255, 255]) mmcv.color_val([255, 255, 255])
with pytest.raises(TypeError): with pytest.raises(TypeError):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment