voxel51 / fiftyone

Refine high-quality datasets and visual AI models
https://fiftyone.ai
Apache License 2.0
8.84k stars 557 forks source link

[Errno 24] Too many open files when call view.annotate(...) with 2000 `Open-Image` images #1623

Open shaojun opened 2 years ago

shaojun commented 2 years ago

Hi, I'm trying to download a small subset with 2000 images of Open Images data of class Bicycle, and then upload the images and annotations to CVAT.

System information

Commands to reproduce

this is what I've done:

dataset = foz.load_zoo_dataset("open-images-v6", split="train", label_types=["detections"], classes=["Bicycle"], max_samples=2000, seed=51, shuffle=True, dataset_name="open-images-bicycle-mini-set-upload-to-cvat-2000-final",)
Downloading split 'train' to '/home/shao/fiftyone/open-images-v6/train' if necessary
Necessary images already downloaded
Existing download of split 'train' is sufficient
Loading 'open-images-v6' split 'train'
 100% |█████████████████████████████████████████████████████████████| 2000/2000 [9.5s elapsed, 0s remaining, 207.7 samples/s]       
Dataset 'open-images-bicycle-mini-set-upload-to-cvat-2000-final' created
>>> view = dataset.view()
>>> anno_key="cvat_existing_field_final"
>>> view.annotate(anno_key, label_field="detections",label_type="detections",classes=["Bicycle","Person"])
Uploading samples to CVAT...
Computing image metadata...
 100% |█████████████████████████████████████████████████████████████| 2000/2000 [1.8s elapsed, 0s remaining, 1.5K samples/s]        
Uncaught exception
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/core/collections.py", line 6272, in annotate
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/annotations.py", line 212, in annotate
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/cvat.py", line 3155, in upload_annotations
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/cvat.py", line 4095, in upload_samples
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/cvat.py", line 4741, in _create_task_upload_data
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/cvat.py", line 3955, in upload_data
OSError: [Errno 24] Too many open files: '/home/shao/fiftyone/open-images-v6/train/data/94b7ac9d54aad7be.jpg'

I then tried to reduce the sample to 600, and annotate(...) again, but got another error:


Uploading samples to CVAT...
Computing image metadata...
 100% |█████████████████████████████████████████████████████████████████| 93/93 [93.8ms elapsed, 0s remaining, 991.0 samples/s] 
Failed to populate metadata on 93 samples. Use `dataset.exists("metadata", False)` to retrieve them
Uncaught exception
Traceback (most recent call last):
  File "fiftyone_download_and_upload_to_CVAT.py", line 10, in <module>
    view.annotate(anno_key, label_field="detections",label_type="detections",classes=["Bicycle","Person"])
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/core/collections.py", line 6272, in annotate
    return foua.annotate(
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/annotations.py", line 212, in annotate
    results = anno_backend.upload_annotations(
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/cvat.py", line 3155, in upload_annotations
    results = api.upload_samples(samples, self)
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/cvat.py", line 4067, in upload_samples
    self._update_shapes_tags_tracks(
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/cvat.py", line 4873, in _update_shapes_tags_tracks
    _id_map, anno_shapes = self._create_shapes_tags_tracks(
  File "/home/shao/.local/lib/python3.8/site-packages/fiftyone/utils/cvat.py", line 5376, in _create_shapes_tags_tracks
    frame_size = (metadata.width, metadata.height)
AttributeError: 'NoneType' object has no attribute 'width'

Describe the problem

the upload to cvat failed.

What areas of FiftyOne does this bug affect?

Willingness to contribute

The FiftyOne Community encourages bug fix contributions. Would you or another member of your organization be willing to contribute a fix for this bug to the FiftyOne codebase?

ehofesmann commented 2 years ago

1) The first error (Too many open files) is a duplicate of this: https://github.com/voxel51/fiftyone/issues/1448 It is resolved using the task_size parameter: https://voxel51.com/docs/fiftyone/integrations/cvat.html#large-annotation-runs

2) For the second error: The image metadata is necessary when uploading samples to CVAT. It seems that there was an issue computing metadata for 93 of your samples. Check to see if those images were downloaded correctly. You can get the filepaths of those samples with the following:

non_metadata_view = dataset.exists("metadata", False)
filepaths = non_metadata_view.values("filepath")
print(filepaths)

If there is an issue with them, you can delete those images and have FiftyOne redownload them by calling foz.load_zoo_dataset again for your subset of open images. If not, your choices are to either ignore those samples or attempt to manually populate the metadata for them using ImageMetadata.build_for()