Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tvm
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cld
ml
tvm
Commits
ba4cc7ba
Commit
ba4cc7ba
authored
6 years ago
by
Siju
Committed by
Tianqi Chen
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Onnx Gather operator added (#1513)
parent
d6f3bf16
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nnvm/python/nnvm/frontend/onnx.py
+14
-2
14 additions, 2 deletions
nnvm/python/nnvm/frontend/onnx.py
nnvm/tests/python/frontend/onnx/test_forward.py
+29
-0
29 additions, 0 deletions
nnvm/tests/python/frontend/onnx/test_forward.py
with
43 additions
and
2 deletions
nnvm/python/nnvm/frontend/onnx.py
+
14
−
2
View file @
ba4cc7ba
...
...
@@ -446,7 +446,6 @@ class Unsqueeze(OnnxOpConverter):
inputs
[
0
]
=
_sym
.
expand_dims
(
inputs
[
0
],
axis
=
axes
,
num_newaxis
=
1
)
return
inputs
[
0
]
class
Slice
(
OnnxOpConverter
):
"""
Operator converter for Slice.
"""
...
...
@@ -487,6 +486,19 @@ class Slice(OnnxOpConverter):
'
ends
'
:
'
end
'
},
ignores
=
[
'
axes
'
])(
inputs
,
attr
)
class
Gather
(
OnnxOpConverter
):
"""
Operator converter for Gather.
"""
@classmethod
def
_impl_v1
(
cls
,
inputs
,
attr
,
params
):
axis
=
attr
[
'
axis
'
]
indices
=
np
.
array
(
attr
[
'
indices
'
],
dtype
=
'
int32
'
)
name
=
'
gather_indices
'
gather_indices
=
_sym
.
Variable
(
name
=
name
,
init
=
indices
)
params
[
name
]
=
indices
return
_sym
.
take
(
inputs
[
0
],
gather_indices
,
axis
=
axis
)
# compatible operators that do NOT require any conversion.
_identity_list
=
[]
...
...
@@ -593,7 +605,7 @@ def _get_convert_map(opset):
'
Split
'
:
AttrCvt
(
'
split
'
,
{
'
split
'
:
'
indices_or_sections
'
}),
'
Slice
'
:
Slice
.
get_converter
(
opset
),
'
Transpose
'
:
AttrCvt
(
'
transpose
'
,
{
'
perm
'
:
'
axes
'
}),
#
'Gather'
'
Gather
'
:
Gather
.
get_converter
(
opset
),
'
Squeeze
'
:
Renamer
(
'
squeeze
'
),
'
Unsqueeze
'
:
Unsqueeze
.
get_converter
(
opset
),
'
Pad
'
:
Pad
.
get_converter
(
opset
),
...
...
This diff is collapsed.
Click to expand it.
nnvm/tests/python/frontend/onnx/test_forward.py
+
29
−
0
View file @
ba4cc7ba
...
...
@@ -189,6 +189,34 @@ def test_unsqueeze():
np
.
testing
.
assert_allclose
(
out_shape
,
tvm_out
.
shape
)
def
verify_gather
(
in_shape
,
indices
,
axis
=
0
):
indices_src
=
np
.
array
(
indices
,
dtype
=
"
int32
"
)
x
=
np
.
random
.
uniform
(
size
=
in_shape
)
out_np
=
np
.
take
(
x
,
indices_src
,
axis
=
axis
)
y
=
helper
.
make_node
(
"
Gather
"
,
[
'
in
'
],
[
'
out
'
],
indices
=
indices
,
axis
=
axis
)
graph
=
helper
.
make_graph
([
y
],
'
gather_test
'
,
inputs
=
[
helper
.
make_tensor_value_info
(
"
in
"
,
TensorProto
.
FLOAT
,
list
(
in_shape
))],
outputs
=
[
helper
.
make_tensor_value_info
(
"
out
"
,
TensorProto
.
FLOAT
,
list
(
out_np
.
shape
))])
model
=
helper
.
make_model
(
graph
,
producer_name
=
'
gather_test
'
)
for
target
,
ctx
in
ctx_list
():
tvm_out
=
get_tvm_output
(
model
,
x
,
target
,
ctx
,
out_np
.
shape
,
'
float32
'
)
np
.
testing
.
assert_allclose
(
out_np
,
tvm_out
)
def
test_gather
():
verify_gather
((
4
,),
[
1
])
verify_gather
((
4
,),
[
0
,
1
,
2
,
3
])
verify_gather
((
4
,
2
),
[
1
],
1
)
verify_gather
((
4
,
3
,
5
,
6
),
[
2
,
1
,
0
,
0
],
-
2
)
def
_test_slice_iteration
(
indata
,
outdata
,
starts
,
ends
,
axes
=
None
):
if
axes
:
y
=
helper
.
make_node
(
"
Slice
"
,
[
'
in
'
],
[
'
out
'
],
axes
=
axes
,
starts
=
starts
,
ends
=
ends
)
...
...
@@ -299,3 +327,4 @@ if __name__ == '__main__':
test_ceil
()
test_clip
()
test_matmul
()
test_gather
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment