class ExcludeLabels(ViewStage): (source)
Constructor: ExcludeLabels(labels, ids, tags, fields, omit_empty)
Excludes the specified labels from a collection.
The returned view will omit samples, sample fields, and individual labels that do not match the specified selection criteria.
You can perform an exclusion 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 exclude specific labels - Provide the ids argument to exclude labels with specific IDs
- Provide the tags argument to exclude labels with specific tags
If multiple criteria are specified, labels must match all of them in order to be excluded.
By default, the exclusion 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 exclude.
Examples:
import fiftyone as fo import fiftyone.zoo as foz dataset = foz.load_zoo_dataset("quickstart") # # Exclude the labels currently selected in the App # session = fo.launch_app(dataset) # Select some labels in the App... stage = fo.ExcludeLabels(labels=session.selected_labels) view = dataset.add_stage(stage) # # Exclude 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.ExcludeLabels(ids=ids) view = dataset.add_stage(stage) print(dataset.count("ground_truth.detections")) print(view.count("ground_truth.detections")) print(dataset.count("predictions.detections")) print(view.count("predictions.detections")) # # Exclude 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")) # Exclude the labels via their tag stage = fo.ExcludeLabels(tags="test") view = dataset.add_stage(stage) print(dataset.count("ground_truth.detections")) print(view.count("ground_truth.detections")) print(dataset.count("predictions.detections")) print(view.count("predictions.detections"))
Parameters | |
labels | a list of dicts specifying the labels to exclude in the
format returned by
fiftyone.core.session.Session.selected_labels |
ids | an ID or iterable of IDs of the labels to exclude |
tags | a tag or iterable of tags of labels to exclude |
fields | a field or iterable of fields from which to exclude |
omit | whether to omit samples that have no labels after filtering |
Method | __init__ |
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 names of fields or embedded fields that contain arrays have been filtered by the stage, if any. |
Method | to |
Returns the MongoDB aggregation pipeline for the stage. |
Method | validate |
Validates that the stage can be applied to the given collection. |
Property | fields |
A list of fields from which labels are being excluded. |
Property | ids |
A list of IDs of labels to exclude. |
Property | labels |
A list of dicts specifying the labels to exclude. |
Property | omit |
Whether to omit samples that have no labels after filtering. |
Property | tags |
A list of tags of labels to exclude. |
Class Method | _params |
Returns a list of JSON dicts describing the stage's supported parameters. |
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. |
Instance Variable | _fields |
Undocumented |
Instance Variable | _ids |
Undocumented |
Instance Variable | _labels |
Undocumented |
Instance Variable | _labels |
Undocumented |
Instance Variable | _omit |
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 fields that have been excluded 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 |
Returns a list of names of fields or embedded fields that may have been edited by the stage, if any.
The "frames." prefix should be omitted when frames is True.
Parameters | |
sample | the
fiftyone.core.collections.SampleCollection to which
the stage is being applied |
frames:False | whether to return sample-level (False) or frame-level (True) fields |
Returns | |
a list of fields, or None if no fields have been edited |
Returns a list of names of fields or embedded fields that contain arrays have been filtered by the stage, if any.
For example, if a stage filters a
fiftyone.core.labels.Detections
field called
"predictions", it should include "predictions.detections" in
the returned list.
The "frames." prefix should be omitted when frames is True.
Parameters | |
sample | the
fiftyone.core.collections.SampleCollection to which
the stage is being applied |
frames:False | whether to return sample-level (False) or frame-level (True) fields |
Returns | |
a list of fields, or None if no fields have been filtered |
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 |
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 |