O'Reilly logo

Hands-On Serverless Deep Learning with TensorFlow and AWS Lambda by Rustem Feyzkhanov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

index.py

In the index.py file, the script looks the same way as it did in the previous section. An additional part has been added, which is reading the URL from the message and writing the result to another queue. The following is the code snippet for index.py:

import boto3import numpy as npimport tensorflow as tfimport os.pathimport refrom urllib.request import urlretrieveimport jsonSESSION = NonestrBucket = 'serverlessdeeplearning'def handler(event, context):    global strBucket    global SESSION    if not os.path.exists('/tmp/imagenet/'):       os.makedirs('/tmp/imagenet/')       ...

The following screenshot shows the part where we retrieve the image and run our model on it, and hence, we write the result of the model to another queue, as shown:

if ('Records' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required