Search code examples
pythonneural-networkgoogle-colaboratory

Can't open label file. (This can be normal only if you use MSCOCO) YoloV4


I'm working with YoloV4 model object detection. I'm trying to train the custom dataset but I'm constantly getting this error line:

Can't open label file. (This can be normal only if you use MSCOCO): data/obj/13_PNG.rf.c87d3ef90086ec0d21254a8a7c97147a.txt 
Can't open label file. (This can be normal only if you use MSCOCO): data/obj/13_PNG.rf.c87d3ef90086ec0d21254a8a7c97147a.txt 
Can't open label file. (This can be normal only if you use MSCOCO): data/obj/13_PNG.rf.c87d3ef90086ec0d21254a8a7c97147a.txt 

Training file paths don't seem to match but I can't figure out how to fix that problem. I'm struggling for hours.

The command I'm trying to run the training process with:

!./darknet detector train data/obj.data cfg/custom-yolov4-detector.cfg yolov4.conv.137 -dont_show

And the train files and directories:

%cd /content/darknet/                                   
%cp {dataset.location}/train/_classes.txt data/obj.names                                    
%mkdir -p data/obj                                    
#copy image and labels                                    
%cp {dataset.location}/train/*.jpg data/obj/                                
%cp {dataset.location}/valid/*.jpg data/obj/ 
%cp {dataset.location}/train/*.txt data/obj/                                  
%cp {dataset.location}/valid/*.txt data/obj/                                  
                               
                                    
with open('data/obj.data', 'w') as out:                                   
  out.write('classes = 2\n')                                    
  out.write('train = data/train.txt\n')                                   
  out.write('valid = data/valid.txt\n')                                   
  out.write('names = data/obj.names\n')                                   
  out.write('backup = backup/')                                   
                                    
#write train file (just the image list)                                   
import os                                   
                                    
with open('data/train.txt', 'w') as out:                                    
  for img in [f for f in os.listdir(dataset.location + '/train') if f.endswith('jpg')]:                                   
    out.write('data/obj/' + img + '\n')                                   
                                    
#write the valid file (just the image list)                                   
import os                                   
                                    
with open('data/valid.txt', 'w') as out:                                    
  for img in [f for f in os.listdir(dataset.location + '/valid') if f.endswith('jpg')]:                                   
    out.write('data/obj/' + img + '\n') 

Solution

  • Make sure that your labels(annotations) and the training image names are the same. If there is a difference between labels and image names, then it will cause this particular error. I had the same error when working with annotation files. For me, it happened when I had to convert from .png to .jpg and that changed the filename in the process.