Skip to content

Update TF version to 1.11 #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"source": [ "source": [
"estimator = TensorFlow(entry_point='mnist.py',\n", "estimator = TensorFlow(entry_point='mnist.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" training_steps=1000, \n", " training_steps=1000, \n",
" evaluation_steps=100,\n", " evaluation_steps=100,\n",
" train_instance_count=1,\n", " train_instance_count=1,\n",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@
"\n", "\n",
"abalone_estimator = TensorFlow(entry_point='abalone.py',\n", "abalone_estimator = TensorFlow(entry_point='abalone.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" training_steps= 100, \n", " training_steps= 100, \n",
" evaluation_steps= 100,\n", " evaluation_steps= 100,\n",
" hyperparameters={'learning_rate': 0.001},\n", " hyperparameters={'learning_rate': 0.001},\n",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@
"\n", "\n",
"abalone_estimator = TensorFlow(entry_point='abalone.py',\n", "abalone_estimator = TensorFlow(entry_point='abalone.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" training_steps= 100, \n", " training_steps= 100, \n",
" evaluation_steps= 100,\n", " evaluation_steps= 100,\n",
" hyperparameters={'learning_rate': 0.001},\n", " hyperparameters={'learning_rate': 0.001},\n",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"\n", "\n",
"mnist_estimator = TensorFlow(entry_point='mnist.py',\n", "mnist_estimator = TensorFlow(entry_point='mnist.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" training_steps=1000, \n", " training_steps=1000, \n",
" evaluation_steps=100,\n", " evaluation_steps=100,\n",
" train_instance_count=2,\n", " train_instance_count=2,\n",
Expand Down Expand Up @@ -233,11 +233,11 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"import json\n", "import json\n",
"from urllib.parse import urlparse\n", "from six.moves.urllib import parse\n",
"\n", "\n",
"import boto3\n", "import boto3\n",
"\n", "\n",
"parsed_url = urlparse(transformer.output_path)\n", "parsed_url = parse.urlparse(transformer.output_path)\n",
"bucket_name = parsed_url.netloc\n", "bucket_name = parsed_url.netloc\n",
"prefix = parsed_url.path[1:]\n", "prefix = parsed_url.path[1:]\n",
"\n", "\n",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"\n", "\n",
"mnist_estimator = TensorFlow(entry_point='mnist.py',\n", "mnist_estimator = TensorFlow(entry_point='mnist.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" training_steps=1000, \n", " training_steps=1000, \n",
" evaluation_steps=100,\n", " evaluation_steps=100,\n",
" train_instance_count=2,\n", " train_instance_count=2,\n",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@
"\n", "\n",
"mnist_estimator = TensorFlow(entry_point='mnist.py',\n", "mnist_estimator = TensorFlow(entry_point='mnist.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" training_steps=10, \n", " training_steps=10, \n",
" evaluation_steps=10,\n", " evaluation_steps=10,\n",
" train_instance_count=2,\n", " train_instance_count=2,\n",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@
"\n", "\n",
"iris_estimator = TensorFlow(entry_point='iris_dnn_classifier.py',\n", "iris_estimator = TensorFlow(entry_point='iris_dnn_classifier.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" output_path=model_artifacts_location,\n", " output_path=model_artifacts_location,\n",
" code_location=custom_code_upload_location,\n", " code_location=custom_code_upload_location,\n",
" train_instance_count=1,\n", " train_instance_count=1,\n",
Expand Down
20 changes: 8 additions & 12 deletions sagemaker-python-sdk/tensorflow_keras_cifar10/cifar10_cnn.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
import os import os


import tensorflow as tf import tensorflow as tf
from tensorflow.python.keras.layers import InputLayer, Conv2D, Activation, MaxPooling2D, Dropout, Flatten, Dense from tensorflow.python.keras.layers import Activation, Conv2D, Dense, Dropout, Flatten, MaxPooling2D
from tensorflow.python.keras.models import Sequential from tensorflow.python.keras.models import Sequential
from tensorflow.python.keras.optimizers import RMSprop
from tensorflow.python.saved_model.signature_constants import PREDICT_INPUTS from tensorflow.python.saved_model.signature_constants import PREDICT_INPUTS
from tensorflow.python.training.rmsprop import RMSPropOptimizer


HEIGHT = 32 HEIGHT = 32
WIDTH = 32 WIDTH = 32
Expand All @@ -30,6 +30,7 @@
NUM_DATA_BATCHES = 5 NUM_DATA_BATCHES = 5
NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = 10000 * NUM_DATA_BATCHES NUM_EXAMPLES_PER_EPOCH_FOR_TRAIN = 10000 * NUM_DATA_BATCHES
BATCH_SIZE = 128 BATCH_SIZE = 128
INPUT_TENSOR_NAME = 'inputs_input' # needs to match the name of the first layer + "_input"




def keras_model_fn(hyperparameters): def keras_model_fn(hyperparameters):
Expand All @@ -44,10 +45,7 @@ def keras_model_fn(hyperparameters):
""" """
model = Sequential() model = Sequential()


# TensorFlow Serving default prediction input tensor name is PREDICT_INPUTS. model.add(Conv2D(32, (3, 3), padding='same', name='inputs', input_shape=(HEIGHT, WIDTH, DEPTH)))
# We must conform to this naming scheme.
model.add(InputLayer(input_shape=(HEIGHT, WIDTH, DEPTH), name=PREDICT_INPUTS))
model.add(Conv2D(32, (3, 3), padding='same'))
model.add(Activation('relu')) model.add(Activation('relu'))
model.add(Conv2D(32, (3, 3))) model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu')) model.add(Activation('relu'))
Expand All @@ -68,15 +66,13 @@ def keras_model_fn(hyperparameters):
model.add(Dense(NUM_CLASSES)) model.add(Dense(NUM_CLASSES))
model.add(Activation('softmax')) model.add(Activation('softmax'))


_model = tf.keras.Model(inputs=model.input, outputs=model.output) opt = RMSPropOptimizer(learning_rate=hyperparameters['learning_rate'], decay=hyperparameters['decay'])


opt = RMSprop(lr=hyperparameters['learning_rate'], decay=hyperparameters['decay']) model.compile(loss='categorical_crossentropy',

_model.compile(loss='categorical_crossentropy',
optimizer=opt, optimizer=opt,
metrics=['accuracy']) metrics=['accuracy'])


return _model return model




def serving_input_fn(hyperparameters): def serving_input_fn(hyperparameters):
Expand Down Expand Up @@ -147,7 +143,7 @@ def _input(mode, batch_size, data_dir):
images, labels = iterator.get_next() images, labels = iterator.get_next()


# We must use the default input tensor name PREDICT_INPUTS # We must use the default input tensor name PREDICT_INPUTS
return {PREDICT_INPUTS: images}, labels return {INPUT_TENSOR_NAME: images}, labels




def _train_preprocess_fn(image, label): def _train_preprocess_fn(image, label):
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -123,10 +123,18 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"def keras_model_fn(hyperparameters):\n", "def keras_model_fn(hyperparameters):\n",
" \"\"\"keras_model_fn receives hyperparameters from the training job and returns a compiled keras model.\n",
" The model will be transformed into a TensorFlow Estimator before training and it will be saved in a \n",
" TensorFlow Serving SavedModel at the end of training.\n",
"\n",
" Args:\n",
" hyperparameters: The hyperparameters passed to the SageMaker TrainingJob that runs your TensorFlow \n",
" training script.\n",
" Returns: A compiled Keras model\n",
" \"\"\"\n",
" model = Sequential()\n", " model = Sequential()\n",
"\n", "\n",
" model.add(InputLayer(input_shape=(HEIGHT, WIDTH, DEPTH), name=PREDICT_INPUTS))\n", " model.add(Conv2D(32, (3, 3), padding='same', name='inputs', input_shape=(HEIGHT, WIDTH, DEPTH)))\n",
" model.add(Conv2D(32, (3, 3), padding='same'))\n",
" model.add(Activation('relu'))\n", " model.add(Activation('relu'))\n",
" model.add(Conv2D(32, (3, 3)))\n", " model.add(Conv2D(32, (3, 3)))\n",
" model.add(Activation('relu'))\n", " model.add(Activation('relu'))\n",
Expand All @@ -147,15 +155,13 @@
" model.add(Dense(NUM_CLASSES))\n", " model.add(Dense(NUM_CLASSES))\n",
" model.add(Activation('softmax'))\n", " model.add(Activation('softmax'))\n",
" \n", " \n",
" _model = tf.keras.Model(inputs=model.input, outputs=model.output)\n", " opt = RMSPropOptimizer(learning_rate=hyperparameters['learning_rate'], decay=hyperparameters['decay'])\n",
"\n",
" opt = RMSprop(lr=hyperparameters['learning_rate'], decay=hyperparameters['decay'])\n",
"\n", "\n",
" _model.compile(loss='categorical_crossentropy',\n", " model.compile(loss='categorical_crossentropy',\n",
" optimizer=opt,\n", " optimizer=opt,\n",
" metrics=['accuracy'])\n", " metrics=['accuracy'])\n",
"\n", "\n",
" return _model" " return model"
] ]
}, },
{ {
Expand Down Expand Up @@ -216,7 +222,7 @@
"\n", "\n",
"estimator = TensorFlow(entry_point='cifar10_cnn.py',\n", "estimator = TensorFlow(entry_point='cifar10_cnn.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" hyperparameters={'learning_rate': 1e-4, 'decay':1e-6},\n", " hyperparameters={'learning_rate': 1e-4, 'decay':1e-6},\n",
" training_steps=1000, evaluation_steps=100,\n", " training_steps=1000, evaluation_steps=100,\n",
" train_instance_count=1, train_instance_type='ml.c4.xlarge')\n", " train_instance_count=1, train_instance_type='ml.c4.xlarge')\n",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
"\n", "\n",
"tensorflow = TensorFlow(entry_point='pipemode.py',\n", "tensorflow = TensorFlow(entry_point='pipemode.py',\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" input_mode='Pipe',\n", " input_mode='Pipe',\n",
" output_path=model_artifacts_location,\n", " output_path=model_artifacts_location,\n",
" code_location=custom_code_upload_location,\n", " code_location=custom_code_upload_location,\n",
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"estimator = TensorFlow(entry_point='resnet_cifar_10.py',\n", "estimator = TensorFlow(entry_point='resnet_cifar_10.py',\n",
" source_dir=source_dir,\n", " source_dir=source_dir,\n",
" role=role,\n", " role=role,\n",
" framework_version='1.10.0',\n", " framework_version='1.11.0',\n",
" hyperparameters={'throttle_secs': 30},\n", " hyperparameters={'throttle_secs': 30},\n",
" training_steps=1000, evaluation_steps=100,\n", " training_steps=1000, evaluation_steps=100,\n",
" train_instance_count=2, train_instance_type='ml.c4.xlarge', \n", " train_instance_count=2, train_instance_type='ml.c4.xlarge', \n",
Expand Down