# Identity Similarity
This repository can helps researchers that want to use face recognition in their researches. You can easly implement powerfull face recognition in your project. I motivated for this repository from
[LPIPS](https://github.com/richzhang/PerceptualSimilarity). The models are borrowed from [Insigtface](https://github.com/deepinsight/insightface/tree/master/recognition/arcface_torch).
**Warning :** Please, be careful when chosing your criterion. Lower is more similar in MSE while higher is more similar in CosineSimilarity.
<img src="docs/similarity_distance_figure.png" >
## Usage
### 1. Training with preprocessed dataset.
In this case, we assume that you have aligned images using a keypoint template and you want to calculate identity similarity between two aligned images or a image and a saved identity vector.
```python
import torch
import numpy as np
from idsim import IdentitySimilarity
idsim = IdentitySimilarity()
template = np.array([[35.066223, 34.23266],
[84.1586, 33.96113],
[59.768444, 62.152763],
[39.60066, 90.89288],
[80.255, 90.66802]], dtype=np.float32)
idsim.set_ref_point(template)
# dummy variables
v1 = torch.rand(1, 512)
im1 = torch.rand(5, 3, 128, 128)
# useful functions
sim_v2v = idsim.forward_v2v(v1, v1)
sim_im2im = idsim.forward_img2img(im1, im1)
sim_v2im = idsim.forward_v2img(v1, im1)
print("\nsim_v2v :", sim_v2v, "\nsim_im2im :", sim_im2im, "\nsim_v2im :", sim_v2im)
```
### 2. Face recognition
In this case, Idsim can caculate identity similarity of your images.
```python
import cv2
from idsim import IdentitySimilarity
idsim = IdentitySimilarity(criterion="Cosine")
img1 = cv2.imread("a.jpg")
img2 = cv2.imread("b.jpg")
v1 = idsim.extract_identity(img1)
v2 = idsim.extract_identity(img2)
sim = idsim.forward_v2v(v1,v2)
print("Similarity :", sim)
```
**Note:** You can check the [proving_differentiability.ipynb](proving_differentiability.ipynb) for an example training.
## Todo
- [] Release pypi package
## Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.
1. Fork the Project
1. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
1. Run `make style && make quality` in the root repo directory, to ensure code quality.
1. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
1. Push to the Branch (`git push origin feature/AmazingFeature`)
1. Open a Pull Request
Raw data
{
"_id": null,
"home_page": "https://github.com/m-pektas/IdentitySimilarity",
"name": "idsim",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "",
"author": "Muhammed Pektas",
"author_email": "mhmdpkts@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4b/42/6c15ea8d4f5a2295821c245cac5f3af7e347dae97ab24f548f0ebe29ce41/idsim-0.0.1.tar.gz",
"platform": null,
"description": "# Identity Similarity\n\nThis repository can helps researchers that want to use face recognition in their researches. You can easly implement powerfull face recognition in your project. I motivated for this repository from \n[LPIPS](https://github.com/richzhang/PerceptualSimilarity). The models are borrowed from [Insigtface](https://github.com/deepinsight/insightface/tree/master/recognition/arcface_torch).\n\n**Warning :** Please, be careful when chosing your criterion. Lower is more similar in MSE while higher is more similar in CosineSimilarity.\n\n\n<img src=\"docs/similarity_distance_figure.png\" >\n\n## Usage\n\n### 1. Training with preprocessed dataset.\n\nIn this case, we assume that you have aligned images using a keypoint template and you want to calculate identity similarity between two aligned images or a image and a saved identity vector.\n```python\n\nimport torch\nimport numpy as np\nfrom idsim import IdentitySimilarity\n\nidsim = IdentitySimilarity()\ntemplate = np.array([[35.066223, 34.23266],\n [84.1586, 33.96113],\n [59.768444, 62.152763],\n [39.60066, 90.89288],\n [80.255, 90.66802]], dtype=np.float32)\nidsim.set_ref_point(template)\n\n# dummy variables\nv1 = torch.rand(1, 512)\nim1 = torch.rand(5, 3, 128, 128)\n\n# useful functions\nsim_v2v = idsim.forward_v2v(v1, v1)\nsim_im2im = idsim.forward_img2img(im1, im1)\nsim_v2im = idsim.forward_v2img(v1, im1)\nprint(\"\\nsim_v2v :\", sim_v2v, \"\\nsim_im2im :\", sim_im2im, \"\\nsim_v2im :\", sim_v2im)\n```\n\n\n### 2. Face recognition \n\nIn this case, Idsim can caculate identity similarity of your images.\n\n```python\nimport cv2\nfrom idsim import IdentitySimilarity\n\nidsim = IdentitySimilarity(criterion=\"Cosine\")\nimg1 = cv2.imread(\"a.jpg\")\nimg2 = cv2.imread(\"b.jpg\")\nv1 = idsim.extract_identity(img1) \nv2 = idsim.extract_identity(img2)\nsim = idsim.forward_v2v(v1,v2)\nprint(\"Similarity :\", sim)\n```\n\n**Note:** You can check the [proving_differentiability.ipynb](proving_differentiability.ipynb) for an example training.\n\n## Todo\n\n- [] Release pypi package\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are **greatly appreciated**.\n\n1. Fork the Project\n1. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)\n1. Run `make style && make quality` in the root repo directory, to ensure code quality.\n1. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)\n1. Push to the Branch (`git push origin feature/AmazingFeature`)\n1. Open a Pull Request\n",
"bugtrack_url": null,
"license": "",
"summary": "Face Recognition Metric",
"version": "0.0.1",
"project_urls": {
"Homepage": "https://github.com/m-pektas/IdentitySimilarity"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9c01b2232f5ac35d678ab0d24c797d1f46d93fcb3de728af67851c7aa93e0f58",
"md5": "9599119bca02738547ae44fb3a9c56cc",
"sha256": "2d53b2f7907983d4b1633cc23cb2275e6ca283fc7c0b3b6ff6cf83ee25401a04"
},
"downloads": -1,
"filename": "idsim-0.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9599119bca02738547ae44fb3a9c56cc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 16255,
"upload_time": "2024-02-26T21:20:14",
"upload_time_iso_8601": "2024-02-26T21:20:14.155330Z",
"url": "https://files.pythonhosted.org/packages/9c/01/b2232f5ac35d678ab0d24c797d1f46d93fcb3de728af67851c7aa93e0f58/idsim-0.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4b426c15ea8d4f5a2295821c245cac5f3af7e347dae97ab24f548f0ebe29ce41",
"md5": "472476b6c2026b05bb73bd5198892612",
"sha256": "da932ef0b698ebfb0048c944d2a6f3e910476c35d8798337cc3a69c389bd44a3"
},
"downloads": -1,
"filename": "idsim-0.0.1.tar.gz",
"has_sig": false,
"md5_digest": "472476b6c2026b05bb73bd5198892612",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 13552,
"upload_time": "2024-02-26T21:20:18",
"upload_time_iso_8601": "2024-02-26T21:20:18.429697Z",
"url": "https://files.pythonhosted.org/packages/4b/42/6c15ea8d4f5a2295821c245cac5f3af7e347dae97ab24f548f0ebe29ce41/idsim-0.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-26 21:20:18",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "m-pektas",
"github_project": "IdentitySimilarity",
"github_not_found": true,
"lcname": "idsim"
}