Welcome! This is the official implementation of the paper "Semantic-Guided Diffusion Model for Single-Step Image Super-Resolution".
- Python 3.10, Pytorch 2.1.2
conda env create -n SamSR python=3.10
conda activate SamSR
pip install -r requirements.txt
from script_segment import generate_masks_from_batch,load_sam_model, generate_weighted_noise, normalize_noise_to_unit_variance
sam_model = load_sam_model()
with th.no_grad():
masks_tensor = generate_masks_from_batch(sam_model, x_lr)
noise_weighted = generate_weighted_noise(masks_tensor)
sam_noise = normalize_noise_to_unit_variance(noise_weighted) #change your gaussian noise to sam noise
python3 inference.py -i [image folder/image path] -o [result folder] --ckpt weights/SamSR_v1.pth --scale 4 --one_step
Download the necessary models. You can download them into the files of weights from the link below:
# Results on RealSet65
python inference.py -i testdata/RealSet65 -o results/SamSR/RealSet65 --scale 4 --ckpt weights/SamSR_v1.pth --one_step
# Results on RealSR
python inference.py -i testdata/RealSet65 -o results/SamSR/RealSR --scale 4 --ckpt weights/SamSR_v1.pth --one_step
If you are running on a GPU with limited memory, you could reduce the patch size by setting --chop_size 256
to avoid out of memory. However, this will slightly degrade the performance.
# Results on RealSet65
python inference.py -i testdata/RealSet65 -o results/SamSR/RealSet65 --scale 4 --ckpt weights/SamSR_v1.pth --one_step --chop_size 256 --task SamSR
# Results on RealSR
python inference.py -i testdata/RealSR -o results/SamSR/RealSR --scale 4 --ckpt weights/SamSR_v1.pth --one_step --chop_size 256 --task SamSR
- Download the image ImageNet-Test (Link) to the testdata folder.
- Unzip the downloaded dataset.
- Test the model
python inference.py -i testdata/imagenet256/lq/ -o results/SamSR/imagenet -r testdata/imagenet256/gt/ --scale 4 --ckpt weights/SamSR_v2.pth --one_step
- Download the necessary models. You can download them into the files of weights from the link below:
- Adjust the data path in the config file. Specifically, correct and complete paths in files of traindata
- Adjust batchsize according your GPUS.
- configs.train.batch: [training batchsize, validation btatchsize]
- configs.train.microbatch: total batchsize = microbatch * #GPUS * num_grad_accumulation
python3 main_distill.py --cfg_path configs/SamSR.yaml --save_dir logs/SamSR
This project is based on ResShift and SinSR.
Please cite our paper if you find our work useful. Thanks!
@article{liu2025semantic,
title={Semantic-guided diffusion model for single-step image super-resolution},
author={Liu, Zihang and Zhang, Zhenyu and Tang, Hao},
journal={arXiv preprint arXiv:2505.07071},
year={2025}
}
If you have any questions, please feel free to contact me via liuzihang@bit.edu.cn
.