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
c98ba601
Commit
c98ba601
authored
Aug 23, 2018
by
Siju
Committed by
Tianqi Chen
Aug 22, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[FRONTEND][COREML]More ops are added (#1619)
parent
00038567
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
1 deletions
+160
-1
nnvm/python/nnvm/frontend/coreml.py
+39
-1
nnvm/tests/python/frontend/coreml/test_forward.py
+121
-0
No files found.
nnvm/python/nnvm/frontend/coreml.py
View file @
c98ba601
...
...
@@ -269,6 +269,40 @@ def UpsampleLayerParams(op, insym, symtab):
def
L2NormalizeLayerParams
(
op
,
insym
,
symtab
):
return
_sym
.
l2_normalize
(
insym
,
eps
=
op
.
epsilon
,
axis
=
1
)
def
LRNLayerParams
(
op
,
insym
,
symtab
):
par
=
{}
par
[
'size'
]
=
op
.
localSize
par
[
'bias'
]
=
op
.
k
par
[
'alpha'
]
=
op
.
alpha
par
[
'beta'
]
=
op
.
beta
par
[
'axis'
]
=
1
#default layout is nchw
return
_sym
.
lrn
(
data
=
insym
,
**
par
)
def
AverageLayerParams
(
op
,
insyms
,
symtab
):
if
not
isinstance
(
insyms
,
list
)
or
len
(
insyms
)
<
2
:
raise
ValueError
(
"Expect minimum 2 inputs"
)
count
=
len
(
insyms
)
_sum
=
insyms
[
0
]
for
i
in
range
(
1
,
count
):
_sum
=
_sym
.
broadcast_add
(
_sum
,
insyms
[
i
])
return
_sum
/
count
def
MaxLayerParams
(
op
,
insyms
,
symtab
):
if
not
isinstance
(
insyms
,
list
)
or
len
(
insyms
)
<
2
:
raise
ValueError
(
"Expect minimum 2 inputs"
)
_max
=
insyms
[
0
]
for
i
in
range
(
1
,
len
(
insyms
)):
_max
=
_sym
.
broadcast_max
(
_max
,
insyms
[
i
])
return
_max
def
MinLayerParams
(
op
,
insyms
,
symtab
):
if
not
isinstance
(
insyms
,
list
)
or
len
(
insyms
)
<
2
:
raise
ValueError
(
"Expect minimum 2 inputs"
)
_min
=
insyms
[
0
]
for
i
in
range
(
1
,
len
(
insyms
)):
_min
=
_sym
.
broadcast_min
(
_min
,
insyms
[
i
])
return
_min
_convert_map
=
{
'NeuralNetworkMeanImage'
:
NeuralNetworkMeanImage
,
'NeuralNetworkImageScaler'
:
NeuralNetworkImageScaler
,
...
...
@@ -286,7 +320,11 @@ _convert_map = {
'PaddingLayerParams'
:
PaddingLayerParams
,
'PermuteLayerParams'
:
PermuteLayerParams
,
'UpsampleLayerParams'
:
UpsampleLayerParams
,
'L2NormalizeLayerParams'
:
L2NormalizeLayerParams
'L2NormalizeLayerParams'
:
L2NormalizeLayerParams
,
'LRNLayerParams'
:
LRNLayerParams
,
'AverageLayerParams'
:
AverageLayerParams
,
'MaxLayerParams'
:
MaxLayerParams
,
'MinLayerParams'
:
MinLayerParams
,
}
def
coreml_op_to_nnvm
(
op
,
inname
,
outname
,
symtab
):
...
...
nnvm/tests/python/frontend/coreml/test_forward.py
View file @
c98ba601
...
...
@@ -223,6 +223,123 @@ def verify_l2_normalize(input_dim, eps):
def
test_forward_l2_normalize
():
verify_l2_normalize
((
1
,
3
,
20
,
20
),
0.001
)
def
verify_lrn
(
input_dim
,
size
,
bias
,
alpha
,
beta
):
dtype
=
"float32"
axis
=
1
a_np
=
np
.
random
.
uniform
(
size
=
input_dim
)
.
astype
(
dtype
)
b_np
=
topi
.
testing
.
lrn_python
(
a_np
,
size
,
axis
,
bias
,
alpha
,
beta
)
input
=
[(
'input'
,
datatypes
.
Array
(
*
input_dim
))]
output
=
[(
'output'
,
datatypes
.
Array
(
*
b_np
.
shape
))]
builder
=
NeuralNetworkBuilder
(
input
,
output
)
builder
.
add_lrn
(
name
=
'LRN'
,
input_name
=
'input'
,
output_name
=
'output'
,
alpha
=
alpha
,
beta
=
beta
,
k
=
bias
,
local_size
=
size
)
model
=
cm
.
models
.
MLModel
(
builder
.
spec
)
for
target
,
ctx
in
ctx_list
():
out
=
run_tvm_graph
(
model
,
a_np
,
'input'
,
b_np
.
shape
,
dtype
)
np
.
testing
.
assert_allclose
(
out
,
b_np
,
rtol
=
1e-5
)
def
test_forward_lrn
():
verify_lrn
((
1
,
3
,
10
,
20
),
3
,
1.0
,
1.0
,
0.5
)
def
verify_average
(
input_dim1
,
input_dim2
,
axis
=
0
):
dtype
=
'float32'
a_np1
=
np
.
random
.
uniform
(
size
=
input_dim1
)
.
astype
(
dtype
)
a_np2
=
np
.
random
.
uniform
(
size
=
input_dim2
)
.
astype
(
dtype
)
b_np
=
np
.
mean
((
a_np1
,
a_np2
),
axis
=
axis
)
inputs
=
[(
'input1'
,
datatypes
.
Array
(
*
input_dim1
)),
(
'input2'
,
datatypes
.
Array
(
*
input_dim2
))]
output
=
[(
'output'
,
datatypes
.
Array
(
*
b_np
.
shape
))]
builder
=
NeuralNetworkBuilder
(
inputs
,
output
)
builder
.
add_elementwise
(
name
=
'MEAN'
,
input_names
=
[
'input1'
,
'input2'
],
output_name
=
'output'
,
mode
=
'AVE'
)
model
=
cm
.
models
.
MLModel
(
builder
.
spec
)
for
target
,
ctx
in
ctx_list
():
out
=
run_tvm_graph
(
model
,
[
a_np1
,
a_np2
],
[
'input1'
,
'input2'
],
b_np
.
shape
,
dtype
)
np
.
testing
.
assert_allclose
(
out
,
b_np
,
rtol
=
1e-5
)
def
test_forward_average
():
verify_average
((
1
,
3
,
20
,
20
),
(
1
,
3
,
20
,
20
))
verify_average
((
3
,
20
,
20
),
(
1
,
3
,
20
,
20
))
verify_average
((
20
,
20
),
(
1
,
3
,
20
,
20
))
def
verify_max
(
input_dim
):
dtype
=
'float32'
a_np1
=
np
.
random
.
uniform
(
size
=
input_dim
)
.
astype
(
dtype
)
a_np2
=
np
.
random
.
uniform
(
size
=
input_dim
)
.
astype
(
dtype
)
a_np3
=
np
.
random
.
uniform
(
size
=
input_dim
)
.
astype
(
dtype
)
b_np
=
np
.
max
((
a_np1
,
a_np2
,
a_np3
),
axis
=
0
)
inputs
=
[(
'input1'
,
datatypes
.
Array
(
*
input_dim
)),
(
'input2'
,
datatypes
.
Array
(
*
input_dim
)),
(
'input3'
,
datatypes
.
Array
(
*
input_dim
))]
output
=
[(
'output'
,
datatypes
.
Array
(
*
b_np
.
shape
))]
builder
=
NeuralNetworkBuilder
(
inputs
,
output
)
builder
.
add_elementwise
(
name
=
'Max'
,
input_names
=
[
'input1'
,
'input2'
,
'input3'
],
output_name
=
'output'
,
mode
=
'MAX'
)
model
=
cm
.
models
.
MLModel
(
builder
.
spec
)
for
target
,
ctx
in
ctx_list
():
out
=
run_tvm_graph
(
model
,
[
a_np1
,
a_np2
,
a_np3
],
[
'input1'
,
'input2'
,
'input3'
],
b_np
.
shape
,
dtype
)
np
.
testing
.
assert_allclose
(
out
,
b_np
,
rtol
=
1e-5
)
def
test_forward_max
():
verify_max
((
1
,
3
,
20
,
20
))
verify_max
((
20
,
20
))
def
verify_min
(
input_dim
):
dtype
=
'float32'
a_np1
=
np
.
random
.
uniform
(
size
=
input_dim
)
.
astype
(
dtype
)
a_np2
=
np
.
random
.
uniform
(
size
=
input_dim
)
.
astype
(
dtype
)
a_np3
=
np
.
random
.
uniform
(
size
=
input_dim
)
.
astype
(
dtype
)
b_np
=
np
.
min
((
a_np1
,
a_np2
,
a_np3
),
axis
=
0
)
inputs
=
[(
'input1'
,
datatypes
.
Array
(
*
input_dim
)),
(
'input2'
,
datatypes
.
Array
(
*
input_dim
)),
(
'input3'
,
datatypes
.
Array
(
*
input_dim
))]
output
=
[(
'output'
,
datatypes
.
Array
(
*
b_np
.
shape
))]
builder
=
NeuralNetworkBuilder
(
inputs
,
output
)
builder
.
add_elementwise
(
name
=
'Min'
,
input_names
=
[
'input1'
,
'input2'
,
'input3'
],
output_name
=
'output'
,
mode
=
'MIN'
)
model
=
cm
.
models
.
MLModel
(
builder
.
spec
)
for
target
,
ctx
in
ctx_list
():
out
=
run_tvm_graph
(
model
,
[
a_np1
,
a_np2
,
a_np3
],
[
'input1'
,
'input2'
,
'input3'
],
b_np
.
shape
,
dtype
)
np
.
testing
.
assert_allclose
(
out
,
b_np
,
rtol
=
1e-5
)
def
test_forward_min
():
verify_min
((
1
,
3
,
20
,
20
))
verify_min
((
20
,
20
))
if
__name__
==
'__main__'
:
test_mobilenet_checkonly
()
test_resnet50_checkonly
()
...
...
@@ -231,3 +348,7 @@ if __name__ == '__main__':
test_forward_MultiplyLayerParams
()
test_forward_UpsampleLayerParams
()
test_forward_l2_normalize
()
test_forward_lrn
()
test_forward_average
()
test_forward_max
()
test_forward_min
()
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