|
43 | 43 | "execution_count": null,
|
44 | 44 | "metadata": {
|
45 | 45 | "collapsed": true
|
| 46 | + "isConfigCell": true |
46 | 47 | },
|
47 | 48 | "outputs": [],
|
48 | 49 | "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)" |
50 | 53 | ]
|
51 | 54 | },
|
52 | 55 | {
|
|
61 | 64 | {
|
62 | 65 | "cell_type": "code",
|
63 | 66 | "execution_count": null,
|
64 |
| - "metadata": { |
65 |
| - "collapsed": true |
66 |
| - }, |
| 67 | + "metadata": {}, |
67 | 68 | "outputs": [],
|
68 | 69 | "source": [
|
69 | 70 | "import os\n",
|
|
119 | 120 | {
|
120 | 121 | "cell_type": "code",
|
121 | 122 | "execution_count": null,
|
122 |
| - "metadata": { |
123 |
| - "collapsed": true |
124 |
| - }, |
| 123 | + "metadata": {}, |
125 | 124 | "outputs": [],
|
126 | 125 | "source": [
|
127 | 126 | "classifier = estimator_fn(run_config = None, params = None)"
|
|
195 | 194 | {
|
196 | 195 | "cell_type": "code",
|
197 | 196 | "execution_count": null,
|
198 |
| - "metadata": { |
199 |
| - "collapsed": true |
200 |
| - }, |
| 197 | + "metadata": {}, |
201 | 198 | "outputs": [],
|
202 | 199 | "source": [
|
203 | 200 | "classifier.train(input_fn = train_func, steps = 1000)"
|
|
209 | 206 | "source": [
|
210 | 207 | "## Set up hosting for the model\n",
|
211 | 208 | "\n",
|
212 |
| - "### Export the model from mxnet\n", |
| 209 | + "### Export the model from tensorflow\n", |
213 | 210 | "\n",
|
214 | 211 | "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",
|
215 | 212 | "\n",
|
|
219 | 216 | {
|
220 | 217 | "cell_type": "code",
|
221 | 218 | "execution_count": null,
|
222 |
| - "metadata": { |
223 |
| - "collapsed": true |
224 |
| - }, |
| 219 | + "metadata": {}, |
225 | 220 | "outputs": [],
|
226 | 221 | "source": [
|
227 | 222 | "exported_model = classifier.export_savedmodel(export_dir_base = 'export/Servo/', \n",
|
|
288 | 283 | {
|
289 | 284 | "cell_type": "code",
|
290 | 285 | "execution_count": null,
|
291 |
| - "metadata": { |
292 |
| - "collapsed": true |
293 |
| - }, |
| 286 | + "metadata": {}, |
294 | 287 | "outputs": [],
|
295 | 288 | "source": [
|
296 | 289 | "%%time\n",
|
|
313 | 306 | "metadata": {},
|
314 | 307 | "outputs": [],
|
315 | 308 | "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)" |
319 | 311 | ]
|
320 | 312 | },
|
321 | 313 | {
|
|
335 | 327 | "source": [
|
336 | 328 | "os.remove('model.tar.gz')\n",
|
337 | 329 | "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)" |
341 | 349 | ]
|
342 | 350 | }
|
343 | 351 | ],
|
|
0 commit comments