Skip to content

Export Your Model

The package runs image classification models exported from Google's Teachable Machine in Keras format.

Steps

  1. Train your image model on Teachable Machine.
  2. Click Export Model, then open the TensorFlow tab.
  3. Choose Keras as the model conversion type.
  4. Download and unzip. Put keras_model.h5 and labels.txt next to your code.

Note

Check the file names in your download. If they differ, pass them as model_path and labels_file_path.

The labels file

Each line of labels.txt holds a class number and a class name:

0 Cat
1 Dog

The package keeps the whole line, so result["class_name"] is "0 Cat". To get only the name:

label = result["class_name"].split(maxsplit=1)[-1]  # "Cat"

Always use the labels.txt that came in the same download as the model, with its lines in their original order.

Class names in any language

The package reads labels.txt as UTF-8, so class names can be in Arabic or any other language. If you edit the file, save it as UTF-8. Versions before 1.3.3 can garble these names on Windows.