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
a32c0794
Unverified
Commit
a32c0794
authored
Feb 18, 2023
by
Sun Jiahao
Committed by
GitHub
Feb 18, 2023
Browse files
[Feature] dev-1.x change np.transpose to torch.permute for speed up (#2277)
* change np.transpose to torch.permute * add comments
parent
dd53c2ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
mmdet3d/datasets/transforms/formating.py
mmdet3d/datasets/transforms/formating.py
+8
-4
No files found.
mmdet3d/datasets/transforms/formating.py
View file @
a32c0794
...
@@ -147,15 +147,19 @@ class Pack3DDetInputs(BaseTransform):
...
@@ -147,15 +147,19 @@ class Pack3DDetInputs(BaseTransform):
if
'img'
in
results
:
if
'img'
in
results
:
if
isinstance
(
results
[
'img'
],
list
):
if
isinstance
(
results
[
'img'
],
list
):
# process multiple imgs in single frame
# process multiple imgs in single frame
imgs
=
[
img
.
transpose
(
2
,
0
,
1
)
for
img
in
results
[
'img'
]]
imgs
=
[
to_tensor
(
img
)
for
img
in
results
[
'img'
]]
imgs
=
np
.
ascontiguousarray
(
np
.
stack
(
imgs
,
axis
=
0
))
imgs
=
torch
.
stack
(
imgs
,
dim
=
0
).
permute
(
0
,
3
,
1
,
2
).
contiguous
()
results
[
'img'
]
=
to_tensor
(
imgs
)
results
[
'img'
]
=
to_tensor
(
imgs
)
else
:
else
:
img
=
results
[
'img'
]
img
=
results
[
'img'
]
if
len
(
img
.
shape
)
<
3
:
if
len
(
img
.
shape
)
<
3
:
img
=
np
.
expand_dims
(
img
,
-
1
)
img
=
np
.
expand_dims
(
img
,
-
1
)
results
[
'img'
]
=
to_tensor
(
# To improve the computational speed by by 3-5 times, apply:
np
.
ascontiguousarray
(
img
.
transpose
(
2
,
0
,
1
)))
# `torch.permute()` rather than `np.transpose()`.
# Refer to https://github.com/open-mmlab/mmdetection/pull/9533
# for more details
results
[
'img'
]
=
to_tensor
(
img
).
permute
(
2
,
0
,
1
).
contiguous
()
for
key
in
[
for
key
in
[
'proposals'
,
'gt_bboxes'
,
'gt_bboxes_ignore'
,
'gt_labels'
,
'proposals'
,
'gt_bboxes'
,
'gt_bboxes_ignore'
,
'gt_labels'
,
...
...
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