fiftyone.core.map.threading#
Threading mapping backend
Classes:
|
Executes map_samples with threading using iter_samples. |
- class fiftyone.core.map.threading.ThreadMapper(batch_cls: Type[SampleBatch], num_workers: int, batch_size: int | None = None, default_progress: bool | None = None)#
Bases:
LocalMapper
Executes map_samples with threading using iter_samples.
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:
Number of samples per worker batch
Number of workers to use
- classmethod create(*, config: FiftyOneConfig, batch_cls: Type[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[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