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
6e085b40
Commit
6e085b40
authored
Dec 13, 2019
by
Alexander Pivovarov
Committed by
Zhi
Dec 13, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix TF resize for dynamic size models (#4510)
parent
7e3bf12e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
15 deletions
+31
-15
python/tvm/relay/frontend/tensorflow.py
+8
-6
tests/python/frontend/tensorflow/test_forward.py
+23
-9
No files found.
python/tvm/relay/frontend/tensorflow.py
View file @
6e085b40
...
...
@@ -416,9 +416,11 @@ def _expand_dims():
extras
=
{
'axis'
:
int
(
axis
),
'num_newaxis'
:
1
})(
inputs
,
attr
)
return
_impl
def
_resize
_bilinear
(
bilinear_op
):
def
_resize
(
method
):
def
_impl
(
inputs
,
attr
,
params
):
size
=
attr
[
'_output_shapes'
][
0
][
1
:
3
]
output_shape0
=
attr
[
'_output_shapes'
][
0
]
# Dynamic size models might have _output_shapes attr equal to [None] here
size
=
output_shape0
[
1
:
3
]
if
output_shape0
is
not
None
else
[
-
1
,
-
1
]
# Important that the size is defined. If an axis is not, we need to infer what
# the shape should be.
if
-
1
in
size
:
...
...
@@ -431,7 +433,7 @@ def _resize_bilinear(bilinear_op):
# Ignore the new attributes from TF2.0, for now.
return
AttrCvt
(
op_name
=
'resize'
,
ignores
=
[
'Tdim'
,
'half_pixel_centers'
],
extras
=
{
'method'
:
bilinear_op
})(
inputs
,
attr
)
extras
=
{
'method'
:
method
})(
inputs
,
attr
)
return
_impl
def
_check_numerics
():
...
...
@@ -1488,9 +1490,9 @@ _convert_map = {
'Relu'
:
AttrCvt
(
'relu'
),
'Relu6'
:
_relu6
(),
'Reshape'
:
_reshape
(),
'ResizeBilinear'
:
_resize
_bilinear
(
'bilinear'
),
'ResizeBicubic'
:
_resize
_bilinear
(
'bilinear'
),
'ResizeNearestNeighbor'
:
_resize
_bilinear
(
'nearest_neighbor'
),
'ResizeBilinear'
:
_resize
(
'bilinear'
),
'ResizeBicubic'
:
_resize
(
'bilinear'
),
'ResizeNearestNeighbor'
:
_resize
(
'nearest_neighbor'
),
'ReverseV2'
:
_reverse_v2
(),
'RightShift'
:
AttrCvt
(
'right_shift'
),
'Round'
:
AttrCvt
(
'round'
),
...
...
tests/python/frontend/tensorflow/test_forward.py
View file @
6e085b40
...
...
@@ -28,7 +28,6 @@ from tensorflow.python.framework import graph_util
from
tensorflow.python.ops
import
nn_ops
from
tensorflow.python.ops
import
nn
from
tensorflow.python.ops
import
array_ops
from
tensorflow.python.ops
import
gen_array_ops
from
tensorflow.python.ops
import
math_ops
from
tensorflow.python.ops
import
variable_scope
from
tensorflow.python.ops
import
variables
...
...
@@ -1438,8 +1437,8 @@ def _test_resize_bilinear_from_tensor(in_shape, align_corners):
with
tf
.
Graph
()
.
as_default
():
in_data
=
array_ops
.
placeholder
(
shape
=
[
in_shape
[
0
],
in_shape
[
1
],
None
,
None
],
dtype
=
data
.
dtype
)
to_shape
=
tf
.
shape
(
in_data
)[
2
:
]
shape
=
[
in_shape
[
0
],
None
,
None
,
in_shape
[
3
]
],
dtype
=
data
.
dtype
)
to_shape
=
tf
.
shape
(
in_data
)[
1
:
3
]
tf
.
image
.
resize_bilinear
(
in_data
,
to_shape
,
align_corners
=
align_corners
)
...
...
@@ -1462,14 +1461,29 @@ def _test_resize_nearest_neighbor(in_shape, to_shape):
compare_tf_with_tvm
(
data
,
'Placeholder:0'
,
'resize_nearest_neighbor:0'
)
def
_test_resize_nearest_neighbor_dynamic_shape
(
in_shape
,
scale
):
""" One iteration of resize nearest neighbor for graph with dynamic input shape """
data
=
np
.
random
.
uniform
(
size
=
in_shape
)
.
astype
(
'float32'
)
with
tf
.
Graph
()
.
as_default
():
in_data
=
array_ops
.
placeholder
(
shape
=
None
,
dtype
=
data
.
dtype
)
# multiply input shape by scale factor
new_shape
=
tf
.
shape
(
in_data
)[
1
:
3
]
*
tf
.
constant
(
scale
,
dtype
=
tf
.
int32
)
tf
.
image
.
resize_nearest_neighbor
(
in_data
,
new_shape
,
name
=
'resize_nearest_neighbor'
)
compare_tf_with_tvm
(
data
,
'Placeholder:0'
,
'resize_nearest_neighbor:0'
)
def
test_forward_resize
():
""" Resize Bilinear, Nearest_Neighbor """
_test_resize_bilinear
((
4
,
16
,
32
,
32
),
[
50
,
50
],
False
)
_test_resize_bilinear
((
6
,
32
,
64
,
64
),
[
20
,
20
],
True
)
_test_resize_bilinear_from_tensor
((
4
,
16
,
32
,
32
),
False
)
_test_resize_bilinear_from_tensor
((
6
,
32
,
50
,
50
),
True
)
_test_resize_nearest_neighbor
((
6
,
32
,
64
,
64
),
[
20
,
20
])
# TF default layout is NHWC
_test_resize_bilinear
((
4
,
32
,
32
,
3
),
[
50
,
50
],
False
)
_test_resize_bilinear
((
6
,
32
,
32
,
3
),
[
20
,
20
],
True
)
_test_resize_bilinear_from_tensor
((
4
,
32
,
32
,
3
),
False
)
_test_resize_bilinear_from_tensor
((
6
,
50
,
50
,
3
),
True
)
_test_resize_nearest_neighbor
((
6
,
32
,
32
,
3
),
[
20
,
20
])
_test_resize_nearest_neighbor_dynamic_shape
((
1
,
16
,
16
,
3
),
scale
=
[
2
,
2
])
#######################################################################
...
...
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