Classes:

 ImageMetadata(*args, **kwargs) Class for storing metadata about image samples. Metadata(*args, **kwargs) Base class for storing metadata about generic samples. VideoMetadata(*args, **kwargs) Class for storing metadata about video samples.

Functions:

 compute_metadata(sample_collection[, …]) Populates the metadata field of all samples in the collection. compute_sample_metadata(sample[, overwrite, …]) Populates the metadata field of the sample. Retrieves the dimensions and number of channels of the given image from a file-like object that is streaming its contents.
class fiftyone.core.metadata.Metadata(*args, **kwargs)

Parameters
• size_bytes (None) – the size of the media, in bytes

• mime_type (None) – the MIME type of the media

Attributes:

 STRICT mime_type A unicode string field. size_bytes A 32 bit integer field.

Methods:

 build_for(path_or_url[, mime_type]) Builds a Metadata object for the given file. Hook for doing document level data cleaning before validation is run. clear_field(field_name) Clears the field from the document. Returns a deep copy of the document. fancy_repr([class_name, select_fields, …]) Generates a customizable string representation of the document. field_to_mongo(field_name) field_to_python(field_name, value) from_dict(d[, extended]) Loads the document from a BSON/JSON dictionary. Loads the document from a JSON string. get_field(field_name) Gets the field of the document. Get text score from text query has_field(field_name) Determines whether the document has a field of the given name. set_field(field_name, value[, create]) Sets the value of a field of the document. to_dict([extended]) Serializes this document to a BSON/JSON dictionary. to_json([pretty_print]) Serializes the document to a JSON string. to_mongo(*args, **kwargs) Return as SON data ready for use with MongoDB. validate([clean]) Ensure that all fields’ values are valid and that required fields are present.

Classes:

 my_metaclass alias of mongoengine.base.metaclasses.DocumentMetaclass
size_bytes

A 32 bit integer field.

mime_type

A unicode string field.

classmethod build_for(path_or_url, mime_type=None)

Builds a Metadata object for the given file.

Parameters
• path_or_url – the path to the data on disk or a URL

• mime_type (None) – the MIME type of the file. If not provided, it will be guessed

Returns
STRICT = False
clean()

Hook for doing document level data cleaning before validation is run.

Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

clear_field(field_name)

Clears the field from the document.

Parameters

field_name – the field name

Raises

ValueError – if the field does not exist

copy()

Returns a deep copy of the document.

Returns

a SerializableDocument

fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)

Generates a customizable string representation of the document.

Parameters
• class_name (None) – optional class name to use

• select_fields (None) – iterable of field names to restrict to

• exclude_fields (None) – iterable of field names to exclude

• **kwargs – additional key-value pairs to include in the string representation

Returns

a string representation of the document

field_to_mongo(field_name)
field_to_python(field_name, value)
classmethod from_dict(d, extended=False)

Loads the document from a BSON/JSON dictionary.

Parameters
• d – a dictionary

• extended (False) – whether the input dictionary may contain serialized extended JSON constructs

Returns

a SerializableDocument

classmethod from_json(s)

Loads the document from a JSON string.

Returns

a SerializableDocument

get_field(field_name)

Gets the field of the document.

Parameters

field_name – the field name

Returns

the field value

Raises

AttributeError – if the field does not exist

get_text_score()

Get text score from text query

has_field(field_name)

Determines whether the document has a field of the given name.

Parameters

field_name – the field name

Returns

True/False

my_metaclass

alias of mongoengine.base.metaclasses.DocumentMetaclass Methods:

 mro() return a type’s method resolution order
set_field(field_name, value, create=False)

Sets the value of a field of the document.

Parameters
• field_name – the field name

• value – the field value

• create (False) – whether to create the field if it does not exist

Raises

ValueError – if field_name is not an allowed field name or does not exist and create == False

to_dict(extended=False)

Serializes this document to a BSON/JSON dictionary.

Parameters

extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format

Returns

a dict

to_json(pretty_print=False)

Serializes the document to a JSON string.

Parameters

pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Returns

a JSON string

to_mongo(*args, **kwargs)

Return as SON data ready for use with MongoDB.

validate(clean=True)

Ensure that all fields’ values are valid and that required fields are present.

Raises ValidationError if any of the fields’ values are found to be invalid.

class fiftyone.core.metadata.ImageMetadata(*args, **kwargs)

Parameters
• size_bytes (None) – the size of the image on disk, in bytes

• mime_type (None) – the MIME type of the image

• width (None) – the width of the image, in pixels

• height (None) – the height of the image, in pixels

• num_channels (None) – the number of channels in the image

Attributes:

 STRICT height A 32 bit integer field. mime_type A unicode string field. num_channels A 32 bit integer field. size_bytes A 32 bit integer field. width A 32 bit integer field.

Methods:

 build_for(img_or_path_or_url[, mime_type]) Builds an ImageMetadata object for the given image. Hook for doing document level data cleaning before validation is run. clear_field(field_name) Clears the field from the document. Returns a deep copy of the document. fancy_repr([class_name, select_fields, …]) Generates a customizable string representation of the document. field_to_mongo(field_name) field_to_python(field_name, value) from_dict(d[, extended]) Loads the document from a BSON/JSON dictionary. Loads the document from a JSON string. get_field(field_name) Gets the field of the document. Get text score from text query has_field(field_name) Determines whether the document has a field of the given name. set_field(field_name, value[, create]) Sets the value of a field of the document. to_dict([extended]) Serializes this document to a BSON/JSON dictionary. to_json([pretty_print]) Serializes the document to a JSON string. to_mongo(*args, **kwargs) Return as SON data ready for use with MongoDB. validate([clean]) Ensure that all fields’ values are valid and that required fields are present.

Classes:

 my_metaclass alias of mongoengine.base.metaclasses.DocumentMetaclass
width

A 32 bit integer field.

height

A 32 bit integer field.

num_channels

A 32 bit integer field.

classmethod build_for(img_or_path_or_url, mime_type=None)

Builds an ImageMetadata object for the given image.

Parameters
• img_or_path_or_url – an image, an image path on disk, or a URL

• mime_type (None) – the MIME type of the image. If not provided, it will be guessed

Returns
STRICT = False
clean()

Hook for doing document level data cleaning before validation is run.

Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

clear_field(field_name)

Clears the field from the document.

Parameters

field_name – the field name

Raises

ValueError – if the field does not exist

copy()

Returns a deep copy of the document.

Returns

a SerializableDocument

fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)

Generates a customizable string representation of the document.

Parameters
• class_name (None) – optional class name to use

• select_fields (None) – iterable of field names to restrict to

• exclude_fields (None) – iterable of field names to exclude

• **kwargs – additional key-value pairs to include in the string representation

Returns

a string representation of the document

field_to_mongo(field_name)
field_to_python(field_name, value)
classmethod from_dict(d, extended=False)

Loads the document from a BSON/JSON dictionary.

Parameters
• d – a dictionary

• extended (False) – whether the input dictionary may contain serialized extended JSON constructs

Returns

a SerializableDocument

classmethod from_json(s)

Loads the document from a JSON string.

Returns

a SerializableDocument

get_field(field_name)

Gets the field of the document.

Parameters

field_name – the field name

Returns

the field value

Raises

AttributeError – if the field does not exist

get_text_score()

Get text score from text query

has_field(field_name)

Determines whether the document has a field of the given name.

Parameters

field_name – the field name

Returns

True/False

mime_type

A unicode string field.

my_metaclass

alias of mongoengine.base.metaclasses.DocumentMetaclass Methods:

 mro() return a type’s method resolution order
set_field(field_name, value, create=False)

Sets the value of a field of the document.

Parameters
• field_name – the field name

• value – the field value

• create (False) – whether to create the field if it does not exist

Raises

ValueError – if field_name is not an allowed field name or does not exist and create == False

size_bytes

A 32 bit integer field.

to_dict(extended=False)

Serializes this document to a BSON/JSON dictionary.

Parameters

extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format

Returns

a dict

to_json(pretty_print=False)

Serializes the document to a JSON string.

Parameters

pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Returns

a JSON string

to_mongo(*args, **kwargs)

Return as SON data ready for use with MongoDB.

validate(clean=True)

Ensure that all fields’ values are valid and that required fields are present.

Raises ValidationError if any of the fields’ values are found to be invalid.

class fiftyone.core.metadata.VideoMetadata(*args, **kwargs)

Parameters
• size_bytes (None) – the size of the video on disk, in bytes

• mime_type (None) – the MIME type of the video

• frame_width (None) – the width of the video frames, in pixels

• frame_height (None) – the height of the video frames, in pixels

• frame_rate (None) – the frame rate of the video

• total_frame_count (None) – the total number of frames in the video

• duration (None) – the duration of the video, in seconds

• encoding_str (None) – the encoding string for the video

Attributes:

 STRICT duration A floating point number field. encoding_str A unicode string field. frame_height A 32 bit integer field. frame_rate A floating point number field. frame_width A 32 bit integer field. mime_type A unicode string field. size_bytes A 32 bit integer field. total_frame_count A 32 bit integer field.

Methods:

 build_for(video_path_or_url[, mime_type]) Builds an VideoMetadata object for the given video. Hook for doing document level data cleaning before validation is run. clear_field(field_name) Clears the field from the document. Returns a deep copy of the document. fancy_repr([class_name, select_fields, …]) Generates a customizable string representation of the document. field_to_mongo(field_name) field_to_python(field_name, value) from_dict(d[, extended]) Loads the document from a BSON/JSON dictionary. Loads the document from a JSON string. get_field(field_name) Gets the field of the document. Get text score from text query has_field(field_name) Determines whether the document has a field of the given name. set_field(field_name, value[, create]) Sets the value of a field of the document. to_dict([extended]) Serializes this document to a BSON/JSON dictionary. to_json([pretty_print]) Serializes the document to a JSON string. to_mongo(*args, **kwargs) Return as SON data ready for use with MongoDB. validate([clean]) Ensure that all fields’ values are valid and that required fields are present.

Classes:

 my_metaclass alias of mongoengine.base.metaclasses.DocumentMetaclass
frame_width

A 32 bit integer field.

frame_height

A 32 bit integer field.

frame_rate

A floating point number field.

total_frame_count

A 32 bit integer field.

duration

A floating point number field.

encoding_str

A unicode string field.

classmethod build_for(video_path_or_url, mime_type=None)

Builds an VideoMetadata object for the given video.

Parameters
• video_path_or_url – the path to a video on disk or a URL

• mime_type (None) – the MIME type of the image. If not provided, it will be guessed

Returns
STRICT = False
clean()

Hook for doing document level data cleaning before validation is run.

Any ValidationError raised by this method will not be associated with a particular field; it will have a special-case association with the field defined by NON_FIELD_ERRORS.

clear_field(field_name)

Clears the field from the document.

Parameters

field_name – the field name

Raises

ValueError – if the field does not exist

copy()

Returns a deep copy of the document.

Returns

a SerializableDocument

fancy_repr(class_name=None, select_fields=None, exclude_fields=None, **kwargs)

Generates a customizable string representation of the document.

Parameters
• class_name (None) – optional class name to use

• select_fields (None) – iterable of field names to restrict to

• exclude_fields (None) – iterable of field names to exclude

• **kwargs – additional key-value pairs to include in the string representation

Returns

a string representation of the document

field_to_mongo(field_name)
field_to_python(field_name, value)
classmethod from_dict(d, extended=False)

Loads the document from a BSON/JSON dictionary.

Parameters
• d – a dictionary

• extended (False) – whether the input dictionary may contain serialized extended JSON constructs

Returns

a SerializableDocument

classmethod from_json(s)

Loads the document from a JSON string.

Returns

a SerializableDocument

get_field(field_name)

Gets the field of the document.

Parameters

field_name – the field name

Returns

the field value

Raises

AttributeError – if the field does not exist

get_text_score()

Get text score from text query

has_field(field_name)

Determines whether the document has a field of the given name.

Parameters

field_name – the field name

Returns

True/False

mime_type

A unicode string field.

my_metaclass

alias of mongoengine.base.metaclasses.DocumentMetaclass Methods:

 mro() return a type’s method resolution order
set_field(field_name, value, create=False)

Sets the value of a field of the document.

Parameters
• field_name – the field name

• value – the field value

• create (False) – whether to create the field if it does not exist

Raises

ValueError – if field_name is not an allowed field name or does not exist and create == False

size_bytes

A 32 bit integer field.

to_dict(extended=False)

Serializes this document to a BSON/JSON dictionary.

Parameters

extended (False) – whether to serialize extended JSON constructs such as ObjectIDs, Binary, etc. into JSON format

Returns

a dict

to_json(pretty_print=False)

Serializes the document to a JSON string.

Parameters

pretty_print (False) – whether to render the JSON in human readable format with newlines and indentations

Returns

a JSON string

to_mongo(*args, **kwargs)

Return as SON data ready for use with MongoDB.

validate(clean=True)

Ensure that all fields’ values are valid and that required fields are present.

Raises ValidationError if any of the fields’ values are found to be invalid.

fiftyone.core.metadata.compute_sample_metadata(sample, overwrite=False, skip_failures=False)

Populates the metadata field of the sample.

Parameters
• overwrite (False) – whether to overwrite existing metadata

• skip_failures (False) – whether to gracefully continue without raising an error if metadata cannot be computed

fiftyone.core.metadata.compute_metadata(sample_collection, overwrite=False, num_workers=None, skip_failures=True)

Populates the metadata field of all samples in the collection.

Any samples with existing metadata are skipped, unless overwrite == True.

Parameters
• sample_collection – a fiftyone.core.collections.SampleCollection

• overwrite (False) – whether to overwrite existing metadata

• num_workers (None) – the number of processes to use. By default, multiprocessing.cpu_count() is used

• skip_failures (True) – whether to gracefully continue without raising an error if metadata cannot be computed for a sample

fiftyone.core.metadata.get_image_info(f)

Retrieves the dimensions and number of channels of the given image from a file-like object that is streaming its contents.

Parameters

f – a file-like object that supports read(), seek(), tell()

Returns

(width, height, num_channels)