Skip to content

Commit

Permalink
[CI] turn on keras frontend test (apache#309)
Browse files Browse the repository at this point in the history
* [CI] turn on keras frontend test

* fix

* using tensorflow cpu version
  • Loading branch information
Huyuwei authored and tqchen committed May 26, 2018
1 parent cd4142c commit 27b4299
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
4 changes: 1 addition & 3 deletions nnvm/python/nnvm/frontend/keras.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ def _convert_pooling(insym, keras_layer, symtab):
def _convert_upsample(insym, keras_layer, _):
_check_data_format(keras_layer)
upsample_type = type(keras_layer).__name__

if upsample_type == "UpSampling1D":
h = keras_layer.size
params = {'scale': h}
Expand All @@ -291,7 +290,6 @@ def _convert_upsample(insym, keras_layer, _):
params = {'scale': h}
else:
raise TypeError("Unsupported upsampling type : {}".format(upsample_type))

return _sym.upsampling(insym, **params)


Expand Down Expand Up @@ -385,7 +383,7 @@ def _default_skip(insym, keras_layer, _): # pylint: disable=unused-argument
'Subtract' : _convert_merge,
'Multiply' : _convert_merge,
'ZeroPadding2D' : _convert_padding,
'UpSampling2D' : _convert_upsample,
'UpSampling2D' : _convert_upsample,

# 'ZeroPadding1D' : _convert_padding,
# 'AveragePooling1D' : _convert_pooling,
Expand Down
49 changes: 29 additions & 20 deletions nnvm/tests/python/frontend/keras/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def get_tvm_output(x, target, ctx, input_name='data', dtype='float32'):
np.testing.assert_allclose(keras_out, tvm_out, rtol=1e-5, atol=1e-5)


def verify_forward_softrelu():
def test_forward_softrelu():
data = keras.layers.Input(shape=(32,32,3))
x = keras.layers.Activation('softplus')(data)
x = keras.layers.Concatenate()([x, x])
Expand All @@ -48,7 +48,7 @@ def verify_forward_softrelu():
verify_keras_frontend(keras_model)


def verify_forward_leaky_relu():
def test_forward_leaky_relu():
data = keras.layers.Input(shape=(32,32,3))
x = keras.layers.LeakyReLU(alpha=0.3)(data)
x = keras.layers.Add()([x, x])
Expand All @@ -57,7 +57,7 @@ def verify_forward_leaky_relu():
verify_keras_frontend(keras_model)


def verify_forward_dense():
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)
Expand All @@ -66,7 +66,7 @@ def verify_forward_dense():
verify_keras_frontend(keras_model)


def verify_forward_transpose_conv():
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.applications.mobilenet.DepthwiseConv2D(kernel_size=(3,3), padding='same')(x)
Expand All @@ -76,7 +76,7 @@ def verify_forward_transpose_conv():
verify_keras_frontend(keras_model)


def verify_forward_separable_conv():
def test_forward_separable_conv():
data = keras.layers.Input(shape=(32,32,3))
x = keras.layers.SeparableConv2D(filters=10, kernel_size=(3,3),
padding='same', activation='relu')(data)
Expand All @@ -87,31 +87,40 @@ def verify_forward_separable_conv():
verify_keras_frontend(keras_model)


def verify_forward_vgg16():
keras_model = keras.applications.vgg16.VGG16(include_top=True, weights='imagenet',
def test_forward_upsample():
data = keras.layers.Input(shape=(32,32,3))
x = keras.layers.UpSampling2D(size=(3,3))(data)
x = keras.layers.GlobalAveragePooling2D()(x)
keras_model = keras.models.Model(data, x)
verify_keras_frontend(keras_model)


def test_forward_vgg16():
keras_model = keras.applications.vgg16.VGG16(include_top=True, weights=None,
input_shape=(224,224,3), classes=1000)
verify_keras_frontend(keras_model)


def verify_forward_xception():
keras_model = keras.applications.xception.Xception(include_top=True, weights='imagenet',
def test_forward_xception():
keras_model = keras.applications.xception.Xception(include_top=True, weights=None,
input_shape=(299,299,3), classes=1000)
verify_keras_frontend(keras_model)


def verify_forward_resnet50():
keras_model = keras.applications.resnet50.ResNet50(include_top=True, weights='imagenet',
def test_forward_resnet50():
keras_model = keras.applications.resnet50.ResNet50(include_top=True, weights=None,
input_shape=(224,224,3), classes=1000)
verify_keras_frontend(keras_model)


if __name__ == '__main__':
verify_forward_softrelu()
verify_forward_leaky_relu()
verify_forward_dense()
verify_forward_transpose_conv()
verify_forward_separable_conv()

verify_forward_vgg16()
verify_forward_xception()
verify_forward_resnet50()
test_forward_softrelu()
test_forward_leaky_relu()
test_forward_dense()
test_forward_transpose_conv()
test_forward_separable_conv()
test_forward_upsample()

test_forward_vgg16()
test_forward_xception()
test_forward_resnet50()
3 changes: 3 additions & 0 deletions nnvm/tests/scripts/task_frontend_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ python -m nose -v tests/python/frontend/onnx || exit -1

echo "Running MXNet frontend test..."
python -m nose -v tests/python/frontend/mxnet || exit -1

echo "Running Keras frontend test..."
python -m nose -v tests/python/frontend/keras || exit -1

0 comments on commit 27b4299

Please sign in to comment.