Train custom images for multiple classes

Good day…

I followed this guide on how to prepare images/annotation files for training a set of iamges to be used for the K210 chip

But sadly this only works for an image set with only one class…

Has anyone stumbled upon a description for several classes to be loaded onto the K210?

When I try to use for example two classes in the config.json file for Yolo I get this error during training, and no tflite file is produced:

ValueError: Invalid tensors ‘detection_layer_30/BiasAdd’ were found

Check the layers of your model. If you add more classes, the layer “detection_layer_X” will have a different number for X (not sure why). So, in fit.py under the ‘save_tflite’ method edit the line:

converter = tf.lite (…) (“model.h5”, output_arrays = [‘detection_layer_30/BiasAdd’])

so that ‘detection_layer_X/BiasAdd’ matches the layer name in your model. If you already have the h5 model, you can copy the save_tflite lines into a python script and skip retraining the model (don’t forget “from keras.models import load_model”).

1 Like

Thanks ! I followed the same tutorial, and had the same problem. It now trains perfectly !

However, now that I have the tflite (and thus the kmodel) when I try to use it on a board, the kpu.load(…) works, so does the kpu.init_yolo2(…), but the kpu.run_yolo2(…) fails, and the while(True) loop stops after 3 turns.

I changed to “detection_layer_55” and trained it for 7 classes, and running it on a Maix Go, if it can help