Python 3.12 vs TF Lite 2.17

The latest versions of TF Lite don't support Python 3.12 yet.

As a workaround, we can use the previous version of TF Lite to serve the models created by TensorFlow 2.17. We tested it with TF Lite 2.14 and the deep learning models we use in the course work successfully with this setup.

Here's how you do it

Python, NumPy, and the TensorFlow Lite runtime form a compatible pinned stack; mixing incompatible generations causes runtime problems.

Figure: Pin and test the runtime components together instead of mixing incompatible generations.

First, use Python 3.10. It means that you will need to use public.ecr.aws/lambda/python:3.10 as the base image:

FROM public.ecr.aws/lambda/python:3.10

Second, use numpy 1.23.1:

RUN pip install numpy==1.23.1

When installing tf lite interpreter for AWS lambda, make sure you don't install dependencies with --no-deps flag:

RUN pip install --no-deps https://github.com/alexeygrigorev/tflite-aws-lambda/raw/main/tflite/tflite_runtime-2.14.0-cp310-cp310-linux_x86_64.whl

If you don't do it, pip will try to upgdate the version of numpy and your code won't work (as the tflite runtime was compiled with numpy 1, not numpy 2).

← Previous: Explore more · Next: Overview →

Optional analytics

Optional analytics are off unless you allow them. Your choice does not affect access to DataTalks.Club, Slack, events, or courses.

Current choice: not chosen.

Privacy Policy

If you allow analytics, self-hosted Umami counts anonymous public pageviews without analytics cookies. Private account and learning pages are excluded. Read the Privacy Policy for the complete data boundary.