{"id":13477078,"url":"https://github.com/andreas128/SRFlow","last_synced_at":"2025-03-27T04:32:22.132Z","repository":{"id":37219158,"uuid":"274157925","full_name":"andreas128/SRFlow","owner":"andreas128","description":"Official SRFlow training code: Super-Resolution using Normalizing Flow in PyTorch","archived":false,"fork":false,"pushed_at":"2022-12-08T11:44:49.000Z","size":877,"stargazers_count":827,"open_issues_count":40,"forks_count":112,"subscribers_count":70,"default_branch":"master","last_synced_at":"2024-08-24T14:36:30.226Z","etag":null,"topics":["image-manipulation","normalizing-flow","paper","super-resolution"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/andreas128.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-06-22T14:21:00.000Z","updated_at":"2024-07-29T10:09:56.000Z","dependencies_parsed_at":"2023-01-25T05:31:02.374Z","dependency_job_id":null,"html_url":"https://github.com/andreas128/SRFlow","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/andreas128%2FSRFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreas128%2FSRFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreas128%2FSRFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/andreas128%2FSRFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/andreas128","download_url":"https://codeload.github.com/andreas128/SRFlow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222194704,"owners_count":16946980,"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":["image-manipulation","normalizing-flow","paper","super-resolution"],"created_at":"2024-07-31T16:01:37.980Z","updated_at":"2025-03-27T04:32:22.126Z","avatar_url":"https://github.com/andreas128.png","language":"Jupyter Notebook","funding_links":[],"categories":["Jupyter Notebook"],"sub_categories":[],"readme":"# SRFlow\n#### Official SRFlow training code: Super-Resolution using Normalizing Flow in PyTorch \u003cbr\u003e\u003cbr\u003e\n#### [[Paper] ECCV 2020 Spotlight](https://bit.ly/2DkwQcg)\n\n\u003cbr\u003e\n\n**News:** Unified Image Super-Resolution and Rescaling [[code](https://bit.ly/2VOKHBb)]\n\u003cbr\u003e\n\u003cbr\u003e\n\n[![SRFlow](https://user-images.githubusercontent.com/11280511/98149322-7ed5c580-1ecd-11eb-8279-f02de9f0df12.gif)](https://bit.ly/3jWFRcr)\n\u003cbr\u003e\n\u003cbr\u003e\n\u003cbr\u003e\n\n# Setup: Data, Environment, PyTorch Demo\n\n\u003cbr\u003e\n\n```bash\ngit clone https://github.com/andreas128/SRFlow.git \u0026\u0026 cd SRFlow \u0026\u0026 ./setup.sh\n```\n\n\u003cbr\u003e\n\nThis oneliner will:\n- Clone SRFlow\n- Setup a python3 virtual env\n- Install the packages from `requirements.txt`\n- Download the pretrained models\n- Download the DIV2K validation data\n- Run the Demo Jupyter Notebook\n\nIf you want to install it manually, read the `setup.sh` file. (Links to data/models, pip packages)\n\n\u003cbr\u003e\n\u003cbr\u003e\n\n# Demo: Try Normalizing Flow in PyTorch\n\n```bash\n./run_jupyter.sh\n```\n\nThis notebook lets you:\n- Load the pretrained models.\n- Super-resolve images.\n- Measure PSNR/SSIM/LPIPS.\n- Infer the Normalizing Flow latent space.\n\n\u003cbr\u003e\u003cbr\u003e\n\n# Testing: Apply the included pretrained models\n\n```bash\nsource myenv/bin/activate                      # Use the env you created using setup.sh\ncd code\nCUDA_VISIBLE_DEVICES=-1 python test.py ./confs/SRFlow_DF2K_4X.yml      # Diverse Images 4X (Dataset Included)\nCUDA_VISIBLE_DEVICES=-1 python test.py ./confs/SRFlow_DF2K_8X.yml      # Diverse Images 8X (Dataset Included)\nCUDA_VISIBLE_DEVICES=-1 python test.py ./confs/SRFlow_CelebA_8X.yml    # Faces 8X\n```\nFor testing, we apply SRFlow to the full images on CPU.\n\n\u003cbr\u003e\u003cbr\u003e\n\n# Training: Reproduce or train on your Data\n\nThe following commands train the Super-Resolution network using Normalizing Flow in PyTorch:\n\n```bash\nsource myenv/bin/activate                      # Use the env you created using setup.sh\ncd code\npython train.py -opt ./confs/SRFlow_DF2K_4X.yml      # Diverse Images 4X (Dataset Included)\npython train.py -opt ./confs/SRFlow_DF2K_8X.yml      # Diverse Images 8X (Dataset Included)\npython train.py -opt ./confs/SRFlow_CelebA_8X.yml    # Faces 8X\n```\n\n- To reduce the GPU memory, reduce the batch size in the yml file.\n- CelebA does not allow us to host the dataset. A script will follow.\n\n### How to prepare CelebA?\n\n**1. Get HD-CelebA-Cropper**\n\n```git clone https://github.com/LynnHo/HD-CelebA-Cropper```\n\n**2. Download the dataset**\n\n`img_celeba.7z` and `annotations.zip` as desribed in the [Readme](https://github.com/LynnHo/HD-CelebA-Cropper).\n\n**3. Run the crop align**\n\n```python3 align.py --img_dir ./data/data --crop_size_h 640 --crop_size_w 640 --order 3 --face_factor 0.6 --n_worker 8```\n\n**4. Downsample for GT**\n\n Use the [matlablike kernel](https://github.com/fatheral/matlab_imresize) to downscale to 160x160 for the GT images.\n\n**5. Downsample for LR**\n\nDownscale the GT using the Matlab kernel to the LR size (40x40 or 20x20)\n\n**6. Train/Validation**\n\nFor training and validation, we use the corresponding sets defined by CelebA (Train: 000001-162770, Validation: 162771-182637)\n\n**7. Pack to pickle for training**\n\n`cd code \u0026\u0026 python prepare_data.py /path/to/img_dir`\n\n\u003cbr\u003e\u003cbr\u003e\n\n# Dataset: How to train on your own data\n\nThe following command creates the pickel files that you can use in the yaml config file:\n\n```bash\ncd code\npython prepare_data.py /path/to/img_dir\n```\n\nThe precomputed DF2K dataset gets downloaded using `setup.sh`. You can reproduce it or prepare your own dataset.\n\n\u003cbr\u003e\u003cbr\u003e\n\n# Our paper explains\n\n- **How to train Conditional Normalizing Flow** \u003cbr\u003e\n  We designed an architecture that archives state-of-the-art super-resolution quality.\n- **How to train Normalizing Flow on a single GPU**  \u003cbr\u003e\n  We based our network on GLOW, which uses up to 40 GPUs to train for image generation. SRFlow only needs a single GPU for training conditional image generation.\n- **How to use Normalizing Flow for image manipulation**  \u003cbr\u003e\n  How to exploit the latent space for Normalizing Flow for controlled image manipulations\n- **See many Visual Results**  \u003cbr\u003e\n  Compare GAN vs Normalizing Flow yourself. We've included a lot of visuals results in our [[Paper]](https://bit.ly/2D9cN0L).\n\n\u003cbr\u003e\u003cbr\u003e\n\n# GAN vs Normalizing Flow - Blog\n\n[![](https://user-images.githubusercontent.com/11280511/98148862-56e66200-1ecd-11eb-817e-87e99dcab6ca.gif)](https://bit.ly/2EdJzhy)\n\n- **Sampling:** SRFlow outputs many different images for a single input.\n- **Stable Training:** SRFlow has much fewer hyperparameters than GAN approaches, and we did not encounter training stability issues.\n- **Convergence:** While GANs cannot converge, conditional Normalizing Flows converge monotonic and stable.\n- **Higher Consistency:** When downsampling the super-resolution, one obtains almost the exact input.\n\nGet a quick introduction to Normalizing Flow in our [[Blog]](https://bit.ly/320bAkH).\n\u003cbr\u003e\u003cbr\u003e\u003cbr\u003e\n\n\u003cbr\u003e\u003cbr\u003e\n\n# Wanna help to improve the code?\n\nIf you found a bug or improved the code, please do the following:\n\n- Fork this repo.\n- Push the changes to your repo.\n- Create a pull request.\n\n\u003cbr\u003e\u003cbr\u003e\n\n# Paper\n[[Paper] ECCV 2020 Spotlight](https://bit.ly/2XcmSks)\n\n```bibtex\n@inproceedings{lugmayr2020srflow,\n  title={SRFlow: Learning the Super-Resolution Space with Normalizing Flow},\n  author={Lugmayr, Andreas and Danelljan, Martin and Van Gool, Luc and Timofte, Radu},\n  booktitle={ECCV},\n  year={2020}\n}\n```\n\u003cbr\u003e\u003cbr\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreas128%2FSRFlow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fandreas128%2FSRFlow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fandreas128%2FSRFlow/lists"}