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

Save detection area with CSVSink #1397

Open
1 of 2 tasks
robmarkcole opened this issue Jul 23, 2024 · 10 comments
Open
1 of 2 tasks

Save detection area with CSVSink #1397

robmarkcole opened this issue Jul 23, 2024 · 10 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@robmarkcole
Copy link

Search before asking

  • I have searched the Supervision issues and found no similar feature requests.

Description

I would like to save all the Detections data to csv. Currently the area is not saved, and my approach below isn't successful. This FR is to save the area (and potentially other detection attributes that are currently not saved)

with sv.CSVSink(csv_path) as sink:
    for detection in detections:
        sink.append(detection, {"area": detection.area})
AttributeError: 'tuple' object has no attribute 'area'

Use case

I will perform filtering in a separate application

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@robmarkcole robmarkcole added the enhancement New feature or request label Jul 23, 2024
@robmarkcole
Copy link
Author

I've also got some functions which will convert the output of JSONSink to coco_json, for importing as pre-annotations. This currently has to calc the area and parse the xyxyxyxy with regex, so if these were exposed more simply this process would be streamlined

@SkalskiP
Copy link
Collaborator

SkalskiP commented Jul 23, 2024

@robmarkcole, you should pass the whole sv.Detections object as a sink.append argument. No loop is needed.

with sv.CSVSink(csv_path) as sink:
    sink.append(detections, {"area": detections.area})     

@SkalskiP
Copy link
Collaborator

@robmarkcole, I see you reacted. Did that solve your problem? If so, I'm closing the issue. ;)

@robmarkcole
Copy link
Author

I still think it would be a nice feature to have out of the box, along with xyxy for the polygon

  • I can make a PR if required

@robmarkcole
Copy link
Author

That appears to result in the entire area array being saved for every row:

image

@SkalskiP
Copy link
Collaborator

Hi @robmarkcole, unfortunately, I won't have time to dig deeper into this problem this week. I'm not going to lie; JSONSink and CSVSink could use some love.

Let me tag @LinasKo here so he can take a look next week.

@SkalskiP SkalskiP added the bug Something isn't working label Jul 25, 2024
@LinasKo
Copy link
Contributor

LinasKo commented Aug 6, 2024

Hi @robmarkcole 👋

I'll look into this.

@LinasKo
Copy link
Contributor

LinasKo commented Aug 6, 2024

This goes surprisingly deep.

@robmarkcole, syntax-wise, the cleanest solution is to add the areas into data, as it's treated differently than custom_data.

with sv.CSVSink(csv_path) as sink:
    detections.data["area"] = detections.area
    sink.append(detections)

This will modify the detections object if you're using it later, however.


@SkalskiP, I can't find @PawelPeczek-Roboflow's issue where he asked for collection-level storage in sv.Detections. Something like data, but applicable to all images, like 'camera_id'.

The issue here is, basically, custom_data is treated as an even more general data, capable of storing collection-level vars. It may store a scalar, a dict - basically anything. We could reduce it to only store lists of things like data, but it will break some implementations.

A good solution would be to first solve Pawel's request, and then come back to edit CSVSink (with deprecations).

@SkalskiP
Copy link
Collaborator

SkalskiP commented Aug 7, 2024

@LinasKo, how about we collect the list of potential improvements for CSVSink and work on v2?

@robmarkcole
Copy link
Author

A related feature request, DataFrameSink as a convenience to avoid

  csv_path = f'/tmp/{image_id}.csv'
  with sv.CSVSink(csv_path) as sink:
      sink.append(detections, {})

  df = pd.read_csv(csv_path)

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

No branches or pull requests

3 participants