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

Improving object detection benchmarking process for unrelated datasets #1778

Open
2 tasks done
patel-zeel opened this issue Jan 20, 2025 · 0 comments
Open
2 tasks done
Labels
enhancement New feature or request

Comments

@patel-zeel
Copy link
Contributor

patel-zeel commented Jan 20, 2025

Search before asking

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

Description

Context

If a model is trained on a dataset, benchmarking with supervision's evaluation API is straightforward.

However, if the dataset was not used to train a model (unrelated dataset), one should follow the "how-to" guide on Benchmarking a model.

What if we can improve this with a simpler API?

Use case

In cases where the dataset was not used to train the model, people would need to: 1) remap the class names to match with the dataset; 2) transform the class IDs to match with the dataset. Here is what a boilerplate code would look like:

class_mapping = {"dog": "animal", "cat": "animal", "eagle": "bird"}
for _, image, target in dataset:
    result = model.infer(image)[0]
    detection = sv.Detections.from_inference(result)
    
    # check if all mapped values are within the dataset classes
    if not all([value in dataset.classes for value in class_mapping.values()]):
        raise ValueError("All mapped values must be in dataset classes")
    
    # remap class names
    detection['class_name'] = list(map(lambda name: class_mapping[name] if name in class_maping else name, detection['class_name']))

    # remove predicted classes not in the dataset
    detection = detection[np.isin(detection['class_name'], dataset.classes)]

    # remap Class IDs based on Class names
    detection.class_id = np.array([dataset.classes.index(name) for name in detection['class_name']])

Proposed API for the above transformation:

class_mapping = {"dog": "animal", "cat": "animal", "eagle": "bird"}
for _, image, target in dataset:
    result = model.infer(image)[0]
    detection = sv.Detections.from_inference(result)
    detection = detection.transform(dataset, class_mapping=class_mapping)

Where the transform method implements the same logic described in the boilerplate. Note that class_mapping is an optional argument in cases where class names are the same between a model and a dataset.

Additional

No response

Are you willing to submit a PR?

  • Yes I'd like to help by submitting a PR!
@patel-zeel patel-zeel added the enhancement New feature or request label Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant