Skip to content

Commit 4bc36bb

Browse files
committed
abalone
1 parent b0636f8 commit 4bc36bb

File tree

10 files changed

+177
-176
lines changed

10 files changed

+177
-176
lines changed

sagemaker-python-sdk/1P_kmeans_highlevel/kmeans_mnist.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
},
5656
"outputs": [],
5757
"source": [
58-
"role='<your SageMaker execution role here>'\n",
58+
"from sagemaker import get_execution_role\n",
59+
"\n",
60+
"role = get_execution_role()\n",
5961
"bucket='<bucket-name>'"
6062
]
6163
},

sagemaker-python-sdk/1P_kmeans_lowlevel/kmeans_mnist_lowlevel.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@
5555
},
5656
"outputs": [],
5757
"source": [
58-
"role='<your SageMaker execution role here>'\n",
58+
"from sagemaker import get_execution_role\n",
59+
"\n",
60+
"role = get_execution_role()\n",
5961
"bucket='<bucket-name>'"
6062
]
6163
},

sagemaker-python-sdk/mxnet_gluon_cifar10/cifar10.ipynb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@
2525
"import sagemaker\n",
2626
"from sagemaker.mxnet import MXNet\n",
2727
"from mxnet import gluon\n",
28+
"from sagemaker import get_execution_role\n",
2829
"\n",
2930
"sagemaker_session = sagemaker.Session()\n",
3031
"\n",
31-
"# Replace with a role that gives SageMaker access to S3 and CloudWatch\n",
32-
"# see 1-Creating_a_role_allowing_SageMaker_to_access_S3_CloudWatch_ECR.ipynb\n",
33-
"role='SageMakerRole'"
32+
"role = get_execution_role()"
3433
]
3534
},
3635
{

sagemaker-python-sdk/mxnet_gluon_mnist/mnist_with_gluon.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
"import sagemaker\n",
2222
"from sagemaker.mxnet import MXNet\n",
2323
"from mxnet import gluon\n",
24+
"from sagemaker import get_execution_role\n",
2425
"\n",
2526
"sagemaker_session = sagemaker.Session()\n",
2627
"\n",
27-
"# Replace with a role that gives SageMaker access to S3 and CloudWatch\n",
28-
"role='SageMakerRole'"
28+
"role = get_execution_role()"
2929
]
3030
},
3131
{

sagemaker-python-sdk/mxnet_mnist/mxnet_mnist.ipynb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@
1818
},
1919
"outputs": [],
2020
"source": [
21+
"from sagemaker import get_execution_role\n",
22+
"\n",
2123
"#Bucket location to save your custom code in tar.gz format.\n",
2224
"custom_code_upload_location = 's3://<bucket-name>/customcode/mxnet_mnist'\n",
2325
"#Bucket location where results of model training are saved.\n",
2426
"model_artifacts_location = 's3://<bucket-name>/artifacts'\n",
25-
"role='<your SageMaker execution role here>'"
27+
"\n",
28+
"role = get_execution_role()"
2629
]
2730
},
2831
{

sagemaker-python-sdk/tensorflow_abalone_age_predictor_using_keras/tensorflow_abalone_age_predictor_using_keras.ipynb

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
"source": [
77
"# Creating Estimators in tf.estimator with Keras\n",
88
"\n",
9-
"If you are getting started using SageMaker, check [iris-dnn-classifier-using-estimators/tutorial.ipynb](iris-dnn-classifier-using-estimators/tutorial.ipynb) first.\n",
10-
"\n",
11-
"This tutorial covers how to create your own `Estimator` using the building\n",
12-
"blocks provided in `tf.estimator`, which will predict the ages of\n",
9+
"This tutorial covers how to create your own training script using the building\n",
10+
"blocks provided in `tf.keras`, which will predict the ages of\n",
1311
"[abalones](https://en.wikipedia.org/wiki/Abalone) based on their physical\n",
1412
"measurements. You'll learn how to do the following:\n",
1513
"\n",
@@ -54,7 +52,7 @@
5452
"cell_type": "markdown",
5553
"metadata": {},
5654
"source": [
57-
"## Let's start by setting up the environment."
55+
"### Set up the environment"
5856
]
5957
},
6058
{
@@ -67,18 +65,18 @@
6765
"source": [
6866
"import os\n",
6967
"import sagemaker\n",
68+
"from sagemaker import get_execution_role\n",
7069
"\n",
7170
"sagemaker_session = sagemaker.Session()\n",
7271
"\n",
73-
"# Replace with a role (either name or full arn) that gives SageMaker access to S3 and cloudwatch\n",
74-
"role='SageMakerRole'"
72+
"role = get_execution_role()"
7573
]
7674
},
7775
{
7876
"cell_type": "markdown",
7977
"metadata": {},
8078
"source": [
81-
"## Uploading the data"
79+
"### Upload the data to a S3 bucket"
8280
]
8381
},
8482
{
@@ -96,7 +94,15 @@
9694
"cell_type": "markdown",
9795
"metadata": {},
9896
"source": [
99-
"# Complete source code"
97+
"**sagemaker_session.upload_data** will upload the abalone dataset from your machine to a bucket named **sagemaker-{your aws account number}**, if you don't have this bucket yet, sagemaker_session will create it for you."
98+
]
99+
},
100+
{
101+
"cell_type": "markdown",
102+
"metadata": {},
103+
"source": [
104+
"## Complete source code\n",
105+
"Here is the full code for the network model:"
100106
]
101107
},
102108
{
@@ -337,11 +343,13 @@
337343
" # Calculate loss using mean squared error\n",
338344
" loss = tf.losses.mean_squared_error(labels, predictions)\n",
339345
" ...\n",
340-
"```\n",
341-
"\n",
342-
"See the [tf.losses$API guide](https://www.tensorflow.org/api_docs/python/tf/losses) for a\n",
343-
"full list of loss functions and more details on supported arguments and usage.\n",
344-
"\n",
346+
"```"
347+
]
348+
},
349+
{
350+
"cell_type": "markdown",
351+
"metadata": {},
352+
"source": [
345353
"Supplementary metrics for evaluation can be added to an `eval_metric_ops` dict.\n",
346354
"The following code defines an `rmse` metric, which calculates the root mean\n",
347355
"squared error for the model predictions. Note that the `labels` tensor is cast\n",
@@ -375,9 +383,6 @@
375383
" loss=loss, global_step=tf.train.get_global_step())\n",
376384
"```\n",
377385
"\n",
378-
"For a full list of optimizers, and other details, see the\n",
379-
"@{$python/train#optimizers$API guide}.\n",
380-
"\n",
381386
"### The complete abalone `model_fn`\n",
382387
"\n",
383388
"Here's the final, complete `model_fn` for the abalone age predictor. The\n",
@@ -435,8 +440,7 @@
435440
"cell_type": "markdown",
436441
"metadata": {},
437442
"source": [
438-
"# Submitting script for training in SageMaker\n",
439-
"\n",
443+
"# Submitting script for training\n",
440444
"\n",
441445
"We can use the SDK to run our local training script on SageMaker infrastructure.\n",
442446
"\n",
@@ -456,10 +460,12 @@
456460
"from sagemaker.tensorflow import TensorFlow\n",
457461
"\n",
458462
"abalone_estimator = TensorFlow(entry_point='abalone.py',\n",
459-
" role=role,\n",
460-
" hyperparameters={'training_steps': 100, 'learning_rate': 0.001},\n",
461-
" train_instance_count=1,\n",
462-
" train_instance_type='ml.c4.xlarge')\n",
463+
" role=role,\n",
464+
" training_steps= 100, \n",
465+
" evaluation_steps= 100,\n",
466+
" hyperparameters={'learning_rate': 0.001},\n",
467+
" train_instance_count=1,\n",
468+
" train_instance_type='ml.c4.xlarge')\n",
463469
"\n",
464470
"abalone_estimator.fit(inputs)"
465471
]
@@ -470,11 +476,11 @@
470476
"source": [
471477
"`estimator.fit` will deploy a script in a container for training and returs the SageMaker model name using the following arguments:\n",
472478
"\n",
473-
"* `framework=tensorflow`. Tells submit_training that it is a tensorflow container.\n",
474-
"* `script=\"abalone.py\"`. The relative path to the script that will be deployed to the container.\n",
475-
"* `data=\"s3://bucket_name/abalone-estimator-training\"`. The S3 location of the bucket that we uploaded earlier.\n",
476-
"* `role=\"maeve-pullrole\"`. AWS role that gives your account access to SageMaker training and hosting\n",
477-
"* `hyperparameters={'training_steps' : 100}`. Model and training hyperparameters. \n",
479+
"* **`entry_point=\"abalone.py\"`** The path to the script that will be deployed to the container.\n",
480+
"* **`training_steps=100`** The number of training steps of the training job.\n",
481+
"* **`evaluation_steps=100`** The number of evaluation steps of the training job.\n",
482+
"* **`role`**. AWS role that gives your account access to SageMaker training and hosting\n",
483+
"* **`hyperparameters={'learning_rate' : 0.001}`**. Training hyperparameters. \n",
478484
"\n",
479485
"Running the code block above will do the following actions:\n",
480486
"* deploy your script in a container with tensorflow installed\n",
@@ -501,8 +507,7 @@
501507
},
502508
"outputs": [],
503509
"source": [
504-
"abalone_predictor = abalone_estimator.deploy(initial_instance_count=1,\n",
505-
" instance_type='ml.c4.xlarge')"
510+
"abalone_predictor = abalone_estimator.deploy(initial_instance_count=1, instance_type='ml.c4.xlarge')"
506511
]
507512
},
508513
{

0 commit comments

Comments
 (0)