{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Using Amazon Elastic Inference with a pre-trained TensorFlow Serving model from NGC on SageMaker\n", "\n", "This notebook demonstrates how to enable and use Amazon Elastic Inference with our predefined SageMaker TensorFlow Serving containers.\n", "\n", "Amazon Elastic Inference (EI) is a resource you can attach to your Amazon EC2 instances to accelerate your deep learning (DL) inference workloads. EI allows you to add inference acceleration to an Amazon SageMaker hosted endpoint or Jupyter notebook for a fraction of the cost of using a full GPU instance. For more information please visit: https://docs.aws.amazon.com/sagemaker/latest/dg/ei.html\n", "\n", "This notebook's main objective is to show how to create an endpoint, backed by an Elastic Inference, to serve our pre-trained TensorFlow Serving model for predictions. With a more efficient cost per performance, Amazon Elastic Inference can prove to be useful for those looking to use GPUs for higher inference performance at a lower cost.\n", "\n", "1. [The model](#The-model)\n", "1. [Setup role for SageMaker](#Setup-role-for-SageMaker)\n", "1. [Load the TensorFlow Serving Model on Amazon SageMaker using Python SDK](#Load-the-TensorFlow-Serving-Model-on-Amazon-SageMaker-using-Python-SDK)\n", "1. [Deploy the trained Model to an Endpoint with EI](#Deploy-the-trained-Model-to-an-Endpoint-with-EI)\n", " 1. [Using EI with a SageMaker notebook instance](#Using-EI-with-a-SageMaker-notebook-instance)\n", " 1. [Invoke the Endpoint to get inferences](#Invoke-the-Endpoint-to-get-inferences)\n", " 1. [Delete the Endpoint](#Delete-the-Endpoint)\n", "\n", "If you are familiar with SageMaker and already have a trained model, skip ahead to the [Deploy the trained Model to an Endpoint with an attached EI accelerator](#Deploy-the-trained-Model-to-an-Endpoint-with-an-attached-EI-accelerator)\n", "\n", "For this example, we will use the SageMaker Python SDK, which helps deploy your models to train and host in SageMaker. In this particular example, we will be interested in only the hosting portion of the SDK.\n", "\n", "1. Set up our pre-trained model for consumption in SageMaker\n", "2. Host the model in an endpoint with EI\n", "3. Make a sample inference request to the model\n", "4. Delete our endpoint after we're done using it\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The model\n", "\n", "The pre-trained model we will be using for this example is a NGC ResNet-50 model from the [NGC Model repository](https://ngc.nvidia.com/catalog/models/nvidia:rntf_fp16/files). For more information in regards to deep residual networks, please check [here](https://github.com/tensorflow/models/tree/master/official/resnet). It isn't a requirement to train our model on SageMaker to use SageMaker for serving our model.\n", "\n", "SageMaker expects our models to be compressed in a tar.gz format in S3. Thankfully, our model already comes in that format. The predefined TensorFlow Serving containers use REST API for handling inferences, for more informationm, please see [Deploying to TensorFlow Serving Endpoints](https://github.com/aws/sagemaker-python-sdk/blob/master/src/sagemaker/tensorflow/deploying_tensorflow_serving.rst#making-predictions-against-a-sagemaker-endpoint).\n", "\n", "To host our model for inferences in SageMaker, we need to first upload the SavedModel to S3. This can be done through the AWS console or AWS command line.\n", "\n", "Let's look at a sample saved_model TF model. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "download: s3://sagemaker-sample-data-us-east-1/tensorflow/model/resnet/resnet_50_v2_fp32_NCHW.tar.gz to ./resnet_50_v2_fp32_NCHW.tar.gz\n" ] } ], "source": [ "!aws s3 cp s3://sagemaker-sample-data-us-east-1/tensorflow/model/resnet/resnet_50_v2_fp32_NCHW.tar.gz ./" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "tar: Ignoring unknown extended header keyword `LIBARCHIVE.creationtime'\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/._.DS_Store\n", "tar: Ignoring unknown extended header keyword `LIBARCHIVE.creationtime'\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/.DS_Store\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/._Servo\n", "tar: Ignoring unknown extended header keyword `LIBARCHIVE.creationtime'\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/._.DS_Store\n", "tar: Ignoring unknown extended header keyword `LIBARCHIVE.creationtime'\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/.DS_Store\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/._1527887769\n", "tar: Ignoring unknown extended header keyword `LIBARCHIVE.creationtime'\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/._.DS_Store\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/.DS_Store\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/._saved_model.pb\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/saved_model.pb\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/._variables\n", "tar: Ignoring unknown extended header keyword `LIBARCHIVE.creationtime'\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/variables/\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/variables/._variables.data-00000-of-00001\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/variables/variables.data-00000-of-00001\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/variables/._variables.index\n", "tar: Ignoring unknown extended header keyword `SCHILY.dev'\n", "tar: Ignoring unknown extended header keyword `SCHILY.ino'\n", "tar: Ignoring unknown extended header keyword `SCHILY.nlink'\n", "export/Servo/1527887769/variables/variables.index\n" ] } ], "source": [ "!tar xvf resnet_50_v2_fp32_NCHW.tar.gz" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "saved_model.pb\tvariables\r\n" ] } ], "source": [ "!ls export/Servo/1527887769/" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "!rm -r export/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Getting a pretrained NGC model in Saved model format" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import time\n", "path = 'export/Servo/'+str(int(float(time.time())))+'/'\n", "!mkdir -p {path}\n", "!wget https://api.ngc.nvidia.com/v2/models/nvidia/rntf_fp16/versions/1/files/SavedModel/saved_model.pb -P {path}\n", "!wget https://api.ngc.nvidia.com/v2/models/nvidia/rntf_fp16/versions/1/files/SavedModel/variables/variables.data-00001-of-00002 -P {path+'variables/'}\n", "!wget https://api.ngc.nvidia.com/v2/models/nvidia/rntf_fp16/versions/1/files/SavedModel/variables/variables.data-00000-of-00002 -P {path+'variables/'}\n", "!wget https://api.ngc.nvidia.com/v2/models/nvidia/rntf_fp16/versions/1/files/SavedModel/variables/variables.index -P {path+'variables/'} \n", "!tar -czvf model.tar.gz export/" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "export/\n", "export/Servo/\n", "export/Servo/1587740359/\n", "export/Servo/1587740359/saved_model.pb\n", "export/Servo/1587740359/variables/\n", "export/Servo/1587740359/variables/variables.index\n", "export/Servo/1587740359/variables/variables.data-00001-of-00002\n", "export/Servo/1587740359/variables/variables.data-00000-of-00002\n" ] } ], "source": [ "!tar -xvf model.tar.gz" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "!rm -r export/" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup role for SageMaker\n", "\n", "Let's start by creating a SageMaker session and specifying the IAM role arn used to give hosting access to your model. See the [documentation](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-roles.html) for how to create these. Note, if more than one role is required for notebook instances, training, and/or hosting, please replace the `sagemaker.get_execution_role()` with a the appropriate full IAM role arn string(s)." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "import sagemaker\n", "\n", "role = sagemaker.get_execution_role()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CPU times: user 1.96 s, sys: 301 ms, total: 2.26 s\n", "Wall time: 1.76 s\n" ] } ], "source": [ "%%time\n", "import boto3\n", "\n", "# use the region-specific saved model object\n", "region = boto3.Session().region_name\n", "saved_model = sagemaker.session.Session().upload_data('model.tar.gz')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load the TensorFlow Serving Model on Amazon SageMaker using Python SDK\n", "\n", "We can use the SageMaker Python SDK to load our pre-trained TensorFlow Serving model for hosting in SageMaker for predictions.\n", "\n", "There are a few parameters that our TensorFlow Serving Model is expecting.\n", "1. `model_data` - The S3 location of a model tar.gz file to load in SageMaker\n", "2. `role` - An IAM role name or ARN for SageMaker to access AWS resources on your behalf.\n", "3. `framework_version` - TensorFlow Serving version you want to use for handling your inference request .\n" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "from sagemaker.tensorflow.serving import Model\n", "\n", "tensorflow_model = Model(model_data=saved_model,\n", " role=role,\n", " framework_version='1.14')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Deploy the trained Model to an Endpoint with an attached EI accelerator\n", "\n", "The `deploy()` method creates an endpoint which serves prediction requests in real-time.\n", "\n", "The only change required for utilizing EI with our SageMaker TensorFlow Serving containers only requires providing an `accelerator_type` parameter, which determines which type of EI accelerator to attach to your endpoint. The supported types of accelerators can be found here: https://aws.amazon.com/sagemaker/pricing/instance-types/\n" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "-----------------!CPU times: user 339 ms, sys: 0 ns, total: 339 ms\n", "Wall time: 8min 32s\n" ] } ], "source": [ "%%time\n", "predictor = tensorflow_model.deploy(initial_instance_count=1,\n", " instance_type='ml.p3.2xlarge')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Invoke the Endpoint to get inferences\n", "\n", "Invoking prediction:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{u'outputs': {u'probabilities': [[0.00181863387, 0.000308345247, 0.000224663949, 0.000105218518, 0.000201158255, 0.000512797676, 0.000178170303, 0.00062313606, 0.000490190112, 0.000882363, 0.000362244697, 0.000480229326, 0.00047326702, 0.00022533437, 0.000501258473, 0.000778052257, 0.000779272639, 0.000122643818, 0.000330245733, 0.000326354726, 0.000250201731, 0.000135383525, 0.000283011468, 0.000219680092, 0.000612412, 0.000347099616, 0.00111330161, 0.000182586664, 0.00047361842, 0.000113796239, 0.000702265417, 0.00140311127, 0.000122181867, 0.000335647346, 0.000557845749, 0.000111529356, 0.000558486965, 0.00181321765, 0.00127990067, 0.000611173688, 0.00117498066, 0.000473144464, 0.000119554119, 0.000244195311, 0.000650275324, 0.000232503677, 0.000214546322, 0.000421376608, 0.00202968135, 0.000307032082, 0.000564544869, 0.000623003172, 0.000582267, 0.000890947354, 0.00105615589, 0.000241011177, 0.000209132821, 0.000372110924, 0.00046954, 0.000214680564, 0.00297602499, 0.00146043918, 0.00105875637, 0.00113860774, 0.000300017768, 8.19394627e-05, 0.00027067514, 6.57455239e-05, 0.000236347929, 0.000448960258, 0.000256568514, 0.000332724769, 0.00077429082, 0.00114718731, 0.000401505211, 0.00483689597, 0.00022412221, 0.0048096017, 0.000153273126, 0.00252118707, 0.000216192915, 0.000126094121, 0.000469740655, 0.00019807124, 0.000780265138, 0.000275629427, 0.00136486383, 0.000389673311, 0.000667944, 0.00088560849, 0.00071151572, 0.000161186574, 0.000475393084, 0.000679952384, 0.00126931805, 0.000319489889, 0.00189727067, 0.000539063651, 0.00093162409, 0.000724518322, 0.000983204343, 0.000418257318, 0.000705074694, 0.000576129183, 0.00220003794, 0.000210541126, 0.0001833797, 0.00062886579, 0.000143396479, 0.000623131928, 0.000279267435, 0.000540551438, 0.000248213881, 0.00566534558, 0.00218187715, 0.000349029346, 0.000158608804, 0.00054758176, 0.000332394236, 0.000148105915, 0.000184268691, 0.000531914819, 0.000888988201, 0.000458742958, 5.33692073e-05, 0.000246437616, 0.00176214, 0.000273144426, 0.000411696208, 0.000789569924, 0.00237990147, 0.00025026279, 0.000370462541, 0.000127358871, 0.000778170943, 0.00030519141, 0.000468924263, 0.000175553199, 0.000537971559, 0.000270112359, 0.0001489243, 0.000225652868, 0.000857128063, 0.00043756573, 0.000552840123, 0.00219715061, 0.000279799919, 0.0002907624, 0.000258494518, 0.00089283241, 0.000140565098, 0.00184428541, 0.00069948344, 0.000818366476, 0.000187053796, 0.00197046506, 0.000463528326, 0.000492833147, 0.000581612694, 0.000160298, 0.000430907763, 0.00152708916, 0.0010385107, 0.000951517082, 0.000728172308, 0.00133549247, 0.00112455292, 0.000196821595, 0.00154522154, 0.000368698064, 0.000867534778, 0.000530579069, 0.000561382913, 7.11213288e-05, 0.00214515883, 0.00051202107, 0.000725895807, 0.00088137, 0.00331820175, 0.000802167517, 0.00120810268, 0.000257225736, 0.00107070536, 0.000447510509, 0.000517420413, 0.000338458893, 0.000280801411, 0.000777481648, 0.00162583252, 0.000550594123, 0.00169380871, 0.000539809174, 0.00104491471, 0.000299033738, 0.00053068425, 0.00135288248, 0.00077321945, 0.000772587897, 0.00231577735, 0.00101049372, 0.000953422277, 0.000128838801, 0.0023987575, 0.00218478916, 0.00196645339, 0.000515552645, 0.000361856539, 0.000909285911, 0.000570301432, 0.00566741172, 0.000773330044, 0.000485716184, 0.00144039723, 0.000263644033, 0.000183428405, 0.000641739811, 0.000600486121, 0.000765702396, 0.000306564, 0.00207703374, 0.000228831472, 0.00035622876, 0.000939681428, 0.0095294416, 0.000685060571, 0.000504820549, 0.000303332723, 0.000734437548, 0.000421855075, 0.00151072268, 0.000295420672, 0.00152047828, 0.000268554781, 0.000146253587, 0.0004627257, 0.000374580442, 0.000504248426, 0.000646938337, 0.00138134568, 0.00231992779, 0.00278912578, 0.000376773271, 0.000305775262, 0.00066783285, 0.0009382891, 0.000496827299, 0.00205946108, 0.000689964276, 0.00195664493, 0.000375816, 0.000807057542, 0.00103911, 0.000716301787, 0.000886845577, 0.00824728049, 0.000289564865, 0.000747014768, 0.00201276201, 0.000979153, 0.00103487016, 0.00115937158, 0.00262249936, 0.000851756311, 0.00154799083, 0.000657781551, 0.000252079684, 0.00186792377, 0.000639730366, 0.000780146453, 0.00083480624, 0.00955127738, 0.000825289229, 0.000513420964, 0.00110062596, 0.000950443442, 0.00116322644, 0.000473532826, 0.000228313875, 0.00393075775, 0.000470028812, 0.000945979729, 0.00256210961, 0.00256111263, 0.00224215514, 0.000614670222, 0.000608073664, 0.000175087058, 0.000122769372, 0.000214554588, 0.000604504, 0.000473863125, 0.000409958157, 0.000322602951, 0.000684638799, 0.000586835726, 0.000542557391, 0.000205487682, 0.000299363717, 0.000821342517, 0.00107672939, 0.000455703557, 0.000309506839, 0.000620587438, 0.000492315448, 0.000172351865, 0.000231791579, 0.00749766, 0.00113499817, 0.00252704462, 0.000343952241, 0.000163129051, 0.000609520765, 0.0005144889, 0.0019338876, 0.000497382483, 0.00279286481, 0.00462501682, 0.000145909289, 0.00195461535, 0.000323852, 0.000444397971, 0.000299693231, 0.000382231025, 0.00120562897, 0.000475980778, 0.000498139125, 0.000728262, 0.000357468583, 0.000138519448, 0.000162352197, 0.000486674, 0.000198506095, 0.00040283511, 0.000344973785, 0.000330793846, 0.000287210249, 0.000191439991, 0.000412826135, 0.000393027149, 0.000219527108, 0.000934345415, 0.000172258849, 0.000362183666, 0.000707412953, 0.0002555924, 0.000756148307, 0.000337058853, 0.000317778031, 0.00030066949, 0.00149223453, 0.000660849677, 0.000326890906, 0.000243359391, 0.000526190968, 0.000464719167, 0.000841489935, 0.000521034701, 0.000893735, 0.0048122881, 0.00241791783, 0.000447550963, 0.0074808537, 0.00300753303, 0.000725982827, 0.000795233645, 0.000203732212, 0.000659512356, 0.000150663967, 0.00185958948, 0.00119339838, 0.00263723289, 0.000922954, 0.000415736053, 0.00141570624, 0.000187011436, 0.00108128635, 0.0017948664, 0.00100396702, 0.00105894799, 0.000359093363, 0.00132860185, 0.00338059617, 0.00739794364, 0.00565938745, 0.00058750168, 0.000589330099, 0.00163785019, 0.000572319201, 0.000721409277, 0.000997380121, 0.000146963721, 0.000711698, 0.000851893, 0.000287853269, 0.00094971928, 0.000259958673, 0.000985540799, 0.000347770663, 0.000212618819, 0.000122893543, 0.000471202453, 0.00107299187, 0.00114841922, 0.000524595031, 0.000243302653, 0.000458168797, 0.000894080673, 0.000280790438, 0.000693360285, 0.000646056258, 0.00235296017, 5.83013243e-05, 0.00208266545, 0.000546066265, 0.00157398428, 0.00018617473, 0.000262562215, 0.000133142312, 0.000623981876, 0.000276810082, 0.00104710064, 0.000212808402, 0.00152626948, 0.000764604774, 8.5995569e-05, 0.000260100147, 0.000230730511, 0.00167128677, 0.000798529771, 0.000224498493, 0.00073509611, 0.00141606748, 0.00142345694, 0.000567902578, 6.42504092e-05, 0.000132321875, 0.00110822823, 0.000218831483, 0.000500688271, 0.000299988023, 0.00156237965, 0.000483704905, 0.00194629689, 0.000507678662, 0.00128380337, 0.00183100929, 0.000119126315, 0.00038212043, 0.000505388773, 0.000228200137, 8.4172e-05, 0.00161351752, 0.000346225832, 0.000795217697, 0.000173253226, 9.66480511e-05, 0.000411381625, 0.00077840162, 0.000415592833, 0.00021452237, 6.85659907e-05, 0.000340816798, 0.000737392053, 0.00094931206, 0.000117996024, 0.00149609835, 0.000214858985, 0.000624694396, 0.00203304039, 0.000682016602, 0.000497228757, 0.000362625433, 0.00137973903, 0.000317688, 0.000805349322, 0.000237385451, 7.59564136e-05, 0.000281805551, 0.000840678927, 0.000483418175, 0.000318550621, 0.000868628325, 0.000986811472, 0.000377144897, 0.000541953836, 0.00212234817, 0.00117096794, 0.000368944864, 0.000272088888, 0.000387891603, 0.00570749771, 0.00026610159, 0.0009807772, 0.000565852, 0.000570718199, 0.000387974666, 0.00162254041, 0.000302410801, 0.000326868118, 0.000404983206, 0.000522904098, 0.000806217548, 0.00361724, 0.000648219837, 0.000224805714, 0.000172424523, 0.000585883448, 0.00520115579, 0.000299266743, 0.000142257573, 0.000789273647, 0.000851290766, 0.000596730737, 0.0020876159, 0.00242340309, 9.99409458e-05, 0.00109245814, 0.00108549395, 0.00152553595, 0.000832542544, 0.000726201513, 0.000807530072, 0.00243087648, 0.000643843203, 0.000353588955, 0.000722662, 0.000557451916, 0.0011215671, 0.000409397733, 0.000769456208, 0.000449139596, 0.000526400807, 0.00106906076, 0.000611529103, 0.000575932267, 0.000345311448, 0.000377247226, 0.000303760637, 0.000140469754, 0.000971036381, 0.000877439626, 0.000494575594, 0.00290469849, 0.00294278399, 0.00112656725, 0.000409100146, 0.000813064922, 0.000901461754, 0.000825914321, 0.000440780394, 0.000818023691, 0.000240492052, 0.00209358823, 0.00181334128, 0.00179057429, 0.0020505588, 0.0117246332, 0.000177249793, 0.000477993308, 0.00175596867, 0.000581682601, 0.000284677721, 0.000674749957, 0.00136831496, 0.000357718382, 0.000276803883, 0.000323376793, 0.00103064533, 0.00139627489, 0.000598085404, 0.000570779666, 0.000885579211, 0.000798087451, 0.00146519381, 0.00045422031, 0.00161225931, 0.000660600723, 0.000304816233, 0.000478084374, 0.000375868607, 0.000199969305, 0.000959293393, 0.000151195374, 0.000678571116, 0.000823918497, 0.000955934695, 0.000701004232, 0.00117522164, 0.000451040571, 0.000118124262, 5.16835207e-05, 0.00178205268, 9.13362237e-05, 0.000650835747, 0.000845539675, 0.000805153337, 0.000644469, 0.00208133901, 0.00106665166, 0.00163559942, 0.000661642582, 0.000515352294, 0.00213613803, 0.000473508873, 0.00231083296, 0.000264834438, 0.000783510564, 0.000343014719, 0.000670636655, 0.000670908194, 0.000238202076, 0.000398737902, 0.000935282151, 0.00114213233, 0.000344689266, 0.0017273305, 0.00387180387, 0.000647662615, 0.000187101963, 0.000627097, 0.00089989166, 0.000998216, 0.00116814545, 0.000312355492, 0.000179004579, 0.00116210943, 0.014563133, 0.000960565172, 0.000252180675, 0.00098986621, 0.000451758504, 0.00051865523, 0.0152290789, 7.72508865e-05, 0.000334821088, 0.000158683368, 0.000981299789, 0.000189253406, 0.000361976738, 0.000239157293, 0.000999723212, 0.00119899958, 0.000760355848, 0.00162262889, 0.00285342033, 0.00080972485, 0.00053454889, 0.000401062251, 0.000435375958, 0.000604758854, 0.00152561022, 0.00150581938, 0.000132626912, 0.000990785193, 0.000553900318, 0.000539011846, 0.000730255968, 0.00109574618, 0.000430673244, 0.000366619555, 0.000455754285, 0.00191595196, 0.00015306547, 0.000207085221, 0.0069970279, 0.000567330397, 0.000383742125, 0.00126376131, 0.000499452173, 0.00095750537, 0.000672016293, 0.000728938438, 0.000225105119, 0.000320223888, 0.00136232562, 0.000773622305, 0.00250826147, 0.000562943867, 0.00098532252, 0.00166160194, 0.000813627092, 0.0012714495, 0.00116847747, 0.00169586064, 0.00109709695, 0.00122457894, 0.000556052837, 0.000185081488, 0.0003609673, 0.00283046113, 0.000863428053, 0.000209752499, 0.00354546658, 0.00134039472, 0.000279875443, 0.000837961619, 0.00212691259, 0.000213391148, 0.000156825088, 0.000242118476, 0.00053930172, 0.000255784311, 0.000287081115, 0.00122196786, 0.000780692324, 0.00018906327, 0.000545824063, 0.00533408532, 0.0014922733, 0.000207650737, 0.000413206813, 0.000638818834, 0.000201031973, 0.000494783279, 0.00181865285, 0.000213436229, 0.00115243916, 0.00167804165, 0.000793318322, 0.000671822, 0.00168986782, 0.000118159362, 0.00711823301, 0.00102220359, 0.000657615, 9.38097583e-05, 0.0014871665, 0.00177858875, 0.000609937, 0.000910761883, 0.000604110712, 0.000605110719, 0.00445077149, 0.000762409065, 0.00180533843, 0.00055991509, 0.000958063523, 0.000438583636, 0.000265820941, 0.000177653332, 0.0001319359, 0.000568401127, 0.000333981967, 0.00322533189, 0.000534112391, 0.000661784958, 0.000499121437, 0.000669388275, 0.00109370518, 0.000818236, 0.00023761284, 0.00052546896, 0.00051075255, 0.0112240473, 0.000586126524, 0.000151525514, 0.000927017, 0.000377351418, 8.03564108e-05, 0.00709403632, 0.000354948832, 0.000304364803, 0.000600154046, 0.00281260395, 0.000833155878, 0.000131891939, 0.000444097619, 0.000298342842, 0.000790429767, 0.00012255086, 0.000982080121, 0.00101611414, 0.000851842, 0.000356472796, 0.00236395397, 0.00060183485, 0.001607641, 0.000501137925, 0.00102896849, 0.000307119888, 0.000454866327, 0.000289457355, 0.0016016349, 0.00141213974, 0.00364842592, 0.00227469392, 0.000352525065, 0.00187100156, 0.000782591465, 0.000367421599, 0.000276746723, 0.000684791943, 0.000772009196, 0.00112759799, 0.000477836205, 0.000187382408, 0.00106663862, 0.0013724966, 0.00116494228, 0.00963650644, 0.000231276965, 0.000371447502, 0.000431633642, 0.00125404424, 0.000837902131, 0.000765836216, 0.00165661157, 7.58410752e-05, 0.00126733619, 6.45156906e-05, 0.000392632268, 0.0130252987, 7.22997065e-05, 0.0024698081, 0.000514504907, 8.74657562e-05, 0.000637596182, 0.00104976015, 0.00533466, 0.000422234, 0.000404196035, 0.000477362628, 0.000159189614, 0.000454353547, 0.000152323322, 0.000304997084, 0.00209645927, 0.000211294318, 0.0128327, 0.000610672287, 0.000722342695, 0.00041116905, 0.000531923142, 0.000212974162, 0.00146879139, 0.00017032912, 0.000169887309, 0.00120559079, 0.000517687411, 0.00618876284, 0.000190855208, 0.000364655658, 0.00260245777, 0.000606890128, 0.00394356, 0.00204711966, 0.000524206844, 0.000230416728, 0.00131519604, 0.000382287457, 0.00044822495, 0.000363164232, 0.00110454357, 0.000128025713, 0.000137603536, 0.0106077623, 0.000139757671, 0.000265969546, 0.000138765245, 0.000971617468, 0.000120795259, 0.000257949694, 0.000335980119, 0.000527541037, 0.000691688911, 0.000153520421, 0.000580985448, 0.000266052375, 2.32742022e-05, 0.000419195858, 0.00352020934, 0.0033914235, 0.002389475, 0.00321338605, 0.000388768443, 0.00309456792, 0.00156343752, 0.00243258523, 0.000113461872, 0.00389858079, 0.00167290249, 0.000106328975, 0.000477856782, 0.000330287759, 0.000399733864, 6.64067411e-05, 0.000571109937, 0.000220690985, 0.000828612945, 0.00146975438, 0.000709017331, 0.000306048867, 0.00122134236, 0.00195194408, 0.000826775911, 0.000291103468, 0.000870611286, 0.00153780449, 0.00163125806, 0.00101521623, 0.0016755237, 0.000330929324, 0.00264019589, 0.000763717864, 0.0157013051, 0.000126764979, 0.000802152557, 0.00185685733, 0.000333003234, 0.00164843153, 0.000697139476, 0.000196867695, 0.000635083066, 0.000336771598, 0.000483221811, 0.000277071958, 0.00084195513, 0.000153848014, 0.000749824918, 0.000800322334, 0.000218773886, 0.000356279255, 0.000147899569, 0.000364082051, 0.000229904865, 0.000351486407, 6.72592651e-05, 0.000283301488, 0.000499432383, 0.00091993931, 0.000516543048, 0.000577152881, 0.00441827485, 0.000569297525, 0.000718362629, 0.000401517842, 0.000245783682, 0.000522505317, 0.00024898976, 0.00047509963, 0.000361315819, 0.000333308795, 0.00072498963, 0.000817589113, 0.000427216262, 0.000633809657, 0.000698706426, 0.000440117728, 0.000542879105, 0.000525761046, 0.000350428192, 0.000217187961, 0.000927535119, 0.000324722525, 0.000286613213, 0.000381290156, 0.0010976427, 0.000709400221, 0.000165033402, 0.00040873239, 0.000248886732, 0.000215078137, 0.000782189483, 0.00032830608, 0.0003903209, 0.000375040603, 0.000584724243, 0.00041388633, 0.000472314627, 0.000573517929, 0.000234449501, 0.000319609448, 0.000385958207, 0.000117745913, 0.00232282467, 0.000109417364, 0.000332591531, 0.000346129353, 0.000445533253, 0.00115673011, 0.000360588165, 0.000450031745, 0.000255453255, 0.00104481447, 0.000197172805, 0.000322663196, 0.000610222924, 0.000314763078, 0.000416050694, 0.000222731571, 0.000262284448, 0.00196573045, 0.00118081842, 0.000525173, 0.000468865, 0.000300239102, 0.000836894498, 0.000962540798, 0.000194133157, 0.000684081053, 0.000454676687]], u'classes': [904]}}\n" ] } ], "source": [ "import numpy as np\n", "random_input = np.random.rand(1, 1, 3, 3)\n", "prediction = predictor.predict({'inputs': random_input.tolist()})\n", "print(prediction)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Delete the Endpoint\n", "\n", "After you have finished with this example, remember to delete the prediction endpoint to release the instance(s) associated with it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(predictor.endpoint)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import sagemaker\n", "\n", "predictor.delete_endpoint()" ] } ], "metadata": { "kernelspec": { "display_name": "conda_tensorflow_p27", "language": "python", "name": "conda_tensorflow_p27" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.16" }, "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 }