This script uses the InsightFace model to process a set of images, comparing them to a reference image and sorting them into different "buckets" based on their similarity to the reference image. It also has the option of filtering out NSFW images if the checkbox is enabled. NSFW sensitivity can be changed using the slider. For a default value, set it to 0.7. Setting it to 0 will disable the filter, much like unchecking the checkbox will. The application runs through a Gradio interface for easy of use.
- Python 3.10
- InsightFace library
- Gradio library
- ifnude library
- mediapipe library
-
Clone or download the script: Download the script to your computer.
-
Install the required libraries: Open a command prompt and run the following commands to install the required libraries.
pip install insightface gradio mediapipe ifnude
-
Run the script: Open a command prompt in the directory where you saved the script and run it using Python.
python script_name.py
-
Access the Gradio interface: Once the script is running, open your web browser and navigate to http://127.0.0.1:7860/. This will open the Gradio interface for processing images.
**Method 1
- Run setup (
setup.bat
) to install the venv and dependencies - Run fc (
fc.bat
) to launch the UI
**Method 2
- Run fc (
fc.bat
) to check for and install the venv and dependencies, and launch the UI in one go
fc.bat automatically checks for the venv and dependencies and creates them if they're not present. It will also update the dependencies the first time it runs but not subsequently. If you have run setup.bat earlier then fc.bat wil bypass this stage.
-
Clone or download the script: Download the script to your computer.
git clone https://github.com/formulake/kp-face-similarity.git
-
Navigate to the folder and create a Virtual Environment
cd kp-face-similarity python3 -m venv venv
-
Activate the Venv
source venv/bin/activate
-
Install the required libraries: Open a terminal and run the following commands to install the required libraries.
pip3 install -r requirements.txt
-
Run the script: Open a terminal in the directory where you saved the script and run it using Python.
source venv/bin/activate python3 fc.py
-
Clone or download the script: Download the script to your computer.
git clone https://github.com/formulake/kp-face-similarity.git
-
Navigate to the folder and run fc.py
cd kp-face-similarity python3 fc.py
fc.py automatically checks for the venv and dependencies and creates them if they're not present. It will also update the dependencies the first time it runs but not subsequently.
Access the Gradio interface: Once the script is running, open your web browser and navigate to http://127.0.0.1:7860/. This will open the Gradio interface for processing images.
- Reference Image: Upload the reference image that you want to compare other images to.
- Source Folder Path: Enter the path to the folder containing the images you want to process.
- Select Buckets (10% increments): Choose the similarity thresholds for sorting the images into buckets. Images with similarity scores equal to or higher than the selected thresholds will be placed in the corresponding buckets.
- Enable NSFW check to filter out nude images. You can set the sensitivity slider to avoid false positives. The default value for the slider is 0.7 which works fine most of the time. The detection model used is ifnude
Process Status: The processing status will be displayed in this textbox.
- Make sure that the reference image and source images are in a compatible format (e.g., JPEG, PNG).
- The script will create folders for each selected bucket in the source folder and move images accordingly.
- Images with no detected faces in the source folder will be moved to a "rejected" folder.
If you encounter any issues or errors while using this script, please check the following:
- Ensure that you have installed the required libraries (insightface and gradio) as mentioned in the installation instructions.
- Verify that the paths to the reference image and source folder are correct. The reference folder must be contained within the source folder.
- Check the format of the reference and source images.
- Review the error messages displayed in the "Process Status" textbox for more information.
- For additional assistance, refer to the script's source code or consult the documentation of the InsightFace and Gradio libraries.