Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'int' object is not iterable when importing YOLO dataset #8958

Open
2 tasks done
eKevinHoang opened this issue Jan 17, 2025 · 6 comments
Open
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@eKevinHoang
Copy link

Actions before raising this issue

  • I searched the existing issues and did not find anything similar.
  • I read/searched the docs

Steps to Reproduce

  1. Create a new Prọect in CVAT and go to the project page.
  2. Import a YOLO dataset (images and annotations) via the "Upload Annotations" feature.
  3. Select YOLO Detection 1.0 and dataset in .zip then click OK.
  4. The error occurs.

Expected Behavior

The YOLO dataset should be imported successfully, and the annotations should be visible for editing.

Possible Solution

No response

Context

The dataset structure is as below:

data.yaml
├── train
│   ├── images
│   └── labels
├── valid
│   ├── images
│   └── labels
└── test
    ├── images
    └── labels

Environment

The log detail:


[2025-01-17 10:39:40,125] DEBUG rq.worker: Job import:project-2-dataset raised an exception.
[2025-01-17 10:39:40,129] DEBUG rq.worker: Handling failed execution of job import:project-2-dataset
[2025-01-17 10:39:40,133] DEBUG rq.worker: Handling exception for import:project-2-dataset.
[2025-01-17 10:39:40,134] ERROR rq.worker: [Job import:project-2-dataset]: exception raised while executing (cvat.apps.engine.utils.import_resource_with_clean_up_after)
Traceback (most recent call last):
  File "/opt/venv/lib/python3.10/site-packages/rq/worker.py", line 1431, in perform_job
    rv = job.perform()
  File "/opt/venv/lib/python3.10/site-packages/rq/job.py", line 1280, in perform
    self._result = self._execute()
  File "/opt/venv/lib/python3.10/site-packages/rq/job.py", line 1317, in _execute
    result = self.func(*self.args, **self.kwargs)
  File "/home/django/cvat/apps/engine/utils.py", line 306, in import_resource_with_clean_up_after
    result = func(filename, *args, **kwargs)
  File "/usr/lib/python3.10/contextlib.py", line 79, in inner
    return func(*args, **kwds)
  File "/home/django/cvat/apps/dataset_manager/project.py", line 194, in import_dataset_as_project
    project.import_dataset(f, importer, conv_mask_to_poly=conv_mask_to_poly)
  File "/home/django/cvat/apps/dataset_manager/project.py", line 162, in import_dataset
    importer(dataset_file, temp_dir, project_data, load_data_callback=self.load_dataset_data, **options)
  File "/home/django/cvat/apps/dataset_manager/formats/registry.py", line 36, in __call__
    f_or_cls(*args, **kwargs)
  File "/home/django/cvat/apps/dataset_manager/formats/yolo.py", line 130, in _import_yolo_ultralytics_detection
    _import_common(*args, format_name="yolo_ultralytics_detection", **kwargs)
  File "/home/django/cvat/apps/dataset_manager/formats/yolo.py", line 80, in _import_common
    dataset = Dataset.import_from(temp_dir, format_name,
  File "/opt/venv/lib/python3.10/site-packages/datumaro/components/dataset.py", line 1198, in import_from
    env.make_extractor(src_conf.format, src_conf.url, **extractor_kwargs)
  File "/opt/venv/lib/python3.10/site-packages/datumaro/components/environment.py", line 230, in make_extractor
    return self.extractors.get(name)(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/datumaro/plugins/data_formats/yolo/base.py", line 363, in __init__
    super().__init__(*args, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/datumaro/plugins/data_formats/yolo/base.py", line 181, in __init__
    super().__init__(rootpath=osp.dirname(config_path), image_info=image_info, **kwargs)
  File "/opt/venv/lib/python3.10/site-packages/datumaro/plugins/data_formats/yolo/base.py", line 108, in __init__
    subset.items = self._get_lazy_subset_items(subset_name)
  File "/opt/venv/lib/python3.10/site-packages/datumaro/plugins/data_formats/yolo/base.py", line 197, in _get_lazy_subset_items
    return {
  File "/opt/venv/lib/python3.10/site-packages/datumaro/plugins/data_formats/yolo/base.py", line 197, in <dictcomp>
    return {
  File "/opt/venv/lib/python3.10/site-packages/datumaro/plugins/data_formats/yolo/base.py", line 474, in _get_subset_image_paths
    yield from subset_images_source
TypeError: 'int' object is not iterable

[2025-01-17 10:39:40,134] DEBUG rq.worker: Invoking exception handler <function rq_exception_handler at 0x7fb9557e44c0>
[2025-01-17 10:39:40,134] DEBUG rq.worker: Invoking exception handler <function handle_rq_exception at 0x7fb979d95f30>
[2025-01-17 10:39:40,147] DEBUG rq.worker: Sent heartbeat to prevent worker timeout. Next one should arrive in 480 seconds.
[2025-01-17 10:39:40,148] DEBUG rq.worker: Sent heartbeat to prevent worker timeout. Next one should arrive in 480 seconds.
[2025-01-17 10:39:40,149] INFO rq.worker: Cleaning registries for queue: import
[2025-01-17 10:39:40,152] DEBUG rq.worker: *** Listening on import...
@eKevinHoang eKevinHoang added the bug Something isn't working label Jan 17, 2025
@Eldies
Copy link
Contributor

Eldies commented Jan 21, 2025

@eKevinHoang
Hi! Could you please provide the dataset you are trying to import?

@eKevinHoang
Copy link
Author

eKevinHoang commented Jan 21, 2025

@Eldies You can download any dataset in YOLO format from roboflow.com and try it.

For example, you can use this dataset: https://universe.roboflow.com/object-detection-ifpbo/vehicle-detection-vkwyt/dataset/4

I'm using docker and launch CVAT by docker-compose up -d.

Let me know if you need further assistance!

@eKevinHoang
Copy link
Author

Additionally, I noticed that in CVAT's dataset selection menu, the option for YOLO Dataset refers to version 1.0. However, I attempted to convert my dataset to the YOLO v1.0 structure, and it still could not be imported. The system also requires data.yaml file, which aligns more with newer YOLO formats.

I believe the version label in the supported dataset list should be updated to reflect the actual YOLO version it supports. This would help users better understand the required dataset structure and avoid confusion.

Let me know if you'd like to refine this further!

@beaglebot
Copy link

I think this is caused by a mismatch between the keys cvat expects in data.yaml and what yolov7 actually uses. If you look at its config parser it expects the config file to have keys backup, classes or names, and any other keys found are assumed to be subsets.

In my case I had the nc key with an integer value, which caused the same "TypeError: 'int' object is not iterable when importing YOLO dataset" you are experiencing. Changing the nc key to classes and removing any additional keys fixed the problem for me.

@eKevinHoang
Copy link
Author

@beaglebot I have replaced the key nc with classes. My data.yaml file now looks like this:

classes: 1
names: obj.names
train: train/images
valid: valid/images
backup: backup/

I have referred to this link:
https://github.com/cvat-ai/datumaro/blob/develop/tests/assets/yolo_dataset/yolo_ultralytics_detection/data.yaml

Based on that, I updated my data.yaml file to the following:

path: .
train: train/images

names:
  0: TEST

However, I am still encountering the same error: TypeError: 'int' object is not iterable

Could you please help me identify what might be missing or incorrect?

@beaglebot
Copy link

My data.yaml is:

path: .
train: train.txt
valid: valid.txt

classes: 3

names: 
  0: person
  1: car
  2: nzpost

I can upload annotations with this and it works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants