fiftyone.core.map.mapper#

Abstract mapping backend

Copyright 2017-2025, Voxel51, Inc.

Functions:

check_if_return_is_sample(sample_collection, ...)

Check if the map function returns a sample

Classes:

Mapper(batch_cls, num_workers[, batch_size, ...])

Base class for mapping samples in parallel

LocalMapper(batch_cls, num_workers[, ...])

Base class for mapping samples in parallelizing on the same machine

fiftyone.core.map.mapper.check_if_return_is_sample(sample_collection: SampleCollection[T], map_fcn: Callable[[T], R]) bool#

Check if the map function returns a sample

class fiftyone.core.map.mapper.Mapper(batch_cls: Type[SampleBatch], num_workers: int, batch_size: int | None = None, default_progress: bool | None = None)#

Bases: ABC

Base class for mapping samples in parallel

Methods:

create(*, config, batch_cls[, num_workers, ...])

Create a new mapper instance

map_samples(sample_collection, map_fcn, *[, ...])

Applies map function to each sample and returns an iterator of the results.

Attributes:

num_workers

Number of workers to use

batch_size

Number of samples per worker batch

classmethod create(*, config: FiftyOneConfig, batch_cls: Type[SampleBatch], num_workers: int | None = None, batch_size: int | None = None, **__)#

Create a new mapper instance

property num_workers: int#

Number of workers to use

property batch_size: int | None#

Number of samples per worker batch

map_samples(sample_collection: SampleCollection[T], map_fcn: Callable[[T | U], R], *, iter_fcn: Callable[[SampleCollection[T]], Iterable[Tuple[ObjectId, U]]] | None = None, progress: bool | Literal['workers'] | None = None, save: bool = False, skip_failures: bool = True) Iterator[Tuple[ObjectId, R]]#

Applies map function to each sample and returns an iterator of the results.

Parameters:
  • sample_collection (SampleCollection[T]) – The sample collection to map.

  • map_fcn (Callable[[Union[T, U]], R]) – The map function to apply to each sample.

  • iter_fcn (Callable[[T], U]) – The function to iterate over the sample collection. If not provided the iteration function used is iter_samples.

  • progress (Union[bool, Literal["workers"]]) – Whether or not and how to render progress.

  • save (bool, optional) – Whether to save mutated samples mutated in the map function. Only valid when using the iter_fcn is None. Defaults to False.

  • skip_failures (bool, optional) – Whether to gracefully continue without raising an error if the map function raises an exception for a sample. Defaults to True.

Yields:

Iterator[Tuple[bson.ObjectId, R]] –

The sample ID and the result of

the map function for the sample.

class fiftyone.core.map.mapper.LocalMapper(batch_cls: Type[SampleBatch], num_workers: int, batch_size: int | None = None, default_progress: bool | None = None)#

Bases: Mapper, ABC

Base class for mapping samples in parallelizing on the same machine

Attributes:

batch_size

Number of samples per worker batch

num_workers

Number of workers to use

Methods:

create(*, config, batch_cls[, num_workers, ...])

Create a new mapper instance

map_samples(sample_collection, map_fcn, *[, ...])

Applies map function to each sample and returns an iterator of the results.

property batch_size: int | None#

Number of samples per worker batch

classmethod create(*, config: FiftyOneConfig, batch_cls: Type[SampleBatch], num_workers: int | None = None, batch_size: int | None = None, **__)#

Create a new mapper instance

map_samples(sample_collection: SampleCollection[T], map_fcn: Callable[[T | U], R], *, iter_fcn: Callable[[SampleCollection[T]], Iterable[Tuple[ObjectId, U]]] | None = None, progress: bool | Literal['workers'] | None = None, save: bool = False, skip_failures: bool = True) Iterator[Tuple[ObjectId, R]]#

Applies map function to each sample and returns an iterator of the results.

Parameters:
  • sample_collection (SampleCollection[T]) – The sample collection to map.

  • map_fcn (Callable[[Union[T, U]], R]) – The map function to apply to each sample.

  • iter_fcn (Callable[[T], U]) – The function to iterate over the sample collection. If not provided the iteration function used is iter_samples.

  • progress (Union[bool, Literal["workers"]]) – Whether or not and how to render progress.

  • save (bool, optional) – Whether to save mutated samples mutated in the map function. Only valid when using the iter_fcn is None. Defaults to False.

  • skip_failures (bool, optional) – Whether to gracefully continue without raising an error if the map function raises an exception for a sample. Defaults to True.

Yields:

Iterator[Tuple[bson.ObjectId, R]] –

The sample ID and the result of

the map function for the sample.

property num_workers: int#

Number of workers to use