voxel51 / fiftyone

The open-source tool for building high-quality datasets and computer vision models
https://fiftyone.ai
Apache License 2.0
8.08k stars 537 forks source link

[BUG] load annotations exception while deleting labels #4196

Open spaced opened 5 months ago

spaced commented 5 months ago

Describe the problem

load annotations results in an exception

Code to reproduce issue

>>> gs =fo.load_dataset('test')
>>> gs.list_annotation_runs()
['test1', 'test12']
>>> gs.load_annotations('test12')
Downloading labels from Label Studio...
Download complete
Loading labels for field 'ground_truth'...
Traceback (most recent call last):
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/fiftyone/core/odm/database.py", line 807, in bulk_write
    coll.bulk_write(batch, ordered=ordered)
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/pymongo/_csot.py", line 107, in csot_wrapper
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/pymongo/collection.py", line 569, in bulk_write
    bulk_api_result = blk.execute(write_concern, session)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/pymongo/bulk.py", line 576, in execute
    return self.execute_command(generator, write_concern, session)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/pymongo/bulk.py", line 446, in execute_command
    _raise_bulk_write_error(full_result)
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/pymongo/bulk.py", line 157, in _raise_bulk_write_error
    raise BulkWriteError(full_result)
pymongo.errors.BulkWriteError: batch op errors occurred, full error: {'writeErrors': [{'index': 0, 'code': 2, 'errmsg': 'Cannot apply $pull to a non-array value', 'op': {'q': {'ground_truth.detections': {'$exists': True}}, 'u': {'$pull': {'ground_truth.detections': {'_id': {'$in': [ObjectId('65578a3b7499471472bb40e1'), ObjectId('6551158dfd0a50d1decf13be'), ObjectId('65bd13ddb36066900d2c2d9b'), ObjectId('65511598fd0a50d1decf3849'), ObjectId('6557445e59d3f439ba79cd5d'), ObjectId('65bd1531500399d9ed879671'), ObjectId('65577f7f66df65c20c6de81f'), ObjectId('65bd13ddb36066900d2c2cfc'), ObjectId('65bd13ddb36066900d2c2cfb'), ObjectId('65bd13ddb36066900d2c2cfd'), ObjectId('6551158dfd0a50d1decf13ba'), ObjectId('65bd13deb36066900d2c434a'), ObjectId('65bd13ddb36066900d2c2d0d')]}}}}, 'multi': True, 'upsert': False}}], 'writeConcernErrors': [], 'nInserted': 0, 'nUpserted': 0, 'nMatched': 0, 'nModified': 0, 'nRemoved': 0, 'upserted': []}

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/fiftyone/core/collections.py", line 8837, in load_annotations
    return foua.load_annotations(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/fiftyone/utils/annotations.py", line 1079, in load_annotations
    _merge_labels(
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/fiftyone/utils/annotations.py", line 1486, in _merge_labels
    dataset.delete_labels(ids=_del_ids, fields=label_field)
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/fiftyone/core/dataset.py", line 3230, in delete_labels
    foo.bulk_write(sample_ops, self._sample_collection)
  File "/home/testuser/git/testrepo/model/venv/lib64/python3.11/site-packages/fiftyone/core/odm/database.py", line 816, in bulk_write
    raise ValueError(msg) from bwe
ValueError: Cannot apply $pull to a non-array value

System information

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?

benjaminpkane commented 5 months ago

Hi @spaced, if you add reproduction steps we will be able to diagnose 🙏

andrewaf1 commented 1 month ago

I am experiencing this same issue as well. I loaded a detection dataset from a file, called annotate with classes=dataset.get_classes("gt_bounding_boxes") + ["small_blurry"] (the only difference from when I last did this), labeled 500 images in labels studio, and then called load_annotations.