Exporting Labels as YOLO Format Causes FileExistsError

Question:

I get this error whenever I try and export my labels as yolo format. VOC format works fine.

Traceback (most recent call last):
File "/home/ubuntu/.local/lib/python3.10/site-packages/rest_framework/views.py", line 506, in dispatch
response = handler(request, *args, **kwargs)
File "/home/ubuntu/.local/lib/python3.10/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/ubuntu/.local/lib/python3.10/site-packages/label_studio/data_export/api.py", line 183, in get
export_stream, content_type, filename = DataExport.generate_export_file(
File "/home/ubuntu/.local/lib/python3.10/site-packages/label_studio/data_export/models.py", line 161, in generate_export_file
converter.convert(input_json, tmp_dir, output_format, is_dir=False)
File "/home/ubuntu/.local/lib/python3.10/site-packages/label_studio_converter/converter.py", line 176, in convert
self.convert_to_yolo(input_data, output_data, output_image_dir=image_dir,
File "/home/ubuntu/.local/lib/python3.10/site-packages/label_studio_converter/converter.py", line 612, in convert_to_yolo
with open(label_path, 'x'):
FileExistsError: [Errno 17] File exists: '/tmp/tmppeqtunpn/labels/original-33eeb1f72a72190cec2030b773dc6e5206614319.txt'

Answer:

This error happens when the file already exists in the temporary directory. To resolve it, please do one of the following:

  • Clear your /tmp directory.
  • Ensure that the /tmp directory is writable.

Doing so should remove any existing conflicts when attempting to export the labels in YOLO format from Label Studio.