How to save Detected Class Name in Text file Instead of Label

I can take a look at that portion. Of note, the first value in each line of the file is the class ID index value based on your obj.names file.

It will just require accessing the index for the class label name in obj.names and mapping it (as the key) to the class label name (value) in a variable that is of type, dictionary.

Then use the value (class label name) from the key:value pairs to map the index to the label name before appending it to the end of the line being written for the txt file.

  • note, the key is the class ID index value, and the file uses 0-base indexing (0, 1, 2, etc.)
  • make the keys as type string

The classes are listed alphabetically in that obj.names file, too. So if you know all of your class names in your trained model, you can make the dictionary without even viewing obj.names