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
2ebf1bd1
Commit
2ebf1bd1
authored
Aug 30, 2019
by
Alexander Pivovarov
Committed by
Zhi
Aug 30, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more cases to keras _convert_reshape (#3846)
parent
ec7790e3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
6 deletions
+47
-6
python/tvm/relay/frontend/keras.py
+20
-5
tests/python/frontend/keras/test_forward.py
+27
-1
No files found.
python/tvm/relay/frontend/keras.py
View file @
2ebf1bd1
...
...
@@ -490,11 +490,26 @@ def _convert_concat(inexpr, keras_layer, _):
def
_convert_reshape
(
inexpr
,
keras_layer
,
_
):
_check_data_format
(
keras_layer
)
ch
=
keras_layer
.
input_shape
[
-
1
]
assert
ch
==
keras_layer
.
target_shape
[
-
1
],
\
"Only supports last dimension in target shape being equal to "
\
"the channel number of input tensor."
shape
=
(
-
1
,
ch
)
+
keras_layer
.
target_shape
[:
-
1
]
inshape
=
keras_layer
.
input_shape
# includes batch
tshape
=
keras_layer
.
target_shape
# no batch
if
len
(
inshape
)
==
3
and
len
(
tshape
)
==
1
:
# (?, a, b) -> (-1, ab)
shape
=
(
-
1
,
tshape
[
0
])
elif
len
(
inshape
)
in
[
2
,
3
]
and
len
(
tshape
)
==
2
:
# (?, cc) -> (-1, c, c)
# (?, a, b) -> (-1, c, c)
assert
tshape
[
0
]
==
tshape
[
1
],
\
"Only supports square target shapes, but got {}"
.
format
(
tshape
)
shape
=
(
-
1
,
)
+
tshape
else
:
# (?, h, w, c) -> (-1, c, H, W)
# (?, h, w, c) -> (-1, c, hw)
# (?, hw, c) -> (-1, c, h, w)
ch
=
inshape
[
-
1
]
assert
ch
==
tshape
[
-
1
],
\
"Only supports last dimension in target shape being equal to "
\
"the channel number of input tensor."
shape
=
(
-
1
,
ch
)
+
tshape
[:
-
1
]
return
_op
.
reshape
(
inexpr
,
newshape
=
shape
)
...
...
tests/python/frontend/keras/test_forward.py
View file @
2ebf1bd1
...
...
@@ -193,10 +193,36 @@ def test_forward_upsample(interpolation='nearest'):
def
test_forward_reshape
():
# input_shape len is 3, target_shape len is 3
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
3
))
x
=
keras
.
layers
.
Reshape
(
target_shape
=
(
32
,
32
,
3
))(
data
)
x
=
keras
.
layers
.
Reshape
(
target_shape
=
(
16
,
64
,
3
))(
data
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
)
# input_shape len is 3, target_shape len is 2
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
8
,
3
))
x
=
keras
.
layers
.
Reshape
(
target_shape
=
(
256
,
3
))(
data
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
)
# input_shape len is 2, target_shape len is 3
data
=
keras
.
layers
.
Input
(
shape
=
(
256
,
3
))
x
=
keras
.
layers
.
Reshape
(
target_shape
=
(
8
,
32
,
3
))(
data
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
)
# input_shape len is 2, target_shape len is 1
data
=
keras
.
layers
.
Input
(
shape
=
(
2
,
8
))
x
=
keras
.
layers
.
Reshape
(
target_shape
=
(
16
,))(
data
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
,
need_transpose
=
False
)
# input_shape len is 1, target_shape len is 2
data
=
keras
.
layers
.
Input
(
shape
=
(
16
,))
x
=
keras
.
layers
.
Reshape
(
target_shape
=
(
4
,
4
))(
data
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
,
need_transpose
=
False
)
# input_shape len is 2, target_shape len is 2
data
=
keras
.
layers
.
Input
(
shape
=
(
2
,
8
))
x
=
keras
.
layers
.
Reshape
(
target_shape
=
(
4
,
4
))(
data
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
,
need_transpose
=
False
)
def
test_forward_crop
():
...
...
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