Commit 36466f83 authored by liyinhao's avatar liyinhao
Browse files

Merge branch 'master' into process_raw_data

parents 25d39342 f93167c3
...@@ -67,13 +67,12 @@ def test_getitem(): ...@@ -67,13 +67,12 @@ def test_getitem():
[-1.332374, 1.474838, -0.04405887, -0.00887359], [-1.332374, 1.474838, -0.04405887, -0.00887359],
[2.1336637, -1.3265059, -0.02880373, 0.00638155], [2.1336637, -1.3265059, -0.02880373, 0.00638155],
[0.43895668, -3.0259454, 1.5560012, 1.5911865]]) [0.43895668, -3.0259454, 1.5560012, 1.5911865]])
expected_gt_bboxes_3d = np.array([ expected_gt_bboxes_3d = torch.tensor(
[-1.5005362, -3.512584, 1.8565295, 1.7457027, 0.24149807, 0.57235193], [[-1.5005, -3.5126, 1.5704, 1.7457, 0.2415, 0.5724, 0.0000],
[-2.8848705, 3.4961755, 1.5268247, 0.66170084, 0.17433672, 0.67153597], [-2.8849, 3.4962, 1.1911, 0.6617, 0.1743, 0.6715, 0.0000],
[-1.1585636, -2.192365, 0.61649567, 0.5557011, 2.5375574, 1.2144762], [-1.1586, -2.1924, 0.0093, 0.5557, 2.5376, 1.2145, 0.0000],
[-2.930457, -2.4856408, 0.9722377, 0.6270478, 1.8461524, 0.28697443], [-2.9305, -2.4856, 0.8288, 0.6270, 1.8462, 0.2870, 0.0000],
[3.3114715, -0.00476722, 1.0712197, 0.46191898, 3.8605113, 2.1603441] [3.3115, -0.0048, -0.0090, 0.4619, 3.8605, 2.1603, 0.0000]])
])
expected_gt_labels = np.array([ expected_gt_labels = np.array([
6, 6, 4, 9, 11, 11, 10, 0, 15, 17, 17, 17, 3, 12, 4, 4, 14, 1, 0, 0, 0, 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 0, 0, 0, 5, 5, 5
...@@ -84,8 +83,8 @@ def test_getitem(): ...@@ -84,8 +83,8 @@ def test_getitem():
assert scannet_dataset.CLASSES == class_names assert scannet_dataset.CLASSES == class_names
assert np.allclose(points, expected_points) assert np.allclose(points, expected_points)
assert gt_bboxes_3d[:5].shape == (5, 6) assert gt_bboxes_3d.tensor[:5].shape == (5, 7)
assert np.allclose(gt_bboxes_3d[:5], expected_gt_bboxes_3d) assert torch.allclose(gt_bboxes_3d.tensor[:5], expected_gt_bboxes_3d, 1e-2)
assert np.all(gt_labels.numpy() == expected_gt_labels) assert np.all(gt_labels.numpy() == expected_gt_labels)
assert np.all(pts_semantic_mask.numpy() == expected_pts_semantic_mask) assert np.all(pts_semantic_mask.numpy() == expected_pts_semantic_mask)
assert np.all(pts_instance_mask.numpy() == expected_pts_instance_mask) assert np.all(pts_instance_mask.numpy() == expected_pts_instance_mask)
...@@ -114,42 +113,51 @@ def test_getitem(): ...@@ -114,42 +113,51 @@ def test_getitem():
def test_evaluate(): def test_evaluate():
from mmdet3d.core.bbox.structures import DepthInstance3DBoxes
root_path = './tests/data/scannet' root_path = './tests/data/scannet'
ann_file = './tests/data/scannet/scannet_infos.pkl' ann_file = './tests/data/scannet/scannet_infos.pkl'
scannet_dataset = ScanNetDataset(root_path, ann_file) scannet_dataset = ScanNetDataset(root_path, ann_file)
results = [] results = []
pred_boxes = dict() pred_boxes = dict()
pred_boxes['boxes_3d'] = torch.Tensor( pred_boxes['boxes_3d'] = DepthInstance3DBoxes(
[[ torch.tensor([[
3.52074146e+00, -1.48129511e+00, 1.57035351e+00, 2.31956959e-01, 1.4813e+00, 3.5207e+00, 1.5704e+00, 1.7445e+00, 2.3196e-01,
1.74445975e+00, 5.72351933e-01, 0 5.7235e-01, 0.0000e+00
], ],
[ [
-3.48033905e+00, -2.90395617e+00, 1.19105673e+00, 1.70723915e-01, 2.9040e+00, -3.4803e+00, 1.1911e+00, 6.6078e-01,
6.60776615e-01, 6.71535969e-01, 0 1.7072e-01, 6.7154e-01, 0.0000e+00
], ],
[ [
2.19867110e+00, -1.14655101e+00, 9.25755501e-03, 2.53463078e+00, 1.1466e+00, 2.1987e+00, 9.2576e-03, 5.4184e-01,
5.41841269e-01, 1.21447623e+00, 0 2.5346e+00, 1.2145e+00, 0.0000e+00
], ],
[ [
2.50163722, -2.91681337, 0.82875049, 1.84280431, 0.61697435, 2.9168e+00, 2.5016e+00, 8.2875e-01, 6.1697e-01,
0.28697443, 0 1.8428e+00, 2.8697e-01, 0.0000e+00
], ],
[ [
-0.01335114, 3.3114481, -0.00895238, 3.85815716, 0.44081616, -3.3114e+00, -1.3351e-02, -8.9524e-03, 4.4082e-01,
2.16034412, 0 3.8582e+00, 2.1603e+00, 0.0000e+00
]]) ],
pred_boxes['labels_3d'] = torch.Tensor([6, 6, 4, 9, 11]) [
pred_boxes['scores_3d'] = torch.Tensor([0.5, 1.0, 1.0, 1.0, 1.0]) -2.0135e+00, -3.4857e+00, 9.3848e-01, 1.9911e+00,
2.1603e-01, 1.2767e+00, 0.0000e+00
],
[
-2.1945e+00, -3.1402e+00, -3.8165e-02, 1.4801e+00,
6.8676e-01, 1.0586e+00, 0.0000e+00
],
[
-2.7553e+00, 2.4055e+00, -2.9972e-02, 1.4764e+00,
1.4927e+00, 2.3380e+00, 0.0000e+00
]]))
pred_boxes['labels_3d'] = torch.tensor([6, 6, 4, 9, 11, 11])
pred_boxes['scores_3d'] = torch.tensor([0.5, 1.0, 1.0, 1.0, 1.0, 0.5])
results.append(pred_boxes) results.append(pred_boxes)
metric = [0.25, 0.5] metric = [0.25, 0.5]
ret_dict = scannet_dataset.evaluate(results, metric) ret_dict = scannet_dataset.evaluate(results, metric)
table_average_precision_25 = ret_dict['table_AP_0.25'] assert abs(ret_dict['table_AP_0.25'] - 0.3333) < 0.01
window_average_precision_25 = ret_dict['window_AP_0.25'] assert abs(ret_dict['window_AP_0.25'] - 1.0) < 0.01
counter_average_precision_25 = ret_dict['counter_AP_0.25'] assert abs(ret_dict['counter_AP_0.25'] - 1.0) < 0.01
curtain_average_precision_25 = ret_dict['curtain_AP_0.25'] assert abs(ret_dict['curtain_AP_0.25'] - 1.0) < 0.01
assert abs(table_average_precision_25 - 0.3333) < 0.01
assert abs(window_average_precision_25 - 1) < 0.01
assert abs(counter_average_precision_25 - 1) < 0.01
assert abs(curtain_average_precision_25 - 0.5) < 0.01
...@@ -57,25 +57,15 @@ def test_getitem(): ...@@ -57,25 +57,15 @@ def test_getitem():
[0.6464, 1.5635, 0.0826, 0.0616], [0.6464, 1.5635, 0.0826, 0.0616],
[0.6453, 1.5603, 0.0849, 0.0638], [0.6453, 1.5603, 0.0849, 0.0638],
[0.6488, 1.5786, 0.0461, 0.0251]]) [0.6488, 1.5786, 0.0461, 0.0251]])
expected_gt_bboxes_3d = np.array([[ expected_gt_bboxes_3d = torch.tensor(
-2.012483, 3.9473376, -0.25446942, 2.3730404, 1.9457763, 2.0303352, [[-2.0125, 3.9473, -1.2696, 2.3730, 1.9458, 2.0303, 1.2206],
1.2205974 [-3.7037, 4.2396, -1.3126, 0.6032, 0.9104, 1.0033, 1.2663],
], [0.6529, 2.1638, -1.2370, 0.7348, 1.6113, 2.1694, 2.8140]])
[
-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 = np.array([0, 7, 6]) expected_gt_labels = np.array([0, 7, 6])
original_classes = sunrgbd_dataset.CLASSES original_classes = sunrgbd_dataset.CLASSES
assert np.allclose(points, expected_points, 1e-2) assert np.allclose(points, expected_points, 1e-2)
assert np.allclose(gt_bboxes_3d, expected_gt_bboxes_3d) assert np.allclose(gt_bboxes_3d.tensor, expected_gt_bboxes_3d, 1e-3)
assert np.all(gt_labels_3d.numpy() == expected_gt_labels) assert np.all(gt_labels_3d.numpy() == expected_gt_labels)
assert original_classes == class_names assert original_classes == class_names
...@@ -101,23 +91,19 @@ def test_getitem(): ...@@ -101,23 +91,19 @@ def test_getitem():
def test_evaluate(): def test_evaluate():
from mmdet3d.core.bbox.structures import DepthInstance3DBoxes
root_path = './tests/data/sunrgbd' root_path = './tests/data/sunrgbd'
ann_file = './tests/data/sunrgbd/sunrgbd_infos.pkl' ann_file = './tests/data/sunrgbd/sunrgbd_infos.pkl'
sunrgbd_dataset = SUNRGBDDataset(root_path, ann_file) sunrgbd_dataset = SUNRGBDDataset(root_path, ann_file)
results = [] results = []
pred_boxes = dict() pred_boxes = dict()
pred_boxes['boxes_3d'] = torch.Tensor( pred_boxes['boxes_3d'] = DepthInstance3DBoxes(
[[ torch.tensor(
4.168696, -1.047307, -1.231666, 1.887584, 2.30207, 1.969614, [[1.0473, 4.1687, -1.2317, 2.3021, 1.8876, 1.9696, 1.6956],
1.69564944 [2.5831, 4.8117, -1.2733, 0.5852, 0.8832, 0.9733, 1.6500],
], [-1.0864, 1.9045, -1.2000, 0.7128, 1.5631, 2.1045, 0.1022]]))
[ pred_boxes['labels_3d'] = torch.tensor([0, 7, 6])
4.811675, -2.583086, -1.273334, 0.883176, 0.585172, 0.973334, pred_boxes['scores_3d'] = torch.tensor([0.5, 1.0, 1.0])
1.64999513
], [1.904545, 1.086364, -1.2, 1.563134, 0.71281, 2.104546,
0.1022069]])
pred_boxes['labels_3d'] = torch.Tensor([0, 7, 6])
pred_boxes['scores_3d'] = torch.Tensor([0.5, 1.0, 1.0])
results.append(pred_boxes) results.append(pred_boxes)
metric = [0.25, 0.5] metric = [0.25, 0.5]
ap_dict = sunrgbd_dataset.evaluate(results, metric) ap_dict = sunrgbd_dataset.evaluate(results, metric)
......
...@@ -4,6 +4,8 @@ from os.path import dirname, exists, join ...@@ -4,6 +4,8 @@ from os.path import dirname, exists, join
import pytest import pytest
import torch import torch
from mmdet3d.core.bbox import Box3DMode, LiDARInstance3DBoxes
def _get_config_directory(): def _get_config_directory():
""" Find the predefined detector config directory """ """ Find the predefined detector config directory """
...@@ -129,11 +131,16 @@ def test_anchor3d_head_getboxes(): ...@@ -129,11 +131,16 @@ def test_anchor3d_head_getboxes():
feats = list() feats = list()
feats.append(torch.rand([2, 512, 200, 176], dtype=torch.float32).cuda()) feats.append(torch.rand([2, 512, 200, 176], dtype=torch.float32).cuda())
# fake input_metas
input_metas = [{ input_metas = [{
'sample_idx': 1234 'sample_idx': 1234,
'box_type_3d': LiDARInstance3DBoxes,
'box_mode_3d': Box3DMode.LIDAR
}, { }, {
'sample_idx': 2345 'sample_idx': 2345,
}] # fake input_metas 'box_type_3d': LiDARInstance3DBoxes,
'box_mode_3d': Box3DMode.LIDAR
}]
(cls_score, bbox_pred, dir_cls_preds) = self.forward(feats) (cls_score, bbox_pred, dir_cls_preds) = self.forward(feats)
# test get_boxes # test get_boxes
...@@ -155,11 +162,16 @@ def test_parta2_rpnhead_getboxes(): ...@@ -155,11 +162,16 @@ def test_parta2_rpnhead_getboxes():
feats = list() feats = list()
feats.append(torch.rand([2, 512, 200, 176], dtype=torch.float32).cuda()) feats.append(torch.rand([2, 512, 200, 176], dtype=torch.float32).cuda())
# fake input_metas
input_metas = [{ input_metas = [{
'sample_idx': 1234 'sample_idx': 1234,
'box_type_3d': LiDARInstance3DBoxes,
'box_mode_3d': Box3DMode.LIDAR
}, { }, {
'sample_idx': 2345 'sample_idx': 2345,
}] # fake input_metas 'box_type_3d': LiDARInstance3DBoxes,
'box_mode_3d': Box3DMode.LIDAR
}]
(cls_score, bbox_pred, dir_cls_preds) = self.forward(feats) (cls_score, bbox_pred, dir_cls_preds) = self.forward(feats)
# test get_boxes # test get_boxes
...@@ -169,7 +181,7 @@ def test_parta2_rpnhead_getboxes(): ...@@ -169,7 +181,7 @@ def test_parta2_rpnhead_getboxes():
assert result_list[0]['scores_3d'].shape == torch.Size([512]) assert result_list[0]['scores_3d'].shape == torch.Size([512])
assert result_list[0]['labels_3d'].shape == torch.Size([512]) assert result_list[0]['labels_3d'].shape == torch.Size([512])
assert result_list[0]['cls_preds'].shape == torch.Size([512, 3]) assert result_list[0]['cls_preds'].shape == torch.Size([512, 3])
assert result_list[0]['boxes_3d'].shape == torch.Size([512, 7]) assert result_list[0]['boxes_3d'].tensor.shape == torch.Size([512, 7])
def test_vote_head(): def test_vote_head():
......
...@@ -3,6 +3,7 @@ import torch ...@@ -3,6 +3,7 @@ import torch
from mmcv import Config from mmcv import Config
from torch.nn import BatchNorm1d, ReLU from torch.nn import BatchNorm1d, ReLU
from mmdet3d.core.bbox import Box3DMode, LiDARInstance3DBoxes
from mmdet3d.core.bbox.samplers import IoUNegPiecewiseSampler from mmdet3d.core.bbox.samplers import IoUNegPiecewiseSampler
from mmdet3d.models import PartA2BboxHead from mmdet3d.models import PartA2BboxHead
from mmdet3d.ops import make_sparse_convmodule from mmdet3d.ops import make_sparse_convmodule
...@@ -336,8 +337,10 @@ def test_get_bboxes(): ...@@ -336,8 +337,10 @@ def test_get_bboxes():
use_raw_score=True, use_raw_score=True,
nms_thr=0.01, nms_thr=0.01,
score_thr=0.1)) score_thr=0.1))
input_meta = dict(
box_type_3d=LiDARInstance3DBoxes, box_mode_3d=Box3DMode.LIDAR)
result_list = self.get_bboxes(rois, cls_score, bbox_pred, class_labels, result_list = self.get_bboxes(rois, cls_score, bbox_pred, class_labels,
class_pred, None, cfg) class_pred, [input_meta], cfg)
selected_bboxes, selected_scores, selected_label_preds = result_list[0] selected_bboxes, selected_scores, selected_label_preds = result_list[0]
expected_selected_bboxes = torch.Tensor( expected_selected_bboxes = torch.Tensor(
...@@ -347,7 +350,8 @@ def test_get_bboxes(): ...@@ -347,7 +350,8 @@ def test_get_bboxes():
expected_selected_scores = torch.Tensor([-2.2061, -2.1121, -0.1761]).cuda() expected_selected_scores = torch.Tensor([-2.2061, -2.1121, -0.1761]).cuda()
expected_selected_label_preds = torch.Tensor([2., 2., 2.]).cuda() expected_selected_label_preds = torch.Tensor([2., 2., 2.]).cuda()
assert torch.allclose(selected_bboxes, expected_selected_bboxes, 1e-3) assert torch.allclose(selected_bboxes.tensor, expected_selected_bboxes,
1e-3)
assert torch.allclose(selected_scores, expected_selected_scores, 1e-3) assert torch.allclose(selected_scores, expected_selected_scores, 1e-3)
assert torch.allclose(selected_label_preds, expected_selected_label_preds) assert torch.allclose(selected_label_preds, expected_selected_label_preds)
......
import numpy as np import numpy as np
import torch
from mmdet3d.core.bbox import DepthInstance3DBoxes
from mmdet3d.datasets.pipelines import IndoorFlipData, IndoorGlobalRotScale from mmdet3d.datasets.pipelines import IndoorFlipData, IndoorGlobalRotScale
...@@ -10,15 +12,15 @@ def test_indoor_flip_data(): ...@@ -10,15 +12,15 @@ def test_indoor_flip_data():
sunrgbd_results['points'] = np.array( sunrgbd_results['points'] = np.array(
[[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00], [[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00],
[-3.95979017e-01, 1.05465031e+00, -7.49204338e-01, 6.73096001e-01]]) [-3.95979017e-01, 1.05465031e+00, -7.49204338e-01, 6.73096001e-01]])
sunrgbd_results['gt_bboxes_3d'] = np.array([[ sunrgbd_results['gt_bboxes_3d'] = DepthInstance3DBoxes(
0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728, 3.07028526 np.array([[
], 0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728,
[ 3.07028526
-0.449953, 1.395455, ],
-1.027778, 1.500956, [
1.637298, 0.636364, -0.449953, 1.395455, -1.027778, 1.500956, 1.637298,
-1.58242359 0.636364, -1.58242359
]]) ]]))
sunrgbd_results = sunrgbd_indoor_flip_data(sunrgbd_results) sunrgbd_results = sunrgbd_indoor_flip_data(sunrgbd_results)
sunrgbd_points = sunrgbd_results['points'] sunrgbd_points = sunrgbd_results['points']
sunrgbd_gt_bboxes_3d = sunrgbd_results['gt_bboxes_3d'] sunrgbd_gt_bboxes_3d = sunrgbd_results['gt_bboxes_3d']
...@@ -26,13 +28,12 @@ def test_indoor_flip_data(): ...@@ -26,13 +28,12 @@ def test_indoor_flip_data():
expected_sunrgbd_points = np.array( expected_sunrgbd_points = np.array(
[[-1.02828765, 3.65790772, 0.1972947, 1.61959505], [[-1.02828765, 3.65790772, 0.1972947, 1.61959505],
[0.39597902, 1.05465031, -0.74920434, 0.673096]]) [0.39597902, 1.05465031, -0.74920434, 0.673096]])
expected_sunrgbd_gt_bboxes_3d = np.array([[ expected_sunrgbd_gt_bboxes_3d = torch.tensor(
-0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728, 0.07130739 [[-0.2137, 1.0364, -0.9823, 0.6154, 0.5726, 0.8727, 0.0713],
], [ [0.4500, 1.3955, -1.0278, 1.5010, 1.6373, 0.6364, 4.7240]])
0.449953, 1.395455, -1.027778, 1.500956, 1.637298, 0.636364, 4.72401624
]])
assert np.allclose(sunrgbd_points, expected_sunrgbd_points) assert np.allclose(sunrgbd_points, expected_sunrgbd_points)
assert np.allclose(sunrgbd_gt_bboxes_3d, expected_sunrgbd_gt_bboxes_3d) assert torch.allclose(sunrgbd_gt_bboxes_3d.tensor,
expected_sunrgbd_gt_bboxes_3d, 1e-3)
np.random.seed(0) np.random.seed(0)
scannet_indoor_flip_data = IndoorFlipData(1, 1) scannet_indoor_flip_data = IndoorFlipData(1, 1)
...@@ -40,11 +41,17 @@ def test_indoor_flip_data(): ...@@ -40,11 +41,17 @@ def test_indoor_flip_data():
scannet_results['points'] = np.array( scannet_results['points'] = np.array(
[[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01], [[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01],
[1.3978075e+00, 4.2035791e-01, 3.8729519e-01, 4.0510958e-01]]) [1.3978075e+00, 4.2035791e-01, 3.8729519e-01, 4.0510958e-01]])
scannet_results['gt_bboxes_3d'] = np.array([[ scannet_results['gt_bboxes_3d'] = DepthInstance3DBoxes(
0.55903838, 0.48201692, 0.65688646, 0.65370704, 0.60029864, 0.5163464 np.array([[
], [ 0.55903838, 0.48201692, 0.65688646, 0.65370704, 0.60029864,
-0.03226406, 1.70392646, 0.60348618, 0.65165804, 0.72084366, 0.64667457 0.5163464
]]) ],
[
-0.03226406, 1.70392646, 0.60348618, 0.65165804,
0.72084366, 0.64667457
]]),
box_dim=6,
with_yaw=False)
scannet_results = scannet_indoor_flip_data(scannet_results) scannet_results = scannet_indoor_flip_data(scannet_results)
scannet_points = scannet_results['points'] scannet_points = scannet_results['points']
scannet_gt_bboxes_3d = scannet_results['gt_bboxes_3d'] scannet_gt_bboxes_3d = scannet_results['gt_bboxes_3d']
...@@ -52,13 +59,12 @@ def test_indoor_flip_data(): ...@@ -52,13 +59,12 @@ def test_indoor_flip_data():
expected_scannet_points = np.array( expected_scannet_points = np.array(
[[-1.6110241, 0.16903955, 0.5811581, 0.5989725], [[-1.6110241, 0.16903955, 0.5811581, 0.5989725],
[-1.3978075, -0.42035791, 0.38729519, 0.40510958]]) [-1.3978075, -0.42035791, 0.38729519, 0.40510958]])
expected_scannet_gt_bboxes_3d = np.array([[ expected_scannet_gt_bboxes_3d = torch.tensor(
-0.55903838, -0.48201692, 0.65688646, 0.65370704, 0.60029864, 0.5163464 [[-0.5590, -0.4820, 0.6569, 0.6537, 0.6003, 0.5163, 0.0000],
], [ [0.0323, -1.7039, 0.6035, 0.6517, 0.7208, 0.6467, 0.0000]])
0.03226406, -1.70392646, 0.60348618, 0.65165804, 0.72084366, 0.64667457
]])
assert np.allclose(scannet_points, expected_scannet_points) assert np.allclose(scannet_points, expected_scannet_points)
assert np.allclose(scannet_gt_bboxes_3d, expected_scannet_gt_bboxes_3d) assert torch.allclose(scannet_gt_bboxes_3d.tensor,
expected_scannet_gt_bboxes_3d, 1e-2)
def test_global_rot_scale(): def test_global_rot_scale():
...@@ -69,15 +75,15 @@ def test_global_rot_scale(): ...@@ -69,15 +75,15 @@ def test_global_rot_scale():
sunrgbd_results['points'] = np.array( sunrgbd_results['points'] = np.array(
[[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00], [[1.02828765e+00, 3.65790772e+00, 1.97294697e-01, 1.61959505e+00],
[-3.95979017e-01, 1.05465031e+00, -7.49204338e-01, 6.73096001e-01]]) [-3.95979017e-01, 1.05465031e+00, -7.49204338e-01, 6.73096001e-01]])
sunrgbd_results['gt_bboxes_3d'] = np.array([[ sunrgbd_results['gt_bboxes_3d'] = DepthInstance3DBoxes(
0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728, 3.07028526 np.array([[
], 0.213684, 1.036364, -0.982323, 0.61541, 0.572574, 0.872728,
[ 3.07028526
-0.449953, 1.395455, ],
-1.027778, 1.500956, [
1.637298, 0.636364, -0.449953, 1.395455, -1.027778, 1.500956, 1.637298,
-1.58242359 0.636364, -1.58242359
]]) ]]))
sunrgbd_results = sunrgbd_augment(sunrgbd_results) sunrgbd_results = sunrgbd_augment(sunrgbd_results)
sunrgbd_points = sunrgbd_results['points'] sunrgbd_points = sunrgbd_results['points']
...@@ -86,18 +92,12 @@ def test_global_rot_scale(): ...@@ -86,18 +92,12 @@ def test_global_rot_scale():
expected_sunrgbd_points = np.array( expected_sunrgbd_points = np.array(
[[0.89427376, 3.94489646, 0.21003141, 1.72415094], [[0.89427376, 3.94489646, 0.21003141, 1.72415094],
[-0.47835783, 1.09972989, -0.79757058, 0.71654893]]) [-0.47835783, 1.09972989, -0.79757058, 0.71654893]])
expected_sunrgbd_gt_bboxes_3d = np.array([[ expected_sunrgbd_gt_bboxes_3d = torch.tensor(
0.17080999, 1.11345031, -1.04573864, 0.65513891, 0.60953755, [[0.1708, 1.1135, -1.0457, 0.6551, 0.6095, 0.9291, 3.0192],
0.92906854, 3.01916788 [-0.5543, 1.4591, -1.0941, 1.5979, 1.7430, 0.6774, -1.6335]])
],
[
-0.55427876, 1.45912611,
-1.09412807, 1.59785293,
1.74299674, 0.67744563,
-1.63354097
]])
assert np.allclose(sunrgbd_points, expected_sunrgbd_points) assert np.allclose(sunrgbd_points, expected_sunrgbd_points)
assert np.allclose(sunrgbd_gt_bboxes_3d, expected_sunrgbd_gt_bboxes_3d) assert torch.allclose(sunrgbd_gt_bboxes_3d.tensor,
expected_sunrgbd_gt_bboxes_3d, 1e-3)
np.random.seed(0) np.random.seed(0)
scannet_augment = IndoorGlobalRotScale( scannet_augment = IndoorGlobalRotScale(
...@@ -106,11 +106,17 @@ def test_global_rot_scale(): ...@@ -106,11 +106,17 @@ def test_global_rot_scale():
scannet_results['points'] = np.array( scannet_results['points'] = np.array(
[[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01], [[1.6110241e+00, -1.6903955e-01, 5.8115810e-01, 5.9897250e-01],
[1.3978075e+00, 4.2035791e-01, 3.8729519e-01, 4.0510958e-01]]) [1.3978075e+00, 4.2035791e-01, 3.8729519e-01, 4.0510958e-01]])
scannet_results['gt_bboxes_3d'] = np.array([[ scannet_results['gt_bboxes_3d'] = DepthInstance3DBoxes(
0.55903838, 0.48201692, 0.65688646, 0.65370704, 0.60029864, 0.5163464 np.array([[
], [ 0.55903838, 0.48201692, 0.65688646, 0.65370704, 0.60029864,
-0.03226406, 1.70392646, 0.60348618, 0.65165804, 0.72084366, 0.64667457 0.5163464
]]) ],
[
-0.03226406, 1.70392646, 0.60348618, 0.65165804,
0.72084366, 0.64667457
]]),
box_dim=6,
with_yaw=False)
scannet_results = scannet_augment(scannet_results) scannet_results = scannet_augment(scannet_results)
scannet_points = scannet_results['points'] scannet_points = scannet_results['points']
scannet_gt_bboxes_3d = scannet_results['gt_bboxes_3d'] scannet_gt_bboxes_3d = scannet_results['gt_bboxes_3d']
...@@ -118,10 +124,9 @@ def test_global_rot_scale(): ...@@ -118,10 +124,9 @@ def test_global_rot_scale():
expected_scannet_points = np.array( expected_scannet_points = np.array(
[[1.61240576, -0.15530836, 0.5811581, 0.5989725], [[1.61240576, -0.15530836, 0.5811581, 0.5989725],
[1.39417555, 0.43225122, 0.38729519, 0.40510958]]) [1.39417555, 0.43225122, 0.38729519, 0.40510958]])
expected_scannet_gt_bboxes_3d = np.array([[ expected_scannet_gt_bboxes_3d = torch.tensor(
0.55491157, 0.48676213, 0.65688646, 0.65879754, 0.60584609, 0.5163464 [[0.5549, 0.4868, 0.6569, 0.6588, 0.6058, 0.5163, 0.0000],
], [ [-0.0468, 1.7036, 0.6035, 0.6578, 0.7264, 0.6467, 0.0000]])
-0.04677942, 1.70358975, 0.60348618, 0.65777559, 0.72636927, 0.64667457
]])
assert np.allclose(scannet_points, expected_scannet_points) assert np.allclose(scannet_points, expected_scannet_points)
assert np.allclose(scannet_gt_bboxes_3d, expected_scannet_gt_bboxes_3d) assert torch.allclose(scannet_gt_bboxes_3d.tensor,
expected_scannet_gt_bboxes_3d, 1e-3)
...@@ -2,7 +2,9 @@ import os.path as osp ...@@ -2,7 +2,9 @@ import os.path as osp
import mmcv import mmcv
import numpy as np import numpy as np
import torch
from mmdet3d.core.bbox import DepthInstance3DBoxes
from mmdet3d.datasets.pipelines import Compose from mmdet3d.datasets.pipelines import Compose
...@@ -57,7 +59,8 @@ def test_scannet_pipeline(): ...@@ -57,7 +59,8 @@ def test_scannet_pipeline():
data_path, info['pts_instance_mask_path']) data_path, info['pts_instance_mask_path'])
results['ann_info']['pts_semantic_mask_path'] = osp.join( results['ann_info']['pts_semantic_mask_path'] = osp.join(
data_path, info['pts_semantic_mask_path']) data_path, info['pts_semantic_mask_path'])
results['ann_info']['gt_bboxes_3d'] = scannet_gt_bboxes_3d results['ann_info']['gt_bboxes_3d'] = DepthInstance3DBoxes(
scannet_gt_bboxes_3d, box_dim=6, with_yaw=False)
results['ann_info']['gt_labels_3d'] = scannet_gt_labels_3d results['ann_info']['gt_labels_3d'] = scannet_gt_labels_3d
results['bbox3d_fields'] = [] results['bbox3d_fields'] = []
...@@ -77,13 +80,12 @@ def test_scannet_pipeline(): ...@@ -77,13 +80,12 @@ def test_scannet_pipeline():
[-1.332374, 1.474838, -0.04405887, -0.00887359], [-1.332374, 1.474838, -0.04405887, -0.00887359],
[2.1336637, -1.3265059, -0.02880373, 0.00638155], [2.1336637, -1.3265059, -0.02880373, 0.00638155],
[0.43895668, -3.0259454, 1.5560012, 1.5911865]]) [0.43895668, -3.0259454, 1.5560012, 1.5911865]])
expected_gt_bboxes_3d = np.array([ expected_gt_bboxes_3d = torch.tensor(
[-1.5005362, -3.512584, 1.8565295, 1.7457027, 0.24149807, 0.57235193], [[-1.5005, -3.5126, 1.8565, 1.7457, 0.2415, 0.5724, 0.0000],
[-2.8848705, 3.4961755, 1.5268247, 0.66170084, 0.17433672, 0.67153597], [-2.8849, 3.4962, 1.5268, 0.6617, 0.1743, 0.6715, 0.0000],
[-1.1585636, -2.192365, 0.61649567, 0.5557011, 2.5375574, 1.2144762], [-1.1586, -2.1924, 0.6165, 0.5557, 2.5376, 1.2145, 0.0000],
[-2.930457, -2.4856408, 0.9722377, 0.6270478, 1.8461524, 0.28697443], [-2.9305, -2.4856, 0.9722, 0.6270, 1.8462, 0.2870, 0.0000],
[3.3114715, -0.00476722, 1.0712197, 0.46191898, 3.8605113, 2.1603441] [3.3115, -0.0048, 1.0712, 0.4619, 3.8605, 2.1603, 0.0000]])
])
expected_gt_labels_3d = np.array([ 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, 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 0, 0, 0, 5, 5, 5
...@@ -91,7 +93,8 @@ def test_scannet_pipeline(): ...@@ -91,7 +93,8 @@ def test_scannet_pipeline():
expected_pts_semantic_mask = np.array([3, 1, 2, 2, 15]) expected_pts_semantic_mask = np.array([3, 1, 2, 2, 15])
expected_pts_instance_mask = np.array([44, 22, 10, 10, 57]) expected_pts_instance_mask = np.array([44, 22, 10, 10, 57])
assert np.allclose(points, expected_points) assert np.allclose(points, expected_points)
assert np.allclose(gt_bboxes_3d[:5, :], expected_gt_bboxes_3d) assert torch.allclose(gt_bboxes_3d.tensor[:5, :], expected_gt_bboxes_3d,
1e-2)
assert np.all(gt_labels_3d.numpy() == expected_gt_labels_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_semantic_mask.numpy() == expected_pts_semantic_mask)
assert np.all(pts_instance_mask.numpy() == expected_pts_instance_mask) assert np.all(pts_instance_mask.numpy() == expected_pts_instance_mask)
...@@ -130,12 +133,12 @@ def test_sunrgbd_pipeline(): ...@@ -130,12 +133,12 @@ def test_sunrgbd_pipeline():
np.float32) np.float32)
gt_labels_3d = info['annos']['class'].astype(np.long) gt_labels_3d = info['annos']['class'].astype(np.long)
else: else:
gt_bboxes_3d = np.zeros((1, 6), dtype=np.float32) gt_bboxes_3d = np.zeros((1, 7), dtype=np.float32)
gt_labels_3d = np.zeros((1, ), dtype=np.long) gt_labels_3d = np.zeros((1, ), dtype=np.long)
# prepare input of pipeline # prepare input of pipeline
results['ann_info'] = dict() results['ann_info'] = dict()
results['ann_info']['gt_bboxes_3d'] = gt_bboxes_3d results['ann_info']['gt_bboxes_3d'] = DepthInstance3DBoxes(gt_bboxes_3d)
results['ann_info']['gt_labels_3d'] = gt_labels_3d results['ann_info']['gt_labels_3d'] = gt_labels_3d
results['bbox3d_fields'] = [] results['bbox3d_fields'] = []
results['pts_mask_fields'] = [] results['pts_mask_fields'] = []
...@@ -150,21 +153,11 @@ def test_sunrgbd_pipeline(): ...@@ -150,21 +153,11 @@ def test_sunrgbd_pipeline():
[0.6464, 1.5635, 0.0826, 0.0616], [0.6464, 1.5635, 0.0826, 0.0616],
[0.6453, 1.5603, 0.0849, 0.0638], [0.6453, 1.5603, 0.0849, 0.0638],
[0.6488, 1.5786, 0.0461, 0.0251]]) [0.6488, 1.5786, 0.0461, 0.0251]])
expected_gt_bboxes_3d = np.array([[ expected_gt_bboxes_3d = torch.tensor(
-2.012483, 3.9473376, -0.25446942, 2.3730404, 1.9457763, 2.0303352, [[-2.0125, 3.9473, -0.2545, 2.3730, 1.9458, 2.0303, 1.2206],
1.2205974 [-3.7037, 4.2396, -0.8109, 0.6032, 0.9104, 1.0033, 1.2663],
], [0.6529, 2.1638, -0.1523, 0.7348, 1.6113, 2.1694, 2.8140]])
[
-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]) expected_gt_labels_3d = np.array([0, 7, 6])
assert np.allclose(gt_bboxes_3d, expected_gt_bboxes_3d) assert torch.allclose(gt_bboxes_3d.tensor, expected_gt_bboxes_3d, 1e-3)
assert np.allclose(gt_labels_3d.flatten(), expected_gt_labels_3d) assert np.allclose(gt_labels_3d.flatten(), expected_gt_labels_3d)
assert np.allclose(points, expected_points, 1e-2) assert np.allclose(points, expected_points, 1e-2)
...@@ -4,6 +4,7 @@ import mmcv ...@@ -4,6 +4,7 @@ import mmcv
import numpy as np import numpy as np
import pytest import pytest
from mmdet3d.core.bbox import DepthInstance3DBoxes
from mmdet3d.datasets.pipelines import LoadAnnotations3D, LoadPointsFromFile from mmdet3d.datasets.pipelines import LoadAnnotations3D, LoadPointsFromFile
...@@ -79,7 +80,8 @@ def test_load_annotations3D(): ...@@ -79,7 +80,8 @@ def test_load_annotations3D():
data_path, scannet_info['pts_instance_mask_path']) data_path, scannet_info['pts_instance_mask_path'])
scannet_results['ann_info']['pts_semantic_mask_path'] = osp.join( scannet_results['ann_info']['pts_semantic_mask_path'] = osp.join(
data_path, scannet_info['pts_semantic_mask_path']) data_path, scannet_info['pts_semantic_mask_path'])
scannet_results['ann_info']['gt_bboxes_3d'] = scannet_gt_bboxes_3d scannet_results['ann_info']['gt_bboxes_3d'] = DepthInstance3DBoxes(
scannet_gt_bboxes_3d, box_dim=6, with_yaw=False)
scannet_results['ann_info']['gt_labels_3d'] = scannet_gt_labels_3d scannet_results['ann_info']['gt_labels_3d'] = scannet_gt_labels_3d
scannet_results['bbox3d_fields'] = [] scannet_results['bbox3d_fields'] = []
...@@ -92,7 +94,7 @@ def test_load_annotations3D(): ...@@ -92,7 +94,7 @@ def test_load_annotations3D():
scannet_pts_instance_mask = scannet_results['pts_instance_mask'] scannet_pts_instance_mask = scannet_results['pts_instance_mask']
scannet_pts_semantic_mask = scannet_results['pts_semantic_mask'] scannet_pts_semantic_mask = scannet_results['pts_semantic_mask']
assert scannet_gt_boxes.shape == (27, 6) assert scannet_gt_boxes.tensor.shape == (27, 7)
assert scannet_gt_lbaels.shape == (27, ) assert scannet_gt_lbaels.shape == (27, )
assert scannet_pts_instance_mask.shape == (100, ) assert scannet_pts_instance_mask.shape == (100, )
assert scannet_pts_semantic_mask.shape == (100, ) assert scannet_pts_semantic_mask.shape == (100, )
import argparse
from collections import OrderedDict
import torch
def convert_stem(model_key, model_weight, state_dict, converted_names):
new_key = model_key.replace('stem.conv', 'conv1')
new_key = new_key.replace('stem.bn', 'bn1')
state_dict[new_key] = model_weight
converted_names.add(model_key)
print(f'Convert {model_key} to {new_key}')
def convert_head(model_key, model_weight, state_dict, converted_names):
new_key = model_key.replace('head.fc', 'fc')
state_dict[new_key] = model_weight
converted_names.add(model_key)
print(f'Convert {model_key} to {new_key}')
def convert_reslayer(model_key, model_weight, state_dict, converted_names):
split_keys = model_key.split('.')
layer, block, module = split_keys[:3]
block_id = int(block[1:])
layer_name = f'layer{int(layer[1:])}'
block_name = f'{block_id - 1}'
if block_id == 1 and module == 'bn':
new_key = f'{layer_name}.{block_name}.downsample.1.{split_keys[-1]}'
elif block_id == 1 and module == 'proj':
new_key = f'{layer_name}.{block_name}.downsample.0.{split_keys[-1]}'
elif module == 'f':
if split_keys[3] == 'a_bn':
module_name = 'bn1'
elif split_keys[3] == 'b_bn':
module_name = 'bn2'
elif split_keys[3] == 'c_bn':
module_name = 'bn3'
elif split_keys[3] == 'a':
module_name = 'conv1'
elif split_keys[3] == 'b':
module_name = 'conv2'
elif split_keys[3] == 'c':
module_name = 'conv3'
new_key = f'{layer_name}.{block_name}.{module_name}.{split_keys[-1]}'
else:
raise ValueError(f'Unsupported conversion of key {model_key}')
print(f'Convert {model_key} to {new_key}')
state_dict[new_key] = model_weight
converted_names.add(model_key)
def convert(src, dst):
"""Convert keys in pycls pretrained RegNet models to mmdet style."""
# load caffe model
regnet_model = torch.load(src)
blobs = regnet_model['model_state']
# convert to pytorch style
state_dict = OrderedDict()
converted_names = set()
for key, weight in blobs.items():
if 'stem' in key:
convert_stem(key, weight, state_dict, converted_names)
elif 'head' in key:
convert_head(key, weight, state_dict, converted_names)
elif key.startswith('s'):
convert_reslayer(key, weight, state_dict, converted_names)
# check if all layers are converted
for key in blobs:
if key not in converted_names:
print(f'not converted: {key}')
# save checkpoint
checkpoint = dict()
checkpoint['state_dict'] = state_dict
torch.save(checkpoint, dst)
def main():
parser = argparse.ArgumentParser(description='Convert model keys')
parser.add_argument('src', help='src detectron model path')
parser.add_argument('dst', help='save path')
args = parser.parse_args()
convert(args.src, args.dst)
if __name__ == '__main__':
main()
...@@ -9,7 +9,7 @@ from tools.fuse_conv_bn import fuse_module ...@@ -9,7 +9,7 @@ from tools.fuse_conv_bn import fuse_module
from mmdet3d.datasets import build_dataloader, build_dataset from mmdet3d.datasets import build_dataloader, build_dataset
from mmdet3d.models import build_detector from mmdet3d.models import build_detector
from mmdet.apis import multi_gpu_test, single_gpu_test from mmdet.apis import multi_gpu_test, set_random_seed, single_gpu_test
from mmdet.core import wrap_fp16_model from mmdet.core import wrap_fp16_model
...@@ -76,6 +76,11 @@ def parse_args(): ...@@ -76,6 +76,11 @@ def parse_args():
'--tmpdir', '--tmpdir',
help='tmp directory used for collecting results from multiple ' help='tmp directory used for collecting results from multiple '
'workers, available when gpu_collect is not specified') 'workers, available when gpu_collect is not specified')
parser.add_argument('--seed', type=int, default=0, help='random seed')
parser.add_argument(
'--deterministic',
action='store_true',
help='whether to set deterministic options for CUDNN backend.')
parser.add_argument( parser.add_argument(
'--options', nargs='+', action=MultipleKVAction, help='custom options') '--options', nargs='+', action=MultipleKVAction, help='custom options')
parser.add_argument( parser.add_argument(
...@@ -108,6 +113,7 @@ def main(): ...@@ -108,6 +113,7 @@ def main():
# set cudnn_benchmark # set cudnn_benchmark
if cfg.get('cudnn_benchmark', False): if cfg.get('cudnn_benchmark', False):
torch.backends.cudnn.benchmark = True torch.backends.cudnn.benchmark = True
cfg.model.pretrained = None cfg.model.pretrained = None
cfg.data.test.test_mode = True cfg.data.test.test_mode = True
...@@ -118,6 +124,10 @@ def main(): ...@@ -118,6 +124,10 @@ def main():
distributed = True distributed = True
init_dist(args.launcher, **cfg.dist_params) init_dist(args.launcher, **cfg.dist_params)
# set random seeds
if args.seed is not None:
set_random_seed(args.seed, deterministic=args.deterministic)
# build the dataloader # build the dataloader
# TODO: support multiple images per gpu (only minor changes are needed) # TODO: support multiple images per gpu (only minor changes are needed)
dataset = build_dataset(cfg.data.test) dataset = build_dataset(cfg.data.test)
......
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