-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
TF IRIS BYOM is ready. #129
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,12 +30,12 @@ | |
"\n", | ||
"This notebook can be compared to [Iris classification example notebook](../tensorflow_iris_dnn_classifier_using_estimators/tensorflow_iris_dnn_classifier_using_estimators.ipynb) in terms of its functionality. We will do the same classification task, but we will train the same network locally in the box from where this notebook is being run. We then setup a real-time hosted endpoint in SageMaker.\n", | ||
"\n", | ||
"Consider the following model definition for IRIS classification. This mdoe uses the ``tensorflow.estimator.DNNClassifier`` which is a pre-defined enstimator module for its model definition. The model definition is the same as the one used in the [Iris classification example notebook](../tensorflow_iris_dnn_classifier_using_estimators/tensorflow_iris_dnn_classifier_using_estimators.ipynb)\n", | ||
"Consider the following model definition for IRIS classification. This mode uses the ``tensorflow.estimator.DNNClassifier`` which is a pre-defined estimator module for its model definition. The model definition is the same as the one used in the [Iris classification example notebook](../tensorflow_iris_dnn_classifier_using_estimators/tensorflow_iris_dnn_classifier_using_estimators.ipynb)\n", | ||
"\n", | ||
"## Prequisites and Preprocessing\n", | ||
"### Permissions and environment variables\n", | ||
"\n", | ||
"Here we set up the linkage and authentication to AWS services. In this notebook we only need the roles used to give learning and hosting access to your data. The Sagemaker SDK will use S3 defualt buckets when needed. Supply the role in the variable below." | ||
"Here we set up the linkage and authentication to AWS services. In this notebook we only need the roles used to give learning and hosting access to your data. The Sagemaker SDK will use S3 defualt buckets when needed. If the ``get_execution_role`` does not return a role with the appropriate permissions, you'll need to specify an IAM role arn that does." | ||
] | ||
}, | ||
{ | ||
|
@@ -68,47 +68,7 @@ | |
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import numpy as np\n", | ||
"import tensorflow as tf\n", | ||
"\n", | ||
"INPUT_TENSOR_NAME = 'x'\n", | ||
"\n", | ||
"\n", | ||
"def estimator_fn(run_config, params):\n", | ||
" feature_columns = [tf.feature_column.numeric_column(INPUT_TENSOR_NAME, shape=[4])]\n", | ||
" return tf.estimator.DNNClassifier(feature_columns=feature_columns,\n", | ||
" hidden_units=[10, 20, 10],\n", | ||
" n_classes=3,\n", | ||
" config=run_config)\n", | ||
"\n", | ||
"\n", | ||
"def serving_input_fn():\n", | ||
" feature_spec = {INPUT_TENSOR_NAME: tf.FixedLenFeature(dtype=tf.float32, shape=[4])}\n", | ||
" return tf.estimator.export.build_parsing_serving_input_receiver_fn(feature_spec)()\n", | ||
"\n", | ||
"\n", | ||
"def train_input_fn(training_dir, params):\n", | ||
" \"\"\"Returns input function that would feed the model during training\"\"\"\n", | ||
" return _generate_input_fn(training_dir, 'iris_training.csv')\n", | ||
"\n", | ||
"\n", | ||
"def eval_input_fn(training_dir, params):\n", | ||
" \"\"\"Returns input function that would feed the model during evaluation\"\"\"\n", | ||
" return _generate_input_fn(training_dir, 'iris_test.csv')\n", | ||
"\n", | ||
"\n", | ||
"def _generate_input_fn(training_dir, training_filename):\n", | ||
" training_set = tf.contrib.learn.datasets.base.load_csv_with_header(\n", | ||
" filename=os.path.join(training_dir, training_filename),\n", | ||
" target_dtype=np.int,\n", | ||
" features_dtype=np.float32)\n", | ||
"\n", | ||
" return tf.estimator.inputs.numpy_input_fn(\n", | ||
" x={INPUT_TENSOR_NAME: np.array(training_set.data)},\n", | ||
" y=np.array(training_set.target),\n", | ||
" num_epochs=None,\n", | ||
" shuffle=True)" | ||
"!cat iris_dnn_classifier.py" | ||
] | ||
}, | ||
{ | ||
|
@@ -124,6 +84,7 @@ | |
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from iris_dnn_classifier import estimator_fn\n", | ||
"classifier = estimator_fn(run_config = None, params = None)" | ||
] | ||
}, | ||
|
@@ -180,6 +141,7 @@ | |
}, | ||
"outputs": [], | ||
"source": [ | ||
"from iris_dnn_classifier import train_input_fn\n", | ||
"train_func = train_input_fn('.', params = None)" | ||
] | ||
}, | ||
|
@@ -220,8 +182,11 @@ | |
"metadata": {}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In markdown above:
|
||
"outputs": [], | ||
"source": [ | ||
"from iris_dnn_classifier import serving_input_fn\n", | ||
"\n", | ||
"exported_model = classifier.export_savedmodel(export_dir_base = 'export/Servo/', \n", | ||
" serving_input_receiver_fn = serving_input_fn)\n", | ||
"\n", | ||
"print (exported_model)\n", | ||
"import tarfile\n", | ||
"with tarfile.open('model.tar.gz', mode='w:gz') as archive:\n", | ||
|
@@ -278,7 +243,7 @@ | |
"source": [ | ||
"### Create endpoint\n", | ||
"\n", | ||
"Now the model is ready to be deployed at a SageMaker endpoint. We can use the ``sagemaker.mxnet.model.TensorFlowModel.deploy`` method to do this. Unless you have created or prefer other instances, we recommend using 1 ``'ml.c4.xlarge'`` instance for this training. These are supplied as arguments. " | ||
"Now the model is ready to be deployed at a SageMaker endpoint. We can use the ``sagemaker.mxnet.model.TensorFlowModel.deploy`` method to do this. Unless you have created or prefer other instances, we recommend using 1 ``'ml.c4.xlarge'`` instance for this example. These are supplied as arguments. " | ||
] | ||
}, | ||
{ | ||
|
@@ -298,7 +263,7 @@ | |
"source": [ | ||
"### Validate the endpoint for use\n", | ||
"\n", | ||
"We can now use this endpoint to classify. Run a sample prediction on a sample to ensure that it works. Expect result ``1`` for this particular sample." | ||
"We can now use this endpoint to classify. Run an example prediction on a sample to ensure that it works." | ||
] | ||
}, | ||
{ | ||
|
@@ -335,40 +300,38 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"If you do not want continied use of the endpoint, you can remove it. Remember, open endpoints are charged. If this is a simple test or practice, it is recommended to delete them." | ||
"If you do not want to continue using the endpoint, you can remove it. Remember, open endpoints are charged. If this is a simple test or practice, it is recommended to delete them." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the above:
|
||
"collapsed": true | ||
}, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# sagemaker.Session().delete_endpoint(predictor.endpoint)" | ||
"sagemaker.Session().delete_endpoint(predictor.endpoint)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.", | ||
"kernelspec": { | ||
"display_name": "Environment (conda_tensorflow_p36)", | ||
"display_name": "conda_tensorflow_p27", | ||
"language": "python", | ||
"name": "conda_tensorflow_p36" | ||
"name": "conda_tensorflow_p27" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
"version": 2 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.3" | ||
} | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.11" | ||
}, | ||
"notice": "Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the \"License\"). You may not use this file except in compliance with the License. A copy of the License is located at http://aws.amazon.com/apache2.0/ or in the \"license\" file accompanying this file. This file is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License." | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typos in markdown above... "mdoe" instead of "mode". And "enstimator" should be "estimator". Also instead of "Supply the role in the variable below", let's go with "If the get_execution_role() function does not return a role with the appropriate permissions, you'll need to specify an IAM role arn that does."