{"id":26206959,"url":"https://github.com/guaishou74851/adcsr","last_synced_at":"2025-04-15T09:27:47.986Z","repository":{"id":281964375,"uuid":"943721654","full_name":"Guaishou74851/AdcSR","owner":"Guaishou74851","description":"(CVPR 2025) Adversarial Diffusion Compression for Real-World Image Super-Resolution [PyTorch]","archived":false,"fork":false,"pushed_at":"2025-04-05T03:32:15.000Z","size":37929,"stargazers_count":49,"open_issues_count":3,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-05T04:23:32.646Z","etag":null,"topics":["adversarial-diffusion-compression","adversarial-distillation","computer-vision","cvpr2025","deep-learning","deep-neural-networks","diffusion-models","image-reconstruction","image-restoration","one-step-diffusion","one-step-diffusion-model","pruning","python","python3","pytorch","super-resolution"],"latest_commit_sha":null,"homepage":"https://arxiv.org/abs/2411.13383","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/Guaishou74851.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-06T06:49:39.000Z","updated_at":"2025-04-05T03:32:18.000Z","dependencies_parsed_at":"2025-03-12T04:36:32.487Z","dependency_job_id":null,"html_url":"https://github.com/Guaishou74851/AdcSR","commit_stats":null,"previous_names":["guaishou74851/adcsr"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guaishou74851%2FAdcSR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guaishou74851%2FAdcSR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guaishou74851%2FAdcSR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Guaishou74851%2FAdcSR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Guaishou74851","download_url":"https://codeload.github.com/Guaishou74851/AdcSR/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249042289,"owners_count":21203256,"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":["adversarial-diffusion-compression","adversarial-distillation","computer-vision","cvpr2025","deep-learning","deep-neural-networks","diffusion-models","image-reconstruction","image-restoration","one-step-diffusion","one-step-diffusion-model","pruning","python","python3","pytorch","super-resolution"],"created_at":"2025-03-12T05:18:53.918Z","updated_at":"2025-04-15T09:27:47.979Z","avatar_url":"https://github.com/Guaishou74851.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n   \u003cimg src=\"assets/icon.png\" alt=\"icon\" width=\"200px\"/\u003e\n\u003c/p\u003e\n\n# (CVPR 2025) Adversarial Diffusion Compression for Real-World Image Super-Resolution [PyTorch]\n\n[![icon](https://img.shields.io/badge/ArXiv-Paper-\u003cCOLOR\u003e.svg)](https://arxiv.org/abs/2411.13383) [![Hugging Face](https://img.shields.io/badge/Code_\u0026_Models-%F0%9F%A4%97%20Hugging%20Face-blue)](https://huggingface.co/Guaishou74851/AdcSR) ![visitors](https://visitor-badge.laobi.icu/badge?page_id=Guaishou74851.AdcSR)\n\n[Bin Chen](https://scholar.google.com/citations?user=aZDNm98AAAAJ)\u003csup\u003e1,3,\\*\u003c/sup\u003e\n| [Gehui Li](https://github.com/cvsym)\u003csup\u003e1,\\*\u003c/sup\u003e\n| [Rongyuan Wu](https://scholar.google.com/citations?user=A-U8zE8AAAAJ)\u003csup\u003e2,3,\\*\u003c/sup\u003e\n| [Xindong Zhang](https://scholar.google.com/citations?user=q76RnqIAAAAJ)\u003csup\u003e3\u003c/sup\u003e\n| [Jie Chen](https://aimia-pku.github.io/)\u003csup\u003e1,†\u003c/sup\u003e\n| [Jian Zhang](https://jianzhang.tech/)\u003csup\u003e1,†\u003c/sup\u003e\n| [Lei Zhang](https://www4.comp.polyu.edu.hk/~cslzhang/)\u003csup\u003e2,3\u003c/sup\u003e\n\n\u003csup\u003e1\u003c/sup\u003e *School of Electronic and Computer Engineering, Peking University*\n\n\u003csup\u003e2\u003c/sup\u003e *The Hong Kong Polytechnic University*, \u003csup\u003e3\u003c/sup\u003e *OPPO Research Institute*\n\n\u003csup\u003e*\u003c/sup\u003e Equal Contribution. \u003csup\u003e†\u003c/sup\u003e Corresponding Authors.\n\n⭐ **If AdcSR is helpful to you, please star this repo. Thanks!** 🤗\n\n## 📝 Overview\n\n### Highlights\n\n- **Adversarial Diffusion Compression (ADC).** We remove and prune redundant modules from the one-step diffusion network [OSEDiff](https://github.com/cswry/OSEDiff) and apply adversarial distillation to retain generative capabilities despite reduced capacity.\n- **Real-Time [Stable Diffusion](https://huggingface.co/stabilityai/stable-diffusion-2-1)-Based Image Super-Resolution.** AdcSR super-resolves a 128×128 image to 512×512 **in just 0.03s 🚀** on an A100 GPU.\n- **Competitive Visual Quality.** Despite **74% fewer parameters 📉** than [OSEDiff](https://github.com/cswry/OSEDiff), AdcSR achieves **competitive image quality** across multiple benchmarks.\n\n### Framework\n\n1. **Structural Compression**\n   - **Removable modules** (VAE encoder, text prompt extractor, cross-attention, time embeddings) are eliminated.\n   - **Prunable modules** (UNet, VAE decoder) are **channel-pruned** to optimize efficiency while preserving performance.\n\n\u003cp align=\"center\"\u003e\n   \u003cimg src=\"assets/teaser.png\" alt=\"teaser\" width=\"55%\"/\u003e\n\u003c/p\u003e\n\n2. **Two-Stage Training**\n   1. **Pretraining a Pruned VAE Decoder** to maintain its ability to decode latent representations.\n   2. **Adversarial Distillation** to align compressed network features with the teacher model (e.g., [OSEDiff](https://github.com/cswry/OSEDiff)) and ground truth images.\n\n\u003cp align=\"center\"\u003e\n   \u003cimg src=\"assets/method.png\" alt=\"method\" /\u003e\n\u003c/p\u003e\n\n## 😍 Visual Results\n\n[\u003cimg src=\"assets/demo1.png\" height=\"240px\"/\u003e](https://imgsli.com/MzU2MjU1) [\u003cimg src=\"assets/demo2.png\" height=\"240px\"/\u003e](https://imgsli.com/MzU2MjU2) [\u003cimg src=\"assets/demo3.png\" height=\"240px\"/\u003e](https://imgsli.com/MzU2MjU3)\n\n[\u003cimg src=\"assets/demo4.png\" height=\"242px\"/\u003e](https://imgsli.com/MzU2NTg4) [\u003cimg src=\"assets/demo5.png\" height=\"242px\"/\u003e](https://imgsli.com/MzU2NTkw) [\u003cimg src=\"assets/demo6.png\" height=\"242px\"/\u003e](https://imgsli.com/MzU2NTk1)\n\n[\u003cimg src=\"assets/demo7.png\" height=\"319px\"/\u003e](https://imgsli.com/MzU2OTE0) [\u003cimg src=\"assets/demo8.png\" height=\"319px\"/\u003e](https://imgsli.com/MzU2OTE1)\n\nhttps://github.com/user-attachments/assets/1211cefa-8704-47f5-82cd-ec4ef084b9ec\n\n\u003cimg src=\"assets/comp.png\" alt=\"comp\" width=\"840px\" /\u003e\n\n## ⚙ Installation\n\n```shell\ngit clone https://github.com/Guaishou74851/AdcSR.git\ncd AdcSR\nconda create -n AdcSR python=3.10\nconda activate AdcSR\npip install --upgrade pip\npip install -r requirements.txt\nchmod +x train.sh train_debug.sh test_debug.sh evaluate_debug.sh\n```\n\n## ⚡ Test\n\n1. **Download test datasets** (`DIV2K-Val.zip`, `DRealSR.zip`, `RealSR.zip`) from [Hugging Face](https://huggingface.co/Guaishou74851/AdcSR) or [PKU Disk](https://disk.pku.edu.cn/link/AAD499197CBF054392BC4061F904CC4026).\n2. **Unzip** them into `./testset/`, ensuring the structure:\n   ```\n   ./testset/DIV2K-Val/LR/xxx.png\n   ./testset/DIV2K-Val/HR/xxx.png\n   ./testset/DRealSR/LR/xxx.png\n   ./testset/DRealSR/HR/xxx.png\n   ./testset/RealSR/LR/xxx.png\n   ./testset/RealSR/HR/xxx.png\n   ```\n3. **Download model weights** (`net_params_200.pkl`) from the same link and place it in `./weight/`.  \n4. **Run the test script** (or modify and execute `./test_debug.sh` for convenience):  \n   ```bash\n   python test.py --LR_dir=path_to_LR_images --SR_dir=path_to_SR_images\n   ```\n   The results will be saved in `path_to_SR_images`.\n5. **Test Your Own Images**:\n   - Place your **low-resolution (LR)** images into `./testset/xxx/`.\n   - Run the command with `--LR_dir=./testset/xxx/ --SR_dir=./yyy/`, and the model will perform **x4 super-resolution**.\n\n## 🍭 Evaluation\n\nRun the evaluation script (or modify and execute `./evaluate_debug.sh` for convenience):\n```bash\npython evaluate.py --HR_dir=path_to_HR_images --SR_dir=path_to_SR_images\n```\n\n## 🔥 Train\n\nThis repo provides code for **Stage 2** training (**adversarial distillation**). For **Stage 1** (pretraining the channel-pruned VAE decoder), refer to our paper and use the code of [Latent Diffusion Models](https://github.com/CompVis/latent-diffusion) repo.\n\n1. **Download pretrained model weights** (`DAPE.pth`, `halfDecoder.ckpt`, `osediff.pkl`, `ram_swin_large_14m.pth`) from [Hugging Face](https://huggingface.co/Guaishou74851/AdcSR) or [PKU Disk](https://disk.pku.edu.cn/link/AAD499197CBF054392BC4061F904CC4026), and place them in `./weight/pretrained/`.\n2. **Download the [LSDIR](https://huggingface.co/ofsoundof/LSDIR) dataset** and store it in your preferred location.\n3. **Modify the dataset path** in `config.yml`:\n   ```yaml\n   dataroot_gt: path_to_HR_images_of_LSDIR\n   ```\n4. **Run the training script** (or modify and execute `./train.sh` or `./train_debug.sh`):\n   ```bash\n   CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7 python -m torch.distributed.run --nproc_per_node=8 --master_port=23333 train.py\n   ```\n   The trained model will be saved in `./weight/`.\n   \n## 🥰 Acknowledgement\n\nThis project is built upon the codes of [Latent Diffusion Models](https://github.com/CompVis/latent-diffusion), [Diffusers](https://github.com/huggingface/diffusers), [BasicSR](https://github.com/XPixelGroup/BasicSR), and [OSEDiff](https://github.com/cswry/OSEDiff). We sincerely thank the authors of these repos for their significant contributions.\n\n## 🎓 Citation\n\nIf you find our work helpful, please consider citing:\n\n```latex\n@inproceedings{chen2025adversarial,\n  title={Adversarial Diffusion Compression for Real-World Image Super-Resolution},\n  author={Chen, Bin and Li, Gehui and Wu, Rongyuan and Zhang, Xindong and Chen, Jie and Zhang, Jian and Zhang, Lei},\n  booktitle={Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition},\n  year={2025}\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguaishou74851%2Fadcsr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguaishou74851%2Fadcsr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguaishou74851%2Fadcsr/lists"}