{"id":19295337,"url":"https://github.com/vict0rsch/pytorch-fid-wrapper","last_synced_at":"2025-04-22T08:30:43.754Z","repository":{"id":57457924,"uuid":"308954703","full_name":"vict0rsch/pytorch-fid-wrapper","owner":"vict0rsch","description":"A simple wrapper around @mseitzer's great pytorch-fid work to compute Fréchet Inception Distance in-memory from batches of images, using PyTorch","archived":false,"fork":false,"pushed_at":"2020-11-08T17:08:28.000Z","size":32,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T21:07:14.845Z","etag":null,"topics":["fid","generative-adversarial-network","python","pytorch"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vict0rsch.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-10-31T19:12:11.000Z","updated_at":"2024-08-06T19:06:30.000Z","dependencies_parsed_at":"2022-09-06T14:41:17.221Z","dependency_job_id":null,"html_url":"https://github.com/vict0rsch/pytorch-fid-wrapper","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/vict0rsch%2Fpytorch-fid-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vict0rsch%2Fpytorch-fid-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vict0rsch%2Fpytorch-fid-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vict0rsch%2Fpytorch-fid-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vict0rsch","download_url":"https://codeload.github.com/vict0rsch/pytorch-fid-wrapper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250206001,"owners_count":21392164,"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":["fid","generative-adversarial-network","python","pytorch"],"created_at":"2024-11-09T22:42:09.953Z","updated_at":"2025-04-22T08:30:43.510Z","avatar_url":"https://github.com/vict0rsch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pytorch-fid-wrapper\nA simple wrapper around [@mseitzer](https://github.com/mseitzer)'s great [**pytorch-fid**](https://github.com/mseitzer/pytorch-fid) work.\n\nThe goal is to compute the Fréchet Inception Distance between two sets of images *in-memory* using PyTorch.\n\n## Installation\n\n[![PyPI](https://img.shields.io/pypi/v/pytorch-fid-wrapper.svg)](https://pypi.org/project/pytorch-fid/)\n\n```\npip install pytorch-fid-wrapper\n```\n\nRequires (and will install) (as `pytorch-fid`):\n  * Python \u003e= 3.5\n  * Pillow\n  * Numpy\n  * Scipy\n  * Torch\n  * Torchvision\n\n## Usage\n\n```python\nimport  pytorch_fid_wrapper as pfw\n\n# ---------------------------\n# -----  Initial Setup  -----\n# ---------------------------\n\n# Optional: set pfw's configuration with your parameters once and for all\npfw.set_config(batch_size=BATCH_SIZE, dims=DIMS, device=DEVICE)\n\n# Optional: compute real_m and real_s only once, they will not change during training\nreal_m, real_s = pfw.get_stats(real_images)\n\n...\n\n# -------------------------------------\n# -----  Computing the FID Score  -----\n# -------------------------------------\n\nval_fid = pfw.fid(fake_images, real_m=real_m, real_s=real_s) # (1)\n\n# OR\n\nval_fid = pfw.fid(fake_images, real_images=new_real_images) # (2)\n```\n\nAll `_images` variables in the example above are `torch.Tensor` instances with shape `N x C x H x W`. They will be sent to the appropriate device depending on what you ask for (see [Config](#config)).\n\nTo compute the FID score between your fake images and some real dataset, you can **either** re-use pre-computed stats `real_m`, `real_s` at each validation stage `(1)`, **or** provide another dataset for which the stats will be computed (in addition to your fake images' which are computed in both scenarios) `(2)`. Score is computed in `pfw.fid_score.calculate_frechet_distance(...)`, following [`pytorch-fid`](https://github.com/mseitzer/pytorch-fid)'s implementation.\n\nPlease refer to [**pytorch-fid**](https://github.com/mseitzer/pytorch-fid) for any documentation on the InceptionV3 implementation or FID calculations.\n\n## Config\n\n`pfw.get_stats(...)` and `pfw.fid(...)` need to know what block of the InceptionV3 model to use (`dims`), on what device to compute inference (`device`) and with what batch size (`batch_size`).\n\nDefault values are in `pfw.params`: `batch_size = 50`, `dims = 2048` and `device = \"cpu\"`. If you want to override those, you have two options:\n\n1/ override any of these parameters in the function calls. For instance:\n  ```python\n  pfw.fid(fake_images, new_real_data, device=\"cuda:0\")\n  ```\n2/ override the params globally with `pfw.set_config` and set them for all future calls without passing parameters again. For instance:\n  ```python\n  pfw.set_config(batch_size=100, dims=768, device=\"cuda:0\")\n  ...\n  pfw.fid(fake_images, new_real_data)\n  ```\n\n## Recognition\n\nRemember to cite their work if using [`pytorch-fid-wrapper`](https://github.com/vict0rsch/pytorch-fid-wrapper) or [`pytorch-fid`](https://github.com/mseitzer/pytorch-fid):\n\n```\n@misc{Seitzer2020FID,\n  author={Maximilian Seitzer},\n  title={{pytorch-fid: FID Score for PyTorch}},\n  month={August},\n  year={2020},\n  note={Version 0.1.1},\n  howpublished={\\url{https://github.com/mseitzer/pytorch-fid}},\n}\n```\n\n## License\n\nThis implementation is licensed under the Apache License 2.0.\n\nFID was introduced by Martin Heusel, Hubert Ramsauer, Thomas Unterthiner, Bernhard Nessler and Sepp Hochreiter in \"GANs Trained by a Two Time-Scale Update Rule Converge to a Local Nash Equilibrium\", see [https://arxiv.org/abs/1706.08500](https://arxiv.org/abs/1706.08500)\n\nThe original implementation is by the Institute of Bioinformatics, JKU Linz, licensed under the Apache License 2.0.\nSee [https://github.com/bioinf-jku/TTUR](https://github.com/bioinf-jku/TTUR).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvict0rsch%2Fpytorch-fid-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvict0rsch%2Fpytorch-fid-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvict0rsch%2Fpytorch-fid-wrapper/lists"}