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

Added "allow_new_labels" flag for class_labels tensor #2830

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

Conversation

nvoxland-al
Copy link
Contributor

🚀 🚀 Pull Request

Impact

  • Bug fix (non-breaking change which fixes expected existing functionality)
  • Enhancement/New feature (adds functionality without impacting existing logic)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

By default, tensors with htype="class_label" will accept any new values added to them. This PR adds a new allow_new_labels=False setting in the tensor "info" which changes that behavior to instead throw an exception if an unknown label is added.

The available labels are set in the info["class_names"] setting, either when the tensor is originally created:

        ds.create_tensor(
            "labels",
            htype="class_label",
            class_names=["cat", "dog", "horse"],
            allow_new_labels=False,
        )

or set/updated later:

ds.labels.info.update(allow_new_labels=False)
ds.labels.info.update(class_names=["cat", "dog", "horse")

Things to be aware of

If you update the class_names to be a different order or skipping existing labels, the label_id->text mapping will be off and reading from the tensor will give you incorrect results.

Copy link

@nvoxland-al nvoxland-al marked this pull request as draft July 12, 2024 14:14
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.

2 participants