Code Monkey home page Code Monkey logo

face_clustering's Introduction

Sort similar looking face pictures to clusters using FaceNet and KMeans

Prerequisites

  • installed dependencies tensorflow and opencv libraries.
pip install tensorflow
conda install opencv
  • correct PYTHONPATH=full_path_to_folder/scr
  • pretrained FaceNet model in the folder ./models/. You can download it here.
  • images dataset in the ./data/folder_with_images/. I used LFW dataset. Unzip it to ./data/lfw/. The directory should be in the correct openface format:
my_database
└───a_person
│   │   image00.jpg
│   │   image01.jpg
│   
└───b_person
│   │   image00.jpg
│   
└───c_person
│   │   image00.jpg
│   │   image01.jpg
│   │   image02.jpg
│   │   image03.jpg

How to run

  1. Clean folders ./np_embeddings , ./data/clustered, ./data/sorted
  • Run export_embeddings.py
    This will generate embeddings and labels for images.
    To make it working add PYTHONPATH=full_path_to_folder/scr to you sources. If you are using PyCharm simply add to Enviroment Varianbles PYTHONPATH value full_path_to_folder/scr.

  • Run Distance_matrix.py.
    This step will give you the matrix with all of the Euclidean distances between faces. Numpy array is saved to ./np_embeddings/embeddings.npy It will take some time because the matrix size of NxN with zeros on the main diagonal. This file is quiet big - 1.4GB. We need it to sort faces.

  1. Run Cluster_faces.py.
    First, it will sort all off the face images based on the closest distance and save sorted images to ./data/sorted. Second, it will cluster images using Kmeans algorithm. Number of cluster by default is 30. You can change it if you like.

Result

This is what you get in the end. KMeans does a pretty good job to cluster 128-dimentional image embeddings.
result

Disclaimer

This work is based on FaceNet achievement. You can check FaceNet model and papers here.

face_clustering's People

Contributors

pavelkrolevets avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

face_clustering's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.