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
2fa3a67e
Unverified
Commit
2fa3a67e
authored
Mar 03, 2019
by
Haichen Shen
Committed by
GitHub
Mar 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Relay][Frontend] Add slice axis op in mxnet converter (#2706)
* Add slice axis op in mxnet converter * Fix lint
parent
c8373ece
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
0 deletions
+48
-0
python/tvm/relay/frontend/mxnet.py
+29
-0
tests/python/frontend/mxnet/test_forward.py
+19
-0
No files found.
python/tvm/relay/frontend/mxnet.py
View file @
2fa3a67e
...
@@ -194,6 +194,34 @@ def _mx_slice(inputs, attrs):
...
@@ -194,6 +194,34 @@ def _mx_slice(inputs, attrs):
return
_op
.
strided_slice
(
inputs
[
0
],
**
new_attrs
)
return
_op
.
strided_slice
(
inputs
[
0
],
**
new_attrs
)
def
_mx_slice_axis
(
inputs
,
attrs
):
assert
len
(
inputs
)
==
1
shape
=
ir_pass
.
infer_type
(
inputs
[
0
])
.
checked_type
.
shape
axis
=
attrs
.
get_int
(
"axis"
)
ax_beg
=
attrs
.
get_int
(
"begin"
)
ax_end
=
attrs
.
get_str
(
"end"
)
if
ax_end
==
"None"
:
ax_end
=
int
(
shape
[
axis
])
else
:
ax_end
=
int
(
ax_end
)
if
ax_beg
<
0
:
ax_beg
+=
int
(
shape
[
axis
])
if
ax_end
<
0
:
ax_end
+=
int
(
shape
[
axis
])
assert
ax_beg
>=
0
and
ax_beg
<
int
(
shape
[
axis
])
assert
ax_end
>
ax_beg
and
ax_end
<=
int
(
shape
[
axis
])
begin
=
[]
end
=
[]
for
i
,
dim
in
enumerate
(
shape
):
if
i
!=
axis
:
begin
.
append
(
0
)
end
.
append
(
dim
)
else
:
begin
.
append
(
ax_beg
)
end
.
append
(
ax_end
)
return
_op
.
strided_slice
(
inputs
[
0
],
begin
,
end
)
def
_mx_split
(
inputs
,
attrs
):
def
_mx_split
(
inputs
,
attrs
):
axis
=
attrs
.
get_int
(
"axis"
,
1
)
axis
=
attrs
.
get_int
(
"axis"
,
1
)
new_attrs
=
{}
new_attrs
=
{}
...
@@ -423,6 +451,7 @@ _convert_map = {
...
@@ -423,6 +451,7 @@ _convert_map = {
"BatchNorm_v1"
:
_mx_batch_norm
,
"BatchNorm_v1"
:
_mx_batch_norm
,
"LRN"
:
_mx_lrn
,
"LRN"
:
_mx_lrn
,
"slice"
:
_mx_slice
,
"slice"
:
_mx_slice
,
"slice_axis"
:
_mx_slice_axis
,
"SliceChannel"
:
_mx_split
,
"SliceChannel"
:
_mx_split
,
"split"
:
_mx_split
,
"split"
:
_mx_split
,
"expand_dims"
:
_mx_expand_dims
,
"expand_dims"
:
_mx_expand_dims
,
...
...
tests/python/frontend/mxnet/test_forward.py
View file @
2fa3a67e
...
@@ -337,6 +337,23 @@ def test_forward_scalar_ops():
...
@@ -337,6 +337,23 @@ def test_forward_scalar_ops():
tvm
.
testing
.
assert_allclose
(
op_res
.
asnumpy
(),
ref_res
.
asnumpy
())
tvm
.
testing
.
assert_allclose
(
op_res
.
asnumpy
(),
ref_res
.
asnumpy
())
def
test_forward_slice_axis
():
def
verify
(
shape
,
axis
,
begin
,
end
):
data_np
=
np
.
random
.
uniform
(
size
=
shape
)
.
astype
(
"float32"
)
ref_res
=
mx
.
nd
.
slice_axis
(
mx
.
nd
.
array
(
data_np
),
axis
,
begin
,
end
)
mx_sym
=
mx
.
sym
.
slice_axis
(
mx
.
sym
.
var
(
"data"
),
axis
,
begin
,
end
)
new_sym
,
_
=
relay
.
frontend
.
from_mxnet
(
mx_sym
,
{
"data"
:
shape
})
for
target
,
ctx
in
ctx_list
():
for
kind
in
[
"graph"
,
"debug"
]:
intrp
=
relay
.
create_executor
(
kind
,
ctx
=
ctx
,
target
=
target
)
op_res
=
intrp
.
evaluate
(
new_sym
)(
data_np
)
tvm
.
testing
.
assert_allclose
(
op_res
.
asnumpy
(),
ref_res
.
asnumpy
())
verify
((
3
,
4
),
0
,
1
,
2
)
verify
((
3
,
4
),
0
,
1
,
None
)
verify
((
3
,
4
),
1
,
0
,
2
)
verify
((
3
,
4
),
1
,
-
3
,
-
1
)
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
test_forward_mlp
()
test_forward_mlp
()
test_forward_vgg
()
test_forward_vgg
()
...
@@ -363,3 +380,4 @@ if __name__ == '__main__':
...
@@ -363,3 +380,4 @@ if __name__ == '__main__':
test_forward_broadcast_ops
()
test_forward_broadcast_ops
()
test_forward_elemwise_ops
()
test_forward_elemwise_ops
()
test_forward_scalar_ops
()
test_forward_scalar_ops
()
test_forward_slice_axis
()
\ No newline at end of file
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