Skip to content

Commit cdf63b0

Browse files
author
Yijie Zhuang
committed
update notebooks with python sdk get_image_url method (aws#2)
1 parent 7a6b883 commit cdf63b0

File tree

14 files changed

+336
-211
lines changed

14 files changed

+336
-211
lines changed

introduction_to_amazon_algorithms/blazingtext_word2vec_text8/blazingtext_word2vec_text8.ipynb

+3-7
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,9 @@
162162
},
163163
"outputs": [],
164164
"source": [
165-
"containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/blazingtext:latest',\n",
166-
" 'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/blazingtext:latest',\n",
167-
" 'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/blazingtext:latest',\n",
168-
" 'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/blazingtext:latest',\n",
169-
" 'ap-northeast-1': '501404015308.dkr.ecr.ap-northeast-1.amazonaws.com/blazingtext:latest',\n",
170-
" 'ap-northeast-2': '306986355934.dkr.ecr.ap-northeast-2.amazonaws.com/blazingtext:latest'}\n",
171-
"container = containers[region_name]\n",
165+
"from sagemaker.amazon.amazon_estimator import get_image_uri\n",
166+
"container = get_image_uri(region_name, 'blazingtext')\n",
167+
"\n",
172168
"print('Using SageMaker BlazingText container: {} ({})'.format(container, region_name))"
173169
]
174170
},

introduction_to_amazon_algorithms/deepar_synthetic/deepar_synthetic.ipynb

+26-17
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@
4040
{
4141
"cell_type": "code",
4242
"execution_count": null,
43-
"metadata": {},
43+
"metadata": {
44+
"collapsed": true
45+
},
4446
"outputs": [],
4547
"source": [
4648
"!conda install -y s3fs"
@@ -49,7 +51,9 @@
4951
{
5052
"cell_type": "code",
5153
"execution_count": null,
52-
"metadata": {},
54+
"metadata": {
55+
"collapsed": true
56+
},
5357
"outputs": [],
5458
"source": [
5559
"import boto3\n",
@@ -101,15 +105,8 @@
101105
},
102106
"outputs": [],
103107
"source": [
104-
"containers = {\n",
105-
" 'us-east-1': '522234722520.dkr.ecr.us-east-1.amazonaws.com/forecasting-deepar:latest',\n",
106-
" 'us-east-2': '566113047672.dkr.ecr.us-east-2.amazonaws.com/forecasting-deepar:latest',\n",
107-
" 'us-west-2': '156387875391.dkr.ecr.us-west-2.amazonaws.com/forecasting-deepar:latest',\n",
108-
" 'eu-west-1': '224300973850.dkr.ecr.eu-west-1.amazonaws.com/forecasting-deepar:latest',\n",
109-
" 'ap-northeast-1': '633353088612.dkr.ecr.ap-northeast-1.amazonaws.com/forecasting-deepar:latest',\n",
110-
" 'ap-northeast-2': '204372634319.dkr.ecr.ap-northeast-2.amazonaws.com/forecasting-deepar:latest'\n",
111-
"}\n",
112-
"image_name = containers[boto3.Session().region_name]"
108+
"from sagemaker.amazon.amazon_estimator import get_image_uri\n",
109+
"image_name = get_image_uri(boto3.Session().region_name, 'forecasting-deepar')"
113110
]
114111
},
115112
{
@@ -209,7 +206,9 @@
209206
{
210207
"cell_type": "code",
211208
"execution_count": null,
212-
"metadata": {},
209+
"metadata": {
210+
"collapsed": true
211+
},
213212
"outputs": [],
214213
"source": [
215214
"time_series[0].plot()\n",
@@ -241,7 +240,9 @@
241240
{
242241
"cell_type": "code",
243242
"execution_count": null,
244-
"metadata": {},
243+
"metadata": {
244+
"collapsed": true
245+
},
245246
"outputs": [],
246247
"source": [
247248
"time_series[0].plot(label='test')\n",
@@ -385,7 +386,9 @@
385386
{
386387
"cell_type": "code",
387388
"execution_count": null,
388-
"metadata": {},
389+
"metadata": {
390+
"collapsed": true
391+
},
389392
"outputs": [],
390393
"source": [
391394
"data_channels = {\n",
@@ -415,7 +418,9 @@
415418
{
416419
"cell_type": "code",
417420
"execution_count": null,
418-
"metadata": {},
421+
"metadata": {
422+
"collapsed": true
423+
},
419424
"outputs": [],
420425
"source": [
421426
"job_name = estimator.latest_training_job.name\n",
@@ -537,7 +542,9 @@
537542
{
538543
"cell_type": "code",
539544
"execution_count": null,
540-
"metadata": {},
545+
"metadata": {
546+
"collapsed": true
547+
},
541548
"outputs": [],
542549
"source": [
543550
"for k in range(len(list_of_df)):\n",
@@ -561,7 +568,9 @@
561568
{
562569
"cell_type": "code",
563570
"execution_count": null,
564-
"metadata": {},
571+
"metadata": {
572+
"collapsed": true
573+
},
565574
"outputs": [],
566575
"source": [
567576
"sagemaker_session.delete_endpoint(endpoint_name)"

introduction_to_amazon_algorithms/factorization_machines_mnist/factorization_machines_mnist.ipynb

+41-19
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"cell_type": "code",
5757
"execution_count": null,
5858
"metadata": {
59+
"collapsed": true,
5960
"isConfigCell": true
6061
},
6162
"outputs": [],
@@ -83,7 +84,9 @@
8384
{
8485
"cell_type": "code",
8586
"execution_count": null,
86-
"metadata": {},
87+
"metadata": {
88+
"collapsed": true
89+
},
8790
"outputs": [],
8891
"source": [
8992
"%%time\n",
@@ -107,7 +110,9 @@
107110
{
108111
"cell_type": "code",
109112
"execution_count": null,
110-
"metadata": {},
113+
"metadata": {
114+
"collapsed": true
115+
},
111116
"outputs": [],
112117
"source": [
113118
"%matplotlib inline\n",
@@ -142,7 +147,9 @@
142147
{
143148
"cell_type": "code",
144149
"execution_count": null,
145-
"metadata": {},
150+
"metadata": {
151+
"collapsed": true
152+
},
146153
"outputs": [],
147154
"source": [
148155
"import io\n",
@@ -169,6 +176,7 @@
169176
"cell_type": "code",
170177
"execution_count": null,
171178
"metadata": {
179+
"collapsed": true,
172180
"scrolled": true
173181
},
174182
"outputs": [],
@@ -192,7 +200,9 @@
192200
{
193201
"cell_type": "code",
194202
"execution_count": null,
195-
"metadata": {},
203+
"metadata": {
204+
"collapsed": true
205+
},
196206
"outputs": [],
197207
"source": [
198208
"output_location = 's3://{}/{}/output'.format(bucket, prefix)\n",
@@ -215,15 +225,13 @@
215225
{
216226
"cell_type": "code",
217227
"execution_count": null,
218-
"metadata": {},
228+
"metadata": {
229+
"collapsed": true
230+
},
219231
"outputs": [],
220232
"source": [
221-
"containers = {'us-west-2': '174872318107.dkr.ecr.us-west-2.amazonaws.com/factorization-machines:latest',\n",
222-
" 'us-east-1': '382416733822.dkr.ecr.us-east-1.amazonaws.com/factorization-machines:latest',\n",
223-
" 'us-east-2': '404615174143.dkr.ecr.us-east-2.amazonaws.com/factorization-machines:latest',\n",
224-
" 'eu-west-1': '438346466558.dkr.ecr.eu-west-1.amazonaws.com/factorization-machines:latest',\n",
225-
" 'ap-northeast-1': '351501993468.dkr.ecr.ap-northeast-1.amazonaws.com/factorization-machines:latest',\n",
226-
" 'ap-northeast-2': '835164637446.dkr.ecr.ap-northeast-2.amazonaws.com/factorization-machines:latest'}"
233+
"from sagemaker.amazon.amazon_estimator import get_image_uri\n",
234+
"container = get_image_uri(boto3.Session().region_name, 'factorization-machines')"
227235
]
228236
},
229237
{
@@ -240,15 +248,17 @@
240248
{
241249
"cell_type": "code",
242250
"execution_count": null,
243-
"metadata": {},
251+
"metadata": {
252+
"collapsed": true
253+
},
244254
"outputs": [],
245255
"source": [
246256
"import boto3\n",
247257
"import sagemaker\n",
248258
"\n",
249259
"sess = sagemaker.Session()\n",
250260
"\n",
251-
"fm = sagemaker.estimator.Estimator(containers[boto3.Session().region_name],\n",
261+
"fm = sagemaker.estimator.Estimator(container,\n",
252262
" role, \n",
253263
" train_instance_count=1, \n",
254264
" train_instance_type='ml.c4.xlarge',\n",
@@ -275,7 +285,9 @@
275285
{
276286
"cell_type": "code",
277287
"execution_count": null,
278-
"metadata": {},
288+
"metadata": {
289+
"collapsed": true
290+
},
279291
"outputs": [],
280292
"source": [
281293
"fm_predictor = fm.deploy(initial_instance_count=1,\n",
@@ -297,7 +309,9 @@
297309
{
298310
"cell_type": "code",
299311
"execution_count": null,
300-
"metadata": {},
312+
"metadata": {
313+
"collapsed": true
314+
},
301315
"outputs": [],
302316
"source": [
303317
"import json\n",
@@ -324,7 +338,9 @@
324338
{
325339
"cell_type": "code",
326340
"execution_count": null,
327-
"metadata": {},
341+
"metadata": {
342+
"collapsed": true
343+
},
328344
"outputs": [],
329345
"source": [
330346
"result = fm_predictor.predict(train_set[0][30:31])\n",
@@ -343,7 +359,9 @@
343359
{
344360
"cell_type": "code",
345361
"execution_count": null,
346-
"metadata": {},
362+
"metadata": {
363+
"collapsed": true
364+
},
347365
"outputs": [],
348366
"source": [
349367
"import numpy as np\n",
@@ -359,7 +377,9 @@
359377
{
360378
"cell_type": "code",
361379
"execution_count": null,
362-
"metadata": {},
380+
"metadata": {
381+
"collapsed": true
382+
},
363383
"outputs": [],
364384
"source": [
365385
"import pandas as pd\n",
@@ -388,7 +408,9 @@
388408
{
389409
"cell_type": "code",
390410
"execution_count": null,
391-
"metadata": {},
411+
"metadata": {
412+
"collapsed": true
413+
},
392414
"outputs": [],
393415
"source": [
394416
"import sagemaker\n",

introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-fulltraining.ipynb

+5-14
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,13 @@
5555
"import boto3\n",
5656
"import re\n",
5757
"from sagemaker import get_execution_role\n",
58+
"from sagemaker.amazon.amazon_estimator import get_image_uri\n",
5859
"\n",
5960
"role = get_execution_role()\n",
6061
"\n",
6162
"bucket='<<bucket-name>>' # customize to your bucket\n",
62-
"containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/image-classification:latest',\n",
63-
" 'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/image-classification:latest',\n",
64-
" 'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/image-classification:latest',\n",
65-
" 'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/image-classification:latest',\n",
66-
" 'ap-northeast-1': '501404015308.dkr.ecr.ap-northeast-1.amazonaws.com/image-classification:latest',\n",
67-
" 'ap-northeast-2': '306986355934.dkr.ecr.ap-northeast-2.amazonaws.com/image-classification:latest'}\n",
68-
"training_image = containers[boto3.Session().region_name]"
63+
"\n",
64+
"training_image = get_image_uri(boto3.Session().region_name, 'image-classification')"
6965
]
7066
},
7167
{
@@ -354,13 +350,8 @@
354350
"model_data = info['ModelArtifacts']['S3ModelArtifacts']\n",
355351
"print(model_data)\n",
356352
"\n",
357-
"containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/image-classification:latest',\n",
358-
" 'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/image-classification:latest',\n",
359-
" 'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/image-classification:latest',\n",
360-
" 'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/image-classification:latest',\n",
361-
" 'ap-northeast-1': '501404015308.dkr.ecr.ap-northeast-1.amazonaws.com/image-classification:latest',\n",
362-
" 'ap-northeast-2': '306986355934.dkr.ecr.ap-northeast-2.amazonaws.com/image-classification:latest'}\n",
363-
"hosting_image = containers[boto3.Session().region_name]\n",
353+
"hosting_image = get_image_uri(boto3.Session().region_name, 'image-classification')\n",
354+
"\n",
364355
"primary_container = {\n",
365356
" 'Image': hosting_image,\n",
366357
" 'ModelDataUrl': model_data,\n",

introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-lst-format.ipynb

+6-8
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,13 @@
5757
"%%time\n",
5858
"import boto3\n",
5959
"from sagemaker import get_execution_role\n",
60+
"from sagemaker.amazon.amazon_estimator import get_image_uri\n",
6061
"\n",
6162
"role = get_execution_role()\n",
6263
"\n",
6364
"bucket='<<bucket-name>>' # customize to your bucket\n",
64-
"containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/image-classification:latest',\n",
65-
" 'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/image-classification:latest',\n",
66-
" 'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/image-classification:latest',\n",
67-
" 'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/image-classification:latest',\n",
68-
" 'ap-northeast-1': '501404015308.dkr.ecr.ap-northeast-1.amazonaws.com/image-classification:latest',\n",
69-
" 'ap-northeast-2': '306986355934.dkr.ecr.ap-northeast-2.amazonaws.com/image-classification:latest'}\n",
70-
"training_image = containers[boto3.Session().region_name]"
65+
"\n",
66+
"training_image = get_image_uri(boto3.Session().region_name, 'image-classification')"
7167
]
7268
},
7369
{
@@ -497,7 +493,9 @@
497493
"info = sage.describe_training_job(TrainingJobName=job_name)\n",
498494
"model_data = info['ModelArtifacts']['S3ModelArtifacts']\n",
499495
"print(model_data)\n",
500-
"hosting_image = containers[boto3.Session().region_name]\n",
496+
"\n",
497+
"hosting_image = get_image_uri(boto3.Session().region_name, 'image-classification')\n",
498+
"\n",
501499
"primary_container = {\n",
502500
" 'Image': hosting_image,\n",
503501
" 'ModelDataUrl': model_data,\n",

introduction_to_amazon_algorithms/imageclassification_caltech/Image-classification-transfer-learning.ipynb

+6-14
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,14 @@
5454
"import boto3\n",
5555
"import re\n",
5656
"from sagemaker import get_execution_role\n",
57+
"from sagemaker.amazon.amazon_estimator import get_image_uri\n",
5758
"\n",
5859
"role = get_execution_role()\n",
5960
"\n",
6061
"bucket='<<bucket-name>>' # customize to your bucket\n",
6162
"\n",
62-
"containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/image-classification:latest',\n",
63-
" 'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/image-classification:latest',\n",
64-
" 'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/image-classification:latest',\n",
65-
" 'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/image-classification:latest',\n",
66-
" 'ap-northeast-1': '501404015308.dkr.ecr.ap-northeast-1.amazonaws.com/image-classification:latest',\n",
67-
" 'ap-northeast-2': '306986355934.dkr.ecr.ap-northeast-2.amazonaws.com/image-classification:latest'}\n",
68-
"training_image = containers[boto3.Session().region_name]\n",
63+
"training_image = get_image_uri(boto3.Session().region_name, 'image-classification')\n",
64+
"\n",
6965
"print(training_image)"
7066
]
7167
},
@@ -370,13 +366,9 @@
370366
"info = sage.describe_training_job(TrainingJobName=job_name)\n",
371367
"model_data = info['ModelArtifacts']['S3ModelArtifacts']\n",
372368
"print(model_data)\n",
373-
"containers = {'us-west-2': '433757028032.dkr.ecr.us-west-2.amazonaws.com/image-classification:latest',\n",
374-
" 'us-east-1': '811284229777.dkr.ecr.us-east-1.amazonaws.com/image-classification:latest',\n",
375-
" 'us-east-2': '825641698319.dkr.ecr.us-east-2.amazonaws.com/image-classification:latest',\n",
376-
" 'eu-west-1': '685385470294.dkr.ecr.eu-west-1.amazonaws.com/image-classification:latest',\n",
377-
" 'ap-northeast-1': '501404015308.dkr.ecr.ap-northeast-1.amazonaws.com/image-classification:latest',\n",
378-
" 'ap-northeast-2': '306986355934.dkr.ecr.ap-northeast-2.amazonaws.com/image-classification:latest'}\n",
379-
"hosting_image = containers[boto3.Session().region_name]\n",
369+
"\n",
370+
"hosting_image = get_image_uri(boto3.Session().region_name, 'image-classification')\n",
371+
"\n",
380372
"primary_container = {\n",
381373
" 'Image': hosting_image,\n",
382374
" 'ModelDataUrl': model_data,\n",

0 commit comments

Comments
 (0)