{"id":20391825,"url":"https://github.com/zpdesu/ii2s","last_synced_at":"2026-03-16T20:33:30.348Z","repository":{"id":57728452,"uuid":"382127342","full_name":"ZPdesu/II2S","owner":"ZPdesu","description":"Improved StyleGAN Embedding: Where are the Good Latents?","archived":false,"fork":false,"pushed_at":"2022-04-02T01:02:54.000Z","size":114206,"stargazers_count":117,"open_issues_count":2,"forks_count":10,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-03-26T06:23:52.394Z","etag":null,"topics":["deeo-learning","gan","generative-model","image-embedding"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ZPdesu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-07-01T18:48:40.000Z","updated_at":"2025-01-09T23:46:46.000Z","dependencies_parsed_at":"2022-09-10T21:04:07.283Z","dependency_job_id":null,"html_url":"https://github.com/ZPdesu/II2S","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/ZPdesu%2FII2S","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZPdesu%2FII2S/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZPdesu%2FII2S/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ZPdesu%2FII2S/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ZPdesu","download_url":"https://codeload.github.com/ZPdesu/II2S/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248563472,"owners_count":21125286,"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":["deeo-learning","gan","generative-model","image-embedding"],"created_at":"2024-11-15T03:37:00.754Z","updated_at":"2026-03-16T20:33:30.283Z","avatar_url":"https://github.com/ZPdesu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Improved StyleGAN Embedding: Where are the Good Latents?\n\n[Peihao Zhu](https://github.com/ZPdesu),\n[Rameen Abdal](https://github.com/RameenAbdal),\n[Yipeng Qin](https://scholar.google.com/citations?user=ojgWPpgAAAAJ\u0026hl=en),\n[John Femiani](https://scholar.google.com/citations?user=rS1xJIIAAAAJ\u0026hl=en),\n[Peter Wonka](http://peterwonka.net/)\u003cbr/\u003e\n\n\n[arXiv](https://arxiv.org/abs/2012.09036) | [BibTeX](#bibtex) | [Video](https://youtu.be/6grbAFtKvBU)\n\n\n\u003e **Abstract** StyleGAN is able to produce photorealistic images that are almost indistinguishable from real photos. The reverse problem of finding an embedding for a given image poses a challenge. Embeddings that reconstruct an image well are not always robust to editing operations. In this paper, we address the problem of finding an embedding that both reconstructs images and also supports image editing tasks. First, we introduce a new normalized space to analyze the diversity and the quality of the reconstructed latent codes. This space can help answer the question of where good latent codes are located in latent space. Second, we propose an improved embedding algorithm using a novel regularization method based on our analysis. Finally, we analyze the quality of different embedding algorithms. We compare our results with the current state-of-the-art methods and achieve a better trade-off between reconstruction quality and editing quality.\n\n\n\u003cp align=\"center\"\u003e\n\u003cimg src=\"docs/MainFigure.png\" width=\"800px\"/\u003e\n\u003c/p\u003e\n\n## Description\nOfficial Implementation of \"\u003ca href=\"https://arxiv.org/abs/2012.09036\"\u003eImproved StyleGAN Embedding: Where are the Good Latents?\u003c/a\u003e\".\n\n\n## Getting Started\n\n### Prerequisites\n- Linux or macOS\n- NVIDIA GPU + CUDA CuDNN\n- Python 3\n\n### Installation\n- Clone the repository:\n``` \ngit clone https://github.com/ZPdesu/II2S.git\ncd II2S\n```\n- Dependencies:\nWe recommend running this repository using [Anaconda](https://docs.anaconda.com/anaconda/install/). \nAll dependencies for defining the environment are provided in `environment/environment.yml`.\n\n### Pretrained Models\n\nIf the automatic download doesn't work, please download the pre-trained models from the following links.\n\n| Path | Description\n| :--- | :----------\n|[FFHQ StyleGAN](https://drive.google.com/uc?id=1AT6bNR2ppK8f2ETL_evT27f3R_oyWNHS) | StyleGAN model pretrained on [FFHQ](https://github.com/NVlabs/ffhq-dataset) with 1024x1024 output resolution.\n|[Metfaces StyleGAN](https://drive.google.com/uc?id=16wM2PwVWzaMsRgPExvRGsq6BWw_muKbf) | StyleGAN model pretrained on [Metfaces](https://github.com/NVlabs/metfaces-dataset) with 1024x1024 output resolution.\n|[AFHQ-Dog StyleGAN](https://drive.google.com/uc?id=16v6jPtKVlvq8rg2Sdi3-R9qZEVDgvvEA) | StyleGAN model pretrained on [AFHQ-Dog](https://github.com/clovaai/stargan-v2) with 512x512 output resolution.\n|[AFHQ-Cat StyleGAN](https://drive.google.com/uc?id=1HXLER5R3EMI8DSYDBZafoqpX4EtyOf2R) | StyleGAN model pretrained on [AFHQ-Cat](https://github.com/clovaai/stargan-v2) with 512x512 output resolution.\n|[AFHQ-Wild StyleGAN](https://drive.google.com/uc?id=14OnzO4QWaAytKXVqcfWo_o2MzoR4ygnr)) | StyleGAN model pretrained on [AFHQ-Wild](https://github.com/clovaai/stargan-v2) with 512x512 output resolution.\n|[Face Landmark Model](https://drive.google.com/uc?id=17kwWXLN9fA6acrBWqfuQCBdcc1ULmBc9) | Face landmark model used in [dlib](http://dlib.net/face_landmark_detection.py.html).\n\nBy default, we assume that all models are downloaded and saved to the directory `pretrained_models`.\n\n\n## Embedding\nTo embed images, make sure the hyper-parameters are configured in `options/face_embed_options.py`.\nThen run the code\n```\npython main.py --input_dir XXX --output_dir XXX\n```\n\n### Different input formats\nPlease perform the following adjustments in `main.py` to expand the input types.\n\n1. Input folder\n```\nii2s.invert_images(image_path=args.input_dir, output_dir=args.output_dir)\n```\n2. Image path\n```\nii2s.invert_images(image_path='input/28.jpg', output_dir=args.output_dir)\n```\n3. Image path list\n```\nii2s.invert_images(image_path=['input/28.jpg', 'input/90.jpg'], output_dir=args.output_dir)\n```\n\n### Save output and return latents\nTo save output and return latent codes, users can make the follwoing adjustments in `main.py`.\n```\nfinal_latents = ii2s.invert_images(image_path=args.input_dir, output_dir=args.output_dir, return_latents=True, save_output=True)\n```\n\n### Align input images\nBy default, the input should be aligned images with 1024x1024 resolution. Users can run `align_face.py` to align unprocessed images and save them in another folder, then make the following modifications in `main.py`.\n\n```\nfinal_latents = ii2s.invert_images(image_path=args.input_dir, output_dir=args.output_dir, return_latents=True, save_output=True, align_input=False)\n```\n\nWe also allow the alignment step during the embedding process.\n\n```\nfinal_latents = ii2s.invert_images(image_path=args.input_dir, output_dir=args.output_dir, return_latents=True, save_output=True, align_input=True)\n```\n\n## BibTeX\n\n```\n@misc{zhu2020improved,\n    title={Improved StyleGAN Embedding: Where are the Good Latents?},\n    author={Peihao Zhu and Rameen Abdal and Yipeng Qin and John Femiani and Peter Wonka},\n    year={2020},\n    eprint={2012.09036},\n    archivePrefix={arXiv},\n    primaryClass={cs.CV}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzpdesu%2Fii2s","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzpdesu%2Fii2s","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzpdesu%2Fii2s/lists"}