{"id":13826718,"url":"https://github.com/sajjjadayobi/FaceLib","last_synced_at":"2025-07-09T01:31:09.172Z","repository":{"id":40631033,"uuid":"239371413","full_name":"sajjjadayobi/FaceLib","owner":"sajjjadayobi","description":"Face Analysis: Detection, Age Gender Estimation \u0026 Recognition","archived":false,"fork":false,"pushed_at":"2024-06-12T17:40:34.000Z","size":10748,"stargazers_count":288,"open_issues_count":3,"forks_count":52,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-08-05T09:15:40.552Z","etag":null,"topics":["age-gender","deep-learning","face","face-detection","face-recognition","facial-expression-recognition","gender-estimation","pytorch","recognition","retinaface"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sajjjadayobi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-09T20:43:46.000Z","updated_at":"2024-07-31T08:36:09.000Z","dependencies_parsed_at":"2022-07-14T04:10:43.108Z","dependency_job_id":null,"html_url":"https://github.com/sajjjadayobi/FaceLib","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajjjadayobi%2FFaceLib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajjjadayobi%2FFaceLib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajjjadayobi%2FFaceLib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sajjjadayobi%2FFaceLib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sajjjadayobi","download_url":"https://codeload.github.com/sajjjadayobi/FaceLib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225476383,"owners_count":17480215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["age-gender","deep-learning","face","face-detection","face-recognition","facial-expression-recognition","gender-estimation","pytorch","recognition","retinaface"],"created_at":"2024-08-04T09:01:43.116Z","updated_at":"2024-11-20T05:31:01.386Z","avatar_url":"https://github.com/sajjjadayobi.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# [FaceLib](https://github.com/sajjjadayobi/FaceLib): Face Analysis\nUsed for face detection, facial expression, AgeGender estimation and recognition with PyTorch.\n- Instalation: `pip install git+https://github.com/sajjjadayobi/FaceLib.git`\n\n## How to use:\nCheck this [example_notebook](https://github.com/sajjjadayobi/FaceLib/blob/master/example_notebook.ipynb) or take a look at the following sections\n \n## 1. Face Detection: RetinaFace\nYou can use these backbone networks: Resnet50, mobilenet. Default model is `mobilenet` and it will be automatically downloaded.\n- The following example illustrates the ease of use of this package on your webcam:\n```python\n     from facelib import WebcamFaceDetector\n   detector = WebcamFaceDetector()\n   detector.run()\n```\n- Low-level access to bounding boxes and face landmarks\n```python\n   from facelib import FaceDetector\n   detector = FaceDetector()\n   boxes, scores, landmarks = detector.detect_faces(image)\n```\n\n## 2. Face Alignment: Using face landmarkd\nFor face aligment always use the `detect_align` function it gives you better performance.\n- Face detection and aligment using the `detect_align` function.\n```python\n from facelib import FaceDetector\n detector = FaceDetector()\n faces, boxes, scores, landmarks = detector.detect_align(image)\n```\n\nOriginal | Aligned \u0026 Resized | Original | Aligned \u0026 Resized |\n|---|---|---|---|\n|![image](https://github.com/sajjjadayobi/FaceLib/blob/master/facelib/imgs/input1.jpg)|![image](https://github.com/sajjjadayobi/FaceLib/blob/master/facelib/imgs/res1.jpg)|![image](https://github.com/sajjjadayobi/FaceLib/blob/master/facelib/imgs/input2.jpg)|![image](https://github.com/sajjjadayobi/FaceLib/blob/master/facelib/imgs/res2.jpg)|\n\n\n## 3. Age \u0026 Gender Estimation:\n`ShufflenetFull` is the default model, and it will be automatically downloaded.\n- Age and gender estimation live on your webcam (or any camera)\n ```python\nfrom facelib import WebcamAgeGenderEstimator\nestimator = WebcamAgeGenderEstimator()\nestimator.run()\n```\n  \n- Low-lvel access to ages and genders \n```python\nfrom facelib import FaceDetector, AgeGenderEstimator\nface_detector = FaceDetector()\nage_gender_detector = AgeGenderEstimator()\n\nfaces, boxes, scores, landmarks = face_detector.detect_align(image)\ngenders, ages = age_gender_detector.detect(faces)\nprint(genders, ages)\n```\n\n## 4. Facial Expression Recognition:\nThe default model is `densnet121` and it will be automatically downloaded. Note that face size must be (224, 224).\n- Emotion detector live on your webcam\n```python\nfrom facelib import WebcamEmotionDetector\ndetector = WebcamEmotionDetector()\ndetector.run()\n```\n\n- Emotions as an array with their probabilities\n```python\nfrom facelib import FaceDetector, EmotionDetector\nface_detector = FaceDetector(face_size=(224, 224))\nemotion_detector = EmotionDetector()\n\nfaces, boxes, scores, landmarks = face_detector.detect_align(image)\nemotions, probab = emotion_detector.detect_emotion(faces)\n```\n- on my Webcam 🙂\n![Alt Text](https://github.com/sajjjadayobi/FaceLib/blob/master/facelib/imgs/emotion.gif)\n\n## 5. Face Recognition: InsightFace\n- This module is a pytorch reimplementation of Arcface(paper), or Insightface(Github)\n\n#### Pretrained Models \u0026 Performance\n- IR-SE50\n\n\n| LFW(%) | CFP-FF(%) | CFP-FP(%) | AgeDB-30(%) | calfw(%) | cplfw(%) | vgg2_fp(%) |\n| ------ | --------- | --------- | ----------- | -------- | -------- | ---------- |\n| 0.9952 | 0.9962    | 0.9504    | 0.9622      | 0.9557   | 0.9107   | 0.9386     |\n- Mobilefacenet\n\n| LFW(%) | CFP-FF(%) | CFP-FP(%) | AgeDB-30(%) | calfw(%) | cplfw(%) | vgg2_fp(%) |\n| ------ | --------- | --------- | ----------- | -------- | -------- | ---------- |\n| 0.9918 | 0.9891    | 0.8986    | 0.9347      | 0.9402   | 0.866    | 0.9100     |\n\n#### Prepare the Facebank\nSave the images of the **faces** you want to detect in this folder\n```\nInsightface/models/data/facebank/\n  ---\u003e person_1/\n      ---\u003e img_1.jpg\n      ---\u003e img_2.jpg\n  ---\u003e person_2/\n      ---\u003e img_1.jpg\n      ---\u003e img_2.jpg\n```\nYou can save a new preson in facebank with 2 ways:\n- Use `add_from_webcam`: it takes 4 images and saves them on facebank.\n```python\n from facelib import add_from_webcam\n add_from_webcam(person_name='sajjad')\n```\n- use `add_from_folder`: it takes a path with some images from just a person.\n```python\n from facelib import add_from_folder\n add_from_folder(folder_path='./', person_name='sajjad')\n```\n\n#### Recognizer\nThe default model is `mobilenet` and it will be automatically downloaded \n- Face Recognition live on your webcam\n```python\nfrom facelib import WebcamVerify\nverifier = WebcamVerify(update=True)\nverifier.run()\n```\n- Low-level access to your images\n```python\nimport cv2\nfrom facelib import FaceRecognizer, FaceDetector\nfrom facelib import update_facebank, load_facebank, special_draw, get_config\n\nconf = get_config()\n# conf.use_mobilenet=False # if you want to use the bigger model\ndetector = FaceDetector(device=conf.device)\nface_rec = FaceRecognizer(conf)\n\n# set True when you add someone new to the facebank\nupdate_facebank_for_add_new_person = False\nif update_facebank_for_add_new_person:\n    targets, names = update_facebank(conf, face_rec.model, detector)\nelse:\n    targets, names = load_facebank(conf)\n\nimage = cv2.imread(your_path)\nfaces, boxes, scores, landmarks = detector.detect_align(image)\nresults, score = face_rec.infer(faces, targets)\nprint(names[results.cpu()])\nfor idx, bbox in enumerate(boxes):\n    special_draw(image, bbox, landmarks[idx], names[results[idx]+1], score[idx])\n```\n![image](https://github.com/sajjjadayobi/FaceLib/blob/master/facelib/imgs/face_rec.jpg)\n\nReference: [InsightFace](https://github.com/TreB1eN/InsightFace_Pytorch)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajjjadayobi%2FFaceLib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsajjjadayobi%2FFaceLib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsajjjadayobi%2FFaceLib/lists"}