Skip to content

Commit a76bc3f

Browse files
author
Venkatesan
committed
reflecting David,s comments on the PR
1 parent 171dcb4 commit a76bc3f

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

sagemaker-python-sdk/mxnet_mnist_byom/mxnet_mnist.ipynb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@
6161
"execution_count": 2,
6262
"metadata": {
6363
"collapsed": true
64+
"isConfigCell": true
6465
},
6566
"outputs": [],
6667
"source": [
67-
"role = '<your SageMaker execution role here>'"
68+
"import boto3\n",
69+
"assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n",
70+
"role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)"
6871
]
6972
},
7073
{
@@ -271,6 +274,13 @@
271274
"print(predictor.endpoint)"
272275
]
273276
},
277+
{
278+
"cell_type": "markdown",
279+
"metadata": {},
280+
"source": [
281+
"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."
282+
]
283+
},
274284
{
275285
"cell_type": "code",
276286
"execution_count": null,
@@ -279,7 +289,7 @@
279289
},
280290
"outputs": [],
281291
"source": [
282-
"sagemaker.Session().delete_endpoint(predictor.endpoint)"
292+
"# sagemaker.Session().delete_endpoint(predictor.endpoint)"
283293
]
284294
},
285295
{
@@ -305,9 +315,9 @@
305315
],
306316
"metadata": {
307317
"kernelspec": {
308-
"display_name": "Python 3",
309-
"language": "python",
310-
"name": "python3"
318+
"display_name": "conda_python3",
319+
"language": "conda_python3",
320+
"name": "conda_python3"
311321
},
312322
"language_info": {
313323
"codemirror_mode": {

sagemaker-python-sdk/tensorflow_iris_byom/tensorflow_BYOM_iris.ipynb

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@
4343
"execution_count": null,
4444
"metadata": {
4545
"collapsed": true
46+
"isConfigCell": true
4647
},
4748
"outputs": [],
4849
"source": [
49-
"role = '<your SageMaker execution role here>'"
50+
"import boto3\n",
51+
"assumed_role = boto3.client('sts').get_caller_identity()['Arn']\n",
52+
"role = re.sub(r'^(.+)sts::(\\d+):assumed-role/(.+?)/.*$', r'\\1iam::\\2:role/\\3', assumed_role)"
5053
]
5154
},
5255
{
@@ -61,9 +64,7 @@
6164
{
6265
"cell_type": "code",
6366
"execution_count": null,
64-
"metadata": {
65-
"collapsed": true
66-
},
67+
"metadata": {},
6768
"outputs": [],
6869
"source": [
6970
"import os\n",
@@ -119,9 +120,7 @@
119120
{
120121
"cell_type": "code",
121122
"execution_count": null,
122-
"metadata": {
123-
"collapsed": true
124-
},
123+
"metadata": {},
125124
"outputs": [],
126125
"source": [
127126
"classifier = estimator_fn(run_config = None, params = None)"
@@ -195,9 +194,7 @@
195194
{
196195
"cell_type": "code",
197196
"execution_count": null,
198-
"metadata": {
199-
"collapsed": true
200-
},
197+
"metadata": {},
201198
"outputs": [],
202199
"source": [
203200
"classifier.train(input_fn = train_func, steps = 1000)"
@@ -209,7 +206,7 @@
209206
"source": [
210207
"## Set up hosting for the model\n",
211208
"\n",
212-
"### Export the model from mxnet\n",
209+
"### Export the model from tensorflow\n",
213210
"\n",
214211
"In order to set up hosting, we have to import the model from training to hosting. We will begin by exporting the model from TensorFlow and saving it down. Analogous to the [MXNet example](../mxnet_mnist_byom/mxnet_mnist.ipynb), some structure needs to be followed. The exported model has to be converted into a form that is readable by ``sagemaker.mxnet.model.MXNetModel``. The following code describes exporting the model in a form that does the same:\n",
215212
"\n",
@@ -219,9 +216,7 @@
219216
{
220217
"cell_type": "code",
221218
"execution_count": null,
222-
"metadata": {
223-
"collapsed": true
224-
},
219+
"metadata": {},
225220
"outputs": [],
226221
"source": [
227222
"exported_model = classifier.export_savedmodel(export_dir_base = 'export/Servo/', \n",
@@ -288,9 +283,7 @@
288283
{
289284
"cell_type": "code",
290285
"execution_count": null,
291-
"metadata": {
292-
"collapsed": true
293-
},
286+
"metadata": {},
294287
"outputs": [],
295288
"source": [
296289
"%%time\n",
@@ -313,9 +306,8 @@
313306
"metadata": {},
314307
"outputs": [],
315308
"source": [
316-
"predict_samples = {}\n",
317-
"predict_samples ={INPUT_TENSOR_NAME: np.array([[6.4,3.2,4.5,1.5]])}\n",
318-
"predictor.predict(np.array([[6.4,3.2,4.5,1.5]]))"
309+
"sample = [6.4,3.2,4.5,1.5]\n",
310+
"predictor.predict(sample)"
319311
]
320312
},
321313
{
@@ -335,9 +327,25 @@
335327
"source": [
336328
"os.remove('model.tar.gz')\n",
337329
"import shutil\n",
338-
"shutil.rmtree('export')\n",
339-
"\n",
340-
"sagemaker.Session().delete_endpoint(predictor.endpoint)"
330+
"shutil.rmtree('export')"
331+
]
332+
},
333+
{
334+
"cell_type": "markdown",
335+
"metadata": {},
336+
"source": [
337+
"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."
338+
]
339+
},
340+
{
341+
"cell_type": "code",
342+
"execution_count": null,
343+
"metadata": {
344+
"collapsed": true
345+
},
346+
"outputs": [],
347+
"source": [
348+
"# sagemaker.Session().delete_endpoint(predictor.endpoint)"
341349
]
342350
}
343351
],

0 commit comments

Comments
 (0)