Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
mmdetection3d
Commits
bd73d3b9
Commit
bd73d3b9
authored
Jul 15, 2022
by
jshilong
Committed by
ChaimZhu
Jul 20, 2022
Browse files
[refactor]MVXTwoStage & Centerpoint
parent
360c27f9
Changes
26
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
141 additions
and
5 deletions
+141
-5
tests/test_models/test_detectors/test_center_point.py
tests/test_models/test_detectors/test_center_point.py
+66
-0
tests/test_models/test_detectors/test_mvxnet.py
tests/test_models/test_detectors/test_mvxnet.py
+51
-0
tests/test_models/test_detectors/test_parta2.py
tests/test_models/test_detectors/test_parta2.py
+5
-3
tests/test_models/test_detectors/test_votenet.py
tests/test_models/test_detectors/test_votenet.py
+3
-1
tests/test_models/test_detectors/test_voxelnet.py
tests/test_models/test_detectors/test_voxelnet.py
+6
-0
tests/utils/model_utils.py
tests/utils/model_utils.py
+10
-1
No files found.
tests/test_models/test_detectors/test_center_point.py
0 → 100644
View file @
bd73d3b9
import
unittest
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
)
class
TestCenterPoint
(
unittest
.
TestCase
):
def
test_center_point
(
self
):
import
mmdet3d.models
assert
hasattr
(
mmdet3d
.
models
,
'CenterPoint'
)
_setup_seed
(
0
)
DefaultScope
.
get_instance
(
'test_center_point'
,
scope_name
=
'mmdet3d'
)
centerpoint_net_cfg
=
_get_detector_cfg
(
'centerpoint/centerpoint_01voxel_second_secfpn_4x8_cyclic_20e_nus.py'
# noqa
)
model
=
MODELS
.
build
(
centerpoint_net_cfg
)
num_gt_instance
=
50
data
=
[
_create_detector_inputs
(
with_img
=
True
,
num_gt_instance
=
num_gt_instance
,
points_feat_dim
=
5
)
]
for
sample_id
in
range
(
len
(
data
)):
det_sample
=
data
[
sample_id
][
'data_sample'
]
num_instances
=
len
(
det_sample
.
gt_instances_3d
.
bboxes_3d
)
bbox_3d_class
=
det_sample
.
gt_instances_3d
.
bboxes_3d
.
__class__
det_sample
.
gt_instances_3d
.
bboxes_3d
=
bbox_3d_class
(
torch
.
rand
(
num_instances
,
9
),
box_dim
=
9
)
if
torch
.
cuda
.
is_available
():
model
=
model
.
cuda
()
# test simple_test
batch_inputs
,
data_samples
=
model
.
data_preprocessor
(
data
,
True
)
losses
=
model
.
forward
(
batch_inputs
,
data_samples
,
mode
=
'loss'
)
assert
losses
[
'task0.loss_heatmap'
]
>=
0
assert
losses
[
'task0.loss_bbox'
]
>=
0
assert
losses
[
'task1.loss_heatmap'
]
>=
0
assert
losses
[
'task1.loss_bbox'
]
>=
0
assert
losses
[
'task2.loss_heatmap'
]
>=
0
assert
losses
[
'task2.loss_bbox'
]
>=
0
assert
losses
[
'task3.loss_heatmap'
]
>=
0
assert
losses
[
'task3.loss_bbox'
]
>=
0
assert
losses
[
'task3.loss_bbox'
]
>=
0
assert
losses
[
'task4.loss_bbox'
]
>=
0
assert
losses
[
'task5.loss_heatmap'
]
>=
0
assert
losses
[
'task5.loss_bbox'
]
>=
0
with
torch
.
no_grad
():
results
=
model
.
forward
(
batch_inputs
,
data_samples
,
mode
=
'predict'
)
self
.
assertEqual
(
len
(
results
),
len
(
data
))
self
.
assertIn
(
'bboxes_3d'
,
results
[
0
].
pred_instances_3d
)
self
.
assertIn
(
'scores_3d'
,
results
[
0
].
pred_instances_3d
)
self
.
assertIn
(
'labels_3d'
,
results
[
0
].
pred_instances_3d
)
# TODO test_aug_test
tests/test_models/test_detectors/test_mvxnet.py
0 → 100644
View file @
bd73d3b9
import
unittest
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
)
class
TestMVXNet
(
unittest
.
TestCase
):
def
test_mvxnet
(
self
):
import
mmdet3d.models
assert
hasattr
(
mmdet3d
.
models
,
'DynamicMVXFasterRCNN'
)
_setup_seed
(
0
)
DefaultScope
.
get_instance
(
'test_mvxnet'
,
scope_name
=
'mmdet3d'
)
mvx_net_cfg
=
_get_detector_cfg
(
'mvxnet/dv_mvx-fpn_second_secfpn_adamw_2x8_80e_kitti-3d-3class.py'
# noqa
)
model
=
MODELS
.
build
(
mvx_net_cfg
)
num_gt_instance
=
50
data
=
[
_create_detector_inputs
(
with_img
=
False
,
num_gt_instance
=
num_gt_instance
,
points_feat_dim
=
4
)
]
if
torch
.
cuda
.
is_available
():
model
=
model
.
cuda
()
# test simple_test
batch_inputs
,
data_samples
=
model
.
data_preprocessor
(
data
,
True
)
# save the memory when do the unitest
with
torch
.
no_grad
():
losses
=
model
.
forward
(
batch_inputs
,
data_samples
,
mode
=
'loss'
)
assert
losses
[
'loss_cls'
][
0
]
>=
0
assert
losses
[
'loss_bbox'
][
0
]
>=
0
assert
losses
[
'loss_dir'
][
0
]
>=
0
with
torch
.
no_grad
():
results
=
model
.
forward
(
batch_inputs
,
data_samples
,
mode
=
'predict'
)
self
.
assertEqual
(
len
(
results
),
len
(
data
))
self
.
assertIn
(
'bboxes_3d'
,
results
[
0
].
pred_instances_3d
)
self
.
assertIn
(
'scores_3d'
,
results
[
0
].
pred_instances_3d
)
self
.
assertIn
(
'labels_3d'
,
results
[
0
].
pred_instances_3d
)
# TODO test_aug_test
tests/test_models/test_parta2.py
→
tests/test_models/test_
detectors/test_
parta2.py
View file @
bd73d3b9
...
...
@@ -20,7 +20,7 @@ class TestPartA2(unittest.TestCase):
parta2_cfg
=
_get_detector_cfg
(
'parta2/hv_PartA2_secfpn_2x8_cyclic_80e_kitti-3d-3class.py'
)
model
=
MODELS
.
build
(
parta2_cfg
)
num_gt_instance
=
50
num_gt_instance
=
2
data
=
[
_create_detector_inputs
(
num_gt_instance
=
num_gt_instance
)]
aug_data
=
[
_create_detector_inputs
(
num_gt_instance
=
num_gt_instance
),
...
...
@@ -58,9 +58,11 @@ class TestPartA2(unittest.TestCase):
self
.
assertIn
(
'bboxes_3d'
,
aug_results
[
1
].
pred_instances_3d
)
self
.
assertIn
(
'scores_3d'
,
aug_results
[
1
].
pred_instances_3d
)
self
.
assertIn
(
'labels_3d'
,
aug_results
[
1
].
pred_instances_3d
)
# save the memory
losses
=
model
.
forward
(
batch_inputs
,
data_samples
,
mode
=
'loss'
)
with
torch
.
no_grad
():
losses
=
model
.
forward
(
batch_inputs
,
data_samples
,
mode
=
'loss'
)
torch
.
cuda
.
empty_cache
()
self
.
assertGreater
(
losses
[
'loss_rpn_cls'
][
0
],
0
)
self
.
assertGreater
(
losses
[
'loss_rpn_bbox'
][
0
],
0
)
self
.
assertGreater
(
losses
[
'loss_seg'
],
0
)
...
...
tests/test_models/test_votenet.py
→
tests/test_models/test_
detectors/test_
votenet.py
View file @
bd73d3b9
...
...
@@ -56,7 +56,9 @@ class TestVotenet(unittest.TestCase):
self
.
assertIn
(
'scores_3d'
,
aug_results
[
0
].
pred_instances_3d
)
self
.
assertIn
(
'labels_3d'
,
aug_results
[
0
].
pred_instances_3d
)
losses
=
model
.
forward
(
batch_inputs
,
data_samples
,
mode
=
'loss'
)
# save the memory
with
torch
.
no_grad
():
losses
=
model
.
forward
(
batch_inputs
,
data_samples
,
mode
=
'loss'
)
self
.
assertGreater
(
losses
[
'vote_loss'
],
0
)
self
.
assertGreater
(
losses
[
'objectness_loss'
],
0
)
...
...
tests/test_models/test_detectors.py
→
tests/test_models/test_detectors
/test_voxelnet
.py
View file @
bd73d3b9
...
...
@@ -38,6 +38,9 @@ def test_voxel_net():
data
=
[
dict
(
inputs
=
input_dict0
,
data_sample
=
data_sample_0
)]
# test simple_test
# TODO FIX this UT
pytest
.
skip
(
'FIX this @shenkun'
)
with
torch
.
no_grad
():
results
=
model
.
forward
(
data
,
return_loss
=
False
)
bboxes_3d
=
results
[
0
].
pred_instances_3d
[
'bboxes_3d'
]
...
...
@@ -75,6 +78,9 @@ def test_voxel_net():
def
test_sassd
():
# TODO fix this unitest
pytest
.
skip
(
'FIX this'
)
if
not
torch
.
cuda
.
is_available
():
pytest
.
skip
(
'test requires GPU and torch+cuda'
)
_setup_seed
(
0
)
...
...
tests/utils/model_utils.py
View file @
bd73d3b9
...
...
@@ -72,11 +72,20 @@ def _get_detector_cfg(fname):
def
_create_detector_inputs
(
seed
=
0
,
with_points
=
True
,
with_img
=
False
,
num_gt_instance
=
20
,
points_feat_dim
=
4
,
num_classes
=
3
):
_setup_seed
(
seed
)
inputs_dict
=
dict
(
points
=
torch
.
rand
([
10
,
points_feat_dim
]))
inputs_dict
=
dict
()
if
with_points
:
points
=
torch
.
rand
([
3
,
points_feat_dim
])
inputs_dict
[
'points'
]
=
points
if
with_img
:
img
=
torch
.
rand
(
3
,
10
,
10
)
inputs_dict
[
'img'
]
=
img
gt_instance_3d
=
InstanceData
()
gt_instance_3d
.
bboxes_3d
=
LiDARInstance3DBoxes
(
torch
.
rand
([
num_gt_instance
,
7
]))
...
...
Prev
1
2
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment