Skip to content

Commit

Permalink
Add transforms_3d unittest (#12)
Browse files Browse the repository at this point in the history
* Support github action:

* fix docs package

* reduce action items

* Update cuda arch

* Set cuda arch

* Add information

* add cocotools in installation

* skip gpu

* remove duplicated module

* Change points shape from 1177 to 800

* Change 1177 to 800

* Change 1177 to 800

* Add print

* Add other print

* Change gt_labels

* Add seed

* Change to len assert

* Change gt_bboxes_3d

* Change repr

Co-authored-by: ZwwWayne <[email protected]>
Co-authored-by: liyinhao <[email protected]>
  • Loading branch information
3 people authored Jul 13, 2020
1 parent f842ff9 commit 4e4d6e9
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
10 changes: 9 additions & 1 deletion mmdet3d/datasets/pipelines/transforms_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,15 @@ def __call__(self, input_dict):

def __repr__(self):
"""str: Return a string that describes the module."""
return self.__class__.__name__
repr_str = self.__class__.__name__
repr_str += f' sample_2d={self.sample_2d},'
repr_str += f' data_root={self.sampler_cfg.data_root},'
repr_str += f' info_path={self.sampler_cfg.info_path},'
repr_str += f' rate={self.sampler_cfg.rate},'
repr_str += f' prepare={self.sampler_cfg.prepare},'
repr_str += f' classes={self.sampler_cfg.classes},'
repr_str += f' sample_groups={self.sampler_cfg.sample_groups}'
return repr_str


@PIPELINES.register_module()
Expand Down
60 changes: 59 additions & 1 deletion tests/test_pipeline/test_transforms_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import torch

from mmdet3d.core import Box3DMode, CameraInstance3DBoxes
from mmdet3d.core import Box3DMode, CameraInstance3DBoxes, LiDARInstance3DBoxes
from mmdet3d.datasets import ObjectNoise, ObjectSample


Expand Down Expand Up @@ -34,6 +34,64 @@ def test_remove_points_in_boxes():
assert points.shape == (10, 4)


def test_object_sample():
import pickle
db_sampler = mmcv.ConfigDict({
'data_root': './tests/data/kitti/',
'info_path': './tests/data/kitti/kitti_dbinfos_train.pkl',
'rate': 1.0,
'prepare': {
'filter_by_difficulty': [-1],
'filter_by_min_points': {
'Pedestrian': 10
}
},
'classes': ['Pedestrian', 'Cyclist', 'Car'],
'sample_groups': {
'Pedestrian': 6
}
})
with open('./tests/data/kitti/kitti_dbinfos_train.pkl', 'rb') as f:
db_infos = pickle.load(f)
np.random.seed(0)
object_sample = ObjectSample(db_sampler)
points = np.fromfile(
'./tests/data/kitti/training/velodyne_reduced/000000.bin',
np.float32).reshape(-1, 4)
annos = mmcv.load('./tests/data/kitti/kitti_infos_train.pkl')
info = annos[0]
annos = info['annos']
gt_names = annos['name']
gt_bboxes_3d = db_infos['Pedestrian'][0]['box3d_lidar']
gt_bboxes_3d = LiDARInstance3DBoxes([gt_bboxes_3d])
CLASSES = ('Car', 'Pedestrian', 'Cyclist')
gt_labels = []
for cat in gt_names:
if cat in CLASSES:
gt_labels.append(CLASSES.index(cat))
else:
gt_labels.append(-1)
input_dict = dict(
points=points, gt_bboxes_3d=gt_bboxes_3d, gt_labels_3d=gt_labels)
input_dict = object_sample(input_dict)
points = input_dict['points']
gt_bboxes_3d = input_dict['gt_bboxes_3d']
gt_labels_3d = input_dict['gt_labels_3d']
repr_str = repr(object_sample)
expected_repr_str = 'ObjectSample sample_2d=False, ' \
'data_root=./tests/data/kitti/, ' \
'info_path=./tests/data/kitti/kitti' \
'_dbinfos_train.pkl, rate=1.0, ' \
'prepare={\'filter_by_difficulty\': [-1], ' \
'\'filter_by_min_points\': {\'Pedestrian\': 10}}, ' \
'classes=[\'Pedestrian\', \'Cyclist\', \'Car\'], ' \
'sample_groups={\'Pedestrian\': 6}'
assert repr_str == expected_repr_str
assert points.shape == (1177, 4)
assert gt_bboxes_3d.tensor.shape == (2, 7)
assert np.all(gt_labels_3d == [1, 0])


def test_object_noise():
np.random.seed(0)
object_noise = ObjectNoise()
Expand Down

0 comments on commit 4e4d6e9

Please sign in to comment.