fiftyone.core.validation#

Validation utilities.

Copyright 2017-2025, Voxel51, Inc.

Functions:

validate_image_sample(sample)

Validates that the sample's media is an image.

validate_video_sample(sample)

Validates that the sample's media is a video.

validate_collection(sample_collection[,Β ...])

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

validate_image_collection(sample_collection)

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

validate_video_collection(sample_collection)

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

validate_non_grouped_collection(...)

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

validate_collection_label_fields(...[,Β ...])

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

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.

fiftyone.core.validation.validate_image_sample(sample)#

Validates that the sample’s media is an image.

Parameters:

sample – a fiftyone.core.sample.Sample

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:

sample – a fiftyone.core.sample.Sample

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:
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:
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:
fiftyone.core.validation.validate_non_grouped_collection(sample_collection)#

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

Parameters:

sample_collection – a sample collection

Raises:
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:
  • sample – a fiftyone.core.sample.Sample

  • 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:
  • sample – a fiftyone.core.sample.Sample

  • 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 –