Teachable Machine¶

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.
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¶
-
Train an image model in Teachable Machine, with no coding.
-
Download it as a Keras model,
keras_model.h5, with itslabels.txt. -
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.
-
Exported models load on Keras 3, with no need to pin an old TensorFlow version.
-
Get the image back with the class and confidence written on it, ready for OpenCV.
-
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.