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
8f5d3bd2
Commit
8f5d3bd2
authored
Sep 15, 2018
by
Yuwei Hu
Committed by
Tianqi Chen
Sep 15, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Keras] fix weight shape in dilated conv (#1715)
parent
a6724b6e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
31 deletions
+30
-31
nnvm/python/nnvm/frontend/keras.py
+8
-6
nnvm/tests/python/frontend/keras/test_forward.py
+22
-25
No files found.
nnvm/python/nnvm/frontend/keras.py
View file @
8f5d3bd2
...
...
@@ -58,8 +58,10 @@ def _convert_activation(insym, keras_layer, _):
return
_get_elu
(
insym
,
alpha
)
elif
act_type
==
'selu'
:
# Alpha, Gamma values, obtained from https://arxiv.org/abs/1706.02515
alpha
=
keras_layer
.
alpha
if
hasattr
(
keras_layer
,
"alpha"
)
else
1.6732
gamma
=
keras_layer
.
gamma
if
hasattr
(
keras_layer
,
"gamma"
)
else
1.0507
alpha
=
keras_layer
.
alpha
if
hasattr
(
keras_layer
,
"alpha"
)
\
else
1.6732632423543772848170429916717
gamma
=
keras_layer
.
gamma
if
hasattr
(
keras_layer
,
"gamma"
)
\
else
1.0507009873554804934193349852946
return
gamma
*
_get_elu
(
insym
,
alpha
)
elif
act_type
==
'relu6'
:
return
_sym
.
clip
(
insym
,
a_min
=
0
,
a_max
=
6
)
...
...
@@ -155,8 +157,8 @@ def _convert_convolution(insym, keras_layer, symtab):
dilation
=
[
keras_layer
.
dilation_rate
[
0
],
keras_layer
.
dilation_rate
[
1
]]
else
:
dilation
=
[
keras_layer
.
dilation_rate
,
keras_layer
.
dilation_rate
]
kernel_h
=
(
kernel_h
-
1
)
*
dilation
[
0
]
+
1
kernel_w
=
(
kernel_w
-
1
)
*
dilation
[
1
]
+
1
dilated_
kernel_h
=
(
kernel_h
-
1
)
*
dilation
[
0
]
+
1
dilated_
kernel_w
=
(
kernel_w
-
1
)
*
dilation
[
1
]
+
1
stride_h
,
stride_w
=
keras_layer
.
strides
params
=
{
'weight'
:
symtab
.
new_const
(
weight
),
'kernel_size'
:
[
kernel_h
,
kernel_w
],
...
...
@@ -178,8 +180,8 @@ def _convert_convolution(insym, keras_layer, symtab):
elif
keras_layer
.
padding
==
'same'
:
in_h
=
keras_layer
.
input_shape
[
1
]
in_w
=
keras_layer
.
input_shape
[
2
]
pad_t
,
pad_b
=
_get_pad_pair
(
in_h
,
kernel_h
,
stride_h
)
pad_l
,
pad_r
=
_get_pad_pair
(
in_w
,
kernel_w
,
stride_w
)
pad_t
,
pad_b
=
_get_pad_pair
(
in_h
,
dilated_
kernel_h
,
stride_h
)
pad_l
,
pad_r
=
_get_pad_pair
(
in_w
,
dilated_
kernel_w
,
stride_w
)
if
pad_t
==
pad_b
and
pad_l
==
pad_r
:
params
[
'padding'
]
=
(
pad_t
,
pad_l
)
else
:
...
...
nnvm/tests/python/frontend/keras/test_forward.py
View file @
8f5d3bd2
...
...
@@ -73,10 +73,10 @@ def test_forward_elemwise_add():
keras_model
=
keras
.
models
.
Model
(
data
,
y
)
verify_keras_frontend
(
keras_model
)
def
test_forward_dense
():
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
3
))
x
=
keras
.
layers
.
MaxPooling2D
(
pool_size
=
(
2
,
2
))(
data
)
x
=
keras
.
layers
.
Flatten
()(
x
)
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
1
))
x
=
keras
.
layers
.
Flatten
()(
data
)
x
=
keras
.
layers
.
Dropout
(
0.5
)(
x
)
x
=
keras
.
layers
.
Dense
(
10
,
activation
=
'relu'
,
kernel_initializer
=
'uniform'
)(
x
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
...
...
@@ -84,7 +84,7 @@ def test_forward_dense():
def
test_forward_pool
():
data
=
keras
.
layers
.
Input
(
shape
=
(
2
,
2
,
1
))
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
3
2
,
1
))
# maxpool
x
=
keras
.
layers
.
MaxPooling2D
((
3
,
3
),
strides
=
(
1
,
1
),
padding
=
'same'
)(
data
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
...
...
@@ -95,25 +95,20 @@ def test_forward_pool():
verify_keras_frontend
(
keras_model
)
def
test_forward_transpose_conv
():
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
3
))
x
=
keras
.
layers
.
Conv2D
(
filters
=
10
,
kernel_size
=
(
3
,
3
),
strides
=
(
2
,
2
),
padding
=
'same'
)(
data
)
x
=
keras
.
layers
.
DepthwiseConv2D
(
kernel_size
=
(
3
,
3
),
padding
=
'same'
)(
x
)
x
=
keras
.
layers
.
Conv2DTranspose
(
filters
=
64
,
kernel_size
=
(
3
,
3
),
padding
=
'valid'
)(
x
)
x
=
keras
.
layers
.
GlobalMaxPooling2D
()(
x
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
)
def
test_forward_separable_conv
():
def
test_forward_conv
():
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
3
))
x
=
keras
.
layers
.
SeparableConv2D
(
filters
=
10
,
kernel_size
=
(
3
,
3
),
padding
=
'same'
,
activation
=
'relu'
)(
data
)
x
=
keras
.
layers
.
BatchNormalization
(
scale
=
True
,
center
=
False
,
beta_initializer
=
'uniform'
,
gamma_initializer
=
'uniform'
)(
x
)
x
=
keras
.
layers
.
GlobalAveragePooling2D
()(
x
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
)
conv_funcs
=
[
keras
.
layers
.
Conv2D
(
filters
=
10
,
kernel_size
=
(
3
,
3
),
strides
=
(
2
,
2
),
padding
=
'same'
),
keras
.
layers
.
Conv2D
(
filters
=
10
,
kernel_size
=
(
3
,
3
),
dilation_rate
=
(
2
,
2
),
padding
=
'same'
),
keras
.
layers
.
DepthwiseConv2D
(
kernel_size
=
(
3
,
3
),
padding
=
'same'
),
keras
.
layers
.
Conv2DTranspose
(
filters
=
10
,
kernel_size
=
(
3
,
3
),
padding
=
'valid'
),
keras
.
layers
.
SeparableConv2D
(
filters
=
10
,
kernel_size
=
(
3
,
3
),
padding
=
'same'
)]
for
conv_func
in
conv_funcs
:
x
=
conv_func
(
data
)
x
=
keras
.
layers
.
GlobalAveragePooling2D
()(
x
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
)
def
test_forward_upsample
():
...
...
@@ -123,6 +118,7 @@ def test_forward_upsample():
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
)
def
test_forward_reshape
():
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
3
))
x
=
keras
.
layers
.
Reshape
(
target_shape
=
(
32
,
32
,
3
))(
data
)
...
...
@@ -168,6 +164,7 @@ def test_forward_mobilenet():
input_shape
=
(
224
,
224
,
3
),
classes
=
1000
)
verify_keras_frontend
(
keras_model
)
def
test_forward_activations
():
data
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
3
))
weights
=
np
.
random
.
rand
(
1
,
32
,
32
,
3
)
...
...
@@ -187,10 +184,11 @@ def test_forward_activations():
keras
.
layers
.
Activation
(
'linear'
)]
for
act_func
in
act_funcs
:
x
=
act_func
(
data
)
x
=
keras
.
layers
.
Global
Max
Pooling2D
()(
x
)
x
=
keras
.
layers
.
Global
Average
Pooling2D
()(
x
)
keras_model
=
keras
.
models
.
Model
(
data
,
x
)
verify_keras_frontend
(
keras_model
)
def
test_forward_multi_inputs
():
data1
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
3
))
data2
=
keras
.
layers
.
Input
(
shape
=
(
32
,
32
,
3
))
...
...
@@ -239,8 +237,7 @@ if __name__ == '__main__':
test_forward_activations
()
test_forward_dense
()
test_forward_pool
()
test_forward_transpose_conv
()
test_forward_separable_conv
()
test_forward_conv
()
test_forward_upsample
()
test_forward_reshape
()
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