def apply_flash_model(
    samples,
    model,
    label_field="predictions",
    confidence_thresh=None,
    store_logits=False,
    batch_size=None,
    num_workers=None,
    output_dir=None,
    rel_dir=None,
    transform_kwargs=None,
    trainer_kwargs=None,
):
    """Applies the given
    :class:`Lightning Flash model <flash:flash.core.model.Task>` to the samples
    in the collection.

    Args:
        samples: a :class:`fiftyone.core.collections.SampleCollection`
        model: a :class:`flash:flash.core.model.Task`
        label_field ("predictions"): the name of the field in which to store
            the model predictions. When performing inference on video frames,
            the "frames." prefix is optional
        confidence_thresh (None): an optional confidence threshold to apply to
            any applicable labels generated by the model
        store_logits (False): whether to store logits for the model
            predictions. This is only supported when the provided ``model`` has
            logits
        batch_size (None): an optional batch size to use. If not provided, a
            default batch size is used
        num_workers (None): the number of workers for the data loader to use
        output_dir (None): an optional output directory in which to write
            segmentation images. Only applicable if the model generates
            segmentations. If none is provided, the segmentations are stored in
            the database
        rel_dir (None): an optional relative directory to strip from each input
            filepath to generate a unique identifier that is joined with
            ``output_dir`` to generate an output path for each segmentation
            image. This argument allows for populating nested subdirectories in
            ``output_dir`` that match the shape of the input paths. The path is
            converted to an absolute path (if necessary) via
            :func:`fiftyone.core.storage.normalize_path`
        transform_kwargs (None): an optional dict of transform kwargs to pass
            into the created data module used by some models
        trainer_kwargs (None): an optional dict of kwargs used to initialize the
            :mod:`Trainer <flash:flash.core.trainer>`. These can be used to,
            for example, configure the number of GPUs to use and other
            distributed inference parameters
    """
    output = _get_output(model, confidence_thresh, store_logits)

    if trainer_kwargs is None:
        trainer_kwargs = {}

    data_kwargs = {
        "num_workers": num_workers or 1,
        "batch_size": batch_size or 1,
    }
    if transform_kwargs:
        data_kwargs["transform_kwargs"] = transform_kwargs

    datamodule_cls = _MODEL_TO_DATAMODULE_MAP[type(model)]

    datamodule = datamodule_cls.from_fiftyone(
        predict_dataset=samples, **data_kwargs
    )
    predictions = flash.Trainer(**trainer_kwargs).predict(
        model, datamodule=datamodule, output=output
    )
    predictions = list(itertools.chain.from_iterable(predictions))

    if output_dir is not None:
        filename_maker = fou.UniqueFilenameMaker(
            output_dir=output_dir, rel_dir=rel_dir, idempotent=False
        )
        for p in predictions:
            _export_arrays(p["predictions"], p["filepath"], filename_maker)

    predictions = {p["filepath"]: p["predictions"] for p in predictions}
    samples.set_values(label_field, predictions, key_field="filepath")
Applies the given
    :class:`Lightning Flash model <flash:flash.core.model.Task>` to the samples
    in the collection.

    Args:
        samples: a :class:`fiftyone.core.collections.SampleCollection`
        model: a :class:`flash:flash.core.model.Task`
        label_field ("predictions"): the name of the field in which to store
            the model predictions. When performing inference on video frames,
            the "frames." prefix is optional
        confidence_thresh (None): an optional confidence threshold to apply to
            any applicable labels generated by the model
        store_logits (False): whether to store logits for the model
            predictions. This is only supported when the provided ``model`` has
            logits
        batch_size (None): an optional batch size to use. If not provided, a
            default batch size is used
        num_workers (None): the number of workers for the data loader to use
        output_dir (None): an optional output directory in which to write
            segmentation images. Only applicable if the model generates
            segmentations. If none is provided, the segmentations are stored in
            the database
        rel_dir (None): an optional relative directory to strip from each input
            filepath to generate a unique identifier that is joined with
            ``output_dir`` to generate an output path for each segmentation
            image. This argument allows for populating nested subdirectories in
            ``output_dir`` that match the shape of the input paths. The path is
            converted to an absolute path (if necessary) via
            :func:`fiftyone.core.storage.normalize_path`
        transform_kwargs (None): an optional dict of transform kwargs to pass
            into the created data module used by some models
        trainer_kwargs (None): an optional dict of kwargs used to initialize the
            :mod:`Trainer <flash:flash.core.trainer>`. These can be used to,
            for example, configure the number of GPUs to use and other
            distributed inference parameters
    
fiftyone/utils/flash.py