Skip to content
Advertisement

Labelimg crashes when attempting to export YOLO training samples

I’m pretty new to Python and labeling data for deep learning. I have installed Labelimg program in order to label a custom dataset, but it keeps crashing when I create YOLO training samples. Each time I open the program and specify the image directory, I can browse through the images, but when I create my bounding boxes and try to click on the “next image” button, it crashes with an error message.

As a note, I followed this tutorial to install Labelimg.

Here is how I create the error:

  1. Open Anaconda Prompt
  2. Activate the previously-created labelimg environment in conda

conda activate labelimg

  1. Specify location of unzipped labelimg folder

cd D:labelimg

  1. Open python script, followed by location of image directory, previously-created text file with the label name (weed), and previously-created text file with the name of the class in it (weed):

python labelimg.py D:photo_directory D:label.txt D:classes.txt

The program then opens, displaying this:

enter image description here

Notice that I am trying to export samples as YOLO training samples. The name of the picture is “weed0”. Whenever I create my samples and click the “Next Image” button, the program crashes with this error:

Traceback (most recent call last):
  File "labelimg.py", line 1299, in openNextImg
    self.saveFile()
  File "labelimg.py", line 1339, in saveFile
    self._saveFile(savedPath)
  File "labelimg.py", line 1371, in _saveFile
    if annotationFilePath and self.saveLabels(annotationFilePath):
  File "labelimg.py", line 837, in saveLabels
    self.lineColor.getRgb(), self.fillColor.getRgb())
  File "D:labelimglibslabelFile.py", line 89, in saveYoloFormat
    writer.save(targetFile=filename, classList=classList)
  File "D:labelimglibsyolo_io.py", line 64, in save
    out_file = codecs.open(targetFile, 'w', encoding=ENCODE_METHOD)
  File "D:anaconda3envslabelimglibcodecs.py", line 898, in open
    file = builtins.open(filename, mode, buffering)
FileNotFoundError: [Errno 2] No such file or directory: 'D:\weed0.txt'

What can I do to ensure that the program doesn’t crash when exporting YOLO training samples? I have done everything but reinstall the program, which doesn’t make sense to me because I just downloaded it.

Advertisement

Answer

The solution was to convert image files from .jpg to .png files. After this, it worked flawlessly. This tutorial was very helpful:

https://www.youtube.com/watch?v=FGr3N3DLGEI

In addition, as I was collecting imagery with UAV images (dimensions of 4000×3000 pixels), the program does not like images that large. You can export them using PascalVOC format when it comes to large images, but YOLO format doesn’t like images that large. Cropping down to dimensions of 1000 x 1000 works well.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement