# fiftyone.core.validation¶

Validation utilities.

Functions:

 get_field(sample, field_name[, …]) Gets the given sample field and optionally validates its type and value. get_fields(sample, field_names[, …]) Gets the given sample fields and optionally validates their types and values. validate_collection(sample_collection[, …]) Validates that the provided samples are a fiftyone.core.collections.SampleCollection. Validates that the fiftyone.core.collections.SampleCollection has fields with the specified fiftyone.core.labels.Label types. validate_image_collection(sample_collection) Validates that the provided samples are an image fiftyone.core.collections.SampleCollection. validate_image_sample(sample) Validates that the sample’s media is an image. validate_video_collection(sample_collection) Validates that the provided samples are a video fiftyone.core.collections.SampleCollection. validate_video_sample(sample) Validates that the sample’s media is a video.
fiftyone.core.validation.validate_image_sample(sample)

Validates that the sample’s media is an image.

Parameters
Raises

ValueError if the sample's media is not an image

fiftyone.core.validation.validate_video_sample(sample)

Validates that the sample’s media is a video.

Parameters
Raises

ValueError if the sample's media is not a video

fiftyone.core.validation.validate_collection(sample_collection, media_type=None)

Validates that the provided samples are a fiftyone.core.collections.SampleCollection.

Parameters
• sample_collection – a sample collection

• media_type (None) – an optional media type or iterable of media types that the collection must have

Raises
• ValueError – if samples is not a

fiftyone.core.validation.validate_image_collection(sample_collection)

Validates that the provided samples are an image fiftyone.core.collections.SampleCollection.

Parameters

sample_collection – a sample collection

Raises
• ValueError – if samples is not an image

fiftyone.core.validation.validate_video_collection(sample_collection)

Validates that the provided samples are a video fiftyone.core.collections.SampleCollection.

Parameters

sample_collection – a sample collection

Raises
• ValueError – if samples is not a video

fiftyone.core.validation.validate_collection_label_fields(sample_collection, field_names, allowed_label_types, same_type=False)

Validates that the fiftyone.core.collections.SampleCollection has fields with the specified fiftyone.core.labels.Label types.

Parameters
Raises

ValueError if the required conditions are not met

fiftyone.core.validation.get_field(sample, field_name, allowed_types=None, allow_none=True)

Gets the given sample field and optionally validates its type and value.

Parameters
• field_name – the name of the field to get

• allowed_types (None) – an optional iterable of fiftyone.core.labels.Label types to enforce that the field value has

• allow_none (True) – whether to allow the field to be None

Returns

the field value

Raises
• ValueError if the field does not exist or does not meet the specified

• criteria

fiftyone.core.validation.get_fields(sample, field_names, allowed_types=None, same_type=False, allow_none=True)

Gets the given sample fields and optionally validates their types and values.

Parameters
• field_names – an iterable of field names to get

• allowed_types (None) – an optional iterable of fiftyone.core.labels.Label types to enforce that the field values have

• same_type (False) – whether to enforce that all fields have same type

• allow_none (True) – whether to allow the fields to be None

Returns

a tuple of field values

Raises
• ValueError if a field does not exist or does not meet the specified

• criteria