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

Model evaluation subsets backend #5512

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Feb 24, 2025

Change log

Adds support for computing metrics for subsets of a full set of evaluation results via a new use_subset() method.

Example usage

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.utils.random as four
from fiftyone import ViewField as F

dataset = foz.load_zoo_dataset("quickstart")
four.random_split(dataset, {"sunny": 0.7, "cloudy": 0.2, "rainy": 0.1})

results = dataset.evaluate_detections(
    "predictions",
    gt_field="ground_truth",
    eval_key="eval",
)

counts = dataset.count_values("ground_truth.detections.label")
classes = sorted(counts, key=counts.get, reverse=True)[:5]

# Full results
results.print_report(classes=classes)

# Sunny samples
with results.use_subset(field="tags", value="sunny"):
    results.print_report(classes=classes)

# Small objects
bbox_area = F("bounding_box")[2] * F("bounding_box")[3]
small_objects = bbox_area <= 0.05
with results.use_subset(expr=small_objects):
    results.print_report(classes=classes)

Full results:

              precision    recall  f1-score   support

      person       0.52      0.94      0.67       716
        kite       0.59      0.88      0.71       140
         car       0.18      0.80      0.29        61
        bird       0.65      0.78      0.71       110
      carrot       0.09      0.74      0.16        47

   micro avg       0.42      0.90      0.57      1074
   macro avg       0.41      0.83      0.51      1074
weighted avg       0.51      0.90      0.64      1074

Sunny samples:

              precision    recall  f1-score   support

      person       1.00      0.94      0.97       472
        kite       1.00      0.88      0.93       122
         car       1.00      0.91      0.95        34
        bird       1.00      0.78      0.88       106
      carrot       1.00      0.72      0.84        43

   micro avg       1.00      0.90      0.95       777
   macro avg       1.00      0.85      0.92       777
weighted avg       1.00      0.90      0.94       777

Small objects:

              precision    recall  f1-score   support

      person       1.00      0.87      0.93       324
        kite       1.00      0.76      0.87        72
         car       1.00      0.79      0.88        56
        bird       1.00      0.52      0.69        46
      carrot       1.00      0.75      0.86        40

   micro avg       1.00      0.81      0.89       538
   macro avg       1.00      0.74      0.84       538
weighted avg       1.00      0.81      0.89       538

Subsets specification

Subset field

subset_field = "tags"
subsets = {v: (subset_field, v) for v in dataset.distinct(subset_field)}
"""
{
    'cloudy': ('tags', 'cloudy'),
    'rainy': ('tags', 'rainy'),
    'sunny': ('tags', 'sunny'),
}
"""

Subset expressions

from fiftyone import ViewField as F

bbox_area = F("bounding_box")[2] * F("bounding_box")[3]
subsets = {
    "Small objects": bbox_area <= 0.05,
    "Medium objects": (0.05 <= bbox_area) & (bbox_area <= 0.5),
    "Large objects": bbox_area > 0.5,
}

Subsets analysis

def analyze_subsets(results, subsets, classes=None):
    subset_reports = {}
    subset_metrics = {}

    for subset_name, subset_def in subsets.items():
        if isinstance(subset_def, tuple):
            field, value = subset_def
            kwargs = dict(field=field, value=value)
        else:
            kwargs = dict(expr=subset_def)

        with results.use_subset(**kwargs):
            subset_reports[subset_name] = results.report(classes=classes)
            subset_metrics[subset_name] = results.metrics(classes=classes)

    return subset_reports, subset_metrics

Copy link
Contributor

coderabbitai bot commented Feb 24, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -504,6 +505,24 @@ def load_view(self, ctx):
field = view_options.get("field", None)
missing = ctx.panel.get_state("missing", "(none)")

# Restrict to subset, if applicable
subset_name = view_state.get("subset_name", None)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should wire up view callbacks for the ME panel, assuming that:

  • A subset_name parameter is set that encodes the name of the subset (bar) that the user clicked on
  • A subsets dict is available in panel state that encodes the user's current subsets definition, using the structure described in the Subsets specification section of the PR description

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant