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
a2870fef
Commit
a2870fef
authored
6 years ago
by
Siju
Committed by
Tianqi Chen
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[NNVM][TENSORFLOW]Local Response Normalization added for tensorflow (#1522)
parent
32076df8
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
nnvm/python/nnvm/frontend/tensorflow.py
+15
-0
15 additions, 0 deletions
nnvm/python/nnvm/frontend/tensorflow.py
nnvm/tests/python/frontend/tensorflow/test_forward.py
+35
-0
35 additions, 0 deletions
nnvm/tests/python/frontend/tensorflow/test_forward.py
with
50 additions
and
0 deletions
nnvm/python/nnvm/frontend/tensorflow.py
+
15
−
0
View file @
a2870fef
...
...
@@ -468,6 +468,20 @@ def _fill():
ignores
=
[
'
index_type
'
,
'
T
'
])(
new_inputs
,
attr
)
return
_impl
def
_lrn
():
def
_impl
(
inputs
,
attr
,
params
):
new_inputs
=
[]
attr_new
=
{}
depth_radius
=
attr
.
get
(
'
depth_radius
'
,
5
)
size
=
(
depth_radius
*
2
)
+
1
attr_new
[
'
axis
'
]
=
3
# Fix axis, NHWC format
attr_new
[
'
size
'
]
=
size
attr_new
[
'
bias
'
]
=
attr
.
get
(
'
bias
'
,
1
)
attr_new
[
'
alpha
'
]
=
attr
.
get
(
'
alpha
'
,
1
)
*
size
attr_new
[
'
beta
'
]
=
attr
.
get
(
'
beta
'
,
0.5
)
return
AttrCvt
(
op_name
=
'
lrn
'
)(
new_inputs
,
attr_new
)
return
_impl
def
_gather_v2
():
"
Tensorflow now support only gatherv2
"
def
_impl
(
inputs
,
attr
,
params
):
...
...
@@ -680,6 +694,7 @@ _convert_map = {
'
Fill
'
:
_fill
(),
'
GatherV2
'
:
_gather_v2
(),
'
StridedSlice
'
:
_stridedSlice
(),
'
LRN
'
:
_lrn
(),
}
# _convert_map_rnn defines maps of rnn operator name to
...
...
This diff is collapsed.
Click to expand it.
nnvm/tests/python/frontend/tensorflow/test_forward.py
+
35
−
0
View file @
a2870fef
...
...
@@ -855,6 +855,40 @@ def test_forward_ptb():
assert
(
tvm_sample_str
==
tf_sample_str
)
#######################################################################
# LRN (Local Response Normalization)
# ----------------------------------
def
_test_lrn
(
ishape
,
size
,
axis
,
bias
,
alpha
,
beta
):
"""
testing local response normalization
"""
lrn_depth_radius
=
size
/
2
inp_array
=
np
.
random
.
uniform
(
size
=
ishape
).
astype
(
np
.
float32
)
with
tf
.
Graph
().
as_default
():
in1
=
tf
.
placeholder
(
shape
=
inp_array
.
shape
,
dtype
=
inp_array
.
dtype
,
name
=
"
lrn0_data
"
)
nn_ops
.
local_response_normalization
(
in1
,
name
=
"
lrn
"
,
depth_radius
=
lrn_depth_radius
,
bias
=
bias
,
alpha
=
alpha
,
beta
=
beta
)
with
tf
.
Session
()
as
sess
:
graph_def
=
tf
.
graph_util
.
convert_variables_to_constants
(
sess
,
sess
.
graph
.
as_graph_def
(
add_shapes
=
True
),
[
'
lrn
'
],)
tf_output
=
run_tf_graph
(
sess
,
inp_array
,
'
lrn0_data:0
'
,
'
lrn:0
'
)
tvm_output
=
run_tvm_graph
(
graph_def
,
inp_array
,
"
lrn0_data
"
,
tf_output
.
shape
,
tf_output
.
dtype
)
np
.
testing
.
assert_allclose
(
tf_output
,
tvm_output
,
atol
=
1e-3
,
rtol
=
1e-3
)
sess
.
close
()
def
test_forward_lrn
():
_test_lrn
((
1
,
3
,
20
,
20
),
3
,
1
,
1.0
,
1.0
,
0.5
)
# Main
# ----
if
__name__
==
'
__main__
'
:
...
...
@@ -875,3 +909,4 @@ if __name__ == '__main__':
test_forward_stridedslice
()
test_forward_gather
()
test_forward_ptb
()
test_forward_lrn
()
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