Convert Figma logo to code with AI

cmusatyalab logoopenface

Face recognition with deep neural networks.

15,090
3,599
15,090
0

Top Related Projects

13,708

Face recognition using Tensorflow

The world's simplest facial recognition api for Python and the command line

State-of-the-art 2D and 3D Face Analysis Project

11,722

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python

Pretrained Pytorch face detection (MTCNN) and facial recognition (InceptionResnet) models

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js

Quick Overview

OpenFace is an open-source face recognition library that uses deep neural networks to provide state-of-the-art face recognition capabilities. It's designed to be both accurate and efficient, making it suitable for various applications, from security systems to social media platforms.

Pros

  • High accuracy in face recognition tasks
  • Efficient implementation, suitable for real-time applications
  • Open-source, allowing for customization and community contributions
  • Supports multiple platforms (Linux, macOS, and Windows)

Cons

  • Requires significant computational resources for training
  • Dependency on external libraries and tools
  • Limited documentation for advanced use cases
  • May require fine-tuning for specific applications

Code Examples

  1. Face detection and alignment:
import cv2
import openface

align = openface.AlignDlib("models/dlib/shape_predictor_68_face_landmarks.dat")
rgbImg = cv2.imread("image.jpg")
bb = align.getLargestFaceBoundingBox(rgbImg)
alignedFace = align.align(96, rgbImg, bb, landmarkIndices=openface.AlignDlib.OUTER_EYES_AND_NOSE)
  1. Face representation:
import openface

net = openface.TorchNeuralNet("models/openface/nn4.small2.v1.t7", 96)
rep = net.forward(alignedFace)
  1. Face comparison:
import numpy as np

d = rep1 - rep2
distance = np.dot(d, d)
similarity = 1 / (1 + distance)

Getting Started

  1. Install dependencies:
pip install numpy scipy scikit-learn pandas
  1. Clone the repository:
git clone https://github.com/cmusatyalab/openface.git
cd openface
  1. Install OpenFace:
python setup.py install
  1. Download pre-trained models:
./models/get-models.sh
  1. Run the demo:
./demos/compare.py images/examples/{lennon*,clapton*}

This will compare images of John Lennon and Eric Clapton, demonstrating the face recognition capabilities of OpenFace.

Competitor Comparisons

13,708

Face recognition using Tensorflow

Pros of FaceNet

  • Higher accuracy in face recognition tasks
  • Supports larger datasets and more complex models
  • More active development and community support

Cons of FaceNet

  • Requires more computational resources
  • Steeper learning curve for implementation
  • Less focus on real-time performance

Code Comparison

OpenFace:

import openface
align = openface.AlignDlib("models/dlib/shape_predictor_68_face_landmarks.dat")
net = openface.TorchNeuralNet("models/openface/nn4.small2.v1.t7", 96)
rep = net.forward(aligned_face)

FaceNet:

import facenet
images_placeholder = tf.placeholder(tf.float32, shape=(None, 160, 160, 3), name='input_image')
embeddings = facenet.inference(images_placeholder, keep_probability, phase_train=False, weight_decay=0.0)
feed_dict = {images_placeholder: aligned_images, phase_train_placeholder: False}
emb_array = sess.run(embeddings, feed_dict=feed_dict)

Both repositories provide face recognition capabilities, but FaceNet offers higher accuracy and supports larger datasets. However, it requires more computational resources and has a steeper learning curve. OpenFace is more lightweight and focuses on real-time performance, making it suitable for applications with limited resources. The code comparison shows that FaceNet uses TensorFlow, while OpenFace uses Torch, reflecting differences in their underlying architectures and implementation approaches.

The world's simplest facial recognition api for Python and the command line

Pros of face_recognition

  • Easier to use with a high-level Python API
  • More comprehensive documentation and examples
  • Includes additional features like facial landmark detection and face encoding

Cons of face_recognition

  • Less flexible for custom deep learning models
  • May have lower performance for large-scale applications
  • Depends on dlib, which can be challenging to install on some systems

Code Comparison

face_recognition:

import face_recognition

image = face_recognition.load_image_file("image.jpg")
face_locations = face_recognition.face_locations(image)
face_encodings = face_recognition.face_encodings(image, face_locations)

OpenFace:

import openface

align = openface.AlignDlib("shape_predictor_68_face_landmarks.dat")
net = openface.TorchNeuralNet("nn4.small2.v1.t7", imgDim=96)
aligned_face = align.align(96, image, bb)
rep = net.forward(aligned_face)

OpenFace provides lower-level access to the face recognition pipeline, allowing for more customization but requiring more code and understanding of the underlying processes. face_recognition offers a simpler API for common tasks, making it more accessible for beginners and rapid prototyping.

State-of-the-art 2D and 3D Face Analysis Project

Pros of InsightFace

  • Higher accuracy and performance in face recognition tasks
  • Supports a wider range of deep learning models and architectures
  • More active development and frequent updates

Cons of InsightFace

  • Steeper learning curve and more complex implementation
  • Requires more computational resources for training and inference

Code Comparison

OpenFace:

import openface

align = openface.AlignDlib("models/dlib/shape_predictor_68_face_landmarks.dat")
net = openface.TorchNeuralNet("models/openface/nn4.small2.v1.t7", 96)

InsightFace:

from insightface.app import FaceAnalysis

app = FaceAnalysis(name='buffalo_l')
app.prepare(ctx_id=0, det_size=(640, 640))

Both repositories focus on face recognition, but InsightFace offers more advanced features and higher accuracy. OpenFace is simpler to use and requires fewer resources, making it suitable for smaller projects or devices with limited computational power. InsightFace is better suited for large-scale applications and research purposes, providing state-of-the-art performance in face recognition tasks.

11,722

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python

Pros of Deepface

  • More comprehensive face analysis capabilities (emotion, age, gender, race)
  • Supports multiple deep learning models and backends
  • Active development with frequent updates

Cons of Deepface

  • Larger dependency footprint
  • May be slower for simple face recognition tasks
  • Steeper learning curve for beginners

Code Comparison

Openface:

import openface
align = openface.AlignDlib("models/dlib/shape_predictor_68_face_landmarks.dat")
net = openface.TorchNeuralNet("models/openface/nn4.small2.v1.t7", 96)
rep = net.forward(align.getAllFaceBoundingBoxes(rgbImg)[0])

Deepface:

from deepface import DeepFace
result = DeepFace.analyze(img_path = "img.jpg", 
        actions = ['age', 'gender', 'emotion', 'race'])
verification = DeepFace.verify("img1.jpg", "img2.jpg")

Summary

Deepface offers more comprehensive face analysis features and supports multiple models, making it suitable for complex tasks. However, it may be overkill for simple face recognition. Openface is more lightweight and focused on face recognition, potentially offering better performance for basic tasks. The choice between them depends on the specific requirements of your project.

Pretrained Pytorch face detection (MTCNN) and facial recognition (InceptionResnet) models

Pros of facenet-pytorch

  • Implemented in PyTorch, offering better integration with modern deep learning workflows
  • Provides pre-trained models and easy-to-use interfaces for face recognition tasks
  • Actively maintained with regular updates and improvements

Cons of facenet-pytorch

  • Less comprehensive documentation compared to OpenFace
  • Fewer pre-processing tools and utilities for face detection and alignment

Code Comparison

OpenFace (Python):

import openface
align = openface.AlignDlib("shape_predictor_68_face_landmarks.dat")
net = openface.TorchNeuralNet("nn4.small2.v1.t7", imgDim=96)
rep = net.forward(align.align(96, rgbImg, bb))

facenet-pytorch (Python):

from facenet_pytorch import MTCNN, InceptionResnetV1
mtcnn = MTCNN()
resnet = InceptionResnetV1(pretrained='vggface2').eval()
img_cropped = mtcnn(img)
embedding = resnet(img_cropped.unsqueeze(0))

Both repositories offer face recognition capabilities, but facenet-pytorch provides a more modern implementation using PyTorch. OpenFace offers more comprehensive tools and documentation, while facenet-pytorch focuses on providing pre-trained models and easy integration with PyTorch workflows.

JavaScript API for face detection and face recognition in the browser and nodejs with tensorflow.js

Pros of face-api.js

  • JavaScript-based, making it easier to integrate into web applications
  • Supports real-time face detection and recognition in the browser
  • Includes pre-trained models for various face-related tasks

Cons of face-api.js

  • May have lower accuracy compared to OpenFace's deep learning approach
  • Limited to browser environments, while OpenFace can be used in various platforms
  • Smaller community and fewer updates compared to OpenFace

Code Comparison

face-api.js:

await faceapi.loadSsdMobilenetv1Model('/models')
const detections = await faceapi.detectAllFaces(image)

OpenFace:

import openface
align = openface.AlignDlib("models/dlib/shape_predictor_68_face_landmarks.dat")
net = openface.TorchNeuralNet("models/openface/nn4.small2.v1.t7", 96)

Both libraries offer face detection and recognition capabilities, but their implementations differ significantly. face-api.js is more suitable for web-based projects, while OpenFace provides a more robust solution for various platforms and potentially higher accuracy. The choice between the two depends on the specific requirements of your project, such as the target environment, desired accuracy, and ease of integration.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

OpenFace • Build Status Release License Gitter

Free and open source face recognition with deep neural networks.



This research was supported by the National Science Foundation (NSF) under grant number CNS-1518865. Additional support was provided by the Intel Corporation, Google, Vodafone, NVIDIA, and the Conklin Kistler family fund. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and should not be attributed to their employers or funding sources.

What's in this repository?

Citations

Please cite OpenFace in your publications if it helps your research. The following is a BibTeX and plaintext reference for our OpenFace tech report.

@techreport{amos2016openface,
  title={OpenFace: A general-purpose face recognition
    library with mobile applications},
  author={Amos, Brandon and Bartosz Ludwiczuk and Satyanarayanan, Mahadev},
  year={2016},
  institution={CMU-CS-16-118, CMU School of Computer Science},
}

B. Amos, B. Ludwiczuk, M. Satyanarayanan,
"Openface: A general-purpose face recognition library with mobile applications,"
CMU-CS-16-118, CMU School of Computer Science, Tech. Rep., 2016.

Licensing

Unless otherwise stated, the source code and trained Torch and Python model files are copyright Carnegie Mellon University and licensed under the Apache 2.0 License. Portions from the following third party sources have been modified and are included in this repository. These portions are noted in the source files and are copyright their respective authors with the licenses listed.

ProjectModifiedLicense
Atcold/torch-TripletEmbeddingNoMIT
facebook/fbnnYesBSD
dlib-models (68 face landmark detector)NoCC0