Export Your Model¶
The package runs image classification models exported from Google's Teachable Machine in Keras format.
Steps¶
- Train your image model on Teachable Machine.
- Click Export Model, then open the TensorFlow tab.
- Choose Keras as the model conversion type.
- Download and unzip. Put
keras_model.h5andlabels.txtnext 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.