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

[BUG] CVAT fouc.import_annotations not importing video annotations #4316

Open
1 of 3 tasks
Rephil2 opened this issue Apr 27, 2024 · 0 comments
Open
1 of 3 tasks

[BUG] CVAT fouc.import_annotations not importing video annotations #4316

Rephil2 opened this issue Apr 27, 2024 · 0 comments
Labels
bug Bug fixes

Comments

@Rephil2
Copy link

Rephil2 commented Apr 27, 2024

Describe the problem

Value Error raised when fetching a video with specific rectangle type (non-outside tracked object).
The video downloads just fine:

Downloading media...
 100% |█████████████████████| 1/1 [1.2s elapsed, 0s remaining, 0.8 samples/s] 
 100% |█████████████████████| 1/1 [19.6ms elapsed, 0s remaining, 54.3 samples/s] 

but this error kicks in immediately after:

[5778](https://file+.vscode-resource.vscode-cdn.net/home/cystodev1/code/cystoaid_data_pipline/~/.local/lib/python3.10/site-packages/fiftyone/utils/cvat.py:5778) print(f'5770:anno_type: {anno_type}, prev_frame: {prev_frame}, prev_outside: {prev_outside}')
   [5779](https://file+.vscode-resource.vscode-cdn.net/home/cystodev1/code/cystoaid_data_pipline/~/.local/lib/python3.10/site-packages/fiftyone/utils/cvat.py:5779) if (anno_type == "track" and prev_frame is not None and not prev_outside):
-> [5780](https://file+.vscode-resource.vscode-cdn.net/home/cystodev1/code/cystoaid_data_pipline/~/.local/lib/python3.10/site-packages/fiftyone/utils/cvat.py:5780)     for frame in range( prev_frame + 1, min(max(frame_id_map), frame_stop) + 1 ):
   [5781](https://file+.vscode-resource.vscode-cdn.net/home/cystodev1/code/cystoaid_data_pipline/~/.local/lib/python3.10/site-packages/fiftyone/utils/cvat.py:5781)         anno = deepcopy(prev_anno)
   [5782](https://file+.vscode-resource.vscode-cdn.net/home/cystodev1/code/cystoaid_data_pipline/~/.local/lib/python3.10/site-packages/fiftyone/utils/cvat.py:5782)         anno["frame"] = frame
ValueError: max() arg is an empty sequence

Code/Video to reproduce issue

You need a video in CVAT that uses the track rectangle. The rectangle must be set to non-outside tracked on at least the second to last frame so it fills the remaining frames with rectangle copies of its the last instance.

fouc.import_annotations(
    dataset,
    task_ids=cvat_task_ids,
    download_media=True,
    data_path=dir_data,
    backend='cvat',
    label_types={'detections': 'ground_truth'},
    insert_new=True,
    url=os.getenv("FIFTYONE_CVAT_URL"),
    username=os.getenv("FIFTYONE_CVAT_USERNAME"),
    password=os.getenv("FIFTYONE_CVAT_PASSWORD"),
)

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 22.04): 22.04
  • Python version (python --version): Python 3.10.12
  • FiftyOne version (fiftyone --version): FiftyOne v0.23.7, Voxel51, Inc
  • FiftyOne installed from (pip or source): pip

Other info/logs

I found a fix.
I noticed if I ran the import_annotations method on a video with no rectangles on the ending frame of the video i could get passed the error and upon further inspection I could see that the difference between the two was a relative and absolute path assignment.
By setting the absolute path below the video data loads correctly regardless of if the video ends on an outside tracked frame or not.
Im not sure where the absolute path should actually be set but this fixed the issue for me.

/home/cystodev1/.local/lib/python3.10/site-packages/fiftyone/utils/cvat.py:

def _parse_task_metadata(
    api,
    task_id,
    data_map,
    task_filepaths,
    ignored_filenames,
    download_tasks,
    data_dir=None,
    download_media=False,
):
    resp = api.get(api.task_data_meta_url(task_id)).json()
    start_frame = resp.get("start_frame", None)
    stop_frame = resp.get("stop_frame", None)
    chunk_size = resp.get("chunk_size", None)
    
    #MY FIX START
    data_dir = f'{os.getcwd()}/{data_dir}'
    #MY FIX END
    
    cvat_id_map = {}
    for frame_id, frame in enumerate(resp["frames"]):
        filename = frame["name"]
        filepath = data_map.get(filename, None)
        
        if download_media:
            if filepath is None and data_dir:
                filepath = os.path.join(data_dir, filename)

            if filepath and not os.path.exists(filepath):
                download_tasks.append(
                    (
                        api,
                        task_id,
                        frame_id,
                        filepath,
                        start_frame,
                        stop_frame,
                        chunk_size,
                    )
                )

        if filepath is not None:
            cvat_id_map[filepath] = frame_id
            task_filepaths.append(filepath)
        else:
            ignored_filenames.append(filename)

    return cvat_id_map

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?

  • Yes. I can contribute a fix for this bug independently
  • Yes. I would be willing to contribute a fix for this bug with guidance
    from the FiftyOne community
  • No. I cannot contribute a bug fix at this time
@Rephil2 Rephil2 added the bug Bug fixes label Apr 27, 2024
@Rephil2 Rephil2 changed the title [BUG] CVAT fouc.import_annotations not importing annotations [BUG] CVAT fouc.import_annotations not importing video annotations Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

No branches or pull requests

1 participant