Commit d626eab8 by Yuwei Hu Committed by Tianqi Chen

[CI] turn on keras frontend test (#309)

* [CI] turn on keras frontend test

* fix

* using tensorflow cpu version
parent 2374852e
...@@ -273,7 +273,6 @@ def _convert_pooling(insym, keras_layer, symtab): ...@@ -273,7 +273,6 @@ def _convert_pooling(insym, keras_layer, symtab):
def _convert_upsample(insym, keras_layer, _): def _convert_upsample(insym, keras_layer, _):
_check_data_format(keras_layer) _check_data_format(keras_layer)
upsample_type = type(keras_layer).__name__ upsample_type = type(keras_layer).__name__
if upsample_type == "UpSampling1D": if upsample_type == "UpSampling1D":
h = keras_layer.size h = keras_layer.size
params = {'scale': h} params = {'scale': h}
...@@ -291,7 +290,6 @@ def _convert_upsample(insym, keras_layer, _): ...@@ -291,7 +290,6 @@ def _convert_upsample(insym, keras_layer, _):
params = {'scale': h} params = {'scale': h}
else: else:
raise TypeError("Unsupported upsampling type : {}".format(upsample_type)) raise TypeError("Unsupported upsampling type : {}".format(upsample_type))
return _sym.upsampling(insym, **params) return _sym.upsampling(insym, **params)
...@@ -385,7 +383,7 @@ _convert_map = { ...@@ -385,7 +383,7 @@ _convert_map = {
'Subtract' : _convert_merge, 'Subtract' : _convert_merge,
'Multiply' : _convert_merge, 'Multiply' : _convert_merge,
'ZeroPadding2D' : _convert_padding, 'ZeroPadding2D' : _convert_padding,
'UpSampling2D' : _convert_upsample, 'UpSampling2D' : _convert_upsample,
# 'ZeroPadding1D' : _convert_padding, # 'ZeroPadding1D' : _convert_padding,
# 'AveragePooling1D' : _convert_pooling, # 'AveragePooling1D' : _convert_pooling,
......
...@@ -39,7 +39,7 @@ def verify_keras_frontend(keras_model): ...@@ -39,7 +39,7 @@ def verify_keras_frontend(keras_model):
np.testing.assert_allclose(keras_out, tvm_out, rtol=1e-5, atol=1e-5) 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)) data = keras.layers.Input(shape=(32,32,3))
x = keras.layers.Activation('softplus')(data) x = keras.layers.Activation('softplus')(data)
x = keras.layers.Concatenate()([x, x]) x = keras.layers.Concatenate()([x, x])
...@@ -48,7 +48,7 @@ def verify_forward_softrelu(): ...@@ -48,7 +48,7 @@ def verify_forward_softrelu():
verify_keras_frontend(keras_model) verify_keras_frontend(keras_model)
def verify_forward_leaky_relu(): def test_forward_leaky_relu():
data = keras.layers.Input(shape=(32,32,3)) data = keras.layers.Input(shape=(32,32,3))
x = keras.layers.LeakyReLU(alpha=0.3)(data) x = keras.layers.LeakyReLU(alpha=0.3)(data)
x = keras.layers.Add()([x, x]) x = keras.layers.Add()([x, x])
...@@ -57,7 +57,7 @@ def verify_forward_leaky_relu(): ...@@ -57,7 +57,7 @@ def verify_forward_leaky_relu():
verify_keras_frontend(keras_model) verify_keras_frontend(keras_model)
def verify_forward_dense(): def test_forward_dense():
data = keras.layers.Input(shape=(32,32,3)) data = keras.layers.Input(shape=(32,32,3))
x = keras.layers.MaxPooling2D(pool_size=(2,2))(data) x = keras.layers.MaxPooling2D(pool_size=(2,2))(data)
x = keras.layers.Flatten()(x) x = keras.layers.Flatten()(x)
...@@ -66,7 +66,7 @@ def verify_forward_dense(): ...@@ -66,7 +66,7 @@ def verify_forward_dense():
verify_keras_frontend(keras_model) verify_keras_frontend(keras_model)
def verify_forward_transpose_conv(): def test_forward_transpose_conv():
data = keras.layers.Input(shape=(32,32,3)) 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.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) x = keras.applications.mobilenet.DepthwiseConv2D(kernel_size=(3,3), padding='same')(x)
...@@ -76,7 +76,7 @@ def verify_forward_transpose_conv(): ...@@ -76,7 +76,7 @@ def verify_forward_transpose_conv():
verify_keras_frontend(keras_model) verify_keras_frontend(keras_model)
def verify_forward_separable_conv(): def test_forward_separable_conv():
data = keras.layers.Input(shape=(32,32,3)) data = keras.layers.Input(shape=(32,32,3))
x = keras.layers.SeparableConv2D(filters=10, kernel_size=(3,3), x = keras.layers.SeparableConv2D(filters=10, kernel_size=(3,3),
padding='same', activation='relu')(data) padding='same', activation='relu')(data)
...@@ -87,31 +87,40 @@ def verify_forward_separable_conv(): ...@@ -87,31 +87,40 @@ def verify_forward_separable_conv():
verify_keras_frontend(keras_model) verify_keras_frontend(keras_model)
def verify_forward_vgg16(): def test_forward_upsample():
keras_model = keras.applications.vgg16.VGG16(include_top=True, weights='imagenet', 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) input_shape=(224,224,3), classes=1000)
verify_keras_frontend(keras_model) verify_keras_frontend(keras_model)
def verify_forward_xception(): def test_forward_xception():
keras_model = keras.applications.xception.Xception(include_top=True, weights='imagenet', keras_model = keras.applications.xception.Xception(include_top=True, weights=None,
input_shape=(299,299,3), classes=1000) input_shape=(299,299,3), classes=1000)
verify_keras_frontend(keras_model) verify_keras_frontend(keras_model)
def verify_forward_resnet50(): def test_forward_resnet50():
keras_model = keras.applications.resnet50.ResNet50(include_top=True, weights='imagenet', keras_model = keras.applications.resnet50.ResNet50(include_top=True, weights=None,
input_shape=(224,224,3), classes=1000) input_shape=(224,224,3), classes=1000)
verify_keras_frontend(keras_model) verify_keras_frontend(keras_model)
if __name__ == '__main__': if __name__ == '__main__':
verify_forward_softrelu() test_forward_softrelu()
verify_forward_leaky_relu() test_forward_leaky_relu()
verify_forward_dense() test_forward_dense()
verify_forward_transpose_conv() test_forward_transpose_conv()
verify_forward_separable_conv() test_forward_separable_conv()
test_forward_upsample()
verify_forward_vgg16()
verify_forward_xception() test_forward_vgg16()
verify_forward_resnet50() test_forward_xception()
test_forward_resnet50()
...@@ -7,3 +7,6 @@ python -m nose -v tests/python/frontend/onnx || exit -1 ...@@ -7,3 +7,6 @@ python -m nose -v tests/python/frontend/onnx || exit -1
echo "Running MXNet frontend test..." echo "Running MXNet frontend test..."
python -m nose -v tests/python/frontend/mxnet || exit -1 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment