class _SampleMixin(object): (source)
Known subclasses: fiftyone.core.sample.Sample
, fiftyone.core.sample.SampleView
Undocumented
Method | __getattr__ |
Undocumented |
Method | __getitem__ |
Undocumented |
Method | __iter__ |
Undocumented |
Method | __setattr__ |
Undocumented |
Method | __setitem__ |
Undocumented |
Method | add |
Adds the given labels to the sample. |
Method | clear |
Undocumented |
Method | compute |
Populates the metadata field of the sample. |
Method | copy |
Returns a deep copy of the sample that has not been added to the database. |
Method | get |
Undocumented |
Method | merge |
Merges the fields of the given sample into this sample. |
Method | set |
Undocumented |
Method | to |
Serializes the sample to a JSON dictionary. |
Property | dataset |
Undocumented |
Property | filename |
The basename of the media's filepath. |
Property | media |
The media type of the sample. |
Method | _parse |
Undocumented |
Method | _secure |
Undocumented |
Property | _dataset |
Undocumented |
Adds the given labels to the sample.
The provided labels can be any of the following:
A
fiftyone.core.labels.Label
instance, in which case the labels are directly saved in the specified label_fieldA dict mapping keys to
fiftyone.core.labels.Label
instances. In this case, the labels are added as follows:for key, value in labels.items(): sample[label_key(key)] = value
A dict mapping frame numbers to
fiftyone.core.labels.Label
instances. In this case, the provided labels are interpreted as frame-level labels that should be added as follows:sample.frames.merge( { frame_number: {label_field: label} for frame_number, label in labels.items() } )
A dict mapping frame numbers to dicts mapping keys to
fiftyone.core.labels.Label
instances. In this case, the provided labels are interpreted as frame-level labels that should be added as follows:sample.frames.merge( { frame_number: { label_key(key): value for key, value in frame_dict.items() } for frame_number, frame_dict in labels.items() } )
In the above, the label_key function maps label dict keys to field names, and is defined from label_field as follows:
if isinstance(label_field, dict): label_key = lambda k: label_field.get(k, k) elif label_field is not None: label_key = lambda k: label_field + "_" + k else: label_key = lambda k: k
Parameters | |
labels | a fiftyone.core.labels.Label or dict of labels per
the description above |
labelNone | the sample field, prefix, or dict defining in which field(s) to save the labels |
confidenceNone | an optional confidence threshold to apply to any applicable labels before saving them |
expandTrue | whether to dynamically add new fields encountered to the dataset schema. If False, an error is raised if any fields are not in the dataset schema |
validate:True | whether to validate values for existing fields |
dynamic:False | whether to declare dynamic attributes |
Returns a deep copy of the sample that has not been added to the database.
Parameters | |
fields:None | an optional field or iterable of fields to which to restrict the copy. This can also be a dict mapping existing field names to new field names |
omitNone | an optional field or iterable of fields to exclude from the copy |
Returns | |
a Sample |
Merges the fields of the given sample into this sample.
The behavior of this method is highly customizable. By default, all
top-level fields from the provided sample are merged in, overwriting
any existing values for those fields, with the exception of list fields
(e.g., tags) and label list fields (e.g.,
fiftyone.core.labels.Detections
fields), in which case the
elements of the lists themselves are merged. In the case of label list
fields, labels with the same id in both samples are updated rather
than duplicated.
To avoid confusion between missing fields and fields whose value is None, None-valued fields are always treated as missing while merging.
This method can be configured in numerous ways, including:
- Whether new fields can be added to the dataset schema
- Whether list fields should be treated as ordinary fields and merged as a whole rather than merging their elements
- Whether to merge only specific fields, or all but certain fields
- Mapping input sample fields to different field names of this sample
Parameters | |
sample | a fiftyone.core.sample.Sample |
fields:None | an optional field or iterable of fields to which to restrict the merge. May contain frame fields for video samples. This can also be a dict mapping field names of the input sample to field names of this sample |
omitNone | an optional field or iterable of fields to exclude from the merge. May contain frame fields for video samples |
mergeTrue | whether to merge the elements of list fields
(e.g., tags) and label list fields (e.g.,
fiftyone.core.labels.Detections fields) rather than
merging the entire top-level field like other field types.
For label lists fields, existing
fiftyone.core.label.Label elements are either replaced
(when overwrite is True) or kept (when overwrite is
False) when their id matches a label from the provided
sample |
overwrite:True | whether to overwrite (True) or skip (False) existing fields and label elements |
expandTrue | whether to dynamically add new fields encountered to the dataset schema. If False, an error is raised if any fields are not in the dataset schema |
validate:True | whether to validate values for existing fields |
dynamic:False | whether to declare dynamic embedded document fields |