{"id":14958968,"url":"https://github.com/patlevin/face-detection-tflite","last_synced_at":"2025-04-06T05:17:30.280Z","repository":{"id":46177520,"uuid":"343263188","full_name":"patlevin/face-detection-tflite","owner":"patlevin","description":"Face and iris detection for Python based on MediaPipe ","archived":false,"fork":false,"pushed_at":"2024-05-13T21:36:06.000Z","size":7052,"stargazers_count":153,"open_issues_count":4,"forks_count":29,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-03-30T04:08:52.395Z","etag":null,"topics":["face-detection","machine-learning","tensorflow-lite","tensorflow-models"],"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/patlevin.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-01T02:06:46.000Z","updated_at":"2025-03-12T09:24:08.000Z","dependencies_parsed_at":"2024-06-19T13:27:36.090Z","dependency_job_id":"1fc9976a-bc2e-48cb-86c2-dcd0412766b9","html_url":"https://github.com/patlevin/face-detection-tflite","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patlevin%2Fface-detection-tflite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patlevin%2Fface-detection-tflite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patlevin%2Fface-detection-tflite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patlevin%2Fface-detection-tflite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patlevin","download_url":"https://codeload.github.com/patlevin/face-detection-tflite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247436290,"owners_count":20938533,"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":["face-detection","machine-learning","tensorflow-lite","tensorflow-models"],"created_at":"2024-09-24T13:18:36.418Z","updated_at":"2025-04-06T05:17:30.256Z","avatar_url":"https://github.com/patlevin.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Face Detection For Python\r\n\r\nThis package implements parts of Google®'s [**MediaPipe**](https://mediapipe.dev/#!) models in pure Python (with a little help from Numpy and PIL) without `Protobuf` graphs and with minimal dependencies (just [**TF Lite**](https://www.tensorflow.org/lite/api_docs) and [**Pillow**](https://python-pillow.org/)).\r\n\r\n## Models and Examples\r\n\r\nThe package provides the following models:\r\n\r\n* Face Detection\r\n\r\n![Face detection example](https://raw.githubusercontent.com/patlevin/face-detection-tflite/main/docs/group_photo.jpg)\r\n\r\n* Face Landmark Detection\r\n\r\n![Face landmark example](https://raw.githubusercontent.com/patlevin/face-detection-tflite/main/docs/portrait_fl.jpg)\r\n\r\n* Iris Landmark Detection\r\n\r\n![Iris landmark example](https://raw.githubusercontent.com/patlevin/face-detection-tflite/main/docs/eyes.jpg)\r\n\r\n* Iris recoloring example\r\n\r\n![Iris recoloring example](https://raw.githubusercontent.com/patlevin/face-detection-tflite/main/docs/recolored.jpg)\r\n\r\n## Motivation\r\n\r\nThe package doesn't use the graph approach implemented by **MediaPipe** and\r\nis therefore not as flexible. It is, however, somewhat easier to use and\r\nunderstand and more accessible to recreational programming and experimenting\r\nwith the pretrained ML models than the rather complex **MediaPipe** framework.\r\n\r\nHere's how face detection works and an image like shown above can be produced:\r\n\r\n```python\r\nfrom fdlite import FaceDetection, FaceDetectionModel\r\nfrom fdlite.render import Colors, detections_to_render_data, render_to_image \r\nfrom PIL import Image\r\n\r\nimage = Image.open('group.jpg')\r\ndetect_faces = FaceDetection(model_type=FaceDetectionModel.BACK_CAMERA)\r\nfaces = detect_faces(image)\r\nif not len(faces):\r\n    print('no faces detected :(')\r\nelse:\r\n    render_data = detections_to_render_data(faces, bounds_color=Colors.GREEN)\r\n    render_to_image(render_data, image).show()\r\n```\r\n\r\nWhile this example isn't that much simpler than the **MediaPipe** equivalent,\r\nsome models (e.g. iris detection) aren't available in the Python API.\r\n\r\nNote that the package ships with five models:\r\n\r\n* `FaceDetectionModel.FRONT_CAMERA` - a smaller model optimised for\r\n  selfies and close-up portraits; this is the default model used\r\n* `FaceDetectionModel.BACK_CAMERA` - a larger model suitable for group\r\n images and wider shots with smaller faces\r\n* `FaceDetectionModel.SHORT` - a model best suited for short range images,\r\n  i.e. faces are within 2 metres from the camera\r\n* `FaceDetectionModel.FULL` - a model best suited for mid range images,\r\n  i.e. faces are within 5 metres from the camera\r\n* `FaceDetectionModel.FULL_SPARSE` - a model best suited for mid range images,\r\n  i.e. faces are within 5 metres from the camera\r\n\r\nThe `FaceDetectionModel.FULL` and `FaceDetectionModel.FULL_SPARSE` models are\r\nequivalent in terms of detection quality. They differ in that the full model\r\nis a dense model whereas the sparse model runs up to 30% faster on CPUs. On a\r\nGPU, both models exhibit similar runtime performance. In addition, the dense\r\nfull model has slightly better [Recall](https://en.wikipedia.org/wiki/Precision_and_recall),\r\nwhereas the sparse model features a higher [Precision](https://en.wikipedia.org/wiki/Precision_and_recall).\r\n\r\nIf you don't know whether the image is a close-up portrait or you get no\r\ndetections with the default model, try using the `BACK_CAMERA`-model instead.\r\n\r\n## Installation\r\n\r\nThe latest release version is available in [PyPI](https://pypi.org/project/face-detection-tflite/0.1.0/)\r\nand can be installed via:\r\n\r\n```sh\r\npip install -U face-detection-tflite\r\n```\r\n\r\nThe package can be also installed from source by navigating to the folder\r\ncontaining `setup.py` and running\r\n\r\n```sh\r\npip install .\r\n```\r\n\r\nfrom a shell or command prompt.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatlevin%2Fface-detection-tflite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatlevin%2Fface-detection-tflite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatlevin%2Fface-detection-tflite/lists"}