<!-- # hard line break macro for HTML -->

# fiftyone.core.map

* [fiftyone.core.map.batcher](fiftyone.core.map.batcher.md)
  * [fiftyone.core.map.batcher.batch](fiftyone.core.map.batcher.batch.md)
    * [`SampleBatch`](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)
      * [`SampleBatch.split()`](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch.split)
      * [`SampleBatch.total`](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch.total)
      * [`SampleBatch.create_subset()`](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch.create_subset)
  * [fiftyone.core.map.batcher.id_batch](fiftyone.core.map.batcher.id_batch.md)
    * [`SampleIdBatch`](fiftyone.core.map.batcher.id_batch.md#fiftyone.core.map.batcher.id_batch.SampleIdBatch)
      * [`SampleIdBatch.get_max_batch_size()`](fiftyone.core.map.batcher.id_batch.md#fiftyone.core.map.batcher.id_batch.SampleIdBatch.get_max_batch_size)
      * [`SampleIdBatch.split()`](fiftyone.core.map.batcher.id_batch.md#fiftyone.core.map.batcher.id_batch.SampleIdBatch.split)
      * [`SampleIdBatch.total`](fiftyone.core.map.batcher.id_batch.md#fiftyone.core.map.batcher.id_batch.SampleIdBatch.total)
      * [`SampleIdBatch.create_subset()`](fiftyone.core.map.batcher.id_batch.md#fiftyone.core.map.batcher.id_batch.SampleIdBatch.create_subset)
  * [fiftyone.core.map.batcher.slice_batch](fiftyone.core.map.batcher.slice_batch.md)
    * [`SampleSliceBatch`](fiftyone.core.map.batcher.slice_batch.md#fiftyone.core.map.batcher.slice_batch.SampleSliceBatch)
      * [`SampleSliceBatch.split()`](fiftyone.core.map.batcher.slice_batch.md#fiftyone.core.map.batcher.slice_batch.SampleSliceBatch.split)
      * [`SampleSliceBatch.total`](fiftyone.core.map.batcher.slice_batch.md#fiftyone.core.map.batcher.slice_batch.SampleSliceBatch.total)
      * [`SampleSliceBatch.create_subset()`](fiftyone.core.map.batcher.slice_batch.md#fiftyone.core.map.batcher.slice_batch.SampleSliceBatch.create_subset)
  * [Module contents](fiftyone.core.map.batcher.md#module-fiftyone.core.map.batcher)
    * [`SampleBatch`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleBatch)
      * [`SampleBatch.split()`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleBatch.split)
      * [`SampleBatch.total`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleBatch.total)
      * [`SampleBatch.create_subset()`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleBatch.create_subset)
    * [`SampleIdBatch`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleIdBatch)
      * [`SampleIdBatch.get_max_batch_size()`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleIdBatch.get_max_batch_size)
      * [`SampleIdBatch.split()`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleIdBatch.split)
      * [`SampleIdBatch.total`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleIdBatch.total)
      * [`SampleIdBatch.create_subset()`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleIdBatch.create_subset)
    * [`SampleSliceBatch`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleSliceBatch)
      * [`SampleSliceBatch.split()`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleSliceBatch.split)
      * [`SampleSliceBatch.total`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleSliceBatch.total)
      * [`SampleSliceBatch.create_subset()`](fiftyone.core.map.batcher.md#fiftyone.core.map.batcher.SampleSliceBatch.create_subset)

* [fiftyone.core.map.factory](fiftyone.core.map.factory.md)
  * [`MapperFactory`](fiftyone.core.map.factory.md#fiftyone.core.map.factory.MapperFactory)
    * [`MapperFactory.batch_methods()`](fiftyone.core.map.factory.md#fiftyone.core.map.factory.MapperFactory.batch_methods)
    * [`MapperFactory.mapper_keys()`](fiftyone.core.map.factory.md#fiftyone.core.map.factory.MapperFactory.mapper_keys)
    * [`MapperFactory.create()`](fiftyone.core.map.factory.md#fiftyone.core.map.factory.MapperFactory.create)
* [fiftyone.core.map.mapper](fiftyone.core.map.mapper.md)
  * [`check_if_return_is_sample()`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.check_if_return_is_sample)
  * [`Mapper`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.Mapper)
    * [`Mapper.create()`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.Mapper.create)
    * [`Mapper.num_workers`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.Mapper.num_workers)
    * [`Mapper.batch_size`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.Mapper.batch_size)
    * [`Mapper.map_samples()`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.Mapper.map_samples)
  * [`LocalMapper`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.LocalMapper)
    * [`LocalMapper.batch_size`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.LocalMapper.batch_size)
    * [`LocalMapper.create()`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.LocalMapper.create)
    * [`LocalMapper.map_samples()`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.LocalMapper.map_samples)
    * [`LocalMapper.num_workers`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.LocalMapper.num_workers)
* [fiftyone.core.map.process](fiftyone.core.map.process.md)
  * [`ProcessMapper`](fiftyone.core.map.process.md#fiftyone.core.map.process.ProcessMapper)
    * [`ProcessMapper.create()`](fiftyone.core.map.process.md#fiftyone.core.map.process.ProcessMapper.create)
    * [`ProcessMapper.batch_size`](fiftyone.core.map.process.md#fiftyone.core.map.process.ProcessMapper.batch_size)
    * [`ProcessMapper.map_samples()`](fiftyone.core.map.process.md#fiftyone.core.map.process.ProcessMapper.map_samples)
    * [`ProcessMapper.num_workers`](fiftyone.core.map.process.md#fiftyone.core.map.process.ProcessMapper.num_workers)
* [fiftyone.core.map.threading](fiftyone.core.map.threading.md)
  * [`ThreadMapper`](fiftyone.core.map.threading.md#fiftyone.core.map.threading.ThreadMapper)
    * [`ThreadMapper.create()`](fiftyone.core.map.threading.md#fiftyone.core.map.threading.ThreadMapper.create)
    * [`ThreadMapper.batch_size`](fiftyone.core.map.threading.md#fiftyone.core.map.threading.ThreadMapper.batch_size)
    * [`ThreadMapper.map_samples()`](fiftyone.core.map.threading.md#fiftyone.core.map.threading.ThreadMapper.map_samples)
    * [`ThreadMapper.num_workers`](fiftyone.core.map.threading.md#fiftyone.core.map.threading.ThreadMapper.num_workers)
* [fiftyone.core.map.typing](fiftyone.core.map.typing.md)
  * [`SampleCollection`](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)
    * [`SampleCollection.iter_samples()`](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection.iter_samples)
    * [`SampleCollection.values()`](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection.values)

## Module contents

Map package declaration.

Copyright 2017-2026, Voxel51, Inc.
<br/>
[voxel51.com](https://voxel51.com/)
<br/>
<br/>

**Classes:**

| [`Mapper`](#fiftyone.core.map.Mapper)(batch_cls, num_workers[, batch_size, ...])   | Base class for mapping samples in parallel              |
|------------------------------------------------------------------------------------|---------------------------------------------------------|
| [`MapperFactory`](#fiftyone.core.map.MapperFactory)()                              | Manage mapper implementations                           |
| [`ProcessMapper`](#fiftyone.core.map.ProcessMapper)(batch_cls, num_workers[, ...]) | Executes map_samples using multiprocessing.             |
| [`ThreadMapper`](#fiftyone.core.map.ThreadMapper)(batch_cls, num_workers[, ...])   | Executes map_samples with threading using iter_samples. |

### *class* fiftyone.core.map.Mapper(batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int, batch_size: int | None = None, default_progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | None = None)

Bases: `ABC`

Base class for mapping samples in parallel

**Methods:**

| [`create`](#fiftyone.core.map.Mapper.create)(\*, config, batch_cls[, num_workers, ...])       | Create a new mapper instance                                                |
|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [`map_samples`](#fiftyone.core.map.Mapper.map_samples)(sample_collection, map_fcn, \*[, ...]) | Applies map function to each sample and returns an iterator of the results. |

**Attributes:**

| [`num_workers`](#fiftyone.core.map.Mapper.num_workers)   | Number of workers to use           |
|----------------------------------------------------------|------------------------------------|
| [`batch_size`](#fiftyone.core.map.Mapper.batch_size)     | Number of samples per worker batch |

#### *classmethod* create(, config: [FiftyOneConfig](fiftyone.core.config.md#fiftyone.core.config.FiftyOneConfig), batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.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](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T], map_fcn: Callable[[T | U], R], , iter_fcn: Callable[[[SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T]], Iterable[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), U]]] | None = None, progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | Literal['workers'] | None = None, save: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = False, skip_failures: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = True) → Iterator[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), R]]

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

* **Parameters:**
  * **sample_collection** ([*SampleCollection*](fiftyone.core.collections.md#fiftyone.core.collections.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*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *Literal* *[* *"workers"* *]* *]*) – Whether or
    not and how to render progress.
  * **save** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.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*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.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.MapperFactory

Bases: `object`

Manage mapper implementations

**Methods:**

| [`batch_methods`](#fiftyone.core.map.MapperFactory.batch_methods)()                 | Get available batch methods     |
|-------------------------------------------------------------------------------------|---------------------------------|
| [`mapper_keys`](#fiftyone.core.map.MapperFactory.mapper_keys)()                     | Get available mapper class keys |
| [`create`](#fiftyone.core.map.MapperFactory.create)([mapper_key, num_workers, ...]) | Create a mapper instance        |

#### *classmethod* batch_methods() → List[str]

Get available batch methods

#### *classmethod* mapper_keys() → List[str]

Get available mapper class keys

#### *classmethod* create(mapper_key: str | None = None, num_workers: int | None = None, batch_method: str | None = None, batch_size: int | None = None, \*\*mapper_extra_kwargs) → [Mapper](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.Mapper)

Create a mapper instance

### *class* fiftyone.core.map.ProcessMapper(batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int, batch_size: int | None = None, default_progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | None = None)

Bases: [`LocalMapper`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.LocalMapper)

Executes map_samples using multiprocessing.

**Methods:**

| [`create`](#fiftyone.core.map.ProcessMapper.create)(\*, config, batch_cls[, num_workers, ...])       | Create a new mapper instance                                                |
|------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [`map_samples`](#fiftyone.core.map.ProcessMapper.map_samples)(sample_collection, map_fcn, \*[, ...]) | Applies map function to each sample and returns an iterator of the results. |

**Attributes:**

| [`batch_size`](#fiftyone.core.map.ProcessMapper.batch_size)   | Number of samples per worker batch   |
|---------------------------------------------------------------|--------------------------------------|
| [`num_workers`](#fiftyone.core.map.ProcessMapper.num_workers) | Number of workers to use             |

#### *classmethod* create(, config: [FiftyOneConfig](fiftyone.core.config.md#fiftyone.core.config.FiftyOneConfig), batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int | None = None, batch_size: int | None = None, \*\*\_\_)

Create a new mapper instance

#### *property* batch_size *: int | None*

Number of samples per worker batch

#### map_samples(sample_collection: [SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T], map_fcn: Callable[[T | U], R], , iter_fcn: Callable[[[SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T]], Iterable[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), U]]] | None = None, progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | Literal['workers'] | None = None, save: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = False, skip_failures: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = True) → Iterator[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), R]]

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

* **Parameters:**
  * **sample_collection** ([*SampleCollection*](fiftyone.core.collections.md#fiftyone.core.collections.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*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *Literal* *[* *"workers"* *]* *]*) – Whether or
    not and how to render progress.
  * **save** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.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*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.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

### *class* fiftyone.core.map.ThreadMapper(batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int, batch_size: int | None = None, default_progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | None = None)

Bases: [`LocalMapper`](fiftyone.core.map.mapper.md#fiftyone.core.map.mapper.LocalMapper)

Executes map_samples with threading using iter_samples.

**Methods:**

| [`create`](#fiftyone.core.map.ThreadMapper.create)(\*, config, batch_cls[, num_workers, ...])       | Create a new mapper instance                                                |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| [`map_samples`](#fiftyone.core.map.ThreadMapper.map_samples)(sample_collection, map_fcn, \*[, ...]) | Applies map function to each sample and returns an iterator of the results. |

**Attributes:**

| [`batch_size`](#fiftyone.core.map.ThreadMapper.batch_size)   | Number of samples per worker batch   |
|--------------------------------------------------------------|--------------------------------------|
| [`num_workers`](#fiftyone.core.map.ThreadMapper.num_workers) | Number of workers to use             |

#### *classmethod* create(, config: [FiftyOneConfig](fiftyone.core.config.md#fiftyone.core.config.FiftyOneConfig), batch_cls: Type[[SampleBatch](fiftyone.core.map.batcher.batch.md#fiftyone.core.map.batcher.batch.SampleBatch)], num_workers: int | None = None, batch_size: int | None = None, \*\*\_\_)

Create a new mapper instance

#### *property* batch_size *: int | None*

Number of samples per worker batch

#### map_samples(sample_collection: [SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T], map_fcn: Callable[[T | U], R], , iter_fcn: Callable[[[SampleCollection](fiftyone.core.map.typing.md#fiftyone.core.map.typing.SampleCollection)[T]], Iterable[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), U]]] | None = None, progress: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) | Literal['workers'] | None = None, save: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = False, skip_failures: [bool](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) = True) → Iterator[Tuple[[ObjectId](https://pymongo.readthedocs.io/en/stable/api/bson/objectid.html#bson.objectid.ObjectId), R]]

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

* **Parameters:**
  * **sample_collection** ([*SampleCollection*](fiftyone.core.collections.md#fiftyone.core.collections.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*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.bool) *,* *Literal* *[* *"workers"* *]* *]*) – Whether or
    not and how to render progress.
  * **save** ([*bool*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.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*](fiftyone.core.stages.md#fiftyone.core.stages.Exists.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
