{"id":18613979,"url":"https://github.com/jingyunliang/hcflow","last_synced_at":"2025-08-02T10:34:22.384Z","repository":{"id":38536077,"uuid":"392257931","full_name":"JingyunLiang/HCFlow","owner":"JingyunLiang","description":"Official PyTorch code for Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021) ","archived":false,"fork":false,"pushed_at":"2021-09-29T10:33:05.000Z","size":2346,"stargazers_count":191,"open_issues_count":4,"forks_count":28,"subscribers_count":11,"default_branch":"main","last_synced_at":"2025-04-08T06:42:11.185Z","etag":null,"topics":["face-image-super-resolution","flow","iccv2021","image-rescaling","image-sr","image-super-resolution","normalizing-flow","super-resolution"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2108.05301","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/JingyunLiang.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":"2021-08-03T09:14:11.000Z","updated_at":"2025-03-28T08:15:26.000Z","dependencies_parsed_at":"2022-08-18T19:21:50.280Z","dependency_job_id":null,"html_url":"https://github.com/JingyunLiang/HCFlow","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/JingyunLiang/HCFlow","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JingyunLiang%2FHCFlow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JingyunLiang%2FHCFlow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JingyunLiang%2FHCFlow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JingyunLiang%2FHCFlow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JingyunLiang","download_url":"https://codeload.github.com/JingyunLiang/HCFlow/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JingyunLiang%2FHCFlow/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268371770,"owners_count":24239794,"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","status":"online","status_checked_at":"2025-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["face-image-super-resolution","flow","iccv2021","image-rescaling","image-sr","image-super-resolution","normalizing-flow","super-resolution"],"created_at":"2024-11-07T03:24:34.756Z","updated_at":"2025-08-02T10:34:22.322Z","avatar_url":"https://github.com/JingyunLiang.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021)\n\n\n[![arXiv](https://img.shields.io/badge/arXiv-Paper-\u003cCOLOR\u003e.svg)](https://arxiv.org/abs/2108.05301)\n[![GitHub Stars](https://img.shields.io/github/stars/JingyunLiang/HCFlow?style=social)](https://github.com/JingyunLiang/HCFlow)\n[![download](https://img.shields.io/github/downloads/JingyunLiang/HCFlow/total.svg)](https://github.com/JingyunLiang/HCFlow/releases)\n[ \u003ca href=\"https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"google colab logo\"\u003e\u003c/a\u003e](https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb)\n\u003ca href=\"https://replicate.ai/jingyunliang/hcflow-sr\"\u003e\u003cimg src=\"https://img.shields.io/static/v1?label=Replicate\u0026message=Demo and Docker Image\u0026color=blue\"\u003e\u003c/a\u003e\n\nThis repository is the official PyTorch implementation of Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling\n([arxiv](https://arxiv.org/pdf/2108.05301.pdf), [supp](https://github.com/JingyunLiang/HCFlow/releases)).\n\n\n:rocket:  :rocket:  :rocket: **News**: \n - Sep. 07, 2021: We add an [online Colob demo \u003ca href=\"https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"google colab logo\"\u003e\u003c/a\u003e](https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb) for easy comparison of HCFlow and [SRFlow](https://github.com/andreas128/SRFlow).\n - Sep.06, 2021: See our recent work [SwinIR: Transformer-based image restoration](https://github.com/JingyunLiang/SwinIR) [![arXiv](https://img.shields.io/badge/arXiv-Paper-\u003cCOLOR\u003e.svg)](https://arxiv.org/abs/2108.10257)[![GitHub Stars](https://img.shields.io/github/stars/JingyunLiang/SwinIR?style=social)](https://github.com/JingyunLiang/SwinIR)[![download](https://img.shields.io/github/downloads/JingyunLiang/SwinIR/total.svg)](https://github.com/JingyunLiang/SwinIR/releases)[ \u003ca href=\"https://colab.research.google.com/gist/JingyunLiang/a5e3e54bc9ef8d7bf594f6fee8208533/swinir-demo-on-real-world-image-sr.ipynb\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"google colab logo\"\u003e\u003c/a\u003e](https://colab.research.google.com/gist/JingyunLiang/a5e3e54bc9ef8d7bf594f6fee8208533/swinir-demo-on-real-world-image-sr.ipynb)\n - Aug. 17, 2021: See our recent work for [blind SR: Mutual Affine Network for Spatially Variant Kernel Estimation in Blind Image Super-Resolution (MANet), ICCV2021](https://github.com/JingyunLiang/MANet) [![arXiv](https://img.shields.io/badge/arXiv-Paper-\u003cCOLOR\u003e.svg)](https://arxiv.org/abs/2108.05302)[![GitHub Stars](https://img.shields.io/github/stars/JingyunLiang/MANet?style=social)](https://github.com/JingyunLiang/MANet)\n[![download](https://img.shields.io/github/downloads/JingyunLiang/MANet/total.svg)](https://github.com/JingyunLiang/MANet/releases)[ \u003ca href=\"https://colab.research.google.com/gist/JingyunLiang/4ed2524d6e08343710ee408a4d997e1c/manet-demo-on-spatially-variant-kernel-estimation.ipynb\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"google colab logo\"\u003e\u003c/a\u003e](https://colab.research.google.com/gist/JingyunLiang/4ed2524d6e08343710ee408a4d997e1c/manet-demo-on-spatially-variant-kernel-estimation.ipynb)\n - Aug. 17, 2021: See our recent work for [real-world image SR: Designing a Practical Degradation Model for Deep Blind Image Super-Resolution (BSRGAN), ICCV2021](https://github.com/cszn/BSRGAN) [![arXiv](https://img.shields.io/badge/arXiv-Paper-\u003cCOLOR\u003e.svg)](https://arxiv.org/abs/2103.14006)\n[![GitHub Stars](https://img.shields.io/github/stars/cszn/BSRGAN?style=social)](https://github.com/cszn/BSRGAN)\n - Aug. 17, 2021: See our previous [flow-based kernel estimation: Flow-based Kernel Prior with Application to Blind Super-Resolution (FKP), CVPR2021](https://github.com/JingyunLiang/FKP) [![arXiv](https://img.shields.io/badge/arXiv-Paper-\u003cCOLOR\u003e.svg)](https://arxiv.org/abs/2103.15977)\n[![GitHub Stars](https://img.shields.io/github/stars/JingyunLiang/FKP?style=social)](https://github.com/JingyunLiang/FKP)\n ---\n\n\u003e Normalizing flows have recently demonstrated promising results for low-level vision tasks. For image super-resolution (SR), it learns to predict diverse photo-realistic high-resolution (HR) images from the low-resolution (LR) image rather than learning a deterministic mapping. For image rescaling, it achieves high accuracy by jointly modelling the downscaling and upscaling processes. While existing approaches employ specialized techniques for these two tasks, we set out to unify them in a single formulation. In this paper, we propose the hierarchical conditional flow (HCFlow) as a unified framework for image SR and image rescaling. More specifically, HCFlow learns a bijective mapping between HR and LR image pairs by modelling the distribution of the LR image and the rest high-frequency component simultaneously. In particular, the high-frequency component is conditional on the LR image in a hierarchical manner. To further enhance the performance, other losses such as perceptual loss and GAN loss are combined with the commonly used negative log-likelihood loss in training. Extensive experiments on general image SR, face image SR and image rescaling have demonstrated that the proposed HCFlow achieves state-of-the-art performance in terms of both quantitative metrics and visual quality.\n\u003e\u003cp align=\"center\"\u003e\n  \u003e \u003cimg height=\"120\" src=\"./illustrations/computation_graph.png\"\u003e\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u003cimg height=\"120\" src=\"./illustrations/architecture.png\"\u003e\n\u003c/p\u003e\n\n## Requirements\n- Python 3.7, PyTorch == 1.7.1\n- Requirements: opencv-python, lpips, natsort, etc.\n- Platforms: Ubuntu 16.04, cuda-11.0\n\n\n```bash\ncd HCFlow-master\npip install -r requirements.txt \n```\n\n## Quick Run (takes 1 Minute)\nTo run the code with one command (without preparing data), run following command. Or you can go to our [online Colob demo \u003ca href=\"https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb\"\u003e\u003cimg src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"google colab logo\"\u003e\u003c/a\u003e](https://colab.research.google.com/gist/JingyunLiang/cdb3fef89ebd174eaa43794accb6f59d/hcflow-demo-on-x8-face-image-sr.ipynb) to have a try.\n```bash\ncd codes\n# face image SR\npython test_HCFlow.py --opt options/test/test_SR_CelebA_8X_HCFlow.yml\n\n# general image SR\npython test_HCFlow.py --opt options/test/test_SR_DF2K_4X_HCFlow.yml\n\n# image rescaling\npython test_HCFlow.py --opt options/test/test_Rescaling_DF2K_4X_HCFlow.yml\n```\n---\n\n## Data Preparation\nThe framework of this project is based on [MMSR](https://github.com/open-mmlab/mmediting) and [SRFlow](https://github.com/andreas128/SRFlow). To prepare data, put training and testing sets in `./datasets` as `./datasets/DIV2K/HR/0801.png`. Commonly used SR datasets can be downloaded [here](https://github.com/xinntao/BasicSR/blob/master/docs/DatasetPreparation.md#common-image-sr-datasets). \nThere are two ways for accerleration in data loading: First, one can use `./scripts/png2npy.py` to generate `.npy` files and use `data/GTLQnpy_dataset.py`. Second, one can use `.pklv4` dataset (*recommended*) and use `data/LRHR_PKL_dataset.py`. Please refer to [SRFlow](https://github.com/andreas128/SRFlow#dataset-how-to-train-on-your-own-data) for more details. Prepared datasets can be downloaded [here](http://data.vision.ee.ethz.ch/alugmayr/SRFlow/datasets.zip).\n\n## Training\n\nTo train HCFlow for general image SR/ face image SR/ image rescaling, run this command:\n\n```bash\ncd codes\n\n# face image SR\npython train_HCFlow.py --opt options/train/train_SR_CelebA_8X_HCFlow.yml\n\n# general image SR\npython train_HCFlow.py --opt options/train/train_SR_DF2K_4X_HCFlow.yml\n\n# image rescaling\npython train_HCFlow.py --opt options/train/train_Rescaling_DF2K_4X_HCFlow.yml\n```\nAll trained models can be downloaded from [here](https://github.com/JingyunLiang/HCFlow/releases).\n\n\n## Testing\n\nPlease follow the **Quick Run** section. Just modify the dataset path in `test_HCFlow_*.yml`.\n\n## Results\nWe achieved state-of-the-art performance on general image SR, face image SR and image rescaling. \n\u003e \u003cimg height=\"400\" src=\"./illustrations/face_result.png\"\u003e\n\u003e \nFor more results, please refer to the [paper](https://arxiv.org/abs/2108.05301) and [supp](https://github.com/JingyunLiang/HCFlow/releases) for details. \n\n## Citation\n    @inproceedings{liang21hierarchical,\n      title={Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling},\n      author={Liang, Jingyun and Lugmayr, Andreas and Zhang, Kai and Danelljan, Martin and Van Gool, Luc and Timofte, Radu},\n      booktitle={IEEE International Conference on Computer Vision},\n      year={2021}\n    }\n\n\n## License \u0026 Acknowledgement\n\nThis project is released under the Apache 2.0 license. The codes are based on [MMSR](https://github.com/open-mmlab/mmediting), [SRFlow](https://github.com/andreas128/SRFlow), [IRN](https://github.com/pkuxmq/Invertible-Image-Rescaling) and [Glow-pytorch](https://github.com/chaiyujin/glow-pytorch). Please also follow their licenses. Thanks for their great works.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjingyunliang%2Fhcflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjingyunliang%2Fhcflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjingyunliang%2Fhcflow/lists"}