{"id":15028296,"url":"https://github.com/tamarott/singan","last_synced_at":"2025-04-13T04:59:15.271Z","repository":{"id":37773941,"uuid":"202940640","full_name":"tamarott/SinGAN","owner":"tamarott","description":"Official pytorch implementation of the paper: \"SinGAN: Learning a Generative Model from a Single Natural Image\"","archived":false,"fork":false,"pushed_at":"2023-05-26T07:19:48.000Z","size":97168,"stargazers_count":3331,"open_issues_count":107,"forks_count":612,"subscribers_count":63,"default_branch":"master","last_synced_at":"2025-04-13T04:59:03.221Z","etag":null,"topics":["animation","arbitrery-sizes","gan","harmonization","image-edit","official","singan","single-image","single-image-animation","single-image-generation","single-image-super-resolution","super-resolution"],"latest_commit_sha":null,"homepage":"https://tamarott.github.io/SinGAN.htm","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tamarott.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2019-08-17T23:37:07.000Z","updated_at":"2025-04-11T15:26:34.000Z","dependencies_parsed_at":"2022-07-10T02:46:14.861Z","dependency_job_id":"9651378b-2353-4a0f-bd6b-7576e98070b3","html_url":"https://github.com/tamarott/SinGAN","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/tamarott%2FSinGAN","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamarott%2FSinGAN/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamarott%2FSinGAN/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tamarott%2FSinGAN/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tamarott","download_url":"https://codeload.github.com/tamarott/SinGAN/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248665758,"owners_count":21142123,"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":["animation","arbitrery-sizes","gan","harmonization","image-edit","official","singan","single-image","single-image-animation","single-image-generation","single-image-super-resolution","super-resolution"],"created_at":"2024-09-24T20:07:58.917Z","updated_at":"2025-04-13T04:59:15.248Z","avatar_url":"https://github.com/tamarott.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SinGAN\n\n[Project](https://tamarott.github.io/SinGAN.htm) | [Arxiv](https://arxiv.org/pdf/1905.01164.pdf) | [CVF](http://openaccess.thecvf.com/content_ICCV_2019/papers/Shaham_SinGAN_Learning_a_Generative_Model_From_a_Single_Natural_Image_ICCV_2019_paper.pdf) | [Supplementary materials](https://openaccess.thecvf.com/content_ICCV_2019/supplemental/Shaham_SinGAN_Learning_a_ICCV_2019_supplemental.pdf) | [Talk (ICCV`19)](https://youtu.be/mdAcPe74tZI?t=3191) \n### Official pytorch implementation of the paper: \"SinGAN: Learning a Generative Model from a Single Natural Image\"\n#### ICCV 2019 Best paper award (Marr prize)\n\n\n## Random samples from a *single* image\nWith SinGAN, you can train a generative model from a single natural image, and then generate random samples from the given image, for example:\n\n![](imgs/teaser.PNG)\n\n\n## SinGAN's applications\nSinGAN can be also used for a line of image manipulation tasks, for example:\n ![](imgs/manipulation.PNG)\nThis is done by injecting an image to the already trained model. See section 4 in our [paper](https://arxiv.org/pdf/1905.01164.pdf) for more details.\n\n\n### Citation\nIf you use this code for your research, please cite our paper:\n\n```\n@inproceedings{rottshaham2019singan,\n  title={SinGAN: Learning a Generative Model from a Single Natural Image},\n  author={Rott Shaham, Tamar and Dekel, Tali and Michaeli, Tomer},\n  booktitle={Computer Vision (ICCV), IEEE International Conference on},\n  year={2019}\n}\n```\n\n## Code\n\n### Install dependencies\n\n```\npython -m pip install -r requirements.txt\n```\n\nThis code was tested with python 3.6, torch 1.4\n\nPlease note: the code currently only supports torch 1.4 or earlier because of the optimization scheme.\n\nFor later torch versions, you may try this repository: https://github.com/kligvasser/SinGAN (results won't necessarily be identical to the official implementation).\n\n\n###  Train\nTo train SinGAN model on your own image, put the desired training image under Input/Images, and run\n\n```\npython main_train.py --input_name \u003cinput_file_name\u003e\n```\n\nThis will also use the resulting trained model to generate random samples starting from the coarsest scale (n=0).\n\nTo run this code on a cpu machine, specify `--not_cuda` when calling `main_train.py`\n\n###  Random samples\nTo generate random samples from any starting generation scale, please first train SinGAN model on the desired image (as described above), then run \n\n```\npython random_samples.py --input_name \u003ctraining_image_file_name\u003e --mode random_samples --gen_start_scale \u003cgeneration start scale number\u003e\n```\n\npay attention: for using the full model, specify the generation start scale to be 0, to start the generation from the second scale, specify it to be 1, and so on. \n\n###  Random samples of arbitrary sizes\nTo generate random samples of arbitrary sizes, please first train SinGAN model on the desired image (as described above), then run \n\n```\npython random_samples.py --input_name \u003ctraining_image_file_name\u003e --mode random_samples_arbitrary_sizes --scale_h \u003chorizontal scaling factor\u003e --scale_v \u003cvertical scaling factor\u003e\n```\n\n###  Animation from a single image\n\nTo generate short animation from a single image, run\n\n```\npython animation.py --input_name \u003cinput_file_name\u003e \n```\n\nThis will automatically start a new training phase with noise padding mode.\n\n###  Harmonization\n\nTo harmonize a pasted object into an image (See example in Fig. 13 in [our paper](https://arxiv.org/pdf/1905.01164.pdf)), please first train SinGAN model on the desired background image (as described above), then save the naively pasted reference image and it's binary mask under \"Input/Harmonization\" (see saved images for an example). Run the command\n\n```\npython harmonization.py --input_name \u003ctraining_image_file_name\u003e --ref_name \u003cnaively_pasted_reference_image_file_name\u003e --harmonization_start_scale \u003cscale to inject\u003e\n\n```\n\nPlease note that different injection scale will produce different harmonization effects. The coarsest injection scale equals 1. \n\n###  Editing\n\nTo edit an image, (See example in Fig. 12 in [our paper](https://arxiv.org/pdf/1905.01164.pdf)), please first train SinGAN model on the desired non-edited image (as described above), then save the naive edit as a reference image under \"Input/Editing\" with a corresponding binary map (see saved images for an example). Run the command\n\n```\npython editing.py --input_name \u003ctraining_image_file_name\u003e --ref_name \u003cedited_image_file_name\u003e --editing_start_scale \u003cscale to inject\u003e\n\n```\nboth the masked and unmasked output will be saved.\nHere as well, different injection scale will produce different editing effects. The coarsest injection scale equals 1. \n\n###  Paint to Image\n\nTo transfer a paint into a realistic image (See example in Fig. 11 in [our paper](https://arxiv.org/pdf/1905.01164.pdf)), please first train SinGAN model on the desired image (as described above), then save your paint under \"Input/Paint\", and run the command\n\n```\npython paint2image.py --input_name \u003ctraining_image_file_name\u003e --ref_name \u003cpaint_image_file_name\u003e --paint_start_scale \u003cscale to inject\u003e\n\n```\nHere as well, different injection scale will produce different editing effects. The coarsest injection scale equals 1. \n\nAdvanced option: Specify quantization_flag to be True, to re-train *only* the injection level of the model, to get a on a color-quantized version of upsampled generated images from the previous scale. For some images, this might lead to more realistic results.\n\n### Super Resolution\nTo super resolve an image, please run:\n```\npython SR.py --input_name \u003cLR_image_file_name\u003e\n```\nThis will automatically train a SinGAN model correspond to 4x upsampling factor (if not exist already).\nFor different SR factors, please specify it using the parameter `--sr_factor` when calling the function.\nSinGAN's results on the BSD100 dataset can be download from the 'Downloads' folder.\n\n## Additional Data and Functions\n\n### Single Image Fréchet Inception Distance (SIFID score)\nTo calculate the SIFID between real images and their corresponding fake samples, please run:\n```\npython SIFID/sifid_score.py --path2real \u003creal images path\u003e --path2fake \u003cfake images path\u003e \n```  \nMake sure that each of the fake images file name is identical to its corresponding real image file name. Images should be saved in `.jpg` format.\n\n### Super Resolution Results\nSinGAN's SR results on the BSD100 dataset can be download from the 'Downloads' folder.\n\n### User Study\nThe data used for the user study can be found in the Downloads folder. \n\nreal folder: 50 real images, randomly picked from the [places database](http://places.csail.mit.edu/)\n\nfake_high_variance folder: random samples starting from n=N for each of the real images \n\nfake_mid_variance folder: random samples starting from n=N-1 for each of the real images \n\nFor additional details please see section 3.1 in our [paper](https://arxiv.org/pdf/1905.01164.pdf)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamarott%2Fsingan","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftamarott%2Fsingan","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftamarott%2Fsingan/lists"}