Sign In

One way to chose the Best LoRa Snapshot : Face Similarity Checker with GUI - Update 2 with Fixes

One way to chose the Best LoRa Snapshot  : Face Similarity Checker with GUI - Update 2 with Fixes

Context of this article

As a part of my journey from the last two years experimenting in training LoRas, one problem which I constantly faced in the past(SD 1.5 days) and now ( Flux) is how to chose which snapshot of the LorA is looking the best. In the past I used to do grid analysis to generate a grid of the same picture with all the LoRa Snapshots to visually check which picture is looking good enough, but it tended to be quite subjective and I was researching on if there is any programmatic way to identify which LoRa is the best looking or closest to the original. This article is about a way that I found which is quite useful and thought to share it for anyone who might be on the same journey.

Case in Focus as an example

The original image used for Training:

the Grid of all images generated from various stages(snapshots for every 100 steps) during the training:

to my eyes, the differences are so subtle that it remains a subjective method to chose which one looks good enough or close enough to the original.

and what if I want to compare all of my training images with all of my generated images and pick which generated image is the best of all?

ENTER THE PROGRAMMATIC WAY TO DETERMINE THIS

We are going to use a PIP Module called Face-recognition : ( https://pypi.org/project/face-recognition/ )

This model is suposed to have an accuracy of 99.38% on the Labeled Faces in the Wild benchmark and so we are going to learn how to use this model to help us identify the best LoRa snapshot by calculating the similarity percentage between the original picture and our generated picture with the help of the following tool/application named : Face Similarity Checker

User Guide for Face Similarity Checker

This guide will help you set up and use the Face Similarity Checker application, even if you have no prior experience with Python or programming.

Step 1: Prerequisites

Install Python:

  1. Download and install Python from the official website: https://www.python.org/downloads/.

  2. Use Python 3.11.11 or above: Python 3.11.11 Download Link.

    1. Update: December 23-2024 : There has been a reported issue by with 3.13.x versions of Python, its better to stick to Python 3.10.9 or 3.10.11 or 3.11.11.

    Issue reported and fix found by : @HockeyStar53, Thank you HockeyStar53

  3. During installation, make sure to check the box that says "Add Python to PATH".

Download the Program Files:

  1. Obtain the program script (face_similarity_gui_V2.0.py) attached to this article.

  2. Save it in a folder on your computer. For this guide, let’s say you saved it in a folder named FaceSimilarityChecker.

Step 2: Setting Up the Application

Open Command Prompt/Terminal:

  • Windows: Press Win + R, type cmd, and press Enter.

  • macOS/Linux: Open the Terminal app.

Navigate to the Program Folder:

  1. Use the cd command to go to the folder where you saved the program file. For example:

    cd C:\Users\YourUsername\Downloads\FaceSimilarityChecker
    

Run the Program:

  1. Enter the following command to start the application:

    python face_similarity_gui_V2.0.py
    

What Happens Next:

  1. The application will check if all required tools are installed.

  2. If the tools are missing, it will:

    • Automatically set up a virtual environment in a folder named venv.

    • Download and install the required libraries (this step may take a few minutes).

Example output during setup:

Setting up virtual environment...
Installing required modules...
Collecting face_recognition
  Using cached face_recognition-1.3.0-py2.py3-none-any.whl (15 kB)
Collecting dlib
  Using cached dlib-19.24.6.tar.gz (3.4 MB)
  Preparing metadata (setup.py) ... done
Collecting numpy
  Using cached numpy-2.2.0-cp310-cp310-win_amd64.whl (12.9 MB)
Collecting Pillow
  Using cached pillow-11.0.0-cp310-cp310-win_amd64.whl (2.6 MB)
Collecting Click>=6.0
  Using cached click-8.1.7-py3-none-any.whl (97 kB)
Collecting face-recognition-models>=0.3.0
  Using cached face_recognition_models-0.3.0.tar.gz (100.1 MB)
  Preparing metadata (setup.py) ... done
Collecting colorama
  Using cached colorama-0.4.6-py2.py3-none-any.whl (25 kB)
Installing collected packages: face-recognition-models, dlib, Pillow, numpy, colorama, Click, face_recognition
  DEPRECATION: face-recognition-models is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for face-recognition-models ... done
  DEPRECATION: dlib is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
  Running setup.py install for dlib ... done
Successfully installed Click-8.1.7 Pillow-11.0.0 colorama-0.4.6 dlib-19.24.6 face-recognition-models-0.3.0 face_recognition-1.3.0 numpy-2.2.0

[notice] A new release of pip available: 22.3.1 -> 24.3.1
[notice] To update, run: D:\OPERA\venv\Scripts\python.exe -m pip install --upgrade pip
Switching to virtual environment...
Installing required modules...
Requirement already satisfied: face_recognition in d:\opera\venv\lib\site-packages (1.3.0)
Requirement already satisfied: dlib in d:\opera\venv\lib\site-packages (19.24.6)
Requirement already satisfied: numpy in d:\opera\venv\lib\site-packages (2.2.0)
Requirement already satisfied: Pillow in d:\opera\venv\lib\site-packages (from face_recognition) (11.0.0)
Requirement already satisfied: Click>=6.0 in d:\opera\venv\lib\site-packages (from face_recognition) (8.1.7)
Requirement already satisfied: face-recognition-models>=0.3.0 in d:\opera\venv\lib\site-packages (from face_recognition) (0.3.0)
Requirement already satisfied: colorama in d:\opera\venv\lib\site-packages (from Click>=6.0->face_recognition) (0.4.6)

[notice] A new release of pip available: 22.3.1 -> 24.3.1
[notice] To update, run: D:\OPERA\venv\Scripts\python.exe -m pip install --upgrade pip

Example output on sunsequent runs:

Installing required modules...
Requirement already satisfied: face_recognition in d:\opera\venv\lib\site-packages (1.3.0)
Requirement already satisfied: dlib in d:\opera\venv\lib\site-packages (19.24.6)
Requirement already satisfied: numpy in d:\opera\venv\lib\site-packages (2.2.0)
Requirement already satisfied: face-recognition-models>=0.3.0 in d:\opera\venv\lib\site-packages (from face_recognition) (0.3.0)
Requirement already satisfied: Click>=6.0 in d:\opera\venv\lib\site-packages (from face_recognition) (8.1.7)
Requirement already satisfied: Pillow in d:\opera\venv\lib\site-packages (from face_recognition) (11.0.0)
Requirement already satisfied: colorama in d:\opera\venv\lib\site-packages (from Click>=6.0->face_recognition) (0.4.6)
[notice] A new release of pip available: 22.3.1 -> 24.3.1
[notice] To update, run: D:\OPERA\venv\Scripts\python.exe -m pip install --upgrade pip
Switching to virtual environment...
Installing required modules...
Requirement already satisfied: face_recognition in d:\opera\venv\lib\site-packages (1.3.0)
Requirement already satisfied: dlib in d:\opera\venv\lib\site-packages (19.24.6)
Requirement already satisfied: numpy in d:\opera\venv\lib\site-packages (2.2.0)
Requirement already satisfied: face-recognition-models>=0.3.0 in d:\opera\venv\lib\site-packages (from face_recognition) (0.3.0)
Requirement already satisfied: Click>=6.0 in d:\opera\venv\lib\site-packages (from face_recognition) (8.1.7)
Requirement already satisfied: Pillow in d:\opera\venv\lib\site-packages (from face_recognition) (11.0.0)
Requirement already satisfied: colorama in d:\opera\venv\lib\site-packages (from Click>=6.0->face_recognition) (0.4.6)
[notice] A new release of pip available: 22.3.1 -> 24.3.1
[notice] To update, run: D:\OPERA\venv\Scripts\python.exe -m pip install --upgrade pip

After this, you should see the GUI Popup

Example screenshot:

Step 3: Using the GUI Application

Steps in the GUI:

  1. Select the Training Images Folder:

    • Click the Browse button next to "Training Images Folder".

    • Choose the folder containing the training images (e.g., photos of a person in various poses).

  2. Select the Generated Images Folder:

    • Click the Browse button next to "Generated Images Folder".

    • Choose the folder containing the generated images (e.g., images generated by various LoRa snapshots).

    • A useful tip is to name the generated images meaningfully, such as 100_steps.jpg for a snapshot with 100 steps, 200_steps.jpg for 200 steps, etc.

  3. Start Processing:

    • Click the Start Processing button.

    • The application will:

      • Compare each training image with all generated images.

      • Display a progress bar showing the current progress.

      • List comparison results in the text area below.

Example GUI:

Once processing is complete, the application will:

  1. Highlight the best match for each training image.

  2. Provide the overall best generated image recommendation.

Step 4: Understanding the Results

What the Results Mean:

  • The program compares faces from training images to faces in generated images and calculates a similarity score.

    • 100%: Exact match.

    • 0%: No similarity.

    • Anything in between: Represents partial similarity.

Output in the Text Area:

For each training image, the program displays the similarity percentage with each generated image.

  1. Best Match for Each Training Image:

Once its done doing this for all of the training images, we get to the final recommendation

  1. Final Recommendation:

    • The generated image that performed best across all training images is recommended.

Step 5: Exiting the Application

  • Close the application window when you’re done.

Step 6: Troubleshooting

Python Not Found:

  • If the program says python is not recognized, it means Python is not properly installed or added to PATH.

  • Reinstall Python and ensure the "Add Python to PATH" option is checked during installation.

Error During Setup:

  • If you see errors about missing libraries (e.g., dlib or face_recognition), restart the program, and it will install the required tools automatically.

Slow Processing:

  • Large images or folders with many images may take time to process. Let the program complete its task.

Optional: Run Without GUI

If you prefer to run the program without a GUI:

  1. Open the program file (face_similarity_gui_V2.0.py) in any text editor.

  2. Comment out the last line:

    # create_gui()
    
  3. Add this instead:

    training_folder = "path_to_training_images_folder"
    generated_folder = "path_to_generated_images_folder"
    process_training_images(training_folder, generated_folder, print, None)
    
  4. Replace path_to_training_images_folder and path_to_generated_images_folder with the actual paths to your folders.

  5. Save the file and run it again using:

    python face_similarity_gui_V2.0.py
    

Note :

  1. This works best if the photos only have one face, else the program compares with the first face it can find in the picture while ignoring others, its best to do this test with portrait shots for a single subject in focus to get the best out of this.

    One Example prompt which I use for testing on SD FLUX is :

    A Woman  stands on a vast, dry, reddish-brown plain at golden hour.  She exudes a serene, yet confident aura.  Her long, dark hair flows freely around her shoulders, gently moving in the breeze. She wears a fitted, black, ribbed-knit turtleneck sweater with a sleek, structured appearance, showcasing her form.  Completing her look are medium-wash blue jeans, creating a stylish, minimalist aesthetic.  Her expression is calm and composed, looking directly at the camera with a soft, natural makeup look. The lighting is soft and warm, highlighting her features with a sun-kissed glow, while the ambient light casts subtle shadows in a warm, golden tone.  The plain stretches out to the horizon, creating a stark contrast with the woman's attire. Soft, hazy light from the sunset creates a serene and timeless atmosphere.  The camera position is slightly elevated, creating a flattering perspective.  The focus remains on the subject, with the plain subtly blurred in the background, emphasizing the woman's presence. The overall artistic style suggests a contemporary fashion portrait, using natural light and a simple but elegant composition.
    
    Seed: 1565324511
    Model: flux1-dev, 
    Steps: 30, 
    CFG Scale: 1, 
    Aspect Ratio: Width: 1536, Height: 1024, 
    Sampler: UniPC (Unified Predictor-Corrector), 
    Flux Guidance Scale: 4, 
    VAE: ae

Release notes/ Version Rants

Face Similarity Checker Now with GUI- Version 2

As per the review comment given by : @reaper557 ( https://civitai.com/user/reaper557) on my original content in this article, which I have now cleaned up and mostly deleted, I have now added a GUI which works with both GUI as well as a command line option. I have also fixed an issue with the way venv was getting created or [NOT] and this new version of the script should hopefully work better.

9

Comments