-
Notifications
You must be signed in to change notification settings - Fork 560
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
Adding support for dynamic embedded document field schemas #1825
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
benjaminpkane
approved these changes
Nov 4, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…into add-dynamic-fields-ben
Custom embedded fields in the App
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change log
add_sample_field()
andadd_frame_field()
select_fields()
andexclude_fields()
dynamic=True
flag that can be passed to dataset factory methods that will cause all dynamic embedded document attributes that are encountered to be automatically added to the dataset's schemaschema()
aggregation that can be used to compute the observed type(s) of arbitrarily nested embedded documentsget_dynamic_field_schema()
andadd_dynamic_sample_fields()
methods for automatically detecting and declaring dynamic sample fieldsget_dynamic_frame_field_schema()
andadd_dynamic_frame_fields()
methods for detecting and declaring dynamic frame fieldsflat=True
option toget_field_schema()
andget_frame_field_schema()
methods that returns all embedded document fields as top-level keysNotes
evaluate_detections()
will automatically add the dynamic attributes that it populates to the dataset's schemaadd_samples()
,from_dir()
, etcExample usage
Previously undeclared dynamic attributes can now be declared:
Detection evaluation automatically declares the dynamic attributes that it populates:
Design documentation
Any field(s) of your FiftyOne datasets that contain
DynamicEmbeddedDocument
values can have arbitrary custom attributes added to their instances.For example, all
Label
andMetadata
classes are dynamic, so you can add custom attributes to them as follows:By default, dynamic attributes are not included in a dataset's schema, which means that these attributes may contain arbitrary heterogenous values across the dataset's samples.
However, FiftyOne provides methods that you can use to formally declare custom dynamic attributes, which allows you to enforce type constraints, filter by these custom attributes in the App, and more.
You can use
get_dynamic_field_schema()
to detect the names and type(s) of any undeclared dynamic embedded document attributes on a dataset:You can then use
add_sample_field()
to declare a specific dynamic embedded document attribute:or you can use the
add_dynamic_sample_fields()
method to declare all dynamic embedded document attribute(s) that contain values of a single type:You can provide the optional
flat=True
option toget_field_schema()
to retrieve a flattened version of a dataset's schema that includes all embedded document attributes as top-level keys:By default, dynamic attributes are not declared on a dataset's schema when samples are added to it:
However, methods such as
add_samples()
andfrom_dir()
provide an optionaldynamic=True
option that you can provide to automatically declare any dynamic embedded document attributes encountered while importing data:Note that, when declaring dynamic attributes on non-empty datasets, you must ensure that the attribute's type is consistent with any existing values in that field, e.g., by first running
get_dynamic_field_schema()
to check the existing type(s). Methods likeadd_sample_field()
andadd_samples(..., dynamic=True)
do not validate newly declared field's types against existing field values:If you declare a dynamic attribute with a type that is not compatible with existing values in that field, you will need to remove that field from the dataset's schema using
remove_dynamic_sample_field()
in order for the dataset to be usable again:You can use
select_fields()
andexclude_fields()
to create views that select/exclude specific dynamic attributes from your dataset and its schema: