25. import tensorflow as tf
import boto3
# ...
# load the model
# ...
def handler(event, context):
img = download_image(event['url'])
preds = predict(img)
result = decode_predictions(preds)[0]
return result
index.py:
26. # install dependencies to “build” folder
pip install -r requirements.txt -t build
# put our code there as well
cp index.py build
# pack everything into a zip file
cd build && zip -r ../build.zip * & cd ..
* do this in Docker (amazonlinux)
*
34. What to do?
● TensorFlow for JS or Java
● TF-Serving (C++)
● TF-Lite (mobile)
35. TensorFlow JS
Pros
● Fits within limits
Cons
● JavaScript
● No NumPy, re-writing pre- & post-processing
https://github.com/lucleray/tensorflow-lambda
36. TensorFlow JS
Pros
● Fits within limits
Cons
● JavaScript
● No NumPy, re-writing pre- & post-processing
https://github.com/lucleray/tensorflow-lambda
37. TensorFlow Serving
Pros
● Fits within limits
● We already know how to use it for serving TF models
Cons
● Tricky to use in Lambda
● Only C++, No Python bindings
38. TensorFlow Serving
Pros
● Fits within limits
● We already know how to use it for serving TF models
Cons
● Tricky to use in Lambda
● Only C++, No Python bindings
42. TensorFlow Lite runs on mobile phones,
embedded Linux devices, and microcontrollers.
43. TensorFlow Lite runs on mobile phones,
embedded Linux devices, and microcontrollers.
On Linux, you can use C++ and Python
https://www.tensorflow.org/lite/guide/inference
61. Deep Learning with AWS Lambda
Pros:
● Easy to deploy
● Serverless!
● Scales down to 0
● Great for small load (<1 mln
images)
Cons:
● Initially not straightforward
● Monitoring (CloudWatch)
● Undocumented behaviour
● Expensive for high load (>10
mln images daily)
62. Main takeaways
● Serving deep learning without infrastructure is possible
● TensorFlow 2.2 is heavy, but TensorFlow Lite is lite
● AWS Lambda is good for small load, but expensive under
heavy load