class documentation
class Schema(Aggregation): (source)
Constructor: Schema(field_or_expr, expr, dynamic_only, _doc_type, _include_private)
Extracts the names and types of the attributes of a specified embedded document field across all samples in a collection.
Schema aggregations are useful for detecting the presence and types of
dynamic attributes of fiftyone.core.labels.Label
fields across
a collection.
Examples:
import fiftyone as fo dataset = fo.Dataset() sample1 = fo.Sample( filepath="image1.png", ground_truth=fo.Detections( detections=[ fo.Detection( label="cat", bounding_box=[0.1, 0.1, 0.4, 0.4], foo="bar", hello=True, ), fo.Detection( label="dog", bounding_box=[0.5, 0.5, 0.4, 0.4], hello=None, ) ] ) ) sample2 = fo.Sample( filepath="image2.png", ground_truth=fo.Detections( detections=[ fo.Detection( label="rabbit", bounding_box=[0.1, 0.1, 0.4, 0.4], foo=None, ), fo.Detection( label="squirrel", bounding_box=[0.5, 0.5, 0.4, 0.4], hello="there", ), ] ) ) dataset.add_samples([sample1, sample2]) # # Get schema of all dynamic attributes on the detections in a # `Detections` field # aggregation = fo.Schema("ground_truth.detections", dynamic_only=True) print(dataset.aggregate(aggregation)) # {'foo': StringField, 'hello': [BooleanField, StringField]}
Parameters | |
field | a field name, embedded.field.name,
fiftyone.core.expressions.ViewExpression , or
MongoDB expression
defining the field or expression to aggregate |
expr | a fiftyone.core.expressions.ViewExpression or
MongoDB expression
to apply to field_or_expr (which must be a field) before
aggregating |
dynamic | whether to only include dynamically added attributes |
Method | __init__ |
Undocumented |
Method | default |
Returns the default result for this aggregation. |
Method | parse |
Parses the output of to_mongo . |
Method | to |
Returns the MongoDB aggregation pipeline for this aggregation. |
Method | _kwargs |
Returns a list of [name, value] lists describing the parameters of this aggregation instance. |
Instance Variable | _doc |
Undocumented |
Instance Variable | _dynamic |
Undocumented |
Instance Variable | _include |
Undocumented |
Inherited from Aggregation
:
Method | __eq__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Property | field |
The name of the field being computed on, if any. |
Property | safe |
Whether nan/inf values will be ignored when dealing with floating point values. |
Class Method | _from |
Creates an Aggregation instance from a serialized JSON dict representation of it. |
Method | _needs |
Whether the aggregation requires frame labels of video samples to be attached. |
Method | _needs |
Whether the aggregation requires group slice(s) to be attached. |
Method | _serialize |
Returns a JSON dict representation of the Aggregation . |
Instance Variable | _expr |
Undocumented |
Instance Variable | _field |
Undocumented |
Instance Variable | _safe |
Undocumented |
Instance Variable | _uuid |
Undocumented |
Property | _has |
Whether the aggregation's result is returned across multiple documents. |
Property | _is |
Whether the aggregation has big results and its pipeline is defined by a single $project stage and thus can be combined with other such aggregations. |
def __init__(self, field_or_expr, expr=None, dynamic_only=False, _doc_type=None, _include_private=False):
(source)
¶
Undocumented
Parses the output of to_mongo
.
Parameters | |
d | the result dict |
Returns | |
a dict mapping field names to fiftyone.core.fields.Field
instances. If a field's values takes multiple non-None types, the
list of observed types will be returned |
Returns the MongoDB aggregation pipeline for this aggregation.
Parameters | |
sample | the
fiftyone.core.collections.SampleCollection to which
the aggregation is being applied |
context:None | a path context from which to resolve |
Returns | |
a MongoDB aggregation pipeline (list of dicts) |