Sort By Face

Related tags

Computer Vision SBF
Overview

Sort-By-Face

This is an application with which you can either sort all the pictures by faces from a corpus of photos or retrieve all your photos from the corpus
by submitting a picture of yours.

Setup:

Requirements:

  • python 3.8.5
  • Anaconda 4.9.2+

If anaconda isn't installed, install it from here

  • Clone the repository
  • Download the folder called Models/ from here into the same directory where you cloned the repository.
  • Run conda env create -f environment.yml to create the environment.
  • Run conda activate sorter.
  • Run pip install -r requirements.txt
  • In case you want to run the notebook then make sure Jupyter notebook is installed and accessible for all environments in your system.

Instructions:

  • Put the directory where the folders are located into the project folder.
  • Run python embedder.py -src /path/to/images. Any non image file extensions are safely ignored. This command utilizes all the cores in the system for parallel processing.
  • In case you want to reduce the number of parallel processes, run python embedder.py -src /path/to/images --processes number-of-processes.
  • Both absolute and relative paths work but relative paths are recommended.
  • The above command then calculates all the embeddings for the faces in the pictures. NOTE: It takes a significant amount of time for large directories.
  • The embeddings are saved in a pickle file called embeddings.pickle.

Sort an entire corpus of photos:

  • Run python sort_images.py. This runs the clustering algorithm with the default parameters of threshold and iterations for the clustering algorithm.
  • If you want to tweak the parameters, run python sort_images.py -t threshold -itr num-iterations to alter the threshold and iterations respectively.
  • If you think pictures are missing try reducing the threshold and increasing the iterations. Something like 0.64 and 35 iterations should work.
  • Once the clustering is finished all the images are stored into a folder called Sorted-pictures. Each subdirectory in it corresponds to the unique person identified.

Get pictures of a single person from the corpus:

  • To get pictures of a single person you will need to provide a picture of that person. It is recommended that the picture clears the following requirements for better results:
    • Image must have width and height greater than 160px.
    • Image must consist of only one face (The program is exited when multiple faces are detected)
    • Image must be preferably well lit and recognizable by a human.
  • Run python get_individual.py -src /path/to/person's/image -dest /path/to/copy/images.
  • This script also allows to tweak with the parameters with the same arguments as mentioned before.
  • Once clustering is done all the pictures are copied into the destination

Evaluation of clustering algorithm:

The notebook On testing on the Labeled Faces in the Wild dataset the following results were obtained. (threshold = 0.67, iterations=30)

  • Precision: 0.89
  • Recall: 0.99
  • F-measure: 0.95
  • Clusters formed: 6090 (5749 unique labels in the dataset)

The code for evaluation has been uploaded in this notebook

The LFW dataset has many images containing more than one face but only has a single label. This can have an effect on the evaluation metrics and the clusters formed. These factors have been discussed in detail in the notebook.
For example by running the script get_individual.py and providing a photo of George Bush will result in some images like this.

In Layman terms we have gathered all the 'photobombs' of George Bush in the dataset, but all the labels for the 'photobombs' correspond to a different person.
NOTE: this does not effect the clustering for the original person as the scripts treat each face seperately but refer to the same image.

How it works:

  • Given a corpus of photos inside a directory this application first detects the faces in the photos.
  • Face alignment is then done using dlib, such that the all the eyes for the faces is at the same coordinates.
  • Then the image is passed through a Convolutional Neural Network to generate 128-Dimensional embeddings.
  • These embeddings are then used in a graph based clustering algorithm called 'Chinese Whispers'.
  • The clustering algorithm assigns a cluster to each individual identified by it.
  • After the algorithm the images are copied into seperate directories corresponding to their clusters.
  • For a person who wants to retrieve only his images, only the images which are in the same cluster as the picture submitted by the user is copied.

Model used for embedding extraction:

The project uses a model which was first introduced in this [4] . It uses a keras model converted from David Sandberg's implementation in this repository.
In particular it uses the model with the name 20170512-110547 which was converted using this script.

All the facenet models are trained using a loss called triplet loss. This loss ensures that the model gives closer embeddings for same people and farther embeddings for different people.
The models are trained on a huge amount of images out of which triplets are generated.

The clustering algorithm:


This project uses a graph based algorithm called Chinese Whispers to cluster the faces. It was first introduced for Natural Language Processing tasks by Chris Biemann in [3] paper.
The authors in [1] and [2] used the concept of a threshold to assign edges to the graphs. i.e there is an edge between two nodes (faces) only if their (dis)similarity metric of their representations is above/below a certain threshold.
In this implementation I have used cosine similarity between face embeddings as the similarity metric.

By combining these ideas we draw the graph like this:

  1. Assign a node to every face detected in the dataset (not every image, because there can be multiple faces in a single image)
  2. Add an edge between two nodes only if the cosine similarity between their embeddings is greater than a threshold.

And the algorithm used for clustering is:

  1. Initially all the nodes are given a seperate cluster.
  2. The algorithm does a specific number of iterations.
  3. For each iteration the nodes are traversed randomly.
  4. Each node is given the cluster which has the highest rank in it's neighbourhood.
  5. The rank of a cluster here is the sum of weights between the current node and the neighbours belonging to that cluster.
  6. In case of a tie between clusters, any one of them is assigned randomly.

The Chinese Whispers algorithm does not converge nor is it deterministic, but it turns out be a very efficient algorithm for some tasks.

References:

This project is inspired by the ideas presented in the following papers

[1] Roy Klip. Fuzzy Face Clustering For Forensic Investigations

[2] Chang L, Pérez-Suárez A, González-Mendoza M. Effective and Generalizable Graph-Based Clustering for Faces in the Wild.

[3] Biemann, Chris. (2006). Chinese whispers: An efficient graph clustering algorithm and its application to natural language processing problems.
[4] Florian Schroff and Dmitry Kalenichenko and James Philbin (2015). FaceNet, a Unified Embedding for Face Recognition and Clustering.

Libraries used:

  • NumPy
  • Tensorflow
  • Keras
  • dlib
  • OpenCv
  • networkx
  • imutils
  • tqdm

Future Scope:

  • A Graphical User Interface (GUI) to help users use the app with ease.
  • GPU optimization to calculate embeddings.
  • Implementation of other clustering methods.
You might also like...
 Face Detection with DLIB
Face Detection with DLIB

Face Detection with DLIB In this project, we have detected our face with dlib and opencv libraries. Setup This Project Install DLIB & OpenCV You can i

Train custom VR face tracking parameters

Pal Buddy Guy: The anipal's best friend This is a small script to improve upon the tracking capabilities of the Vive Pro Eye and facial tracker. You c

nofacedb/faceprocessor is a face recognition engine for NoFaceDB program complex.

faceprocessor nofacedb/faceprocessor is a face recognition engine for NoFaceDB program complex. Tech faceprocessor uses a number of open source projec

Face Anonymizer - FaceAnonApp v1.0
Face Anonymizer - FaceAnonApp v1.0

Face Anonymizer - FaceAnonApp v1.0 Blur faces from image and video files in /data/files folder. Contents Repo of the source files for the FaceAnonApp.

The official repo for OC-SORT: Observation-Centric SORT on video Multi-Object Tracking. OC-SORT is simple, online and robust to occlusion/non-linear motion.
The official repo for OC-SORT: Observation-Centric SORT on video Multi-Object Tracking. OC-SORT is simple, online and robust to occlusion/non-linear motion.

OC-SORT Observation-Centric SORT (OC-SORT) is a pure motion-model-based multi-object tracker. It aims to improve tracking robustness in crowded scenes

Much faster than SORT(Simple Online and Realtime Tracking), a little worse than SORT

QSORT QSORT(Quick + Simple Online and Realtime Tracking) is a simple online and realtime tracking algorithm for 2D multiple object tracking in video s

Sort By Face
Sort By Face

Sort-By-Face This is an application with which you can either sort all the pictures by faces from a corpus of photos or retrieve all your photos from

Motion detector, Full body detection, Upper body detection, Cat face detection, Smile detection, Face detection (haar cascade), Silverware detection, Face detection (lbp), and Sending email notifications
Motion detector, Full body detection, Upper body detection, Cat face detection, Smile detection, Face detection (haar cascade), Silverware detection, Face detection (lbp), and Sending email notifications

Security camera running OpenCV for object and motion detection. The camera will send email with image of any objects it detects. It also runs a server that provides web interface with live stream video.

A Python utility / library to sort imports.
A Python utility / library to sort imports.

Read Latest Documentation - Browse GitHub Code Repository isort your imports, so you don't have to. isort is a Python utility / library to sort import

isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type.
isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type.

isort is a Python utility / library to sort imports alphabetically, and automatically separated into sections and by type. It provides a command line utility, Python library and plugins for various editors to quickly sort all your imports.

People movement type classifier with YOLOv4 detection and SORT tracking.
People movement type classifier with YOLOv4 detection and SORT tracking.

Movement classification The goal of this project would be movement classification of people, in other words, walking (normal and fast) and running. Yo

Real-time multi-object tracker using YOLO v5 and deep sort
Real-time multi-object tracker using YOLO v5 and deep sort

This repository contains a two-stage-tracker. The detections generated by YOLOv5, a family of object detection architectures and models pretrained on the COCO dataset, are passed to a Deep Sort algorithm which tracks the objects. It can track any object that your Yolov5 model was trained to detect.

Official PyTorch Implementation of Rank & Sort Loss [ICCV2021]
Official PyTorch Implementation of Rank & Sort Loss [ICCV2021]

Rank & Sort Loss for Object Detection and Instance Segmentation The official implementation of Rank & Sort Loss. Our implementation is based on mmdete

This is an easy python software which allows to sort images with faces by gender and after by age.

Gender-age Classifier This is an easy python software which allows to sort images with faces by gender and after by age. Usage First install Deepface

Simple yet efficient tool used to check and sort tokens in terms of there validation.
Simple yet efficient tool used to check and sort tokens in terms of there validation.

Discord Token Checker Simple yet efficient tool used to check and sort tokens in terms of there validation.When the program is done,go to the "output"

Using python to generate a bat script of repetitive lines of code that differ in some way but can sort out a group of audio files according to their common names

Batch Sorting Using python to generate a bat script of repetitive lines of code that differ in some way but can sort out a group of audio files accord

py-image-dedup is a tool to sort out or remove duplicates within a photo library

py-image-dedup is a tool to sort out or remove duplicates within a photo library. Unlike most other solutions, py-image-dedup intentionally uses an approximate image comparison to also detect duplicates of images that slightly differ in resolution, color or other minor details.

VSCode extension to sort and refactor python imports using reorder-python-imports.
VSCode extension to sort and refactor python imports using reorder-python-imports.

reorder-python-imports VSCode extension to sort and refactor python imports using reorder-python-imports. Unlike other import organizers, reorder-pyth

Owner
null
When Age-Invariant Face Recognition Meets Face Age Synthesis: A Multi-Task Learning Framework (CVPR 2021 oral)

MTLFace This repository contains the PyTorch implementation and the dataset of the paper: When Age-Invariant Face Recognition Meets Face Age Synthesis

Hzzone 120 Jan 5, 2023
Polaris is a Face recognition attendance system .

Support Me ?? About Polaris ?? Polaris is a system based on facial recognition with a futuristic GUI design, Can easily find people informations store

XN3UR0N 215 Dec 26, 2022
EQFace: An implementation of EQFace: A Simple Explicit Quality Network for Face Recognition

EQFace: A Simple Explicit Quality Network for Face Recognition The first face recognition network that generates explicit face quality online.

DeepCam Shenzhen 141 Dec 31, 2022
Isearch (OSINT) 🔎 Face recognition reverse image search on Instagram profile feed photos.

isearch is an OSINT tool on Instagram. Offers a face recognition reverse image search on Instagram profile feed photos.

Malek salem 20 Oct 25, 2022
A python program to block out your face

Readme This is a small program I threw together in about 6 hours to block out your face. It probably doesn't work very well, so be warned. By default,

null 1 Oct 17, 2021
Face Recognizer using Opencv Python

Face Recognizer using Opencv Python The first step create your own dataset with file open-cv-create_dataset second step You can put the photo accordin

Han Izza 2 Nov 16, 2021
A facial recognition device is a device that takes an image or a video of a human face and compares it to another image faces in a database.

A facial recognition device is a device that takes an image or a video of a human face and compares it to another image faces in a database. The structure, shape and proportions of the faces are compared during the face recognition steps.

Pavankumar Khot 4 Mar 19, 2022
A simple python program to record security cam footage by detecting a face and body of a person in the frame.

SecurityCam A simple python program to record security cam footage by detecting a face and body of a person in the frame. This code was created by me,

null 1 Nov 8, 2021
📷 Face Recognition using Haar-Cascade Classifier, OpenCV, and Python

Face-Recognition-System Face Recognition using Haar-Cascade Classifier, OpenCV and Python. This project is based on face detection and face recognitio

null 1 Jan 10, 2022
Opencv face recognition desktop application

Opencv-Face-Recognition Opencv face recognition desktop application Program developed by Gustavo Wydler Azuaga - 2021-11-19 Screenshots of the program

Gus 1 Nov 19, 2021