## we recommend readers to follow the steps below to succesfully install and run the codes provided:

conda create -n SAITGAN python==3.8
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=10.2 -c pytorch

conda activate SAITGAN
pip install -r requirements.txt

sudo apt-get install wget
sudo apt-get install unzip

############################################### DeepTen ##############################################################################
## currently, since cudatoolkit 10.2 do not work with rtx 30 series or later ones, we will find out incorporating pretrained DeepTen module into our codes in future.

pip install git+https://github.com/zhanghang1989/PyTorch-Encoding/
cd PyTorch-Encoding/
python scripts/prepare_minc.py
CUDA_VISIBLE_DEVICES=0,1,2,3 python train_dist.py --dataset minc --model deepten_resnet50_minc --batch-size 512 --lr 0.004 --epochs 80 --lr-step 60 --lr-scheduler step --weight-decay 5e-4

## we also provide pre-traiend version of DeepTen model :)
https://www.dropbox.com/scl/fi/4tepgh7utvmr5ajka4cz5/deepten_resnet50_minc-1225f149.pth?rlkey=17snk8lshozoyhzgyi9k888u7&dl=0

############################################### SAITGAN ##############################################################################
## We provide essential datasets, pretrained-models to re-produce our work here :)
## first, you need to place several datasets in proper location. don't worry we provide links. just download and unzip

Pretrained model : https://www.dropbox.com/scl/fi/23rzt20yfen1ad1dhza2s/pretrained_models.zip?rlkey=7z2n349ard0jfhqrjhx28a4mf&dl=0
put pretrained model @ KAIR-master/superresolution
unzip it

Trainsets : https://www.dropbox.com/scl/fi/qnwcby85tz60tb9bvswh1/trainsets.zip?rlkey=e30woe7hw8qw4b5j8dhqtfphj&dl=0
put trainsets @ KAIR-master/trainsets
unzip it

Testsets : https://www.dropbox.com/scl/fi/bnbijmcgn0gwaa2u5i6qg/test_data.zip?rlkey=859z9plbo9d0a4vtt26ijihql&dl=0
put pretrained model @ KAIR-master/testsets
unzip it


#### before starting, you need to correct several "data_path" and "model_path" to a proper location ###
#### Re-producing results with pre-trained models
#### Re-producing results with pre-trained models
#### Re-producing results with pre-trained models

# SAIT+BSRNET(PSNR) for DIV2K4D <TRAINED FOR BSRGAN DEGRADATION LR IMAGES>
python main_test_Ours_DIV2K4D.py --task real_sr --scale 4 --network BSR --model_path (your path)/KAIR-master/superresolution/bsrgan_x4_lsgan_Deepten3_RealDegrade_alpha_0.1/models/75000_G.pth --model_DT_path (your path)/KAIR-master/superresolution/bsrgan_x4_lsgan_Deepten3_RealDegrade_alpha_0.1/models/75000_DT.pth --print_img True > testsets/log_BSRNET_Deepten3_lsgan_RealDegrade_quantitative_results_epoch75000.txt

# Naive BSRGAN for DIV2K4D <TRAINED FOR BSRGAN DEGRADATION LR IMAGES (DIV2K, FLICKR2K, OST)>
python main_test_Ours_DIV2K4D.py --task real_sr --scale 4 --network BSR --model_path (your path)/KAIR-master/superresolution/bsrgan_x4_gan_NAIVE_RealDegrade/models/120000_G.pth --print_img True > testsets/log_BSRGAN_Naive_RealDegrade_quantitative_results_epoch120000.txt

# SAIT+SRFormer(PSNR) for DIV2K4D <TRAINED FOR BSRGAN DEGRADATION LR IMAGES> 
python main_test_Ours_DIV2K4D.py --task real_sr --scale 4 --network SRFormer --model_path (your path)/KAIR-master/superresolution/srformer_x4_gan_saitgan/models/80000_G.pth --model_DT_path (your path)/KAIR-master/superresolution/srformer_x4_gan_saitgan/models/80000_DT.pth --print_img True > testsets/log_SRFormer_Deepten3_RealDegrade_quantitative_results_epoch80000.txt

# Naive SRFormer(PSNR) for DIV2K4D <TRAINED FOR BSRGAN DEGRADATION LR IMAGES> 
python main_test_Ours_DIV2K4D.py --task real_sr --scale 4 --network SRFormer --model_path (your path)/KAIR-master/superresolution/srformer_x4_gan/models/90000_G.pth --print_img True > testsets/log_SRFormer_Naive_RealDegrade_quantitative_results_epoch90000.txt

# Naive SwinIR-GAN
python main_test_Ours_DIV2K4D.py --task real_sr --scale 4 --model_path (your path)/KAIR-master/superresolution/swinir_sr_realworld_x4_gan/models/003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.pth --print_img True > testsets/log_SWINIR_realSR_quantitative_results.txt

# SAIT+SwinIR(PSNR) for DIV2K4D <TRAINED FOR BSRGAN DEGRADATION LR IMAGES> 
python main_test_Ours_DIV2K4D.py --task real_sr --scale 4 --network SwinIR --model_path (your path)/KAIR-master/superresolution/swinir_sr_realworld_x4_gan_Deepten3_RealDegrade_alpha_0.1/models/45000_G.pth --model_DT_path (your path)/KAIR-master/superresolution/swinir_sr_realworld_x4_gan_Deepten3_RealDegrade_alpha_0.1/models/45000_DT.pth --print_img True > testsets/log_SwinIR_Deepten3_RealDegrade_quantitative_results_epoch45000.txt

# SAIT+SwinIR(PSNR) for RealSRSet
python main_test_Ours.py --task real_sr --scale 4 --model_path (your path)/KAIR-master/superresolution/swinir_sr_realworld_x4_gan_Deepten3_RealDegrade_alpha_0.1/models/40000_G.pth --folder_lq testsets/RealSRSet+5images --model_DT_path (your path)/KAIR-master/superresolution/swinir_sr_realworld_x4_gan_Deepten3_RealDegrade_alpha_0.1/models/40000_DT.pth


#### Training Models
#### Training Models
#### Training Models
############ Please modify followings in .json files in "option/" : "pretrained_netG", "dataroot_H", "dataroot_L" (for both training and test)

## train Naive BSRGAN on DIV2K+FLICKR2K+OST ONLY
python -m torch.distributed.launch --nproc_per_node=4 --master_port=1234 main_train_psnr_Deepten.py --opt options/train_bsrgan_realDegrade_x4_lsgan_original.json --noDT True --dist True > Logging_bsrgan_original_realDegrade_x4_Naive.txt

## train SAIT+BSRGAN(PSNR)
python -m torch.distributed.launch --nproc_per_node=4 --master_port=1234 main_train_psnr_Deepten.py --opt options/train_bsrgan_realDegrade_x4_lsgan.json --dist True > Logging_bsrgan_realDegrade_x4_lsgan_Deepten3.txt

## train Naive SRFormer on DIV2K+FLICKR2K+OST ONLY (train from server9 = 5,6,7,8 GPUS)
python -m torch.distributed.launch --nproc_per_node=4 --master_port=5678 main_train_psnr_Deepten.py --opt options/train_SRFormer_realDegrade_x4_gan_original.json --noDT True --dist True > Logging_srformer_original_realDegrade_x4_Naive.txt

## train SRFormer+SAITGAN on DIV2K+FLICKR2K+OST ONLY
python -m torch.distributed.launch --nproc_per_node=4 --master_port=1234 main_train_psnr_Deepten.py --opt options/train_SRFormer_realDegrade_x4_gan.json --dist True > Logging_srformer_realDegrade_x4_Deepten3.txt

## train SAIT+SwinIR(PSNR) use BSRGAN's synthesis method to make real degradation LR images
python -m torch.distributed.launch --nproc_per_node=4 --master_port=1234 main_train_psnr_Deepten.py --opt options/swinir/train_swinir_sr_realDegrade_x4_gan.json --dist True > Logging_swinir_realDegrade_x4_gan_Deepten3.txt

## Naive SwinIR
https://github.com/JingyunLiang/SwinIR/releases/download/v0.0/003_realSR_BSRGAN_DFO_s64w8_SwinIR-M_x4_GAN.pth



