class MatchLabels(ViewStage): (source)
Constructor: MatchLabels(labels, ids, tags, filter, ...)
Selects the samples from a collection that contain (or do not contain) at least one label that matches the specified criteria.
Note that, unlike SelectLabels
and FilterLabels
, this
stage will not filter the labels themselves; it only selects the
corresponding samples.
You can perform a selection via one or more of the following methods:
- Provide the labels argument, which should contain a list of dicts
in the format returned by
fiftyone.core.session.Session.selected_labels
, to match specific labels - Provide the ids argument to match labels with specific IDs
- Provide the tags argument to match labels with specific tags
- Provide the filter argument to match labels based on a boolean
fiftyone.core.expressions.ViewExpression
that is applied to each individualfiftyone.core.labels.Label
element - Pass bool=False to negate the operation and instead match samples that do not contain at least one label matching the specified criteria
If multiple criteria are specified, labels must match all of them in order to trigger a sample match.
By default, the selection is applied to all
fiftyone.core.labels.Label
fields, but you can provide the
fields argument to explicitly define the field(s) in which to search.
Examples:
import fiftyone as fo import fiftyone.zoo as foz from fiftyone import ViewField as F dataset = foz.load_zoo_dataset("quickstart") # # Only show samples whose labels are currently selected in the App # session = fo.launch_app(dataset) # Select some labels in the App... stage = fo.MatchLabels(labels=session.selected_labels) view = dataset.add_stage(stage) # # Only include samples that contain labels with the specified IDs # # Grab some label IDs ids = [ dataset.first().ground_truth.detections[0].id, dataset.last().predictions.detections[0].id, ] stage = fo.MatchLabels(ids=ids) view = dataset.add_stage(stage) print(len(view)) print(view.count("ground_truth.detections")) print(view.count("predictions.detections")) # # Only include samples that contain labels with the specified tags # # Grab some label IDs ids = [ dataset.first().ground_truth.detections[0].id, dataset.last().predictions.detections[0].id, ] # Give the labels a "test" tag dataset = dataset.clone() # create copy since we're modifying data dataset.select_labels(ids=ids).tag_labels("test") print(dataset.count_values("ground_truth.detections.tags")) print(dataset.count_values("predictions.detections.tags")) # Retrieve the labels via their tag stage = fo.MatchLabels(tags="test") view = dataset.add_stage(stage) print(len(view)) print(view.count("ground_truth.detections")) print(view.count("predictions.detections")) # # Only include samples that contain labels matching a filter # filter = F("confidence") > 0.99 stage = fo.MatchLabels(filter=filter, fields="predictions") view = dataset.add_stage(stage) print(len(view)) print(view.count("ground_truth.detections")) print(view.count("predictions.detections"))
Parameters | |
labels | a list of dicts specifying the labels to select in the
format returned by
fiftyone.core.session.Session.selected_labels |
ids | an ID or iterable of IDs of the labels to select |
tags | a tag or iterable of tags of labels to select |
filter | a fiftyone.core.expressions.ViewExpression or
MongoDB aggregation expression
that returns a boolean describing whether to select a given label.
In the case of list fields like
fiftyone.core.labels.Detections , the filter is applied to
the list elements, not the root field |
fields | a field or iterable of fields from which to select |
bool | whether to match samples that have (None or True) or do not have (False) at least one label that matches the specified criteria |
Method | __init__ |
Undocumented |
Method | to |
Returns the MongoDB aggregation pipeline for the stage. |
Method | validate |
Validates that the stage can be applied to the given collection. |
Property | bool |
Whether to match samples that have (None or True) or do not have (False) at least one label that matches the specified criteria. |
Property | fields |
A list of fields from which labels are being matched. |
Property | filter |
A filter expression that defines the labels to match. |
Property | ids |
A list of IDs of labels to match. |
Property | labels |
A list of dicts specifying the labels to match. |
Property | tags |
A list of tags of labels to match. |
Class Method | _params |
Returns a list of JSON dicts describing the stage's supported parameters. |
Method | _get |
Undocumented |
Method | _kwargs |
Returns a list of [name, value] lists describing the parameters of this stage instance. |
Method | _make |
Undocumented |
Method | _make |
Undocumented |
Method | _needs |
Whether the stage requires frame labels of video samples to be attached. |
Method | _needs |
Whether the stage requires group slice(s) to be attached. |
Constant | _FILTER |
Undocumented |
Instance Variable | _bool |
Undocumented |
Instance Variable | _fields |
Undocumented |
Instance Variable | _filter |
Undocumented |
Instance Variable | _ids |
Undocumented |
Instance Variable | _labels |
Undocumented |
Instance Variable | _labels |
Undocumented |
Instance Variable | _pipeline |
Undocumented |
Instance Variable | _sample |
Undocumented |
Instance Variable | _tags |
Undocumented |
Inherited from ViewStage
:
Method | __eq__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __str__ |
Undocumented |
Method | get |
Returns a list of names of fields or embedded fields that may have been edited by the stage, if any. |
Method | get |
Returns a list of fields that have been excluded by the stage, if any. |
Method | get |
Returns a list of names of fields or embedded fields that contain arrays have been filtered by the stage, if any. |
Method | get |
Returns the dynamic group expression for the given stage, if any. |
Method | get |
Returns the media type outputted by this stage when applied to the given collection, if and only if it is different from the input type. |
Method | get |
Returns a list of fields that have been selected by the stage, if any. |
Method | load |
Loads the fiftyone.core.view.DatasetView containing the output of the stage. |
Property | has |
Whether this stage's output view should be loaded via load_view rather than appending stages to an aggregation pipeline via to_mongo . |
Property | outputs |
Whether this stage outputs or flattens dynamic groups. |
Class Method | _from |
Creates a ViewStage instance from a serialized JSON dict representation of it. |
Method | _serialize |
Returns a JSON dict representation of the ViewStage . |
Instance Variable | _uuid |
Undocumented |
Undocumented
fiftyone.core.stages.ViewStage.to_mongo
Returns the MongoDB aggregation pipeline for the stage.
Only usable if has_view
is False.
Parameters | |
_ | Undocumented |
sample | the
fiftyone.core.collections.SampleCollection to which
the stage is being applied |
Returns | |
a MongoDB aggregation pipeline (list of dicts) |
fiftyone.core.stages.ViewStage.validate
Validates that the stage can be applied to the given collection.
Parameters | |
sample | a
fiftyone.core.collections.SampleCollection |
Raises | |
ViewStageError | if the stage cannot be applied to the collection |
Whether to match samples that have (None or True) or do not have (False) at least one label that matches the specified criteria.
fiftyone.core.stages.ViewStage._params
Returns a list of JSON dicts describing the stage's supported parameters.
Returns | |
a list of JSON dicts |
fiftyone.core.stages.ViewStage._kwargs
Returns a list of [name, value] lists describing the parameters of this stage instance.
Returns | |
a list of [name, value] lists |
Whether the stage requires frame labels of video samples to be attached.
Parameters | |
sample | the
fiftyone.core.collections.SampleCollection to which
the stage is being applied |
Returns | |
True/False |
Whether the stage requires group slice(s) to be attached.
Parameters | |
sample | the
fiftyone.core.collections.SampleCollection to which
the stage is being applied |
Returns | |
None, or a list of group slices |