Skip to main content

FaceRecognition_Django

· One min read
Pajman Samadi
summary
  • Repository on GitHub.
  • A FaceRecognition module written with facenet pytorch.
  • Use Django as the web framework.
  • Dockerized project.

Module

from face_encoder import FaceEncoder

# Load the module
FE = FaceEncoder('/path/to/main_folder_people/', img_size=160, recognition_threshold=0.3)

# Read images in people folder to create a database
encodes_db = FE.db_prepare(show_face=True, save_file=True, encoding_file_path='./data/encodes_db.pt')

"""--- Different ways to send an input to get results ---"""

# Image path as string
image = FE.recognizer('/path/to/image', encodes_db, pil_write=True)
# PIL.Image
image = FE.recognizer(Image.open('/path/to/image'), encodes_db, pil_write=True)
# numpy image
image = FE.recognizer(np.array(unknown_image), encodes_db, pil_write=True)

Colab

For testing the module yourself, open the prepared jupyter notebook in colab via the following link

Open In Colab

Usage

First: install requirements.txt

$ pip3 install -r requirements.txt

then in your local computer to start Django server run following commands in your terminal:

1- makemigrations

$ python3 manage.py makemigrations

2- migrate

$ python3 manage.py migrate

Optional

  • createsuperuser
$ python3 manage.py createsuperuser

3- runserver

$ python manage.py runserver 0.0.0.0:8000

Docker

$ docker-compose up --build

UI

img