Skip to content

Teachable Machine

Teachable Machine logo

Run image models trained with Google's Teachable Machine in a few lines of Python. Load the exported Keras model and its labels, then classify images.

Get started Browse examples

pip install teachable-machine
from teachable_machine import TeachableMachine

model = TeachableMachine(model_path="keras_model.h5", labels_file_path="labels.txt")
result = model.classify_image("photo.jpg")

print(result["class_name"], result["class_confidence"])

From idea to code

  • 1. Train


    Train an image model in Teachable Machine, with no coding.

  • 2. Export


    Download it as a Keras model, keras_model.h5, with its labels.txt.

  • 3. Run


    Give it an image and get back the class and its confidence.

Why Teachable Machine

  • Short code

    One line loads the model, and one call classifies an image.

  • Works with current TensorFlow

    Exported models load on Keras 3, with no need to pin an old TensorFlow version.

  • Draws the result

    Get the image back with the class and confidence written on it, ready for OpenCV.

  • Documented results

    Every value in the result is described, with its type.

Running on a Raspberry Pi or another small device?

Try Teachable Machine Lite. It runs the TensorFlow Lite export and doesn't need the full TensorFlow.