{ "info": { "author": "Tim Esler", "author_email": "tim.esler@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3" ], "description": "# Face Recognition Using Pytorch \n[![Code Coverage](https://img.shields.io/codecov/c/github/timesler/facenet-pytorch.svg)](https://codecov.io/gh/timesler/facenet-pytorch)\n\n| System | Python | |\n| :---: | :---: | :---: |\n| Linux | 3.5, 3.6, 3.7 | [![Build Status](https://travis-ci.com/timesler/facenet-pytorch.svg?branch=master)](https://travis-ci.com/timesler/facenet-pytorch) |\n| macOS | 3.6, 3.7 | [![Build Status](https://travis-ci.com/timesler/facenet-pytorch.svg?branch=master)](https://travis-ci.com/timesler/facenet-pytorch) |\n| Windows | 3.5, 3.6, 3.7 | [![Build Status](https://travis-ci.com/timesler/facenet-pytorch.svg?branch=master)](https://travis-ci.com/timesler/facenet-pytorch) |\n\nThis is a repository for Inception Resnet (V1) models in pytorch, pretrained on VGGFace2 and CASIA-Webface.\n\nPytorch model weights were initialized using parameters ported from David Sandberg's [tensorflow facenet repo](https://github.com/davidsandberg/facenet).\n\nAlso included in this repo is an efficient pytorch implementation of MTCNN for face detection prior to inference. These models are also pretrained.\n\n## Quick start\n\n1. Either install using pip:\n ```bash\n pip install facenet-pytorch\n ```\n or clone this repo, removing the '-' to allow python imports:\n ```git\n git clone https://github.com/timesler/facenet-pytorch.git facenet_pytorch\n ```\n1. In python, import the module:\n ```python\n from facenet_pytorch import MTCNN, InceptionResnetV1\n ```\n1. If required, create a face _detection_ pipeline using MTCNN:\n ```python\n mtcnn = MTCNN(image_size=, margin=)\n ```\n1. Create an inception resnet (in eval mode):\n ```python\n resnet = InceptionResnetV1(pretrained='vggface2').eval()\n ```\n1. Process an image:\n ```python\n from PIL import Image\n\n img = Image.open()\n\n # Get cropped and prewhitened image tensor\n img_cropped = mtcnn(img, save_path=)\n\n # Calculate embedding (unsqueeze to add batch dimension)\n img_embedding = resnet(img_cropped.unsqueeze(0))\n\n # Or, if using for VGGFace2 classification\n resnet.classify = True\n img_probs = resnet(img_cropped.unsqueeze(0))\n ```\n\nSee `help(MTCNN)` and `help(InceptionResnetV1)` for usage and implementation details.\n\n## Pretrained models\n\nSee: [models/inception_resnet_v1.py](models/inception_resnet_v1.py)\n\nThe following models have been ported to pytorch (with links to download pytorch state_dict's):\n\n|Model name|LFW accuracy (as listed [here](https://github.com/davidsandberg/facenet))|Training dataset|\n| :- | :-: | -: |\n|[20180408-102900](https://drive.google.com/uc?export=download&id=12DYdlLesBl3Kk51EtJsyPS8qA7fErWDX) (111MB)|0.9905|CASIA-Webface|\n|[20180402-114759](https://drive.google.com/uc?export=download&id=1TDZVEBudGaEd5POR5X4ZsMvdsh1h68T1) (107MB)|0.9965|VGGFace2|\n\nThere is no need to manually download the pretrained state_dict's; they are downloaded automatically on model instantiation and cached for future use in the torch cache. To use an Inception Resnet (V1) model for facial recognition/identification in pytorch, use:\n\n```python\nfrom facenet_pytorch import InceptionResnetV1\n\n# For a model pretrained on VGGFace2\nmodel = InceptionResnetV1(pretrained='vggface2').eval()\n\n# For a model pretrained on CASIA-Webface\nmodel = InceptionResnetV1(pretrained='casia-webface').eval()\n\n# For an untrained model with 100 classes\nmodel = InceptionResnetV1(num_classes=100).eval()\n\n# For an untrained 1001-class classifier\nmodel = InceptionResnetV1(classify=True, num_classes=1001).eval()\n```\n\nBoth pretrained models were trained on 160x160 px images, so will perform best if applied to images resized to this shape. For best results, images should also be cropped to the face using MTCNN (see below).\n\nBy default, the above models will return 512-dimensional embeddings of images. To enable classification instead, either pass `classify=True` to the model constructor, or you can set the object attribute afterwards with `model.classify = True`. For VGGFace2, the pretrained model will output logit vectors of length 8631, and for CASIA-Webface logit vectors of length 10575.\n\n## Complete detection and recognition pipeline\n\nFace recognition can be easily applied to raw images by first detecting faces using MTCNN before calculating embedding or probabilities using an Inception Resnet model.\n\nThe example code at [examples/infer.ipynb](examples/infer.ipynb) provides a complete example pipeline utilizing datasets, dataloaders, and optional GPU processing.\n\n## Face tracking in video streams\n\nMTCNN can be used to build a face tracking system (using the `MTCNN.detect()` method). A full face tracking example can be found at [examples/face_tracking.ipynb](examples/face_tracking.ipynb).\n\n![](examples/tracked.gif)\n\n## Use this repo in your own git project\n\nTo use pretrained MTCNN and Inception Resnet V1 models in your own git repo, I recommend first adding this repo as a submodule. Note that the dash ('-') in the repo name should be removed when cloning as a submodule as it will break python when importing:\n\n`git submodule add https://github.com/timesler/facenet-pytorch.git facenet_pytorch`\n\nAlternatively, the code can be installed as a package using pip:\n\n`pip install facenet-pytorch`\n\nModels can then be instantiated simply with the following:\n\n```python\nfrom facenet_pytorch import MTCNN, InceptionResnetV1\n\nmtcnn = MTCNN()\nresnet = InceptionResnetV1(pretrained='vggface2').eval()\n```\n\n## Conversion of parameters from Tensorflow to Pytorch\n\nSee: [models/utils/tensorflow2pytorch.py](models/tensorflow2pytorch.py)\n\nNote that this functionality is not needed to use the models in this repo, which depend only on the saved pytorch `state_dict`'s. \n\nFollowing instantiation of the pytorch model, each layer's weights were loaded from equivalent layers in the pretrained tensorflow models from [davidsandberg/facenet](https://github.com/davidsandberg/facenet).\n\nThe equivalence of the outputs from the original tensorflow models and the pytorch-ported models have been tested and are identical:\n\n---\n`>>> compare_model_outputs(mdl, sess, torch.randn(5, 160, 160, 3).detach())`\n```\nPassing test data through TF model\n\ntensor([[-0.0142, 0.0615, 0.0057, ..., 0.0497, 0.0375, -0.0838],\n [-0.0139, 0.0611, 0.0054, ..., 0.0472, 0.0343, -0.0850],\n [-0.0238, 0.0619, 0.0124, ..., 0.0598, 0.0334, -0.0852],\n [-0.0089, 0.0548, 0.0032, ..., 0.0506, 0.0337, -0.0881],\n [-0.0173, 0.0630, -0.0042, ..., 0.0487, 0.0295, -0.0791]])\n\nPassing test data through PT model\n\ntensor([[-0.0142, 0.0615, 0.0057, ..., 0.0497, 0.0375, -0.0838],\n [-0.0139, 0.0611, 0.0054, ..., 0.0472, 0.0343, -0.0850],\n [-0.0238, 0.0619, 0.0124, ..., 0.0598, 0.0334, -0.0852],\n [-0.0089, 0.0548, 0.0032, ..., 0.0506, 0.0337, -0.0881],\n [-0.0173, 0.0630, -0.0042, ..., 0.0487, 0.0295, -0.0791]],\n grad_fn=)\n\nDistance 1.2874517096861382e-06\n```\n---\n\nIn order to re-run the conversion of tensorflow parameters into the pytorch model, ensure you clone this repo _with submodules_, as the davidsandberg/facenet repo is included as a submodule and parts of it are required for the conversion.\n\n## References\n\n1. David Sandberg's facenet repo: [https://github.com/davidsandberg/facenet](https://github.com/davidsandberg/facenet)\n\n1. F. Schroff, D. Kalenichenko, J. Philbin. _FaceNet: A Unified Embedding for Face Recognition and Clustering_, arXiv:1503.03832, 2015. [PDF](https://arxiv.org/pdf/1503.03832)\n\n1. Q. Cao, L. Shen, W. Xie, O. M. Parkhi, A. Zisserman. _VGGFace2: A dataset for recognising face across pose and age_, International Conference on Automatic Face and Gesture Recognition, 2018. [PDF](http://www.robots.ox.ac.uk/~vgg/publications/2018/Cao18/cao18.pdf)\n\n1. D. Yi, Z. Lei, S. Liao and S. Z. Li. _CASIAWebface: Learning Face Representation from Scratch_, arXiv:1411.7923, 2014. [PDF](https://arxiv.org/pdf/1411.7923)\n\n1. K. Zhang, Z. Zhang, Z. Li and Y. Qiao. _Joint Face Detection and Alignment Using Multitask Cascaded Convolutional Networks_, IEEE Signal Processing Letters, 2016. [PDF](https://kpzhang93.github.io/MTCNN_face_detection_alignment/paper/spl.pdf)\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/timesler/facenet-pytorch", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "facenet-pytorch", "package_url": "https://pypi.org/project/facenet-pytorch/", "platform": "", "project_url": "https://pypi.org/project/facenet-pytorch/", "project_urls": { "Homepage": "https://github.com/timesler/facenet-pytorch" }, "release_url": "https://pypi.org/project/facenet-pytorch/0.3.1/", "requires_dist": [ "numpy", "requests" ], "requires_python": "", "summary": "Pretrained Pytorch face detection and recognition models", "version": "0.3.1" }, "last_serial": 5857671, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "be950a7d004d92257e1e1a08fa68ea64", "sha256": "5f636c3c367ce0e68cda74e4fd85f47e54f45c52f41848e117f9c26d8764d7f5" }, "downloads": -1, "filename": "facenet_pytorch-0.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "be950a7d004d92257e1e1a08fa68ea64", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 1875133, "upload_time": "2019-07-01T23:42:25", "url": "https://files.pythonhosted.org/packages/fd/89/f044114e0e05cff30949e86d7deae24d42aa7505842b3145a3feb10e84b9/facenet_pytorch-0.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "33e34e8dddc121654cd584901b4a6adb", "sha256": "a2e85c560a3c13f4792c04f4fb5be95a4e3e89c1e0a3743c775af22cd9b38e89" }, "downloads": -1, "filename": "facenet-pytorch-0.0.1.tar.gz", "has_sig": false, "md5_digest": "33e34e8dddc121654cd584901b4a6adb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1876306, "upload_time": "2019-07-01T23:42:29", "url": "https://files.pythonhosted.org/packages/9b/37/e0055479a0fe638a75302120e1aec31fe84abe2772f7d94ef3e61287d284/facenet-pytorch-0.0.1.tar.gz" } ], "0.1.0": [ { "comment_text": "", "digests": { "md5": "402dd2013f49a8694417745fa37a3616", "sha256": "d94fabaa27a6c7977eaf527233d0ad67c4d210cefa4b39c15b8c64bfdecf58a3" }, "downloads": -1, "filename": "facenet_pytorch-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "402dd2013f49a8694417745fa37a3616", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 1875771, "upload_time": "2019-07-06T06:00:13", "url": "https://files.pythonhosted.org/packages/c3/73/7efe44bce34b27e4d2fc32b184478d6a9066a7d111d6499546a30183cb13/facenet_pytorch-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "93f100b42cb938e6f54de80064699f19", "sha256": "df055b916c4342bb015e4e10efc60fd9585c94cc27d3d2a635d901612a2ab95b" }, "downloads": -1, "filename": "facenet-pytorch-0.1.0.tar.gz", "has_sig": false, "md5_digest": "93f100b42cb938e6f54de80064699f19", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1876374, "upload_time": "2019-07-06T06:00:17", "url": "https://files.pythonhosted.org/packages/ea/6a/f7b104f7a0493fb9e6801e93102710af011cd9e1a7abb8525503549807b8/facenet-pytorch-0.1.0.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "f7fc3738e06af75b788ae46ee2e977b9", "sha256": "391b3d5d2b37fe82aa10d6c6c65907e1222c243352493c9661aa974fa5e308f8" }, "downloads": -1, "filename": "facenet_pytorch-0.2.2-py3-none-any.whl", "has_sig": false, "md5_digest": "f7fc3738e06af75b788ae46ee2e977b9", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 1877833, "upload_time": "2019-09-10T03:45:27", "url": "https://files.pythonhosted.org/packages/db/93/dec7bf64e86dfce4f290648e1761e98f84e47fb60902ca82066d8cfa5df9/facenet_pytorch-0.2.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "74be158b76947316ff7759ca11e4a7f3", "sha256": "57106171d9c10e1fc41f733888e0c95952e6debd5da5161039a9683db24b10d3" }, "downloads": -1, "filename": "facenet-pytorch-0.2.2.tar.gz", "has_sig": false, "md5_digest": "74be158b76947316ff7759ca11e4a7f3", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1878302, "upload_time": "2019-09-10T03:45:30", "url": "https://files.pythonhosted.org/packages/ee/1a/5407a023e551d6c5cf2acd193b2d3d435d3cf01532a2d0bcd9c13be6a4db/facenet-pytorch-0.2.2.tar.gz" } ], "0.2.3": [ { "comment_text": "", "digests": { "md5": "8ae4197900c9c04c9ae41f43a3568b4c", "sha256": "431dbf090f74512a0acece78fa2b6418fc4266a9684c4048e19668e35f62d9a8" }, "downloads": -1, "filename": "facenet_pytorch-0.2.3-py3-none-any.whl", "has_sig": false, "md5_digest": "8ae4197900c9c04c9ae41f43a3568b4c", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 1877845, "upload_time": "2019-09-11T13:56:52", "url": "https://files.pythonhosted.org/packages/a5/9f/c4e9588517835bfd11d6d1e1752b200f0b3e544513154f8e0a4566a8f77c/facenet_pytorch-0.2.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "54388a526c32523eed08bba60f6f7fdb", "sha256": "21bee4b94d47a1193f13fc18f4670857ef14183e1633438ba861901fb4f14088" }, "downloads": -1, "filename": "facenet-pytorch-0.2.3.tar.gz", "has_sig": false, "md5_digest": "54388a526c32523eed08bba60f6f7fdb", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1878301, "upload_time": "2019-09-11T13:56:56", "url": "https://files.pythonhosted.org/packages/fb/04/c40e8ba0962b5ecad949b5c4f3f77f552f856ebc0a084637303f3ada6000/facenet-pytorch-0.2.3.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "679ba2f68baffd459eafcd8191c2d4be", "sha256": "2dd98756de832638cc00335cba6d54b04a84051a725fbed5b5fd0ded01a302c8" }, "downloads": -1, "filename": "facenet_pytorch-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "679ba2f68baffd459eafcd8191c2d4be", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 1877281, "upload_time": "2019-09-19T04:25:58", "url": "https://files.pythonhosted.org/packages/7d/06/5bb901c04b5a37855f5fb3ac21b0ef43fa87e01b1de3b78e649659b41601/facenet_pytorch-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "9870010cdaf57e8a1f96da2d147ad155", "sha256": "a8a4d7ebc24cff5edf0433e1811046a692053aef1cefd5d48d0958d74ff7b809" }, "downloads": -1, "filename": "facenet-pytorch-0.3.0.tar.gz", "has_sig": false, "md5_digest": "9870010cdaf57e8a1f96da2d147ad155", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1878110, "upload_time": "2019-09-19T04:26:03", "url": "https://files.pythonhosted.org/packages/93/da/636c36e237906278f5162db32b18ca8ecfba1ddc73e4c259c848fde37e76/facenet-pytorch-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "7383b00b94c0839f554391d612559141", "sha256": "ff3c494846e1fac33100805af8027acd6c76dae7aeda91288b0d65c82d22a6f8" }, "downloads": -1, "filename": "facenet_pytorch-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "7383b00b94c0839f554391d612559141", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 1877335, "upload_time": "2019-09-19T16:49:44", "url": "https://files.pythonhosted.org/packages/54/35/ce25a293790804bea0c75074b43280e35b1a3841c7e5b3c23d1a745f5bb2/facenet_pytorch-0.3.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "23dcac1d49d3c005aab36b3e196d0adc", "sha256": "5f2bff7fa5cddde3d00c96f64343c5541ff227d33e076e0ce6cd0f89565d44ec" }, "downloads": -1, "filename": "facenet-pytorch-0.3.1.tar.gz", "has_sig": false, "md5_digest": "23dcac1d49d3c005aab36b3e196d0adc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1878166, "upload_time": "2019-09-19T16:49:47", "url": "https://files.pythonhosted.org/packages/b7/6b/498bf71424ac38d84230e0a056ff8037aab3b60c7616ca406fc833c00684/facenet-pytorch-0.3.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "7383b00b94c0839f554391d612559141", "sha256": "ff3c494846e1fac33100805af8027acd6c76dae7aeda91288b0d65c82d22a6f8" }, "downloads": -1, "filename": "facenet_pytorch-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "7383b00b94c0839f554391d612559141", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 1877335, "upload_time": "2019-09-19T16:49:44", "url": "https://files.pythonhosted.org/packages/54/35/ce25a293790804bea0c75074b43280e35b1a3841c7e5b3c23d1a745f5bb2/facenet_pytorch-0.3.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "23dcac1d49d3c005aab36b3e196d0adc", "sha256": "5f2bff7fa5cddde3d00c96f64343c5541ff227d33e076e0ce6cd0f89565d44ec" }, "downloads": -1, "filename": "facenet-pytorch-0.3.1.tar.gz", "has_sig": false, "md5_digest": "23dcac1d49d3c005aab36b3e196d0adc", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 1878166, "upload_time": "2019-09-19T16:49:47", "url": "https://files.pythonhosted.org/packages/b7/6b/498bf71424ac38d84230e0a056ff8037aab3b60c7616ca406fc833c00684/facenet-pytorch-0.3.1.tar.gz" } ] }