Skip to content

Commit cb5739b

Browse files
committed
Fixed Keras Integ test
1 parent 029123b commit cb5739b

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

tests/data/cifar_10/source/keras_cnn_cifar_10.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,12 @@
1010
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
1111
# ANY KIND, either express or implied. See the License for the specific
1212
# language governing permissions and limitations under the License.
13-
from __future__ import absolute_import
14-
from __future__ import division
15-
from __future__ import print_function
16-
17-
import os
13+
from __future__ import absolute_import, division, print_function
1814

1915
import tensorflow as tf
20-
from tensorflow.python.keras.layers import InputLayer, Conv2D, Activation, MaxPooling2D, Dropout, Flatten, Dense
16+
from tensorflow.python.keras.layers import Activation, Conv2D, Dense, Dropout, Flatten, MaxPooling2D
2117
from tensorflow.python.keras.models import Sequential
22-
from tensorflow.python.keras.optimizers import RMSprop
23-
from tensorflow.python.saved_model.signature_constants import PREDICT_INPUTS
18+
from tensorflow.python.training.rmsprop import RMSPropOptimizer
2419

2520
HEIGHT = 32
2621
WIDTH = 32
@@ -29,7 +24,7 @@
2924
NUM_DATA_BATCHES = 5
3025
NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = 10000 * NUM_DATA_BATCHES
3126
BATCH_SIZE = 128
32-
INPUT_TENSOR_NAME = PREDICT_INPUTS
27+
INPUT_TENSOR_NAME = 'inputs_input' # needs to match the name of the first layer + "_input"
3328

3429

3530
def keras_model_fn(hyperparameters):
@@ -43,10 +38,7 @@ def keras_model_fn(hyperparameters):
4338
"""
4439
model = Sequential()
4540

46-
# TensorFlow Serving default prediction input tensor name is PREDICT_INPUTS.
47-
# We must conform to this naming scheme.
48-
model.add(InputLayer(input_shape=(HEIGHT, WIDTH, DEPTH), name=PREDICT_INPUTS))
49-
model.add(Conv2D(32, (3, 3), padding='same'))
41+
model.add(Conv2D(32, (3, 3), padding='same', name='inputs', input_shape=(HEIGHT, WIDTH, DEPTH)))
5042
model.add(Activation('relu'))
5143
model.add(Conv2D(32, (3, 3)))
5244
model.add(Activation('relu'))
@@ -67,19 +59,17 @@ def keras_model_fn(hyperparameters):
6759
model.add(Dense(NUM_CLASSES))
6860
model.add(Activation('softmax'))
6961

70-
_model = tf.keras.Model(inputs=model.input, outputs=model.output)
71-
72-
opt = RMSprop(lr=hyperparameters['learning_rate'], decay=hyperparameters['decay'])
62+
opt = RMSPropOptimizer(learning_rate=hyperparameters['learning_rate'], decay=hyperparameters['decay'])
7363

74-
_model.compile(loss='categorical_crossentropy',
75-
optimizer=opt,
76-
metrics=['accuracy'])
64+
model.compile(loss='categorical_crossentropy',
65+
optimizer=opt,
66+
metrics=['accuracy'])
7767

78-
return _model
68+
return model
7969

8070

8171
def serving_input_fn(hyperpameters):
82-
inputs = {PREDICT_INPUTS: tf.placeholder(tf.float32, [None, 32, 32, 3])}
72+
inputs = {INPUT_TENSOR_NAME: tf.placeholder(tf.float32, [None, 32, 32, 3])}
8373
return tf.estimator.export.ServingInputReceiver(inputs, inputs)
8474

8575

tests/integ/test_tf_keras.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def test_keras(sagemaker_session, tf_full_version):
3333
source_dir=script_path,
3434
role='SageMakerRole', sagemaker_session=sagemaker_session,
3535
hyperparameters={'learning_rate': 1e-4, 'decay': 1e-6},
36-
training_steps=500, evaluation_steps=5,
36+
training_steps=50, evaluation_steps=5,
3737
train_instance_count=1, train_instance_type='ml.c4.xlarge',
3838
train_max_run=45 * 60)
3939

0 commit comments

Comments
 (0)