«
class documentation

Counts the occurrences of field values in a collection.

This aggregation is typically applied to countable field types (or lists of such types):

Examples:

import fiftyone as fo
from fiftyone import ViewField as F

dataset = fo.Dataset()
dataset.add_samples(
    [
        fo.Sample(
            filepath="/path/to/image1.png",
            tags=["sunny"],
            predictions=fo.Detections(
                detections=[
                    fo.Detection(label="cat"),
                    fo.Detection(label="dog"),
                ]
            ),
        ),
        fo.Sample(
            filepath="/path/to/image2.png",
            tags=["cloudy"],
            predictions=fo.Detections(
                detections=[
                    fo.Detection(label="cat"),
                    fo.Detection(label="rabbit"),
                ]
            ),
        ),
        fo.Sample(
            filepath="/path/to/image3.png",
            predictions=None,
        ),
    ]
)

#
# Compute the tag counts in the dataset
#

aggregation = fo.CountValues("tags")
counts = dataset.aggregate(aggregation)
print(counts)  # dict mapping values to counts

#
# Compute the predicted label counts in the dataset
#

aggregation = fo.CountValues("predictions.detections.label")
counts = dataset.aggregate(aggregation)
print(counts)  # dict mapping values to counts

#
# Compute the predicted label counts after some normalization
#

aggregation = fo.CountValues(
    F("predictions.detections.label").map_values(
        {"cat": "pet", "dog": "pet"}
    ).upper()
)
counts = dataset.aggregate(aggregation)
print(counts)  # dict mapping values to counts
Parameters
field_or_expra field name, embedded.field.name, fiftyone.core.expressions.ViewExpression, or MongoDB expression defining the field or expression to aggregate
expra fiftyone.core.expressions.ViewExpression or MongoDB expression to apply to field_or_expr (which must be a field) before aggregating
safewhether to treat nan/inf values as None when dealing with floating point values
Method __init__ Undocumented
Method default_result Returns the default result for this aggregation.
Method parse_result Parses the output of to_mongo.
Method to_mongo 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 _asc Undocumented
Instance Variable _field_type Undocumented
Instance Variable _first Undocumented
Instance Variable _include Undocumented
Instance Variable _search Undocumented
Instance Variable _selected Undocumented
Instance Variable _sort_by Undocumented

Inherited from Aggregation:

Method __eq__ Undocumented
Method __repr__ Undocumented
Method __str__ Undocumented
Property field_name The name of the field being computed on, if any.
Class Method _from_dict Creates an Aggregation instance from a serialized JSON dict representation of it.
Method _needs_frames Whether the aggregation requires frame labels of video samples to be attached.
Method _needs_group_slices 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_name Undocumented
Instance Variable _safe Undocumented
Instance Variable _uuid Undocumented
Property _has_big_result Whether the aggregation's result is returned across multiple documents.
Property _is_big_batchable 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, safe=False, _first=None, _sort_by='count', _asc=True, _include=None, _search='', _selected=[]): (source)
def default_result(self): (source)

Returns the default result for this aggregation.

Returns
{}
def parse_result(self, d): (source)

Parses the output of to_mongo.

Parameters
dthe result dict
Returns
a dict mapping values to counts
def to_mongo(self, sample_collection, context=None): (source)

Returns the MongoDB aggregation pipeline for this aggregation.

Parameters
sample_collectionthe fiftyone.core.collections.SampleCollection to which the aggregation is being applied
context:Nonea path context from which to resolve
Returns
a MongoDB aggregation pipeline (list of dicts)
def _kwargs(self): (source)

Returns a list of [name, value] lists describing the parameters of this aggregation instance.

Returns
a list of [name, value] lists

Undocumented

_field_type = (source)

Undocumented

Undocumented

_include = (source)

Undocumented

Undocumented

_selected = (source)

Undocumented

_sort_by = (source)

Undocumented