class documentation

class Frames(object): (source)

Known subclasses: fiftyone.core.frame.FramesView

Constructor: Frames(sample)

View In Hierarchy

An ordered dictionary of Frame instances keyed by frame number representing the frames of a video fiftyone.core.sample.Sample.

Frames instances behave like defaultdict(Frame) instances; an empty Frame instance is returned when accessing a new frame number.

Frames instances should never be created manually; they are instantiated automatically when video fiftyone.core.sample.Sample instances are created.

Parameters
samplethe fiftyone.core.sample.Sample to which the frames are attached
Method __bool__ Undocumented
Method __contains__ Undocumented
Method __delitem__ Undocumented
Method __getitem__ Undocumented
Method __init__ Undocumented
Method __iter__ Undocumented
Method __len__ Undocumented
Method __next__ Undocumented
Method __repr__ Undocumented
Method __setitem__ Undocumented
Method __str__ Undocumented
Method add_frame Adds the frame to this instance.
Method clear Removes all frames from this sample.
Method delete_frame Deletes the given frame number from this instance.
Method first Returns the first Frame for the sample.
Method head Returns a list of the first few frames for the sample.
Method items Returns an iterator over the frame numberes and Frame instances for the sample.
Method keys Returns an iterator over the frame numbers with labels in the sample.
Method last Returns the last Frame for the sample.
Method merge Merges the given frames into this instance.
Method reload Reloads all frames for the sample from the database.
Method save Saves all frames for the sample to the database.
Method tail Returns a list of the last few frames for the sample.
Method update Adds the frame labels to this instance.
Method values Returns an iterator over the Frame instances for the sample.
Property field_names An ordered tuple of the names of the fields on the frames.
Method _get_frame_db Undocumented
Method _get_frame_numbers Undocumented
Method _get_frame_numbers_db Undocumented
Method _get_frames_match_stage Undocumented
Method _get_ids_map Undocumented
Method _iter_frames Undocumented
Method _iter_frames_db Undocumented
Method _make_dict Undocumented
Method _make_frame Undocumented
Method _save Undocumented
Method _save_deletions Undocumented
Method _save_replacements Undocumented
Method _set_replacement Undocumented
Method _to_frames_dict Undocumented
Method _validate_frame Undocumented
Instance Variable _delete_all Undocumented
Instance Variable _delete_frames Undocumented
Instance Variable _iter Undocumented
Instance Variable _replacements Undocumented
Instance Variable _sample Undocumented
Property _dataset Undocumented
Property _frame_collection Undocumented
Property _frame_collection_name Undocumented
Property _in_db Undocumented
Property _sample_collection Undocumented
Property _sample_id Undocumented
def __bool__(self): (source)

Undocumented

def __contains__(self, frame_number): (source)

Undocumented

def __delitem__(self, frame_number): (source)

Undocumented

def __getitem__(self, frame_number): (source)

Undocumented

def __init__(self, sample): (source)

Undocumented

def __iter__(self): (source)

Undocumented

def __len__(self): (source)

Undocumented

def __next__(self): (source)

Undocumented

def __repr__(self): (source)

Undocumented

def __setitem__(self, frame_number, frame): (source)

Undocumented

def __str__(self): (source)

Undocumented

def add_frame(self, frame_number, frame, expand_schema=True, validate=True, dynamic=False): (source)

Adds the frame to this instance.

If an existing frame with the same frame number exists, it is overwritten.

If the provided frame is a Frame instance that does not belong to a dataset, it is updated in-place to reflect its membership in this dataset. Otherwise, the provided frame is not modified.

Parameters
frame_numberthe frame number
framea Frame or FrameView
expand_schema:Truewhether to dynamically add new frame fields encountered to the dataset schema. If False, an error is raised if the frame's schema is not a subset of the dataset schema
validate:Truewhether to validate values for existing fields
dynamic:Falsewhether to declare dynamic embedded document fields
def clear(self): (source)

Removes all frames from this sample.

def delete_frame(self, frame_number): (source)

Deletes the given frame number from this instance.

Parameters
frame_numberthe frame number
def first(self): (source)

Returns the first Frame for the sample.

Returns
a Frame
def head(self, num_frames=3): (source)

Returns a list of the first few frames for the sample.

If fewer than num_frames frames exist, only the available frames are returned.

Parameters
num_frames:3the number of frames
Returns
a list of Frame objects
def items(self): (source)

Returns an iterator over the frame numberes and Frame instances for the sample.

The frames are traversed in ascending order.

Returns
a generator that emits (frame_number, Frame) tuples
def keys(self): (source)

Returns an iterator over the frame numbers with labels in the sample.

The frames are traversed in ascending order.

Returns
a generator that emits frame numbers
def last(self): (source)

Returns the last Frame for the sample.

Returns
a Frame
def merge(self, frames, fields=None, omit_fields=None, merge_lists=True, overwrite=True, expand_schema=True, validate=True, dynamic=False): (source)

Merges the given frames into this instance.

The behavior of this method is highly customizable. By default, all top-level fields from the provided frames are merged into existing frames with the same frame numbers (and new frames created as necessary), 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 frames 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 frame 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 frame fields to different field names of this frame
Parameters
frames

can be any of the following

  • a Frames instance
  • a dictionary mapping frame numbers to Frame instances
  • a dictionary mapping frame numbers to dictionaries mapping label fields to fiftyone.core.labels.Label instances
fields:Nonean optional field or iterable of fields to which to restrict the merge. This can also be a dict mapping field names of the input frame to field names of this frame
omit_fields:Nonean optional field or iterable of fields to exclude from the merge
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 frames
overwrite:Truewhether to overwrite (True) or skip (False) existing fields and label elements
expand_schema:Truewhether to dynamically add new frame fields encountered to the dataset schema. If False, an error is raised if the frame's schema is not a subset of the dataset schema
validate:Truewhether to validate values for existing fields
dynamic:Falsewhether to declare dynamic embedded document fields
def reload(self, hard=False): (source)

Reloads all frames for the sample from the database.

Parameters
hard:Falsewhether to reload the frame schema in addition to the field values for the frames. This is necessary if new fields may have been added to the dataset's frame schema
def save(self): (source)

Saves all frames for the sample to the database.

def tail(self, num_frames=3): (source)

Returns a list of the last few frames for the sample.

If fewer than num_frames frames exist, only the available frames are returned.

Parameters
num_frames:3the number of frames
Returns
a list of Frame objects
def update(self, frames, overwrite=True, expand_schema=True, validate=True, dynamic=False): (source)

Adds the frame labels to this instance.

Parameters
frames

can be any of the following

  • a Frames instance
  • a dictionary mapping frame numbers to Frame instances
  • a dictionary mapping frame numbers to dictionaries mapping label fields to fiftyone.core.labels.Label instances
overwrite:Truewhether to overwrite existing frames
expand_schema:Truewhether to dynamically add new frame fields encountered to the dataset schema. If False, an error is raised if the frame's schema is not a subset of the dataset schema
validate:Truewhether to validate values for existing fields
dynamic:Falsewhether to declare dynamic embedded document fields
def values(self): (source)

Returns an iterator over the Frame instances for the sample.

The frames are traversed in ascending order.

Returns
a generator that emits Frame instances
@property
field_names = (source)

An ordered tuple of the names of the fields on the frames.

def _get_frame_db(self, frame_number): (source)

Undocumented

def _get_frame_numbers(self): (source)

Undocumented

def _get_frame_numbers_db(self): (source)

Undocumented

def _get_frames_match_stage(self): (source)

Undocumented

def _get_ids_map(self): (source)

Undocumented

def _iter_frames(self, offset=None): (source)

Undocumented

def _iter_frames_db(self): (source)

Undocumented

def _make_dict(self, frame, include_id=False, created_at=None, last_modified_at=None): (source)

Undocumented

def _make_frame(self, d): (source)

Undocumented

def _save(self, deferred=False): (source)

Undocumented

def _save_deletions(self, deferred=False): (source)

Undocumented

def _save_replacements(self, include_singletons=True, validate=True, deferred=False, **kwargs): (source)

Undocumented

def _set_replacement(self, frame): (source)

Undocumented

def _to_frames_dict(self, include_private=False): (source)

Undocumented

def _validate_frame(self, frame, schema): (source)

Undocumented

_delete_all: bool = (source)

Undocumented

_delete_frames: set = (source)

Undocumented

Undocumented

_replacements: dict = (source)

Undocumented

Undocumented

Undocumented

@property
_frame_collection = (source)

Undocumented

@property
_frame_collection_name = (source)

Undocumented

Undocumented

@property
_sample_collection = (source)

Undocumented

Undocumented