Commit 535344de authored by zhangwenwei's avatar zhangwenwei
Browse files

Merge branch 'indoor_pipeline' into 'master'

Indoor pipeline

See merge request open-mmlab/mmdet.3d!27
parents 0df95010 5b42b739
......@@ -40,7 +40,8 @@ class DefaultFormatBundle(object):
results['img'] = DC(to_tensor(img), stack=True)
for key in [
'proposals', 'gt_bboxes', 'gt_bboxes_3d', 'gt_bboxes_ignore',
'gt_labels', 'gt_labels_3d'
'gt_labels', 'gt_labels_3d', 'pts_instance_mask',
'pts_semantic_mask'
]:
if key not in results:
continue
......@@ -127,8 +128,9 @@ class DefaultFormatBundle3D(DefaultFormatBundle):
gt_bboxes_3d_mask = results['gt_bboxes_3d_mask']
results['gt_bboxes_3d'] = results['gt_bboxes_3d'][
gt_bboxes_3d_mask]
results['gt_names_3d'] = results['gt_names_3d'][
gt_bboxes_3d_mask]
if 'gt_names_3d' in results:
results['gt_names_3d'] = results['gt_names_3d'][
gt_bboxes_3d_mask]
if 'gt_bboxes_mask' in results:
gt_bboxes_mask = results['gt_bboxes_mask']
if 'gt_bboxes' in results:
......@@ -151,10 +153,12 @@ class DefaultFormatBundle3D(DefaultFormatBundle):
dtype=np.int64)
# we still assume one pipeline for one frame LiDAR
# thus, the 3D name is list[string]
results['gt_labels_3d'] = np.array([
self.class_names.index(n) for n in results['gt_names_3d']
],
dtype=np.int64)
if 'gt_names_3d' in results:
results['gt_labels_3d'] = np.array([
self.class_names.index(n)
for n in results['gt_names_3d']
],
dtype=np.int64)
results = super(DefaultFormatBundle3D, self).__call__(results)
return results
......
......@@ -133,7 +133,7 @@ class IndoorGlobalRotScale(object):
def __init__(self, use_height=True, rot_range=None, scale_range=None):
self.use_height = use_height
self.rot_range = rot_range
self.rot_range = np.pi * np.array(rot_range)
self.scale_range = scale_range
def _rotz(self, t):
......
......@@ -92,8 +92,8 @@ class IndoorLoadAnnotations3D(object):
mmcv.check_file_exist(pts_instance_mask_path)
mmcv.check_file_exist(pts_semantic_mask_path)
pts_instance_mask = np.load(pts_instance_mask_path)
pts_semantic_mask = np.load(pts_semantic_mask_path)
pts_instance_mask = np.load(pts_instance_mask_path).astype(np.int)
pts_semantic_mask = np.load(pts_semantic_mask_path).astype(np.int)
results['pts_instance_mask'] = pts_instance_mask
results['pts_semantic_mask'] = pts_semantic_mask
......
......@@ -64,7 +64,7 @@ def test_indoor_flip_data():
def test_global_rot_scale():
np.random.seed(0)
sunrgbd_augment = IndoorGlobalRotScale(
True, rot_range=[-np.pi / 6, np.pi / 6], scale_range=[0.85, 1.15])
True, rot_range=[-1 / 6, 1 / 6], scale_range=[0.85, 1.15])
sunrgbd_results = dict()
sunrgbd_results['points'] = np.array(
[[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00],
......@@ -101,7 +101,7 @@ def test_global_rot_scale():
np.random.seed(0)
scannet_augment = IndoorGlobalRotScale(
True, rot_range=[-np.pi * 1 / 36, np.pi * 1 / 36], scale_range=None)
True, rot_range=[-1 * 1 / 36, 1 / 36], scale_range=None)
scannet_results = dict()
scannet_results['points'] = np.array(
[[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01],
......
......@@ -39,15 +39,16 @@ def test_load_annotations3D():
sunrgbd_info = mmcv.load('./tests/data/sunrgbd/sunrgbd_infos.pkl')[0]
if sunrgbd_info['annos']['gt_num'] != 0:
sunrgbd_gt_bboxes_3d = sunrgbd_info['annos']['gt_boxes_upright_depth']
sunrgbd_gt_labels = sunrgbd_info['annos']['class'].reshape(-1, 1)
sunrgbd_gt_bboxes_3d_mask = np.ones_like(sunrgbd_gt_labels)
sunrgbd_gt_labels_3d = sunrgbd_info['annos']['class']
sunrgbd_gt_bboxes_3d_mask = np.ones_like(
sunrgbd_gt_labels_3d, dtype=np.bool)
else:
sunrgbd_gt_bboxes_3d = np.zeros((1, 6), dtype=np.float32)
sunrgbd_gt_labels = np.zeros((1, 1))
sunrgbd_gt_bboxes_3d_mask = np.zeros((1, 1))
sunrgbd_gt_labels_3d = np.zeros((1, ))
sunrgbd_gt_bboxes_3d_mask = np.zeros((1, ), dtype=np.bool)
assert sunrgbd_gt_bboxes_3d.shape == (3, 7)
assert sunrgbd_gt_labels.shape == (3, 1)
assert sunrgbd_gt_bboxes_3d_mask.shape == (3, 1)
assert sunrgbd_gt_labels_3d.shape == (3, )
assert sunrgbd_gt_bboxes_3d_mask.shape == (3, )
scannet_info = mmcv.load('./tests/data/scannet/scannet_infos.pkl')[0]
scannet_load_annotations3D = IndoorLoadAnnotations3D()
......@@ -55,29 +56,29 @@ def test_load_annotations3D():
data_path = './tests/data/scannet/scannet_train_instance_data'
if scannet_info['annos']['gt_num'] != 0:
scannet_gt_bboxes_3d = scannet_info['annos']['gt_boxes_upright_depth']
scannet_gt_labels = scannet_info['annos']['class'].reshape(-1, 1)
scannet_gt_bboxes_3d_mask = np.ones_like(scannet_gt_labels)
scannet_gt_labels_3d = scannet_info['annos']['class']
scannet_gt_bboxes_3d_mask = np.ones_like(
scannet_gt_labels_3d, dtype=np.bool)
else:
scannet_gt_bboxes_3d = np.zeros((1, 6), dtype=np.float32)
scannet_gt_labels = np.zeros((1, 1))
scannet_gt_bboxes_3d_mask = np.zeros((1, 1))
scannet_gt_labels_3d = np.zeros((1, ))
scannet_gt_bboxes_3d_mask = np.zeros((1, ), dtype=np.bool)
scan_name = scannet_info['point_cloud']['lidar_idx']
scannet_results['pts_instance_mask_path'] = osp.join(
data_path, f'{scan_name}_ins_label.npy')
scannet_results['pts_semantic_mask_path'] = osp.join(
data_path, f'{scan_name}_sem_label.npy')
scannet_results['info'] = scannet_info
scannet_results['gt_bboxes_3d'] = scannet_gt_bboxes_3d
scannet_results['gt_labels'] = scannet_gt_labels
scannet_results['gt_labels_3d'] = scannet_gt_labels_3d
scannet_results['gt_bboxes_3d_mask'] = scannet_gt_bboxes_3d_mask
scannet_results = scannet_load_annotations3D(scannet_results)
scannet_gt_boxes = scannet_results['gt_bboxes_3d']
scannet_gt_lbaels = scannet_results['gt_labels']
scannet_gt_lbaels = scannet_results['gt_labels_3d']
scannet_gt_boxes_mask = scannet_results['gt_bboxes_3d_mask']
scannet_pts_instance_mask = scannet_results['pts_instance_mask']
scannet_pts_semantic_mask = scannet_results['pts_semantic_mask']
assert scannet_gt_boxes.shape == (27, 6)
assert scannet_gt_lbaels.shape == (27, 1)
assert scannet_gt_boxes_mask.shape == (27, 1)
assert scannet_gt_lbaels.shape == (27, )
assert scannet_gt_boxes_mask.shape == (27, )
assert scannet_pts_instance_mask.shape == (100, )
assert scannet_pts_semantic_mask.shape == (100, )
import os.path as osp
import mmcv
import numpy as np
from mmdet3d.datasets.pipelines import Compose
def test_scannet_pipeline():
class_names = ('cabinet', 'bed', 'chair', 'sofa', 'table', 'door',
'window', 'bookshelf', 'picture', 'counter', 'desk',
'curtain', 'refrigerator', 'showercurtrain', 'toilet',
'sink', 'bathtub', 'garbagebin')
np.random.seed(0)
pipelines = [
dict(
type='IndoorLoadPointsFromFile',
use_height=True,
load_dim=6,
use_dim=[0, 1, 2]),
dict(type='IndoorLoadAnnotations3D'),
dict(type='IndoorPointSample', num_points=5),
dict(type='IndoorFlipData', flip_ratio_yz=1.0, flip_ratio_xz=1.0),
dict(
type='IndoorGlobalRotScale',
use_height=True,
rot_range=[-1 / 36, 1 / 36],
scale_range=None),
dict(type='DefaultFormatBundle3D', class_names=class_names),
dict(
type='Collect3D',
keys=[
'points', 'gt_bboxes_3d', 'gt_labels_3d', 'pts_semantic_mask',
'pts_instance_mask'
]),
]
pipeline = Compose(pipelines)
info = mmcv.load('./tests/data/scannet/scannet_infos.pkl')[0]
results = dict()
data_path = './tests/data/scannet/scannet_train_instance_data'
results['data_path'] = data_path
scan_name = info['point_cloud']['lidar_idx']
results['pts_filename'] = osp.join(data_path, f'{scan_name}_vert.npy')
if info['annos']['gt_num'] != 0:
scannet_gt_bboxes_3d = info['annos']['gt_boxes_upright_depth']
scannet_gt_labels_3d = info['annos']['class']
scannet_gt_bboxes_3d_mask = np.ones_like(
scannet_gt_labels_3d, dtype=np.bool)
else:
scannet_gt_bboxes_3d = np.zeros((1, 6), dtype=np.float32)
scannet_gt_labels_3d = np.zeros((1, ))
scannet_gt_bboxes_3d_mask = np.zeros((1, ), dtype=np.bool)
scan_name = info['point_cloud']['lidar_idx']
results['pts_instance_mask_path'] = osp.join(data_path,
f'{scan_name}_ins_label.npy')
results['pts_semantic_mask_path'] = osp.join(data_path,
f'{scan_name}_sem_label.npy')
results['gt_bboxes_3d'] = scannet_gt_bboxes_3d
results['gt_labels_3d'] = scannet_gt_labels_3d
results['gt_bboxes_3d_mask'] = scannet_gt_bboxes_3d_mask
results = pipeline(results)
points = results['points']._data
gt_bboxes_3d = results['gt_bboxes_3d']._data
gt_labels_3d = results['gt_labels_3d']._data
pts_semantic_mask = results['pts_semantic_mask']._data
pts_instance_mask = results['pts_instance_mask']._data
expected_points = np.array(
[[-2.9078157, -1.9569951, 2.3543026, 2.389488],
[-0.71360034, -3.4359822, 2.1330001, 2.1681855],
[-1.332374, 1.474838, -0.04405887, -0.00887359],
[2.1336637, -1.3265059, -0.02880373, 0.00638155],
[0.43895668, -3.0259454, 1.5560012, 1.5911865]])
expected_gt_bboxes_3d = np.array([
[-1.5005362, -3.512584, 1.8565295, 1.7457027, 0.24149807, 0.57235193],
[-2.8848705, 3.4961755, 1.5268247, 0.66170084, 0.17433672, 0.67153597],
[-1.1585636, -2.192365, 0.61649567, 0.5557011, 2.5375574, 1.2144762],
[-2.930457, -2.4856408, 0.9722377, 0.6270478, 1.8461524, 0.28697443],
[3.3114715, -0.00476722, 1.0712197, 0.46191898, 3.8605113, 2.1603441]
])
expected_gt_labels_3d = np.array([
6, 6, 4, 9, 11, 11, 10, 0, 15, 17, 17, 17, 3, 12, 4, 4, 14, 1, 0, 0, 0,
0, 0, 0, 5, 5, 5
])
expected_pts_semantic_mask = np.array([3, 1, 2, 2, 15])
expected_pts_instance_mask = np.array([44, 22, 10, 10, 57])
assert np.allclose(points, expected_points)
assert np.allclose(gt_bboxes_3d[:5, :], expected_gt_bboxes_3d)
assert np.all(gt_labels_3d.numpy() == expected_gt_labels_3d)
assert np.all(pts_semantic_mask.numpy() == expected_pts_semantic_mask)
assert np.all(pts_instance_mask.numpy() == expected_pts_instance_mask)
def test_sunrgbd_pipeline():
class_names = ('bed', 'table', 'sofa', 'chair', 'toilet', 'desk',
'dresser', 'night_stand', 'bookshelf', 'bathtub')
np.random.seed(0)
pipelines = [
dict(
type='IndoorLoadPointsFromFile',
use_height=True,
load_dim=6,
use_dim=[0, 1, 2]),
dict(type='IndoorFlipData', flip_ratio_yz=1.0),
dict(
type='IndoorGlobalRotScale',
use_height=True,
rot_range=[-1 / 6, 1 / 6],
scale_range=[0.85, 1.15]),
dict(type='IndoorPointSample', num_points=5),
dict(type='DefaultFormatBundle3D', class_names=class_names),
dict(
type='Collect3D', keys=['points', 'gt_bboxes_3d', 'gt_labels_3d']),
]
pipeline = Compose(pipelines)
results = dict()
info = mmcv.load('./tests/data/sunrgbd/sunrgbd_infos.pkl')[0]
data_path = './tests/data/sunrgbd/sunrgbd_trainval'
scan_name = info['point_cloud']['lidar_idx']
results['pts_filename'] = osp.join(data_path, 'lidar',
f'{scan_name:06d}.npy')
if info['annos']['gt_num'] != 0:
gt_bboxes_3d = info['annos']['gt_boxes_upright_depth']
gt_labels_3d = info['annos']['class']
gt_bboxes_3d_mask = np.ones_like(gt_labels_3d, dtype=np.bool)
else:
gt_bboxes_3d = np.zeros((1, 6), dtype=np.float32)
gt_labels_3d = np.zeros((1, ))
gt_bboxes_3d_mask = np.zeros((1, ), dtype=np.bool)
results['gt_bboxes_3d'] = gt_bboxes_3d
results['gt_labels_3d'] = gt_labels_3d
results['gt_bboxes_3d_mask'] = gt_bboxes_3d_mask
results = pipeline(results)
points = results['points']._data
gt_bboxes_3d = results['gt_bboxes_3d']._data
gt_labels_3d = results['gt_labels_3d']._data
expected_points = np.array(
[[0.6570105, 1.5538014, 0.24514851, 1.0165423],
[0.656101, 1.558591, 0.21755838, 0.98895216],
[0.6293659, 1.5679953, -0.10004003, 0.67135376],
[0.6068739, 1.5974995, -0.41063973, 0.36075398],
[0.6464709, 1.5573514, 0.15114647, 0.9225402]])
expected_gt_bboxes_3d = np.array([[
-2.012483, 3.9473376, -0.25446942, 2.3730404, 1.9457763, 2.0303352,
1.2205974
],
[
-3.7036808, 4.2396426, -0.81091917,
0.6032123, 0.91040343, 1.003341,
1.2662518
],
[
0.6528646, 2.1638472, -0.15228128,
0.7347852, 1.6113238, 2.1694272,
2.81404
]])
expected_gt_labels_3d = np.array([0, 7, 6])
assert np.allclose(gt_bboxes_3d, expected_gt_bboxes_3d)
assert np.allclose(gt_labels_3d.flatten(), expected_gt_labels_3d)
assert np.allclose(points, expected_points)
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