Search code examples
pythonpytorchyoloyolov5

Class label order in YoloV5 using Ultralytics code


I was trying to train a custom object detector using Ultralytics open-source research. I encountered this problem at the step where we have to generate a .yaml file here. What should be the ordering of those label names? It is not alphabetical as we do in Tensorflow. I don't want my model to mislabel during inference.


Solution

  • The order is arbitrary. You can choose whatever you want. The relevant part is that, in the next step, you must provide a .txt per image, where:

    Each row is class x_center y_center width height format.

    In this case, class will be an integer between 0 and N-1, where N is the number of classes that you defined in the .yaml file.

    So, if in the .yaml file you have:

    nc: 3
    classes: ['cat', 'dog', 'car']
    

    and in my_image.txt you have:

    0 0.156 0.321 0.254 0.198
    2 0.574 0.687 0.115 0.301
    

    Then, it means that, in this image, you have one cat and one car.