Skip to content

Raspberry Pi

Set up

Use the 64-bit Raspberry Pi OS if you can, and follow the Raspberry Pi installation steps. Then check which runtime was installed:

python -c "import teachable_machine_lite as t; print(t.RUNTIME)"

Choose a camera

Camera How to read it Example
USB webcam OpenCV, cv.VideoCapture(0) Webcam Classifier
Camera module (CSI ribbon cable) Picamera2 Raspberry Pi Camera

cv.VideoCapture(0) does not work with the camera module on recent Raspberry Pi OS.

Use all the CPU cores

model = TeachableMachineLite(
    model_path="model.tflite", labels_file_path="labels.txt", num_threads=4)

num_threads=4 matches the four cores of a Raspberry Pi 4 or 5.

Spare the SD card

Pass camera frames to the model directly. There's no need to save each frame as an image file first. See Images and Camera Frames.

32-bit Raspberry Pi OS

On 32-bit Raspberry Pi OS the package uses tflite-runtime, which supports Python 3.11 or earlier and needs NumPy below 2. See Requirements.