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 torch
import torch.nn as nn
import torch.nn.functional as F
......@@ -15,7 +14,8 @@ class TestBilinearGridSample(object):
input = torch.rand(1, 1, 20, 20, dtype=dtype)
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
out = bilinear_grid_sample(input, grid, align_corners=align_corners)
......
......@@ -8,6 +8,7 @@ import onnxruntime as rt
import pytest
import torch
import torch.nn as nn
import torch.nn.functional as F
from packaging import version
onnx_file = 'tmp.onnx'
......@@ -87,10 +88,11 @@ def test_grid_sample(mode, padding_mode, align_corners):
input = torch.rand(1, 1, 10, 10)
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):
return nn.functional.grid_sample(
return F.grid_sample(
input,
grid,
mode=mode,
......@@ -110,7 +112,8 @@ def test_bilinear_grid_sample(align_corners):
input = torch.rand(1, 1, 10, 10)
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):
return bilinear_grid_sample(input, grid, align_corners=align_corners)
......@@ -462,7 +465,7 @@ def test_interpolate():
register_extra_symbolics(opset_version)
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
net = WrapFunction(func)
......
......@@ -7,6 +7,7 @@ import onnx
import pytest
import torch
import torch.nn as nn
import torch.nn.functional as F
try:
from mmcv.tensorrt import (TRTWrapper, is_tensorrt_plugin_loaded, onnx2trt,
......@@ -487,11 +488,10 @@ def test_grid_sample(mode, padding_mode, align_corners):
input = torch.rand(1, 1, 10, 10).cuda()
grid = torch.Tensor([[[1, 0, 0], [0, 1, 0]]])
grid = nn.functional.affine_grid(grid,
(1, 1, 15, 15)).type_as(input).cuda()
grid = F.affine_grid(grid, (1, 1, 15, 15)).type_as(input).cuda()
def func(input, grid):
return nn.functional.grid_sample(
return F.grid_sample(
input,
grid,
mode=mode,
......
......@@ -39,7 +39,7 @@ def test_voxelization(device_type):
device = torch.device(device_type)
# 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 = coors.cpu().detach().numpy()
voxels = voxels.cpu().detach().numpy()
......
......@@ -57,7 +57,7 @@ def test_build_runner():
@pytest.mark.parametrize('runner_class', RUNNERS.module_dict.values())
def test_epoch_based_runner(runner_class):
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
# batch_processor is deprecated
model = OldStyleModel()
......
......@@ -533,6 +533,6 @@ def test_deprecation():
]
for cfg_file in deprecated_cfg_files:
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
cfg = Config.fromfile(cfg_file)
assert cfg.item1 == 'expected'
......@@ -96,15 +96,15 @@ def test_registry():
pass
# begin: test old APIs
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
CATS.register_module(SphynxCat)
assert CATS.get('SphynxCat').__name__ == 'SphynxCat'
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
CATS.register_module(SphynxCat, force=True)
assert CATS.get('SphynxCat').__name__ == 'SphynxCat'
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
@CATS.register_module
class NewCat:
......@@ -112,11 +112,11 @@ def test_registry():
assert CATS.get('NewCat').__name__ == 'NewCat'
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
CATS.deprecated_register_module(SphynxCat, force=True)
assert CATS.get('SphynxCat').__name__ == 'SphynxCat'
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
@CATS.deprecated_register_module
class CuteCat:
......@@ -124,7 +124,7 @@ def test_registry():
assert CATS.get('CuteCat').__name__ == 'CuteCat'
with pytest.warns(UserWarning):
with pytest.warns(DeprecationWarning):
@CATS.deprecated_register_module(force=True)
class NewCat2:
......
......@@ -10,7 +10,7 @@ def test_color():
assert mmcv.color_val('green') == (0, 255, 0)
assert mmcv.color_val((1, 2, 3)) == (1, 2, 3)
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):
mmcv.color_val([255, 255, 255])
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