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
db39fd4a
Unverified
Commit
db39fd4a
authored
Oct 18, 2023
by
Sun Jiahao
Committed by
GitHub
Oct 18, 2023
Browse files
[Enhance] Use Inferencer to implement Demo (#2763)
parent
f4c032e4
Changes
22
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
50 deletions
+46
-50
tests/test_apis/test_inferencers/test_mono_det3d_inferencer.py
.../test_apis/test_inferencers/test_mono_det3d_inferencer.py
+23
-27
tests/test_apis/test_inferencers/test_multi_modality_det3d_inferencer.py
.../test_inferencers/test_multi_modality_det3d_inferencer.py
+23
-23
No files found.
tests/test_apis/test_inferencers/test_mono_det3d_inferencer.py
View file @
db39fd4a
...
@@ -42,13 +42,13 @@ class TestMonoDet3DInferencer(TestCase):
...
@@ -42,13 +42,13 @@ class TestMonoDet3DInferencer(TestCase):
def
test_call
(
self
,
model
):
def
test_call
(
self
,
model
):
# single img
# single img
img_path
=
'demo/data/kitti/000008.png'
img_path
=
'demo/data/kitti/000008.png'
calib
_path
=
'demo/data/kitti/000008.
txt
'
infos
_path
=
'demo/data/kitti/000008.
pkl
'
inferencer
=
MonoDet3DInferencer
(
model
)
inferencer
=
MonoDet3DInferencer
(
model
)
inputs
=
dict
(
img
=
img_path
,
calib
=
calib
_path
)
inputs
=
dict
(
img
=
img_path
,
infos
=
infos
_path
)
res_path
=
inferencer
(
inputs
,
return_vis
=
True
)
res_path
=
inferencer
(
inputs
,
return_vis
=
True
)
# ndarray
# ndarray
img
=
mmcv
.
imread
(
img_path
)
img
=
mmcv
.
imread
(
img_path
)
inputs
=
dict
(
img
=
img
,
calib
=
calib
_path
)
inputs
=
dict
(
img
=
img
,
infos
=
infos
_path
)
res_ndarray
=
inferencer
(
inputs
,
return_vis
=
True
)
res_ndarray
=
inferencer
(
inputs
,
return_vis
=
True
)
self
.
assert_predictions_equal
(
res_path
[
'predictions'
],
self
.
assert_predictions_equal
(
res_path
[
'predictions'
],
res_ndarray
[
'predictions'
])
res_ndarray
[
'predictions'
])
...
@@ -59,16 +59,18 @@ class TestMonoDet3DInferencer(TestCase):
...
@@ -59,16 +59,18 @@ class TestMonoDet3DInferencer(TestCase):
inputs
=
[
inputs
=
[
dict
(
dict
(
img
=
'demo/data/kitti/000008.png'
,
img
=
'demo/data/kitti/000008.png'
,
calib
=
'demo/data/kitti/000008.
txt
'
),
infos
=
'demo/data/kitti/000008.
pkl
'
),
dict
(
dict
(
img
=
'demo/data/kitti/000008.png'
,
img
=
'demo/data/kitti/000008.png'
,
calib
=
'demo/data/kitti/000008.
txt
'
)
infos
=
'demo/data/kitti/000008.
pkl
'
)
]
]
res_path
=
inferencer
(
inputs
,
return_vis
=
True
)
res_path
=
inferencer
(
inputs
,
return_vis
=
True
)
# list of ndarray
# list of ndarray
imgs
=
[
mmcv
.
imread
(
p
[
'img'
])
for
p
in
inputs
]
imgs
=
[
mmcv
.
imread
(
p
[
'img'
])
for
p
in
inputs
]
inputs
[
0
][
'img'
]
=
imgs
[
0
]
inputs
=
[
inputs
[
1
][
'img'
]
=
imgs
[
1
]
dict
(
img
=
imgs
[
0
],
infos
=
'demo/data/kitti/000008.pkl'
),
dict
(
img
=
imgs
[
1
],
infos
=
'demo/data/kitti/000008.pkl'
)
]
res_ndarray
=
inferencer
(
inputs
,
return_vis
=
True
)
res_ndarray
=
inferencer
(
inputs
,
return_vis
=
True
)
self
.
assert_predictions_equal
(
res_path
[
'predictions'
],
self
.
assert_predictions_equal
(
res_path
[
'predictions'
],
res_ndarray
[
'predictions'
])
res_ndarray
[
'predictions'
])
...
@@ -77,36 +79,30 @@ class TestMonoDet3DInferencer(TestCase):
...
@@ -77,36 +79,30 @@ class TestMonoDet3DInferencer(TestCase):
@
parameterized
.
expand
([
'pgd_kitti'
])
@
parameterized
.
expand
([
'pgd_kitti'
])
def
test_visualize
(
self
,
model
):
def
test_visualize
(
self
,
model
):
inputs
=
[
inputs
=
dict
(
dict
(
img
=
'demo/data/kitti/000008.png'
,
img
=
'demo/data/kitti/000008.png'
,
infos
=
'demo/data/kitti/000008.pkl'
)
calib
=
'demo/data/kitti/000008.txt'
),
dict
(
img
=
'demo/data/kitti/000008.png'
,
calib
=
'demo/data/kitti/000008.txt'
)
]
inferencer
=
MonoDet3DInferencer
(
model
)
inferencer
=
MonoDet3DInferencer
(
model
)
# img_out_dir
# img_out_dir
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
inferencer
(
inputs
,
img_
out_dir
=
tmp_dir
)
inferencer
(
inputs
,
out_dir
=
tmp_dir
)
for
img_dir
in
[
'000008.png'
,
'000008.png'
]:
self
.
assertTrue
(
self
.
assertTrue
(
osp
.
exists
(
osp
.
join
(
tmp_dir
,
img_dir
)))
osp
.
exists
(
osp
.
join
(
tmp_dir
,
'vis_camera/CAM2/000008.png'
)))
@
parameterized
.
expand
([
'pgd_kitti'
])
@
parameterized
.
expand
([
'pgd_kitti'
])
def
test_postprocess
(
self
,
model
):
def
test_postprocess
(
self
,
model
):
# return_datasample
# return_datasample
img_path
=
'demo/data/kitti/000008.png'
img_path
=
'demo/data/kitti/000008.png'
calib
_path
=
'demo/data/kitti/000008.
txt
'
infos
_path
=
'demo/data/kitti/000008.
pkl
'
inputs
=
dict
(
img
=
img_path
,
calib
=
calib
_path
)
inputs
=
dict
(
img
=
img_path
,
infos
=
infos
_path
)
inferencer
=
MonoDet3DInferencer
(
model
)
inferencer
=
MonoDet3DInferencer
(
model
)
res
=
inferencer
(
inputs
,
return_datasamples
=
True
)
res
=
inferencer
(
inputs
,
return_datasamples
=
True
)
self
.
assertTrue
(
is_list_of
(
res
[
'predictions'
],
Det3DDataSample
))
self
.
assertTrue
(
is_list_of
(
res
[
'predictions'
],
Det3DDataSample
))
# pred_out_
file
# pred_out_
dir
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
pred_out_file
=
osp
.
join
(
tmp_dir
,
'tmp.json'
)
inputs
=
dict
(
img
=
img_path
,
infos
=
infos_path
)
res
=
inferencer
(
res
=
inferencer
(
inputs
,
print_result
=
True
,
out_dir
=
tmp_dir
)
inputs
,
print_result
=
True
,
pred_out_file
=
pred_out_file
)
dumped_res
=
mmengine
.
load
(
dumped_res
=
mmengine
.
load
(
pred_out_file
)
osp
.
join
(
tmp_dir
,
'preds'
,
'000008.json'
))
self
.
assert_predictions_equal
(
res
[
'predictions'
],
self
.
assertEqual
(
res
[
'predictions'
][
0
],
dumped_res
)
dumped_res
[
'predictions'
])
tests/test_apis/test_inferencers/test_multi_modality_det3d_inferencer.py
View file @
db39fd4a
...
@@ -44,11 +44,11 @@ class TestMultiModalityDet3DInferencer(TestCase):
...
@@ -44,11 +44,11 @@ class TestMultiModalityDet3DInferencer(TestCase):
def
test_call
(
self
):
def
test_call
(
self
):
if
not
torch
.
cuda
.
is_available
():
if
not
torch
.
cuda
.
is_available
():
return
return
calib
_path
=
'
tests
/data/kitti/
training/calib/0
00000.pkl'
infos
_path
=
'
demo
/data/kitti/00000
8
.pkl'
points_path
=
'
tests
/data/kitti/
training/velodyne/0
00000.bin'
points_path
=
'
demo
/data/kitti/00000
8
.bin'
img_path
=
'
tests
/data/kitti/
training/image_2/0
00000.png'
img_path
=
'
demo
/data/kitti/00000
8
.png'
# single img & point cloud
# single img & point cloud
inputs
=
dict
(
points
=
points_path
,
img
=
img_path
,
calib
=
calib
_path
)
inputs
=
dict
(
points
=
points_path
,
img
=
img_path
,
infos
=
infos
_path
)
res_path
=
self
.
inferencer
(
inputs
,
return_vis
=
True
)
res_path
=
self
.
inferencer
(
inputs
,
return_vis
=
True
)
# ndarray
# ndarray
...
@@ -57,7 +57,7 @@ class TestMultiModalityDet3DInferencer(TestCase):
...
@@ -57,7 +57,7 @@ class TestMultiModalityDet3DInferencer(TestCase):
points
=
points
.
reshape
(
-
1
,
4
)
points
=
points
.
reshape
(
-
1
,
4
)
points
=
points
[:,
:
4
]
points
=
points
[:,
:
4
]
img
=
mmcv
.
imread
(
inputs
[
'img'
])
img
=
mmcv
.
imread
(
inputs
[
'img'
])
inputs
=
dict
(
points
=
points
,
img
=
img
,
calib
=
calib
_path
)
inputs
=
dict
(
points
=
points
,
img
=
img
,
infos
=
infos
_path
)
res_ndarray
=
self
.
inferencer
(
inputs
,
return_vis
=
True
)
res_ndarray
=
self
.
inferencer
(
inputs
,
return_vis
=
True
)
self
.
assert_predictions_equal
(
res_path
[
'predictions'
],
self
.
assert_predictions_equal
(
res_path
[
'predictions'
],
res_ndarray
[
'predictions'
])
res_ndarray
[
'predictions'
])
...
@@ -66,8 +66,8 @@ class TestMultiModalityDet3DInferencer(TestCase):
...
@@ -66,8 +66,8 @@ class TestMultiModalityDet3DInferencer(TestCase):
# multiple imgs & point clouds
# multiple imgs & point clouds
inputs
=
[
inputs
=
[
dict
(
points
=
points_path
,
img
=
img_path
,
calib
=
calib
_path
),
dict
(
points
=
points_path
,
img
=
img_path
,
infos
=
infos
_path
),
dict
(
points
=
points_path
,
img
=
img_path
,
calib
=
calib
_path
)
dict
(
points
=
points_path
,
img
=
img_path
,
infos
=
infos
_path
)
]
]
res_path
=
self
.
inferencer
(
inputs
,
return_vis
=
True
)
res_path
=
self
.
inferencer
(
inputs
,
return_vis
=
True
)
# list of ndarray
# list of ndarray
...
@@ -77,7 +77,7 @@ class TestMultiModalityDet3DInferencer(TestCase):
...
@@ -77,7 +77,7 @@ class TestMultiModalityDet3DInferencer(TestCase):
points
=
np
.
frombuffer
(
pts_bytes
,
dtype
=
np
.
float32
)
points
=
np
.
frombuffer
(
pts_bytes
,
dtype
=
np
.
float32
)
points
=
points
.
reshape
(
-
1
,
4
)
points
=
points
.
reshape
(
-
1
,
4
)
img
=
mmcv
.
imread
(
p
[
'img'
])
img
=
mmcv
.
imread
(
p
[
'img'
])
all_inputs
.
append
(
dict
(
points
=
points
,
img
=
img
,
calib
=
p
[
'calib'
]
))
all_inputs
.
append
(
dict
(
points
=
points
,
img
=
img
,
infos
=
infos_path
))
res_ndarray
=
self
.
inferencer
(
all_inputs
,
return_vis
=
True
)
res_ndarray
=
self
.
inferencer
(
all_inputs
,
return_vis
=
True
)
self
.
assert_predictions_equal
(
res_path
[
'predictions'
],
self
.
assert_predictions_equal
(
res_path
[
'predictions'
],
...
@@ -89,12 +89,12 @@ class TestMultiModalityDet3DInferencer(TestCase):
...
@@ -89,12 +89,12 @@ class TestMultiModalityDet3DInferencer(TestCase):
if
not
torch
.
cuda
.
is_available
():
if
not
torch
.
cuda
.
is_available
():
return
return
inputs
=
dict
(
inputs
=
dict
(
points
=
'
tests
/data/kitti/
training/velodyne/0
00000.bin'
,
points
=
'
demo
/data/kitti/00000
8
.bin'
,
img
=
'
tests
/data/kitti/
training/image_2/0
00000.png'
,
img
=
'
demo
/data/kitti/00000
8
.png'
,
calib
=
'tests/data/kitti/training/calib/0
00000.pkl'
),
infos
=
'demo/data/kitti/
00000
8
.pkl'
),
# img_out_dir
# img_out_dir
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
self
.
inferencer
(
inputs
,
img_
out_dir
=
tmp_dir
)
self
.
inferencer
(
inputs
,
out_dir
=
tmp_dir
)
# TODO: For results of LiDAR-based detection, the saved image only
# TODO: For results of LiDAR-based detection, the saved image only
# exists when show=True.
# exists when show=True.
# self.assertTrue(osp.exists(osp.join(tmp_dir, '000000.png')))
# self.assertTrue(osp.exists(osp.join(tmp_dir, '000000.png')))
...
@@ -103,18 +103,18 @@ class TestMultiModalityDet3DInferencer(TestCase):
...
@@ -103,18 +103,18 @@ class TestMultiModalityDet3DInferencer(TestCase):
if
not
torch
.
cuda
.
is_available
():
if
not
torch
.
cuda
.
is_available
():
return
return
# return_datasample
# return_datasample
inputs
=
dict
(
infos_path
=
'demo/data/kitti/000008.pkl'
points
=
'tests/data/kitti/training/velodyne/000000.bin'
,
points_path
=
'demo/data/kitti/000008.bin'
img
=
'tests/data/kitti/training/image_2/000000.png'
,
img_path
=
'demo/data/kitti/000008.png'
calib
=
'tests/data/kitti/training/calib/000000.pkl'
)
# single img & point cloud
inputs
=
dict
(
points
=
points_path
,
img
=
img_path
,
infos
=
infos_path
)
res
=
self
.
inferencer
(
inputs
,
return_datasamples
=
True
)
res
=
self
.
inferencer
(
inputs
,
return_datasamples
=
True
)
self
.
assertTrue
(
is_list_of
(
res
[
'predictions'
],
Det3DDataSample
))
self
.
assertTrue
(
is_list_of
(
res
[
'predictions'
],
Det3DDataSample
))
# pred_out_
file
# pred_out_
dir
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
with
tempfile
.
TemporaryDirectory
()
as
tmp_dir
:
pred_out_file
=
osp
.
join
(
tmp_dir
,
'tmp.json'
)
inputs
=
dict
(
points
=
points_path
,
img
=
img_path
,
infos
=
infos_path
)
res
=
self
.
inferencer
(
res
=
self
.
inferencer
(
inputs
,
print_result
=
True
,
out_dir
=
tmp_dir
)
inputs
,
print_result
=
True
,
pred_out_file
=
pred_out_file
)
dumped_res
=
mmengine
.
load
(
dumped_res
=
mmengine
.
load
(
pred_out_file
)
osp
.
join
(
tmp_dir
,
'preds'
,
'000008.json'
))
self
.
assert_predictions_equal
(
res
[
'predictions'
],
self
.
assertEqual
(
res
[
'predictions'
][
0
],
dumped_res
)
dumped_res
[
'predictions'
])
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