Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tic
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenyuanbo
tic
Commits
a3b13973
Unverified
Commit
a3b13973
authored
Apr 24, 2020
by
Zhao Wu
Committed by
GitHub
Apr 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Frontend] Asymmetric padding of convolution support (#4803)
parent
dbd01140
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
5 additions
and
34 deletions
+5
-34
python/tvm/relay/frontend/coreml.py
+2
-9
python/tvm/relay/frontend/keras.py
+2
-18
python/tvm/relay/frontend/tflite.py
+1
-7
No files found.
python/tvm/relay/frontend/coreml.py
View file @
a3b13973
...
...
@@ -77,10 +77,7 @@ def _ConvolutionLayerParams(op, inexpr, etab):
pad_b
=
valid
.
paddingAmounts
.
borderAmounts
[
0
]
.
endEdgeSize
pad_r
=
valid
.
paddingAmounts
.
borderAmounts
[
1
]
.
endEdgeSize
if
not
all
(
v
==
0
for
v
in
(
pad_t
,
pad_l
,
pad_b
,
pad_r
)):
inexpr
=
_op
.
nn
.
pad
(
data
=
inexpr
,
pad_width
=
((
0
,
0
),
(
0
,
0
),
(
pad_t
,
pad_b
),
(
pad_l
,
pad_r
)))
params
[
'padding'
]
=
(
pad_t
,
pad_l
,
pad_b
,
pad_r
)
elif
op
.
WhichOneof
(
'ConvolutionPaddingType'
)
==
'same'
:
assert
op
.
same
.
asymmetryMode
==
0
,
"Only support BOTTOM_RIGHT_HEAVY mode, "
\
"which is used by tf/caffe and so on"
...
...
@@ -88,11 +85,7 @@ def _ConvolutionLayerParams(op, inexpr, etab):
strides
=
params
[
'strides'
]
pad_t
,
pad_b
=
get_pad_value
(
H
,
kernel
[
0
],
strides
[
0
])
pad_l
,
pad_r
=
get_pad_value
(
W
,
kernel
[
1
],
strides
[
1
])
inexpr
=
_op
.
nn
.
pad
(
data
=
inexpr
,
pad_width
=
((
0
,
0
),
(
0
,
0
),
(
pad_t
,
pad_b
),
(
pad_l
,
pad_r
)))
params
[
'padding'
]
=
(
pad_t
,
pad_l
,
pad_b
,
pad_r
)
else
:
raise
NotImplementedError
(
"Valid/Same convolution padding implemented"
)
...
...
python/tvm/relay/frontend/keras.py
View file @
a3b13973
...
...
@@ -290,15 +290,7 @@ def _convert_convolution(inexpr, keras_layer, etab):
in_w
=
keras_layer
.
input_shape
[
2
]
pad_t
,
pad_b
=
_get_pad_pair
(
in_h
,
dilated_kernel_h
,
stride_h
)
pad_l
,
pad_r
=
_get_pad_pair
(
in_w
,
dilated_kernel_w
,
stride_w
)
if
pad_t
==
pad_b
and
pad_l
==
pad_r
:
params
[
'padding'
]
=
(
pad_t
,
pad_l
)
elif
etab
.
data_layout
==
'NCHW'
:
inexpr
=
_op
.
nn
.
pad
(
data
=
inexpr
,
pad_width
=
(
(
0
,
0
),
(
0
,
0
),
(
pad_t
,
pad_b
),
(
pad_l
,
pad_r
)))
else
:
inexpr
=
_op
.
nn
.
pad
(
data
=
inexpr
,
pad_width
=
(
(
0
,
0
),
(
pad_t
,
pad_b
),
(
pad_l
,
pad_r
),
(
0
,
0
)))
params
[
'padding'
]
=
(
pad_t
,
pad_l
,
pad_b
,
pad_r
)
else
:
msg
=
'Padding with {} is not supported for operator Convolution '
\
'in frontend Keras.'
...
...
@@ -424,15 +416,7 @@ def _convert_separable_convolution(inexpr, keras_layer, etab):
in_w
=
keras_layer
.
input_shape
[
2
]
pad_t
,
pad_b
=
_get_pad_pair
(
in_h
,
kernel_h
,
stride_h
)
pad_l
,
pad_r
=
_get_pad_pair
(
in_w
,
kernel_w
,
stride_w
)
if
pad_t
==
pad_b
and
pad_l
==
pad_r
:
params0
[
'padding'
]
=
(
pad_t
,
pad_l
)
elif
etab
.
data_layout
==
'NCHW'
:
inexpr
=
_op
.
nn
.
pad
(
data
=
inexpr
,
pad_width
=
(
(
0
,
0
),
(
0
,
0
),
(
pad_t
,
pad_b
),
(
pad_l
,
pad_r
)))
else
:
inexpr
=
_op
.
nn
.
pad
(
data
=
inexpr
,
pad_width
=
(
(
0
,
0
),
(
pad_t
,
pad_b
),
(
pad_l
,
pad_r
),
(
0
,
0
)))
params0
[
'padding'
]
=
(
pad_t
,
pad_l
,
pad_b
,
pad_r
)
else
:
msg
=
'Padding with {} is not supported for operator Separable '
\
'Convolution in frontend Keras.'
...
...
python/tvm/relay/frontend/tflite.py
View file @
a3b13973
...
...
@@ -1308,13 +1308,7 @@ class OperatorConverter(object):
pad_left
,
pad_right
=
get_pad_value
(
input_w
,
dilated_kernel_w
,
stride_w
)
do_pad
=
not
(
pad_top
==
0
and
pad_bottom
==
0
and
pad_left
==
0
and
pad_right
==
0
)
if
do_pad
:
pad_value
=
0
if
input_tensor
.
qnn_params
:
pad_value
=
get_scalar_from_constant
(
input_tensor
.
qnn_params
[
'zero_point'
])
in_expr
=
_op
.
nn
.
pad
(
data
=
in_expr
,
pad_width
=
((
0
,
0
),
(
pad_top
,
pad_bottom
),
(
pad_left
,
pad_right
),
(
0
,
0
)),
pad_value
=
float
(
pad_value
))
params
[
'padding'
]
=
[
pad_top
,
pad_left
,
pad_bottom
,
pad_right
]
else
:
raise
tvm
.
error
.
OpAttributeUnImplemented
(
...
...
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