def compute_embeddings(
    samples,
    model,
    embeddings_field=None,
    batch_size=None,
    num_workers=None,
    skip_failures=True,
    progress=None,
    **kwargs,
):
    """Computes embeddings for the samples in the collection using the given
    model.

    This method supports all the following cases:

    -   Using an image model to compute embeddings for an image collection
    -   Using an image model to compute frame embeddings for a video collection
    -   Using a video model to compute embeddings for a video collection

    The ``model`` must expose embeddings, i.e., :meth:`Model.has_embeddings`
    must return ``True``.

    If an ``embeddings_field`` is provided, the embeddings are saved to the
    samples; otherwise, the embeddings are returned in-memory.

    Args:
        samples: a :class:`fiftyone.core.collections.SampleCollection`
        model: a :class:`Model`, Hugging Face Transformers model, Ultralytics
            model, SuperGradients model, or Lightning Flash model
        embeddings_field (None): the name of a field in which to store the
            embeddings. When computing video frame embeddings, the "frames."
            prefix is optional
        batch_size (None): an optional batch size to use, if the model supports
            batching
        num_workers (None): the number of workers to use when loading images.
            Only applicable for Torch-based models
        skip_failures (True): whether to gracefully continue without raising an
            error if embeddings cannot be generated for a sample. Only
            applicable to :class:`Model` instances
        progress (None): whether to render a progress bar (True/False), use the
            default value ``fiftyone.config.show_progress_bars`` (None), or a
            progress callback function to invoke instead
        **kwargs: optional model-specific keyword arguments passed through
            to the underlying inference implementation

    Returns:
        one of the following:

        -   ``None``, if an ``embeddings_field`` is provided
        -   a ``num_samples x num_dim`` array of embeddings, when computing
            embeddings for image/video collections with image/video models,
            respectively, and no ``embeddings_field`` is provided. If
            ``skip_failures`` is ``True`` and any errors are detected, a list
            of length ``num_samples`` is returned instead containing all
            successfully computed embedding vectors along with ``None`` entries
            for samples for which embeddings could not be computed
        -   a dictionary mapping sample IDs to ``num_frames x num_dim`` arrays
            of embeddings, when computing frame embeddings for video
            collections using an image model. If ``skip_failures`` is ``True``
            and any errors are detected, the values of this dictionary will
            contain arrays of embeddings for all frames 1, 2, ... until the
            error occurred, or ``None`` if no embeddings were computed at all
    """
    if _is_flash_model(model):
        return fouf.compute_flash_embeddings(
            samples,
            model,
            embeddings_field=embeddings_field,
            batch_size=batch_size,
            num_workers=num_workers,
            **kwargs,
        )

    model = _convert_model_if_necessary(model)

    if not isinstance(model, Model):
        raise ValueError("Unsupported model type: %s" % type(model))

    if not model.has_embeddings:
        raise ValueError(
            "Model must expose embeddings; found model.has_embeddings = %s"
            % model.has_embeddings
        )

    if samples.media_type == fom.IMAGE:
        fov.validate_image_collection(samples)
    elif samples.media_type == fom.GROUP:
        raise fom.SelectGroupSlicesError((fom.IMAGE, fom.VIDEO))
    elif samples.media_type != fom.VIDEO:
        raise fom.MediaTypeError(
            "Unsupported media type '%s'" % samples.media_type
        )

    if model.media_type == "video" and samples.media_type != fom.VIDEO:
        raise ValueError(
            "Video models can only be applied to video collections"
        )

    if model.media_type not in ("image", "video"):
        raise ValueError(
            "Unsupported model `media_type=%s`. Supported values are "
            "('image', 'video')" % model.media_type
        )

    if isinstance(model, SupportsGetItem):
        field_mapping = kwargs.pop("field_mapping", {})
        field_mapping.update(kwargs)
    else:
        field_mapping = None

    process_video_frames = (
        samples.media_type == fom.VIDEO and model.media_type == "image"
    )

    use_data_loader = (
        isinstance(model, (SupportsGetItem, TorchModelMixin))
        and not process_video_frames
    )

    if num_workers is not None and not use_data_loader:
        logger.warning("Ignoring unsupported `num_workers` parameter")

    if embeddings_field is not None:
        dataset = samples._dataset
        embeddings_field, _is_frame_field = dataset._handle_frame_field(
            embeddings_field
        )

        if "." in embeddings_field:
            ftype = "frame" if _is_frame_field else "sample"
            raise ValueError(
                "Invalid `embeddings_field=%s`. Expected a top-level %s field "
                "name that contains no '.'" % (embeddings_field, ftype)
            )

        if dataset.media_type == fom.VIDEO and model.media_type == "image":
            if not dataset.has_frame_field(embeddings_field):
                dataset.add_frame_field(embeddings_field, fof.VectorField)
        else:
            if not dataset.has_sample_field(embeddings_field):
                dataset.add_sample_field(embeddings_field, fof.VectorField)

    with contextlib.ExitStack() as context:
        if use_data_loader:
            context.enter_context(fou.SetAttributes(model, preprocess=False))

        context.enter_context(model)

        if model.media_type == "video":
            return _compute_video_embeddings(
                samples, model, embeddings_field, skip_failures, progress
            )

        batch_size = _parse_batch_size(batch_size, model, use_data_loader)

        if process_video_frames:
            if batch_size is not None:
                return _compute_frame_embeddings_batch(
                    samples,
                    model,
                    embeddings_field,
                    batch_size,
                    skip_failures,
                    progress,
                )

            return _compute_frame_embeddings_single(
                samples, model, embeddings_field, skip_failures, progress
            )

        if use_data_loader:
            return _compute_image_embeddings_data_loader(
                samples,
                model,
                embeddings_field,
                batch_size,
                num_workers,
                skip_failures,
                progress,
                field_mapping,
            )

        if batch_size is not None:
            return _compute_image_embeddings_batch(
                samples,
                model,
                embeddings_field,
                batch_size,
                skip_failures,
                progress,
            )

        return _compute_image_embeddings_single(
            samples, model, embeddings_field, skip_failures, progress
        )
Computes embeddings for the samples in the collection using the given
    model.

    This method supports all the following cases:

    -   Using an image model to compute embeddings for an image collection
    -   Using an image model to compute frame embeddings for a video collection
    -   Using a video model to compute embeddings for a video collection

    The ``model`` must expose embeddings, i.e., :meth:`Model.has_embeddings`
    must return ``True``.

    If an ``embeddings_field`` is provided, the embeddings are saved to the
    samples; otherwise, the embeddings are returned in-memory.

    Args:
        samples: a :class:`fiftyone.core.collections.SampleCollection`
        model: a :class:`Model`, Hugging Face Transformers model, Ultralytics
            model, SuperGradients model, or Lightning Flash model
        embeddings_field (None): the name of a field in which to store the
            embeddings. When computing video frame embeddings, the "frames."
            prefix is optional
        batch_size (None): an optional batch size to use, if the model supports
            batching
        num_workers (None): the number of workers to use when loading images.
            Only applicable for Torch-based models
        skip_failures (True): whether to gracefully continue without raising an
            error if embeddings cannot be generated for a sample. Only
            applicable to :class:`Model` instances
        progress (None): whether to render a progress bar (True/False), use the
            default value ``fiftyone.config.show_progress_bars`` (None), or a
            progress callback function to invoke instead
        **kwargs: optional model-specific keyword arguments passed through
            to the underlying inference implementation

    Returns:
        one of the following:

        -   ``None``, if an ``embeddings_field`` is provided
        -   a ``num_samples x num_dim`` array of embeddings, when computing
            embeddings for image/video collections with image/video models,
            respectively, and no ``embeddings_field`` is provided. If
            ``skip_failures`` is ``True`` and any errors are detected, a list
            of length ``num_samples`` is returned instead containing all
            successfully computed embedding vectors along with ``None`` entries
            for samples for which embeddings could not be computed
        -   a dictionary mapping sample IDs to ``num_frames x num_dim`` arrays
            of embeddings, when computing frame embeddings for video
            collections using an image model. If ``skip_failures`` is ``True``
            and any errors are detected, the values of this dictionary will
            contain arrays of embeddings for all frames 1, 2, ... until the
            error occurred, or ``None`` if no embeddings were computed at all
    
fiftyone/core/models.py