class documentation

Undocumented

Method __getattr__ Undocumented
Method __getitem__ Undocumented
Method __iter__ Undocumented
Method __setattr__ Undocumented
Method __setitem__ Undocumented
Method add_labels Adds the given labels to the sample.
Method clear_field Undocumented
Method compute_metadata 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_field Undocumented
Method merge Merges the fields of the given sample into this sample.
Method set_field Undocumented
Method to_dict Serializes the sample to a JSON dictionary.
Property dataset_id Undocumented
Property filename The basename of the media's filepath.
Property media_type The media type of the sample.
Method _parse_fields_video Undocumented
Method _secure_media Undocumented
Property _dataset_id Undocumented
def __getattr__(self, name): (source)

Undocumented

def __getitem__(self, field_name): (source)

Undocumented

def __iter__(self): (source)

Undocumented

def __setattr__(self, name, value): (source)

Undocumented

def __setitem__(self, field_name, value): (source)

Undocumented

def add_labels(self, labels, label_field=None, confidence_thresh=None, expand_schema=True, validate=True, dynamic=False): (source)

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_field

  • A 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
labelsa fiftyone.core.labels.Label or dict of labels per the description above
label_field:Nonethe sample field, prefix, or dict defining in which field(s) to save the labels
confidence_thresh:Nonean optional confidence threshold to apply to any applicable labels before saving them
expand_schema:Truewhether 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:Truewhether to validate values for existing fields
dynamic:Falsewhether to declare dynamic attributes
def clear_field(self, field_name): (source)

Undocumented

def compute_metadata(self, overwrite=False, skip_failures=False): (source)

Populates the metadata field of the sample.

Parameters
overwrite:Falsewhether to overwrite existing metadata
skip_failures:Falsewhether to gracefully continue without raising an error if metadata cannot be computed
def copy(self, fields=None, omit_fields=None): (source)

Returns a deep copy of the sample that has not been added to the database.

Parameters
fields:Nonean 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
omit_fields:Nonean optional field or iterable of fields to exclude from the copy
Returns
a Sample
def get_field(self, field_name): (source)

Undocumented

def merge(self, sample, fields=None, omit_fields=None, merge_lists=True, overwrite=True, expand_schema=True, validate=True, dynamic=False): (source)

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
samplea fiftyone.core.sample.Sample
fields:Nonean 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
omit_fields:Nonean optional field or iterable of fields to exclude from the merge. May contain frame fields for video samples
merge_lists:Truewhether 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:Truewhether to overwrite (True) or skip (False) existing fields and label elements
expand_schema:Truewhether 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:Truewhether to validate values for existing fields
dynamic:Falsewhether to declare dynamic embedded document fields
def set_field(self, field_name, value, create=True, validate=True, dynamic=False): (source)

Undocumented

def to_dict(self, include_frames=False, include_private=False): (source)

Serializes the sample to a JSON dictionary.

Parameters
include_frames:Falsewhether to include the frame labels for video samples
include_private:Falsewhether to include private fields
Returns
a JSON dict

Undocumented

The basename of the media's filepath.

The media type of the sample.

def _parse_fields_video(self, fields=None, omit_fields=None): (source)

Undocumented

def _secure_media(self, field_name, value): (source)

Undocumented

@property
_dataset_id = (source)

Undocumented