How to use Tensorflow Lite on AWS Lambda


I’m trying to host a small model I have compiled down to a .tflite on AWS Lambda. Using either the python 3.6 or python 3.7 tflite wheel files available on the tensorflow website I zip up my packages/code, and upload to S3 and link to lambda with space to spare. However, when I test my function it crashes when trying to load tflite. Initially, it couldn’t load shared object files. This was the error

I found this shared object file and moved it up into the local directory, and then got another error

My base system is Ubuntu (Bionic Beaver)
Both these errors come from importing tflite


Okay I solved this today.

Complete solution and compiled dependencies for amazonlinux/aws lambda on my github:

So the problem is that aws lambda runs on amazonlinux which apparently needs a different compilation of the tflite _interpreter_wrapper than the one tensorflow is currently providing on their website.

My solution was to compile it natively on amazonlinux using docker and the script that tensorflow is providing in their git repo.

I created a Dockerfile:

and then ran the following commands:

These commands output a folder called site-packages which contain the corretly compiled tflite python dependencies for amazonlinux and therefore also aws lambda.

Leave a Reply