(CVPR2021) ClassSR: A General Framework to Accelerate Super-Resolution Networks by Data Characteristic

Overview

ClassSR

(CVPR2021) ClassSR: A General Framework to Accelerate Super-Resolution Networks by Data Characteristic

Paper

Authors: Xiangtao Kong, Hengyuan Zhao, Yu Qiao, Chao Dong

Dependencies

Codes

  • Our codes version based on BasicSR.

How to test a single branch

  1. Clone this github repo.
git clone https://github.com/Xiangtaokong/ClassSR.git
cd ClassSR
  1. Download the testing datasets (DIV2K_valid).

  2. Download the divide_val.log and move it to .codes/data_scripts/.

  3. Generate simple, medium, hard (class1, class2, class3) validation data.

cd codes/data_scripts
python extract_subimages_test.py
python divide_subimages_test.py
  1. Download pretrained models and move them to ./experiments/pretrained_models/ folder.

  2. Run testing for a single branch.

cd codes
python test.py -opt options/test/test_FSRCNN.yml
python test.py -opt options/test/test_CARN.yml
python test.py -opt options/test/test_SRResNet.yml
python test.py -opt options/test/test_RCAN.yml
  1. The output results will be sorted in ./results.

How to test ClassSR

  1. Clone this github repo.
git clone https://github.com/Xiangtaokong/ClassSR.git
cd ClassSR
  1. Download the testing datasets (DIV8K). Test8K contains the images (index 1401-1500) from DIV8K. Test2K/4K contain the images (index 1201-1300/1301-1400) from DIV8K which are downsampled to 2K and 4K resolution.

  2. Download pretrained models and move them to ./experiments/pretrained_models/ folder.

  3. Run testing for ClassSR.

cd codes
python test_ClassSR.py -opt options/test/test_ClassSR_FSRCNN.yml
python test_ClassSR.py -opt options/test/test_ClassSR_CARN.yml
python test_ClassSR.py -opt options/test/test_ClassSR_SRResNet.yml
python test_ClassSR.py -opt options/test/test_ClassSR_RCAN.yml
  1. The output results will be sorted in ./results.

How to train a single branch

  1. Clone this github repo.
git clone https://github.com/Xiangtaokong/ClassSR.git
cd ClassSR
  1. Download the training datasets(DIV2K) and validation dataset(Set5).

  2. Download the divide_train.log and move it to .codes/data_scripts/.

  3. Generate simple, medium, hard (class1, class2, class3) training data.

cd codes/data_scripts
python data_augmentation.py
python extract_subimages_train.py
python divide_subimages_train.py
  1. Run training for a single branch (default branch1, the simplest branch).
cd codes
python train.py -opt options/train/train_FSRCNN.yml
python train.py -opt options/train/train_CARN.yml
python train.py -opt options/train/train_SRResNet.yml
python train.py -opt options/train/train_RCAN.yml
  1. The experiments will be sorted in ./experiments.

How to train ClassSR

  1. Clone this github repo.
git clone https://github.com/Xiangtaokong/ClassSR.git
cd ClassSR
  1. Download the training datasets (DIV2K) and validation dataset(DIV2K_valid, index 801-810).

  2. Generate training data (the all data(1.59M) in paper).

cd codes/data_scripts
python data_augmentation.py
python extract_subimages_ClassSR.py
  1. Download pretrained models(pretrained branches) and move them to ./experiments/pretrained_models/ folder.

  2. Run training for ClassSR.

cd codes
python train_ClassSR.py -opt options/train/train_ClassSR_FSRCNN.yml
python train_ClassSR.py -opt options/train/train_ClassSR_CARN.yml
python train_ClassSR.py -opt options/train/train_ClassSR_SRResNet.yml
python train_ClassSR.py -opt options/train/train_ClassSR_RCAN.yml
  1. The experiments will be sorted in ./experiments.

Contact

Email: [email protected]

Comments
  • add rank <=0 when val log

    add rank <=0 when val log

    Thanks for your awesome work. When i run the trian.py with multi card, I find the tb_logger have a bug with rank > 0. Here, rank is checked. train.py#L125

                if rank <= 0:
                    logger.info('Number of val images in [{:s}]: {:d}'.format(
                        dataset_opt['name'], len(val_set)))
    

    But not check in here. train.py#L215

                    # tensorboard logger
                    if opt['use_tb_logger'] and 'debug' not in opt['name']:
                        tb_logger.add_scalar('psnr', avg_psnr, current_step)
    

    It should change to

                    # tensorboard logger
                    if rank <= 0 and opt['use_tb_logger'] and 'debug' not in opt['name']:
                        tb_logger.add_scalar('psnr', avg_psnr, current_step)
    

    the train_ClassSR has same bug.

    opened by Scallions 13
  • 关于生成训练集

    关于生成训练集

    1. 请问一下,论文里“Then we densely crop 1.59M sub-images with size 32 × 32 from LR images. These sub-images are equally divided into three classes (0.53M for each) according to their PSNR values through MSRResNet. ” 这里的1.59M户和0.53M 指的是文件大小还是其他?

    2. 20-04-14 00:47:54.197 - INFO: 0558_s290 - PSNR: 26.473503 dB; SSIM: 0.751480; PSNR_Y: 27.808832 dB; SSIM_Y: 0.769544. 20-04-14 00:47:54.248 - INFO: 0558_s291 - PSNR: 26.580721 dB; SSIM: 0.764139; PSNR_Y: 27.929448 dB; SSIM_Y: 0.785679. 20-04-14 00:47:54.300 - INFO: 0558_s292 - PSNR: 25.955706 dB; SSIM: 0.801685; PSNR_Y: 27.237049 dB; SSIM_Y: 0.822988. divide_train.log 里面scale=1的图名字直接是0558_s290,0558_s291。。。。但是extract_subimages_train.py生成的文件夹DIV2K_scale_sub里面的图名字是1_0558_s290,所以在运行divide_sub_images_train.py时会报错

    3. 论文里说“To prepare the training data, we first downsample3 the original images with scaling factors 0.6, 0.7, 0.8, 0.9 to generate the HR images.” 这个意思时scale=1的图不参与训练吗?

    opened by icey-zhang 13
  • How to get the trained weights  ?

    How to get the trained weights ?

    Thank for the great work.

    I have trained on a custom dataset by using ClassSR repo. But not able to find the trained weights after each epochs . Should i wait to complete the entire epochs to get the trained weights ?

    opened by Samjith888 11
  • Problems encountered when I test and train ClassSR: Bad Results and Lack of LMDB file

    Problems encountered when I test and train ClassSR: Bad Results and Lack of LMDB file

    Recently, I am impressed by your brilliant and impressive idea and work in this paper:" ClassSR: A General Framework to Accelerate Super-Resolution Networks by Data Characteristic". It groundbreakingly accelerates SR models by classing sub-images, which attracts me a lot.

    Therefore, I download the released code on Github, follow the guidance in README.md, and test it. However, the results are weird. Both PSNR and SSIM are acceptable in branches testing, nevertheless, these indexes drop to ~9dB when it comes to the whole model, which confused me a lot.

    And when I try to train the model, it shows that there is a lack of LMDB file to handle validating set "Set5" during the training procedure. 2 affixed pictures demonstrate the situation. I also try to read through the above paper several times, but little things are related to this problem.

    So in a word, there are 2 problems I need your valuable help with:

    1. Is there something wrong when I test the model?

    2. How can I tackle LMDB issues?

    Thank you for your reading and priceless help!

    {"mode":"full","isActive":false}

    opened by DemonsHunter 7
  • How to create a divide_rain.log folder?

    How to create a divide_rain.log folder?

    Hello, I have now generated sub-images. I want to use the generated sub-images to train my models of different branches. How can I create a divide_train.log file suitable for my model?

    opened by vitamin520 7
  • Perhaps the CARN model is incorrectly implemented?

    Perhaps the CARN model is incorrectly implemented?

    https://github.com/Xiangtaokong/ClassSR/blob/0ebefe75b2d5d08cffd8613c78d6dbb323dbd2c5/codes/models/archs/arch_util.py#L103-L114 I face train problems when train class_carn, finally I located the problem in above code. In CARN official repo, I found there are no bn layer, So may be the CARN model is incorrectly implemented?

    https://github.com/nmhkahn/CARN-pytorch/blob/master/carn/model/ops.py#L33-L48

    opened by wangqiim 6
  • 当运行extract_subimages_test.py出现错误

    当运行extract_subimages_test.py出现错误

    E:\Anaconda\envs\torch11\python.exe D:/迅雷下载/ClassSR-main/codes/data_scripts/extract_subimages_test.py process GT... mkdir [D:/迅雷下载/ClassSR-main/data0/xtkong/data/DIV2K_valid_HR_sub/GT] ... [ ] 0/100, elapsed: 0s, ETA: Start... All subprocesses done. process LR... mkdir [D:/迅雷下载/ClassSR-main/data0/xtkong/data/DIV2K_valid_HR_sub/LR] ... [ ] 0/100, elapsed: 0s, ETA: Start... All subprocesses done. Traceback (most recent call last): File "D:/迅雷下载/ClassSR-main/codes/data_scripts/extract_subimages_test.py", line 143, in main() File "D:/迅雷下载/ClassSR-main/codes/data_scripts/extract_subimages_test.py", line 66, in main assert len(data_util._get_paths_from_images(save_GT_folder)) == len( File "D:\迅雷下载\ClassSR-main\codes\data\util.py", line 31, in _get_paths_from_images assert images, '{:s} has no valid image file'.format(path) AssertionError: D:/迅雷下载/ClassSR-main/data0/xtkong/data/DIV2K_valid_HR_sub/GT has no valid image file

    opened by ymtupup 6
  • Training speed

    Training speed

    NICE WORK! I train classSR structure to process the denoising task. the branchs adopt small network, which calculation cost is only about 5 to 16 GMAC. There are two problems that bother me: First, the training speed is too slow. I use two 3090 cards to train models and it takes 12 minutes to run 100iter. However, when I increased to four 3090 cards, the speed did not increase, and the utilization rate of each GPU was very low. Could you please give me some suggestions? Second, because the training is too slow, I used .pth at 30000iter for testing, and the classification is uneven. The image results have a strong sense of demarcation, which is mainly because different patches take different branches.Will this phenomenon be improved in the next training?

    opened by Lucien66 4
  • 训练过程

    训练过程

    您好,Class-Module我已经训练了两万多个Iteration了,但是验证的时候所有的图片还是都只进入一个分支,并没有平均进入三个分支,请问这样可能是什么原因造成的呢,(initial learning rate设置为10-3,the weights w1, w2, w3 are set to 2000,1, 6)

    opened by Martion-z 4
  • Scale 2 not working

    Scale 2 not working

    Hi, first of all thanks for your work! I have question about custom data. If I have HR images with resolution 512384 and lowres with 256192, and I want to convert LR->HR, what parameters should I change change in test_ClassSR_RCAN.yml for example apart from scale ( if I change only scale I've got this error:

    
    sr_img[i*step*self.scale:i*step*self.scale+patch_size*self.scale,j*step*self.scale:j*step*self.scale+patch_size*self.scale,:]+=sr_list[index]
    ValueError: operands could not be broadcast together with shapes (64,64,3) (128,128,3) (64,64,3) 
    
    opened by artemkurylev 4
  • the training process seems to be stuck

    the training process seems to be stuck

    Hi, @Xiangtaokong , Thanks very much for your interesting work. Currently I want to reproduce your work. I follow the readme and finish the data processing. while during run training command "python train_ClassSR.py -opt options/train/train_ClassSR_FSRCNN.yml", it seems to be stuck. Can you give me some suggestions?

    opened by wanglixilinx 4
  • Questions about classification method

    Questions about classification method

    Hi @Xiangtaokong , a nice work for SR acceleration. I have some questions. Could you help me explain these? Thanks ahead.

    • Conflict between the Class loss and Average loss It seems that the Class-loss is designed to teach the Class-Module to predict the probability of branches unevenly, while the Average-loss is trying to teach the Class-Module to predict probability evenly. I think that the Class-Module tries to strike a balance between certain routing and uncertain routing. Could you help me explain this trade off?
    • Loss curve during the training Class-Module Besides, during the training, I find it that Class-loss decreases obviously. But Average-loss changes smoothly. Is this obversation normal? de9da495393269a2fcc8461f881cb78 a4e7e1ccfd13ec16cafe747c68204b9 Waiting for your reply! Thanks for your time!
    opened by HaoDot 1
  • 计算FLOPs相关

    计算FLOPs相关

    您好!我有两个问题需要请教:

    1. 请问代码里为什么需要除以sum(num_ress) ?
    2. 为什么对FRCNN网络的flops还需要加上7.4 ? 期待您的解答,谢谢!!
    def cal_FLOPs(which_model,num_ress):
        if which_model =='classSR_3class_fsrcnn_net':
            flops = ((141 * num_ress[0] + 304 * num_ress[1] + 468 * num_ress[2]) / sum(num_ress))+7.4
            percent=flops/468
        elif which_model=='classSR_3class_carn':
            flops = (0.38 * num_ress[0] + 0.77 * num_ress[1] + 1.15 * num_ress[2]) / sum(num_ress)
            percent = flops / 1.15
        elif which_model=='classSR_3class_srresnet':
            flops = (1.66 * num_ress[0] + 3.44 * num_ress[1] + 5.20 * num_ress[2]) / sum(num_ress)
            percent = flops / 5.20
        elif which_model=='classSR_3class_rcan':
            flops = (10.33 * num_ress[0] + 19.90 * num_ress[1] + 32.60 * num_ress[2]) / sum(num_ress)
            percent = flops / 32.60
        return flops,percent
    
    
    opened by aoaforever 1
Owner
Xiangtao Kong
Xiangtao Kong
MASA-SR: Matching Acceleration and Spatial Adaptation for Reference-Based Image Super-Resolution (CVPR2021)

MASA-SR Official PyTorch implementation of our CVPR2021 paper MASA-SR: Matching Acceleration and Spatial Adaptation for Reference-Based Image Super-Re

DV Lab 126 Dec 20, 2022
Code for C2-Matching (CVPR2021). Paper: Robust Reference-based Super-Resolution via C2-Matching.

C2-Matching (CVPR2021) This repository contains the implementation of the following paper: Robust Reference-based Super-Resolution via C2-Matching Yum

Yuming Jiang 151 Dec 26, 2022
PyTorch code for our paper "Image Super-Resolution with Non-Local Sparse Attention" (CVPR2021).

Image Super-Resolution with Non-Local Sparse Attention This repository is for NLSN introduced in the following paper "Image Super-Resolution with Non-

null 143 Dec 28, 2022
A framework for joint super-resolution and image synthesis, without requiring real training data

SynthSR This repository contains code to train a Convolutional Neural Network (CNN) for Super-resolution (SR), or joint SR and data synthesis. The met

null 83 Jan 1, 2023
PyTorch common framework to accelerate network implementation, training and validation

pytorch-framework PyTorch common framework to accelerate network implementation, training and validation. This framework is inspired by works from MML

Dongliang Cao 3 Dec 19, 2022
PyTorch implementation of Graph Convolutional Networks in Feature Space for Image Deblurring and Super-resolution, IJCNN 2021.

GCResNet PyTorch implementation of Graph Convolutional Networks in Feature Space for Image Deblurring and Super-resolution, IJCNN 2021. The code will

null 11 May 19, 2022
PyTorch code for our ECCV 2018 paper "Image Super-Resolution Using Very Deep Residual Channel Attention Networks"

PyTorch code for our ECCV 2018 paper "Image Super-Resolution Using Very Deep Residual Channel Attention Networks"

Yulun Zhang 1.2k Dec 26, 2022
PyTorch version of the paper 'Enhanced Deep Residual Networks for Single Image Super-Resolution' (CVPRW 2017)

About PyTorch 1.2.0 Now the master branch supports PyTorch 1.2.0 by default. Due to the serious version problem (especially torch.utils.data.dataloade

Sanghyun Son 2.1k Jan 1, 2023
Image Super-Resolution Using Very Deep Residual Channel Attention Networks

Image Super-Resolution Using Very Deep Residual Channel Attention Networks

kongdebug 14 Oct 14, 2022
Torch implementation of "Enhanced Deep Residual Networks for Single Image Super-Resolution"

NTIRE2017 Super-resolution Challenge: SNU_CVLab Introduction This is our project repository for CVPR 2017 Workshop (2nd NTIRE). We, Team SNU_CVLab, (B

Bee Lim 625 Dec 30, 2022
Official PyTorch code for Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021)

Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021) This repository is the official P

Jingyun Liang 159 Dec 30, 2022
Official PyTorch code for Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021)

Hierarchical Conditional Flow: A Unified Framework for Image Super-Resolution and Image Rescaling (HCFlow, ICCV2021) This repository is the official P

Jingyun Liang 159 Dec 30, 2022
Fast and Context-Aware Framework for Space-Time Video Super-Resolution (VCIP 2021)

Fast and Context-Aware Framework for Space-Time Video Super-Resolution Preparation Dependencies PyTorch 1.2.0 CUDA 10.0 DCNv2 cd model/DCNv2 bash make

Xueheng Zhang 1 Mar 29, 2022
Multi-Scale Aligned Distillation for Low-Resolution Detection (CVPR2021)

MSAD Multi-Scale Aligned Distillation for Low-Resolution Detection Lu Qi*, Jason Kuen*, Jiuxiang Gu, Zhe Lin, Yi Wang, Yukang Chen, Yanwei Li, Jiaya J

Jia Research Lab 115 Dec 23, 2022
Multi-Scale Aligned Distillation for Low-Resolution Detection (CVPR2021)

MSAD Multi-Scale Aligned Distillation for Low-Resolution Detection Lu Qi*, Jason Kuen*, Jiuxiang Gu, Zhe Lin, Yi Wang, Yukang Chen, Yanwei Li, Jiaya J

DV Lab 115 Dec 23, 2022
Exploit Camera Raw Data for Video Super-Resolution via Hidden Markov Model Inference

RawVSR This repo contains the official codes for our paper: Exploit Camera Raw Data for Video Super-Resolution via Hidden Markov Model Inference Xiaoh

Xiaohong Liu 23 Oct 8, 2022
Collect super-resolution related papers, data, repositories

Collect super-resolution related papers, data, repositories

WangChaofeng 1.7k Jan 3, 2023
Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data

Real-ESRGAN Real-ESRGAN: Training Real-World Blind Super-Resolution with Pure Synthetic Data Ported from https://github.com/xinntao/Real-ESRGAN Depend

Holy Wu 44 Dec 27, 2022
Accelerate Neural Net Training by Progressively Freezing Layers

FreezeOut A simple technique to accelerate neural net training by progressively freezing layers. This repository contains code for the extended abstra

Andy Brock 203 Jun 19, 2022