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
6faacc6f
Unverified
Commit
6faacc6f
authored
Apr 24, 2020
by
Samuel
Committed by
GitHub
Apr 23, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[MXNET]DepthToSpace & SpaceToDepth Operator (#5408)
parent
e149db28
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
0 deletions
+50
-0
python/tvm/relay/frontend/mxnet.py
+16
-0
tests/python/frontend/mxnet/test_forward.py
+34
-0
No files found.
python/tvm/relay/frontend/mxnet.py
View file @
6faacc6f
...
...
@@ -1073,6 +1073,20 @@ def _mx_one_hot(inputs, attrs):
return
_op
.
one_hot
(
indices
,
on_value
,
off_value
,
depth
,
-
1
,
dtype
)
def
_mx_depth_to_space
(
inputs
,
attrs
):
assert
len
(
inputs
)
==
1
new_attrs
=
{}
new_attrs
[
"block_size"
]
=
attrs
.
get_int
(
"block_size"
)
return
_op
.
nn
.
depth_to_space
(
*
inputs
,
**
new_attrs
)
def
_mx_space_to_depth
(
inputs
,
attrs
):
assert
len
(
inputs
)
==
1
new_attrs
=
{}
new_attrs
[
"block_size"
]
=
attrs
.
get_int
(
"block_size"
)
return
_op
.
nn
.
space_to_depth
(
*
inputs
,
**
new_attrs
)
def
_mx_contrib_fifo_buffer
(
inputs
,
attrs
):
new_attrs
=
{}
new_attrs
[
'axis'
]
=
attrs
.
get_int
(
'axis'
)
...
...
@@ -1854,6 +1868,8 @@ _convert_map = {
"make_loss"
:
_mx_make_loss
,
"_contrib_div_sqrt_dim"
:
_mx_contrib_div_sqrt_dim
,
"one_hot"
:
_mx_one_hot
,
"depth_to_space"
:
_mx_depth_to_space
,
"space_to_depth"
:
_mx_space_to_depth
,
# vision
"_contrib_BilinearResize2D"
:
_mx_resize
,
"_contrib_MultiBoxPrior"
:
_mx_multibox_prior
,
...
...
tests/python/frontend/mxnet/test_forward.py
View file @
6faacc6f
...
...
@@ -995,6 +995,38 @@ def test_forward_swap_axis():
# _verify_swap_axis((4, 5), (5, 4), 0, 0)
def
test_forward_depth_to_space
():
def
verify
(
shape
,
blocksize
=
2
):
x
=
np
.
random
.
uniform
(
size
=
shape
)
.
astype
(
"float32"
)
ref_res
=
mx
.
nd
.
depth_to_space
(
mx
.
nd
.
array
(
x
),
blocksize
)
mx_sym
=
mx
.
sym
.
depth_to_space
(
mx
.
sym
.
var
(
"x"
),
blocksize
)
shape_dict
=
{
"x"
:
x
.
shape
,
}
mod
,
_
=
relay
.
frontend
.
from_mxnet
(
mx_sym
,
shape_dict
)
for
target
,
ctx
in
ctx_list
():
for
kind
in
[
"graph"
,
"debug"
]:
intrp
=
relay
.
create_executor
(
kind
,
mod
=
mod
,
ctx
=
ctx
,
target
=
target
)
op_res
=
intrp
.
evaluate
()(
x
)
tvm
.
testing
.
assert_allclose
(
op_res
.
asnumpy
(),
ref_res
.
asnumpy
(),
rtol
=
1e-3
,
atol
=
1e-5
)
verify
((
1
,
18
,
3
,
3
),
3
)
def
test_forward_space_to_depth
():
def
verify
(
shape
,
blocksize
=
2
):
x
=
np
.
random
.
uniform
(
size
=
shape
)
.
astype
(
"float32"
)
ref_res
=
mx
.
nd
.
space_to_depth
(
mx
.
nd
.
array
(
x
),
blocksize
)
mx_sym
=
mx
.
sym
.
space_to_depth
(
mx
.
sym
.
var
(
"x"
),
blocksize
)
shape_dict
=
{
"x"
:
x
.
shape
,
}
mod
,
_
=
relay
.
frontend
.
from_mxnet
(
mx_sym
,
shape_dict
)
for
target
,
ctx
in
ctx_list
():
for
kind
in
[
"graph"
,
"debug"
]:
intrp
=
relay
.
create_executor
(
kind
,
mod
=
mod
,
ctx
=
ctx
,
target
=
target
)
op_res
=
intrp
.
evaluate
()(
x
)
tvm
.
testing
.
assert_allclose
(
op_res
.
asnumpy
(),
ref_res
.
asnumpy
(),
rtol
=
1e-3
,
atol
=
1e-5
)
verify
((
1
,
1
,
9
,
9
),
3
)
if
__name__
==
'__main__'
:
test_forward_mlp
()
test_forward_vgg
()
...
...
@@ -1047,6 +1079,8 @@ if __name__ == '__main__':
test_forward_instance_norm
()
test_forward_layer_norm
()
test_forward_one_hot
()
test_forward_depth_to_space
()
test_forward_space_to_depth
()
test_forward_convolution
()
test_forward_deconvolution
()
test_forward_cond
()
...
...
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