Package: celeb-detector
Celebrity RecognitionModel to recognize celebrities using a face matching algorithm.Referthisfor detailed documentation.You can also read my article on mediumhere.Basic working of the algorithm includes the following:Face detection is done using MTCNN face detection model.Face encodings are created usingVGGFacemodel in keras.Face matching is done usingannoylibrary (spotify).Installing dependenciesRunpip install -r requirements.txtto install all the dependencies (preferably in a virtual environment).PyPI packageInstallationTo ensure you have all the required additional packages, runpip install -r requirements.txtfirst.To install pip package, run:# pip release versionpipinstallceleb-detector# also install additional dependencies with this (if not installed via requirements.txt file)pipinstallannoykeras-vggfacekeras-applications# Directly from repopipinstallgit+https://github.com/shobhit9618/celeb_recognition.gitIf you are using conda on linux or ubuntu, you can use the following commands to create and use a new environment called celeb-detector:condaenvcreateshobhit9618/celeb-detector
condaactivateceleb-detectorThis will install all the required dependencies. To ensure you are using the latest version of the package, also run (inside the environment):pipinstall--upgradeceleb-detectorUsing pip pakcageFor using my model for predictions, use the following lines of code after installation:importceleb_detector# on running for the first time, this will download vggface modelimg_path='sample_image.jpg'# this supports both local path and web url like https://sample/sample_image_url.jpgceleb_detector.celeb_recognition(img_path)# on running for the first time, 2 files (celeb_mapping.json and celeb_index_60.ann) will downloaded to your home directoryThis 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:importceleb_detectorimg_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 (referthisfor more details on usage) and run as follows:importceleb_detectorfolder_path='celeb_images'celeb_detector.create_celeb_model(folder_path)Create your own celeb modelCreate a dataset of celebs in the following directory structure:celeb_images/celeb-a/celeb-a_1.jpgceleb-a_2.jpg...celeb-b/celeb-b_1.jpgceleb-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_imagesfolder) in thecreate_celeb_model.pyfile.Runcreate_celeb_model.pyfile.Upon successful completion of the code, we getceleb_mapping.json(for storing indexes vs celeb names),celeb_index.ann(ann file for searching encodings) andceleb_name_encoding.pklfiles (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 jupyterProvide paths toceleb_mapping.jsonandceleb_index.annfiles inceleb_recognition.ipynbfile. If you want to try my model, ignore this step.Run all the cells in theceleb_recognition.ipynbfile, the final cell will provide widgets for uploading images and making predictions
(this will also download the necessary model files).NOTE:celeb_recognition.ipynbis a standalone file and does not require any other files from the repo for running.Model predictions in pythonProvide paths toceleb_mapping.jsonandceleb_index.annfiles inceleb_recognition.pyandceleb_utils.pyfiles. If you want to try my model, ignore this step.Runceleb_recognition.pyfile, 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 outputBinderYou can run a binder application by clicking the following link:You can also launch a voila binder application (which only has widgets for image upload and celeb prediction) by clickinghere.Google ColabTo open and runceleb_recognition.ipynbfile in google colab, click the following link: