AWS Lambda is a service from Amazon. The objective of this service is that you to be able to run your code without thinking about servers.
The service takes care of running it and scales it up and down according to the load. But you must exercise caution; you will need to pay for the time when the function is actually used.
In the 8th homework, we created a model to predict hair types. Now, we’ll deploy it using AWS Lambda.
The first step is to create an AWS account, and then configure the AWS CLI tool. AWS CLI is the command line interface for AWS. To use the CLI, you need to have Python. Just having Python is not enough; you also need to install the AWS CLI itself. You can do this by running the following command in the terminal:
pip install awscli
You need to configure the tool, specifying the access token and secret you downloaded earlier when creating a user. One way to do this is to use the configure command:
aws configure
Then, it will ask you for your keys. We go back with AWS Lambda later.
The main difference between TensorFlow and TensorFlow Lite is the amount of memory space required for model deployment. TensorFlow Lite was optimized for mobile devices for this reason this framework requires only a few megabytes, while TensorFlow typically requires several gigabytes. We can deploy models created with TensorFlow using TensorFlow Lite.
For Linux, we can install the library with the following command:
pip install <https://github.com/alexeygrigorev/tflite-aws-lambda/raw/main/tflite/tflite_runtime-2.14.0-cp310-cp310-linux_x86_64.whl>
Then we can import with the following code:
import tflite_runtime.interpreter as tflite
For windows, we don’t need to install nothing, TensorFlow already include TensorFlow Lite such as we can export it with the following code:
import tensorflow.lite as tflite
TF Lite uses a special optimized format for storing models. To use our model with TF Lite, we need to convert our model to this format. We’ll do that next.