Commit 1a47acdd authored by Jingwei Zhang's avatar Jingwei Zhang Committed by ZwwWayne
Browse files

[CI] Add github action CI && refactor `tests/utils/` (#2012)

* update github action ci

* install torch in ci

* fix ci on win

* add __init__ in tests/utils

* add mmdet3d/testing for modeule importing in UT in win

* fix diff path sep on UT

* reduce RAM in voxel_generator

* reduce RAM in anchor_generator

* remove print in UT

* fix lint

* fix pvrcnn ut

* fix lint

* reduce channels in second_fpn
parent 139c6f0c
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestFCAF3d(unittest.TestCase):
......@@ -19,12 +19,12 @@ class TestFCAF3d(unittest.TestCase):
import mmdet3d.models
assert hasattr(mmdet3d.models, 'MinkSingleStage3DDetector')
DefaultScope.get_instance('test_fcaf3d', scope_name='mmdet3d')
_setup_seed(0)
fcaf3d_net_cfg = _get_detector_cfg(
setup_seed(0)
fcaf3d_net_cfg = get_detector_cfg(
'fcaf3d/fcaf3d_2xb8_scannet-3d-18class.py')
model = MODELS.build(fcaf3d_net_cfg)
num_gt_instance = 3
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
num_gt_instance=num_gt_instance,
num_classes=1,
points_feat_dim=6,
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestGroupfree3d(unittest.TestCase):
......@@ -15,12 +15,12 @@ class TestGroupfree3d(unittest.TestCase):
assert hasattr(mmdet3d.models, 'GroupFree3DNet')
DefaultScope.get_instance('test_groupfree3d', scope_name='mmdet3d')
_setup_seed(0)
voxel_net_cfg = _get_detector_cfg(
setup_seed(0)
voxel_net_cfg = get_detector_cfg(
'groupfree3d/groupfree3d_head-L6-O256_4xb8_scannet-seg.py')
model = MODELS.build(voxel_net_cfg)
num_gt_instance = 5
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
num_gt_instance=num_gt_instance,
points_feat_dim=3,
with_pts_semantic_mask=True,
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestH3D(unittest.TestCase):
......@@ -15,11 +15,11 @@ class TestH3D(unittest.TestCase):
assert hasattr(mmdet3d.models, 'H3DNet')
DefaultScope.get_instance('test_H3DNet', scope_name='mmdet3d')
_setup_seed(0)
voxel_net_cfg = _get_detector_cfg('h3dnet/h3dnet_8xb3_scannet-seg.py')
setup_seed(0)
voxel_net_cfg = get_detector_cfg('h3dnet/h3dnet_8xb3_scannet-seg.py')
model = MODELS.build(voxel_net_cfg)
num_gt_instance = 5
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
num_gt_instance=num_gt_instance,
points_feat_dim=4,
bboxes_3d_type='depth',
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestImvoteNet(unittest.TestCase):
......@@ -15,12 +15,12 @@ class TestImvoteNet(unittest.TestCase):
assert hasattr(mmdet3d.models, 'ImVoteNet')
DefaultScope.get_instance('test_imvotenet_img', scope_name='mmdet3d')
_setup_seed(0)
votenet_net_cfg = _get_detector_cfg(
setup_seed(0)
votenet_net_cfg = get_detector_cfg(
'imvotenet/imvotenet_faster-rcnn-r50_fpn_4xb2_sunrgbd-3d.py')
model = MODELS.build(votenet_net_cfg)
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
with_points=False, with_img=True, img_size=128)
if torch.cuda.is_available():
......@@ -49,12 +49,12 @@ class TestImvoteNet(unittest.TestCase):
assert hasattr(mmdet3d.models, 'ImVoteNet')
DefaultScope.get_instance('test_imvotenet', scope_name='mmdet3d')
_setup_seed(0)
votenet_net_cfg = _get_detector_cfg(
setup_seed(0)
votenet_net_cfg = get_detector_cfg(
'imvotenet/imvotenet_stage2_8xb16_sunrgbd-3d.py')
model = MODELS.build(votenet_net_cfg)
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
with_points=True,
with_img=True,
img_size=128,
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestImVoxelNet(unittest.TestCase):
......@@ -15,12 +15,12 @@ class TestImVoxelNet(unittest.TestCase):
assert hasattr(mmdet3d.models, 'ImVoxelNet')
DefaultScope.get_instance('test_ImVoxelNet', scope_name='mmdet3d')
_setup_seed(0)
imvoxel_net_cfg = _get_detector_cfg(
setup_seed(0)
imvoxel_net_cfg = get_detector_cfg(
'imvoxelnet/imvoxelnet_8xb4_kitti-3d-car.py')
model = MODELS.build(imvoxel_net_cfg)
num_gt_instance = 1
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
with_points=False,
with_img=True,
img_size=(128, 128),
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestMVXNet(unittest.TestCase):
......@@ -15,14 +15,14 @@ class TestMVXNet(unittest.TestCase):
assert hasattr(mmdet3d.models, 'DynamicMVXFasterRCNN')
_setup_seed(0)
setup_seed(0)
DefaultScope.get_instance('test_mvxnet', scope_name='mmdet3d')
mvx_net_cfg = _get_detector_cfg(
mvx_net_cfg = get_detector_cfg(
'mvxnet/mvxnet_fpn_dv_second_secfpn_8xb2-80e_kitti-3d-3class.py' # noqa
)
model = MODELS.build(mvx_net_cfg)
num_gt_instance = 1
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
with_img=False, num_gt_instance=num_gt_instance, points_feat_dim=4)
if torch.cuda.is_available():
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestPartA2(unittest.TestCase):
......@@ -15,18 +15,17 @@ class TestPartA2(unittest.TestCase):
assert hasattr(mmdet3d.models, 'PartA2')
DefaultScope.get_instance('test_parta2', scope_name='mmdet3d')
_setup_seed(0)
parta2_cfg = _get_detector_cfg(
setup_seed(0)
parta2_cfg = get_detector_cfg(
'parta2/PartA2_hv_secfpn_8xb2-cyclic-80e_kitti-3d-3class.py')
model = MODELS.build(parta2_cfg)
num_gt_instance = 2
packed_inputs = _create_detector_inputs(
num_gt_instance=num_gt_instance)
packed_inputs = create_detector_inputs(num_gt_instance=num_gt_instance)
# TODO: Support aug data test
# aug_packed_inputs = [
# _create_detector_inputs(num_gt_instance=num_gt_instance),
# _create_detector_inputs(num_gt_instance=num_gt_instance + 1)
# create_detector_inputs(num_gt_instance=num_gt_instance),
# create_detector_inputs(num_gt_instance=num_gt_instance + 1)
# ]
# test_aug_test
# metainfo = {
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestPointRCNN(unittest.TestCase):
......@@ -15,12 +15,12 @@ class TestPointRCNN(unittest.TestCase):
assert hasattr(mmdet3d.models, 'PointRCNN')
DefaultScope.get_instance('test_pointrcnn', scope_name='mmdet3d')
_setup_seed(0)
pointrcnn_cfg = _get_detector_cfg(
setup_seed(0)
pointrcnn_cfg = get_detector_cfg(
'point_rcnn/point-rcnn_8xb2_kitti-3d-3class.py')
model = MODELS.build(pointrcnn_cfg)
num_gt_instance = 2
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
num_points=10101, num_gt_instance=num_gt_instance)
if torch.cuda.is_available():
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestPVRCNN(unittest.TestCase):
......@@ -15,18 +15,17 @@ class TestPVRCNN(unittest.TestCase):
assert hasattr(mmdet3d.models, 'PointVoxelRCNN')
DefaultScope.get_instance('test_pvrcnn', scope_name='mmdet3d')
_setup_seed(0)
pvrcnn_cfg = _get_detector_cfg(
setup_seed(0)
pvrcnn_cfg = get_detector_cfg(
'pvrcnn/pvrcnn_8xb2-80e_kitti-3d-3class.py')
model = MODELS.build(pvrcnn_cfg)
num_gt_instance = 2
packed_inputs = _create_detector_inputs(
num_gt_instance=num_gt_instance)
packed_inputs = create_detector_inputs(num_gt_instance=num_gt_instance)
# TODO: Support aug data test
# aug_packed_inputs = [
# _create_detector_inputs(num_gt_instance=num_gt_instance),
# _create_detector_inputs(num_gt_instance=num_gt_instance + 1)
# create_detector_inputs(num_gt_instance=num_gt_instance),
# create_detector_inputs(num_gt_instance=num_gt_instance + 1)
# ]
# test_aug_test
# metainfo = {
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestSDSSD(unittest.TestCase):
......@@ -15,12 +15,12 @@ class TestSDSSD(unittest.TestCase):
assert hasattr(mmdet3d.models, 'SASSD')
DefaultScope.get_instance('test_sassd', scope_name='mmdet3d')
_setup_seed(0)
voxel_net_cfg = _get_detector_cfg(
setup_seed(0)
voxel_net_cfg = get_detector_cfg(
'sassd/sassd_8xb6-80e_kitti-3d-3class.py')
model = MODELS.build(voxel_net_cfg)
num_gt_instance = 3
packed_inputs = _create_detector_inputs(
packed_inputs = create_detector_inputs(
num_gt_instance=num_gt_instance, num_classes=1)
if torch.cuda.is_available():
......
......@@ -4,8 +4,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestVotenet(unittest.TestCase):
......@@ -15,18 +15,16 @@ class TestVotenet(unittest.TestCase):
assert hasattr(mmdet3d.models, 'VoteNet')
DefaultScope.get_instance('test_vote_net', scope_name='mmdet3d')
_setup_seed(0)
voxel_net_cfg = _get_detector_cfg(
'votenet/votenet_8xb16_sunrgbd-3d.py')
setup_seed(0)
voxel_net_cfg = get_detector_cfg('votenet/votenet_8xb16_sunrgbd-3d.py')
model = MODELS.build(voxel_net_cfg)
num_gt_instance = 50
packed_inputs = _create_detector_inputs(
num_gt_instance=num_gt_instance)
packed_inputs = create_detector_inputs(num_gt_instance=num_gt_instance)
# TODO: Support aug test
# aug_data = [
# _create_detector_inputs(num_gt_instance=num_gt_instance),
# _create_detector_inputs(num_gt_instance=num_gt_instance + 1)
# create_detector_inputs(num_gt_instance=num_gt_instance),
# create_detector_inputs(num_gt_instance=num_gt_instance + 1)
# ]
# # test_aug_test
# metainfo = {
......
......@@ -5,8 +5,8 @@ import torch
from mmengine import DefaultScope
from mmdet3d.registry import MODELS
from tests.utils.model_utils import (_create_detector_inputs,
_get_detector_cfg, _setup_seed)
from mmdet3d.testing import (create_detector_inputs, get_detector_cfg,
setup_seed)
class TestVoxelNet(unittest.TestCase):
......@@ -16,18 +16,17 @@ class TestVoxelNet(unittest.TestCase):
assert hasattr(mmdet3d.models, 'VoxelNet')
DefaultScope.get_instance('test_voxelnet', scope_name='mmdet3d')
_setup_seed(0)
pointpillars_cfg = _get_detector_cfg(
setup_seed(0)
pointpillars_cfg = get_detector_cfg(
'pointpillars/pointpillars_hv_secfpn_8xb6-160e_kitti-3d-3class.py')
model = MODELS.build(pointpillars_cfg)
num_gt_instance = 2
packed_inputs = _create_detector_inputs(
num_gt_instance=num_gt_instance)
packed_inputs = create_detector_inputs(num_gt_instance=num_gt_instance)
# TODO: Support aug_test
# aug_data = [
# _create_detector_inputs(num_gt_instance=num_gt_instance),
# _create_detector_inputs(num_gt_instance=num_gt_instance + 1)
# create_detector_inputs(num_gt_instance=num_gt_instance),
# create_detector_inputs(num_gt_instance=num_gt_instance + 1)
# ]
# # test_aug_test
# metainfo = {
......
......@@ -45,8 +45,8 @@ def test_centerpoint_fpn():
second_cfg = dict(
type='SECOND',
in_channels=64,
out_channels=[64, 128, 256],
in_channels=2,
out_channels=[2, 2, 2],
layer_nums=[3, 5, 5],
layer_strides=[2, 2, 2],
norm_cfg=dict(type='BN', eps=1e-3, momentum=0.01),
......@@ -57,8 +57,8 @@ def test_centerpoint_fpn():
# centerpoint usage of fpn
centerpoint_fpn_cfg = dict(
type='SECONDFPN',
in_channels=[64, 128, 256],
out_channels=[128, 128, 128],
in_channels=[2, 2, 2],
out_channels=[2, 2, 2],
upsample_strides=[0.5, 1, 2],
norm_cfg=dict(type='BN', eps=1e-3, momentum=0.01),
upsample_cfg=dict(type='deconv', bias=False),
......@@ -67,17 +67,17 @@ def test_centerpoint_fpn():
# original usage of fpn
fpn_cfg = dict(
type='SECONDFPN',
in_channels=[64, 128, 256],
in_channels=[2, 2, 2],
upsample_strides=[1, 2, 4],
out_channels=[128, 128, 128])
out_channels=[2, 2, 2])
second_fpn = build_neck(fpn_cfg)
centerpoint_second_fpn = build_neck(centerpoint_fpn_cfg)
input = torch.rand([4, 64, 512, 512])
input = torch.rand([2, 2, 32, 32])
sec_output = second(input)
centerpoint_output = centerpoint_second_fpn(sec_output)
second_output = second_fpn(sec_output)
assert centerpoint_output[0].shape == torch.Size([4, 384, 128, 128])
assert second_output[0].shape == torch.Size([4, 384, 256, 256])
assert centerpoint_output[0].shape == torch.Size([2, 6, 8, 8])
assert second_output[0].shape == torch.Size([2, 6, 16, 16])
......@@ -45,10 +45,10 @@ def test_anchor_3d_range_generator():
'\nrotations=[0, 1.57],\nreshape_out=False,' \
'\nsize_per_range=True)'
assert repr_str == expected_repr_str
featmap_size = (256, 256)
featmap_size = (8, 8)
mr_anchors = anchor_generator.single_level_grid_anchors(
featmap_size, 1.1, device=device)
assert mr_anchors.shape == torch.Size([1, 256, 256, 3, 2, 7])
assert mr_anchors.shape == torch.Size([1, 8, 8, 3, 2, 7])
def test_aligned_anchor_generator():
......@@ -80,108 +80,108 @@ def test_aligned_anchor_generator():
size_per_range=False,
reshape_out=True)
featmap_sizes = [(256, 256), (128, 128), (64, 64)]
featmap_sizes = [(16, 16), (8, 8), (4, 4)]
anchor_generator = TASK_UTILS.build(anchor_generator_cfg)
assert anchor_generator.num_base_anchors == 8
# check base anchors
expected_grid_anchors = [
torch.tensor([[
-51.0000, -51.0000, -1.8000, 2.5981, 0.8660, 1.0000, 0.0000,
-48.0000, -48.0000, -1.8000, 2.5981, 0.8660, 1.0000, 0.0000,
0.0000, 0.0000
],
[
-51.0000, -51.0000, -1.8000, 0.4000, 0.4000, 1.0000,
-48.0000, -48.0000, -1.8000, 0.4000, 0.4000, 1.0000,
1.5700, 0.0000, 0.0000
],
[
-50.6000, -51.0000, -1.8000, 0.4000, 0.4000, 1.0000,
-41.6000, -48.0000, -1.8000, 0.4000, 0.4000, 1.0000,
0.0000, 0.0000, 0.0000
],
[
-50.2000, -51.0000, -1.8000, 1.0000, 1.0000, 1.0000,
-35.2000, -48.0000, -1.8000, 1.0000, 1.0000, 1.0000,
1.5700, 0.0000, 0.0000
],
[
-49.8000, -51.0000, -1.8000, 1.0000, 1.0000, 1.0000,
-28.8000, -48.0000, -1.8000, 1.0000, 1.0000, 1.0000,
0.0000, 0.0000, 0.0000
],
[
-49.4000, -51.0000, -1.8000, 1.7321, 0.5774, 1.0000,
-22.4000, -48.0000, -1.8000, 1.7321, 0.5774, 1.0000,
1.5700, 0.0000, 0.0000
],
[
-49.0000, -51.0000, -1.8000, 1.7321, 0.5774, 1.0000,
-16.0000, -48.0000, -1.8000, 1.7321, 0.5774, 1.0000,
0.0000, 0.0000, 0.0000
],
[
-48.6000, -51.0000, -1.8000, 2.5981, 0.8660, 1.0000,
-9.6000, -48.0000, -1.8000, 2.5981, 0.8660, 1.0000,
1.5700, 0.0000, 0.0000
]],
device=device),
torch.tensor([[
-50.8000, -50.8000, -1.8000, 5.1962, 1.7320, 2.0000, 0.0000,
-44.8000, -44.8000, -1.8000, 5.1962, 1.7320, 2.0000, 0.0000,
0.0000, 0.0000
],
[
-50.8000, -50.8000, -1.8000, 0.8000, 0.8000, 2.0000,
-44.8000, -44.8000, -1.8000, 0.8000, 0.8000, 2.0000,
1.5700, 0.0000, 0.0000
],
[
-50.0000, -50.8000, -1.8000, 0.8000, 0.8000, 2.0000,
-32.0000, -44.8000, -1.8000, 0.8000, 0.8000, 2.0000,
0.0000, 0.0000, 0.0000
],
[
-49.2000, -50.8000, -1.8000, 2.0000, 2.0000, 2.0000,
-19.2000, -44.8000, -1.8000, 2.0000, 2.0000, 2.0000,
1.5700, 0.0000, 0.0000
],
[
-48.4000, -50.8000, -1.8000, 2.0000, 2.0000, 2.0000,
-6.4000, -44.8000, -1.8000, 2.0000, 2.0000, 2.0000,
0.0000, 0.0000, 0.0000
],
[
-47.6000, -50.8000, -1.8000, 3.4642, 1.1548, 2.0000,
6.4000, -44.8000, -1.8000, 3.4642, 1.1548, 2.0000,
1.5700, 0.0000, 0.0000
],
[
-46.8000, -50.8000, -1.8000, 3.4642, 1.1548, 2.0000,
19.2000, -44.8000, -1.8000, 3.4642, 1.1548, 2.0000,
0.0000, 0.0000, 0.0000
],
[
-46.0000, -50.8000, -1.8000, 5.1962, 1.7320, 2.0000,
32.0000, -44.8000, -1.8000, 5.1962, 1.7320, 2.0000,
1.5700, 0.0000, 0.0000
]],
device=device),
torch.tensor([[
-50.4000, -50.4000, -1.8000, 10.3924, 3.4640, 4.0000, 0.0000,
-38.4000, -38.4000, -1.8000, 10.3924, 3.4640, 4.0000, 0.0000,
0.0000, 0.0000
],
[
-50.4000, -50.4000, -1.8000, 1.6000, 1.6000, 4.0000,
-38.4000, -38.4000, -1.8000, 1.6000, 1.6000, 4.0000,
1.5700, 0.0000, 0.0000
],
[
-48.8000, -50.4000, -1.8000, 1.6000, 1.6000, 4.0000,
-12.8000, -38.4000, -1.8000, 1.6000, 1.6000, 4.0000,
0.0000, 0.0000, 0.0000
],
[
-47.2000, -50.4000, -1.8000, 4.0000, 4.0000, 4.0000,
12.8000, -38.4000, -1.8000, 4.0000, 4.0000, 4.0000,
1.5700, 0.0000, 0.0000
],
[
-45.6000, -50.4000, -1.8000, 4.0000, 4.0000, 4.0000,
38.4000, -38.4000, -1.8000, 4.0000, 4.0000, 4.0000,
0.0000, 0.0000, 0.0000
],
[
-44.0000, -50.4000, -1.8000, 6.9284, 2.3096, 4.0000,
-38.4000, -12.8000, -1.8000, 6.9284, 2.3096, 4.0000,
1.5700, 0.0000, 0.0000
],
[
-42.4000, -50.4000, -1.8000, 6.9284, 2.3096, 4.0000,
-12.8000, -12.8000, -1.8000, 6.9284, 2.3096, 4.0000,
0.0000, 0.0000, 0.0000
],
[
-40.8000, -50.4000, -1.8000, 10.3924, 3.4640, 4.0000,
12.8000, -12.8000, -1.8000, 10.3924, 3.4640, 4.0000,
1.5700, 0.0000, 0.0000
]],
device=device)
......@@ -189,9 +189,9 @@ def test_aligned_anchor_generator():
multi_level_anchors = anchor_generator.grid_anchors(
featmap_sizes, device=device)
expected_multi_level_shapes = [
torch.Size([524288, 9]),
torch.Size([131072, 9]),
torch.Size([32768, 9])
torch.Size([2048, 9]),
torch.Size([512, 9]),
torch.Size([128, 9])
]
for i, single_level_anchor in enumerate(multi_level_anchors):
assert single_level_anchor.shape == expected_multi_level_shapes[i]
......
......@@ -6,17 +6,15 @@ from mmdet3d.models.task_modules.voxel import VoxelGenerator
def test_voxel_generator():
np.random.seed(0)
voxel_size = [0.5, 0.5, 0.5]
point_cloud_range = [0, -40, -3, 70.4, 40, 1]
max_num_points = 1000
voxel_size = [5, 5, 1]
point_cloud_range = [0, 0, 0, 20, 40, 4]
max_num_points = 5
self = VoxelGenerator(voxel_size, point_cloud_range, max_num_points)
points = np.random.rand(1000, 4)
points = np.random.uniform(0, 4, (20, 3))
voxels = self.generate(points)
voxels, coors, num_points_per_voxel = voxels
expected_coors = np.array([[7, 81, 1], [6, 81, 0], [7, 80, 1], [6, 81, 1],
[7, 81, 0], [6, 80, 1], [7, 80, 0], [6, 80, 0]])
expected_num_points_per_voxel = np.array(
[120, 121, 127, 134, 115, 127, 125, 131])
assert voxels.shape == (8, 1000, 4)
expected_coors = np.array([[2, 0, 0], [3, 0, 0], [0, 0, 0], [1, 0, 0]])
expected_num_points_per_voxel = np.array([5, 5, 5, 3])
assert voxels.shape == (4, 5, 3)
assert np.all(coors == expected_coors)
assert np.all(num_points_per_voxel == expected_num_points_per_voxel)
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