Skip to content

[BUG]: Image format (RGB/BGR) is inconsistent when using DeepFace.represent #1426

Open
@dakotah-jones

Description

Before You Report a Bug, Please Confirm You Have Done The Following...

  • I have updated to the latest version of the packages.
  • I have searched for both existing issues and closed issues and found none that matched my issue.

DeepFace's version

v0.0.93

Python version

3.12.8

Operating System

Ubuntu 20.04.6 LTS

Dependencies

N/A

Reproducible example

representations = DeepFace.represent(
    file_path,
    model_name='Facenet',
    detector_backend='skip',
    normalization='Facenet'
)

# vs

representations = DeepFace.represent(
    file_path,
    model_name='Facenet',
    detector_backend='retinaface',
    normalization='Facenet'
)

Relevant Log Output

N/A

Expected Result

I expect the image format to be consistent regardless of detector_backend.

What happened instead?

When detector_backend is "skip" the final image used for the embedding is in "RGB" format.
When detector_backend is any other valid option, like "retinaface" the final image used for the embedding is in "BGR" format.

Additional Info

When using detector_backend="skip":

  • The image is loaded using image_utils.load_image. (here)
  • The image is in "BGR" format.
  • The image format is swapped using img = img[:, :, ::-1]. (here)
  • The image is in "RGB" format.
  • The image embedding is calculated.

When using any other detector_backend:

  • detection.extract_faces is called.
  • The color_face argument is defaulted to "rgb"
  • The image is loaded using image_utils.load_image. (here)
  • The image is now in "BGR" format.
  • The color_face argument is "rgb" so the format is swapped using current_img = current_img[:, :, ::-1]. (here)
  • The image is now in "RGB" format.
  • The format is swapped again within represent using img = img[:, :, ::-1]. (here)
  • The image is now in "BGR" format.
  • The image embedding is calculated.

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions