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
MMCV
Commits
cc332b26
Unverified
Commit
cc332b26
authored
Sep 18, 2020
by
robin Han
Committed by
GitHub
Sep 18, 2020
Browse files
add switch for onnx exporter (#564)
parent
21143568
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
8 deletions
+23
-8
mmcv/onnx/symbolic.py
mmcv/onnx/symbolic.py
+23
-8
No files found.
mmcv/onnx/symbolic.py
View file @
cc332b26
"""Modified from https://github.com/pytorch/pytorch."""
import
os
import
numpy
as
np
import
torch
from
torch.nn.modules.utils
import
_pair
,
_single
,
_triple
...
...
@@ -21,14 +23,27 @@ def _interpolate(name, dim, interpolate_mode):
'Constant'
,
value_t
=
torch
.
tensor
([],
dtype
=
torch
.
float32
))
if
scales
is
None
:
input_size
=
g
.
op
(
'Shape'
,
input
)
input_size_beg
=
sym_help
.
_slice_helper
(
g
,
input_size
,
axes
=
[
0
],
ends
=
[
2
],
starts
=
[
0
])
output_size
=
g
.
op
(
'Cast'
,
output_size
,
to_i
=
sym_help
.
cast_pytorch_to_onnx
[
'Long'
])
output_size
=
g
.
op
(
'Concat'
,
input_size_beg
,
output_size
,
axis_i
=
0
)
if
'ONNX_BACKEND'
in
os
.
environ
and
os
.
environ
[
'ONNX_BACKEND'
]
==
'TensorRT'
:
input_size
=
input
.
type
().
sizes
()
# slice the first two dim
input_size
=
input_size
[:
2
]
# convert output_size to int type
output_size
=
sym_help
.
_maybe_get_const
(
output_size
,
'is'
)
input_size
.
extend
(
output_size
)
output_size
=
g
.
op
(
'Constant'
,
value_t
=
torch
.
tensor
(
input_size
,
dtype
=
torch
.
int64
))
else
:
input_size
=
g
.
op
(
'Shape'
,
input
)
input_size_beg
=
sym_help
.
_slice_helper
(
g
,
input_size
,
axes
=
[
0
],
ends
=
[
2
],
starts
=
[
0
])
output_size
=
g
.
op
(
'Cast'
,
output_size
,
to_i
=
sym_help
.
cast_pytorch_to_onnx
[
'Long'
])
output_size
=
g
.
op
(
'Concat'
,
input_size_beg
,
output_size
,
axis_i
=
0
)
scales
=
g
.
op
(
'Constant'
,
value_t
=
torch
.
tensor
([],
dtype
=
torch
.
float32
))
return
g
.
op
(
...
...
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