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

Let's look at the available files. We will look at the index.py file as shown:

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

The main difference is that we run the code inside the handler function and we need to download the model files and image file from the S3 bucket:

if not os.path.exists('/tmp/imagenet/'): os.makedirs('/tmp/imagenet/')strFile = '/tmp/imagenet/inputimage.jpg'downloadFromS3(strBucket,'imagenet/inputimage.jpg',strFile)global SESSION ...

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