Skip to content

Liu-Zihang/SAMSR

Repository files navigation

[IJCAI 2025] Semantic-Guided Diffusion Model for Single-Step Image Super-Resolution

Welcome! This is the official implementation of the paper "Semantic-Guided Diffusion Model for Single-Step Image Super-Resolution".

Alt text

Requirements

  • Python 3.10, Pytorch 2.1.2
conda env create -n SamSR python=3.10
conda activate SamSR
pip install -r requirements.txt

Quickly use our SAM noise Module in your super resolution model

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

Fast Testing

python3 inference.py -i [image folder/image path] -o [result folder] --ckpt weights/SamSR_v1.pth --scale 4 --one_step

Requirements

Reproducing the results in the paper

Download the necessary models. You can download them into the files of weights from the link below:

Results in Table 1

# 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

Results in Table 2

  • 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

Training

Preparing stage

  1. Download the necessary models. You can download them into the files of weights from the link below:
  2. Adjust the data path in the config file. Specifically, correct and complete paths in files of traindata
  3. 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

Acknowledgement

This project is based on ResShift and SinSR.

Citation

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}
}

Contact

If you have any questions, please feel free to contact me via [email protected].

About

Semantic-Guided Diffusion Model for Single-Step Image Super-Resolution

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages