Search code examples
object-detectionyolodarknetdataset

YOLO darknet retrain does not even start saying it could not find *.txt in some *labels* directory


I have been trying to retrain YOLOv3 on a custom dataset. I saved the jpg images and their corresponding txt annotation files in the same directory. I have set the my .data file, .names file and .cfg file appropriately as suggested in many tutorials online. Quite frustratingly, I have been running into the problem where it says Couldn't open file: <some-path>/labels/<some file>.txt. What is annoying here it seems to be looking for .txt files in some labels directory which neither exists, nor did I mention it anywhere. All my .jpg and .txt files are in a directory named images located at the same level as where the system is looking for this labels directory.

What is further annoying is if I do separate .txt files into a labels directory which is where the yolo darknet is looking for, this error goes away but the training never starts.

I have tried many different ways of specifying the paths, using different models, cfg files etc, but all in vain. Please help someone.


Solution

  • After making many attempts from different angles, I found out the right way. The answer to the first question of organizing images and labels is contrary to what most tutorials online suggest. labels should be located in a separate directory from the images. The path to the each .txt file should differ from their corresponding .jpg only in the word images. For example, if the path to an image is <path/to/somewhere/images/somewhere/xyz.jpg>, the path to its corresponding label file should be <path/to/somewhere/labels/somewhere/xyz.txt>.

    As an answer to the second part where the training does not start, make sure to use argument -clear 1 at the end of the darknet training command, i.e. ./darknet detector train cfg/data_file.data cfg/cfg_file.cfg yolov3.weights -clear 1.