Skip to main content

Model to recognize celebrities using a face matching algorithm

Project description

Celebrity Recognition PyPI version Documentation Status Anaconda-Server Badge

Model to recognize celebrities using a face matching algorithm.

Model is based on a dataset of around 6000 images of 60 celebrities (100 each).

Refer this for detailed documentation.

Basic working of the algorithm includes the following:

  • Face detection is done using MTCNN face detection model.

  • Face encodings are created using VGGFace model in keras.

  • Face matching is done using annoy library (spotify).

Installing dependencies

  • Run pip install -r requirements.txt to install all the dependencies (preferably in a virtual environment).

PyPI package

Installation

  • To ensure you have all the required additional packages, run pip install -r requirements.txt first.
  • To install pip package, run:
    # pip release version
    pip install celeb-detector
    # also install additional dependencies with this (if not installed via requirements.txt file)
    pip install annoy keras-vggface keras-applications
    # Directly from repo
    pip install git+https://github.com/shobhit9618/celeb_recognition.git
    
  • If you are using conda on linux or ubuntu, you can use the following commands to create and use a new environment called celeb-detector:
    conda env create shobhit9618/celeb-detector
    conda activate celeb-detector
    
    This will install all the required dependencies. To ensure you are using the latest version of the package, also run (inside the environment):
    pip install --upgrade celeb-detector
    

Using pip pakcage

  • For using my model for predictions, use the following lines of code after installation:

    import celeb_detector # on running for the first time, this will download vggface model
    img_path = 'sample_image.jpg'
    celeb_detector.celeb_recognition(img_path) # on running for the first time, 2 files (celeb_mapping.json and celeb_index_60.ann) will downloaded to the home directory
    
    # if you want to use an image url, just provide the url and add url=True
    url = 'https://sample/sample_image_url.jpg'
    celeb_detector.celeb_recognition(url, url=True)
    

    This returns a list of dictionaries, each dictionary contains bbox coordinates, celeb name and confidence for each face detected in the image (celeb name will be unknown if no matching face detected).

  • For using your own custom model, also provide path to json and ann files as shown below:

    import celeb_detector
    img_path = 'sample_image.jpg'
    ann_path = 'sample_index.ann'
    celeb_map = 'sample_mapping.json'
    celeb_detector.celeb_recognition(img_path, ann_path, celeb_map)
    
  • For creating your own model (refer this for more details on usage) and run as follows:

    import celeb_detector
    folder_path = 'celeb_images'
    celeb_detector.create_celeb_model(folder_path)
    

Create your own celeb model

  • Create a dataset of celebs in the following directory structure:
    celeb_images/
        celeb-a/
            celeb-a_1.jpg
            celeb-a_2.jpg
            ...
        celeb-b/
            celeb-b_1.jpg
            celeb-b_1.jpg
            ...
        ...
    
  • Each folder name will be considered as the corresponding celeb name for the model (WARNING: Do not provide any special characters or spaces in the names).
  • Make sure each image has only 1 face (of the desired celebrity), if there are multiple faces, only the first detected face will be considered.
  • Provide path to the dataset folder (for example, celeb_images folder) in the create_celeb_model.py file.
  • Run create_celeb_model.py file.
  • Upon successful completion of the code, we get celeb_mapping.json (for storing indexes vs celeb names), celeb_index.ann (ann file for searching encodings) and celeb_name_encoding.pkl files (for storing encodings vs indexes for each celeb). (WARNING: You need to provide paths for storing each of these files, default is to store in the current directory)

Model predictions in jupyter

  • Provide paths to celeb_mapping.json and celeb_index.ann files in celeb_recognition.ipynb file. If you want to try my model, ignore this step.
  • Run all the cells in the celeb_recognition.ipynb file, the final cell will provide widgets for uploading images and making predictions (this will also download the necessary model files).
  • NOTE: celeb_recognition.ipynb is a standalone file and does not require any other files from the repo for running.

Model predictions in python

  • Provide paths to celeb_mapping.json and celeb_index.ann files in celeb_recognition.py and celeb_utils.py files. If you want to try my model, ignore this step.
  • Run celeb_recognition.py file, provide path to image in the file.
  • Output includes a list of the identified faces, bounding boxes and the predicted celeb name (unknown if not found).
  • It also displays the output with bounding boxes.

Sample image output

Image

Binder

You can run a binder application by clicking the following link:

Binder

You can also launch a voila binder application (which only has widgets for image upload and celeb prediction) by clicking here.

Google Colab

To open and run celeb_recognition.ipynb file in google colab, click the following link:

Open In Colab

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

celeb_detector-0.0.21.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

celeb_detector-0.0.21-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file celeb_detector-0.0.21.tar.gz.

File metadata

  • Download URL: celeb_detector-0.0.21.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.3

File hashes

Hashes for celeb_detector-0.0.21.tar.gz
Algorithm Hash digest
SHA256 5230fb1ab56cb31428ca8d9f5660139df12d0c0460fa4fdfd10407f178d6f0a2
MD5 a849dcb5db6d1f0d36699932f512c16b
BLAKE2b-256 09d76174ede3a81bcbcf26192a1774250aecffba149c8d4df258464a41125bad

See more details on using hashes here.

File details

Details for the file celeb_detector-0.0.21-py3-none-any.whl.

File metadata

  • Download URL: celeb_detector-0.0.21-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.6.3

File hashes

Hashes for celeb_detector-0.0.21-py3-none-any.whl
Algorithm Hash digest
SHA256 fe4de011a831fd96083f16ef9abdf2b7ca93e9b5ea291e22168320f1b7fee8f0
MD5 330c1c6d79c751a93469b0275cdc7e44
BLAKE2b-256 60b3dd884c527b2cff8af29b7cb0a5a8fbb844fc8b36367380668fb6f5a8bd7a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page