3587jjh commited on
Commit
436e09f
·
verified ·
1 Parent(s): 571728f

Push model using huggingface_hub.

Browse files
Files changed (3) hide show
  1. README.md +5 -93
  2. config.json +54 -0
  3. model.safetensors +3 -0
README.md CHANGED
@@ -1,97 +1,9 @@
1
  ---
2
  tags:
3
- - super-resolution
4
- - Image-to-Image
5
  ---
6
- # Accelerating Image Super-Resolution Networks with Pixel-Level Classification
7
- [![Project Page](https://img.shields.io/badge/Project-Page-green)](https://3587jjh.github.io/PCSR/)
8
- [![arXiv](https://img.shields.io/badge/arXiv-2407.21448-b31b1b)](https://arxiv.org/abs/2407.21448)
9
 
10
- <div align="justify">
11
- <b>Abstract</b>: In recent times, the need for effective super-resolution (SR) techniques has surged, especially for large-scale images ranging 2K to 8K resolutions. For DNN-based SISR, decomposing images into overlapping patches is typically necessary due to computational constraints. In such patch-decomposing scheme, one can allocate computational resources differently based on each patch's difficulty to further improve efficiency while maintaining SR performance. However, this approach has a limitation: computational resources is uniformly allocated within a patch, leading to lower efficiency when the patch contain pixels with varying levels of restoration difficulty. To address the issue, we propose the Pixel-level Classifier for Single Image Super-Resolution (PCSR), a novel method designed to distribute computational resources adaptively at the pixel level. A PCSR model comprises a backbone, a pixel-level classifier, and a set of pixel-level upsamplers with varying capacities. The pixel-level classifier assigns each pixel to an appropriate upsampler based on its restoration difficulty, thereby optimizing computational resource usage. Our method allows for performance and computational cost balance during inference without re-training. Our experiments demonstrate PCSR's advantage over existing patch-distributing methods in PSNR-FLOP trade-offs across different backbone models and benchmarks.
12
- </div>
13
- <br>
14
-
15
- ## Dependencies
16
- - Python 3.7<br>
17
- - Pytorch 1.13<br>
18
- - NVIDIA GPU + CUDA<br>
19
- - Python packages: `pip install numpy opencv-python pandas tqdm fast_pytorch_kmeans`
20
-
21
- ## How to Use
22
- - sudo apt-get install git-lfs<br>
23
- - git lfs install<br>
24
- - git clone https://huggingface.co/3587jjh/pcsr_carn<br>
25
-
26
- ```python
27
- ####### demo.py #######
28
- import torch
29
- import models
30
- from torchvision import transforms
31
- from utils import *
32
- from PIL import Image
33
- import numpy as np
34
-
35
- img_path = 'myimage.png' # only support .png
36
- scale = 4 # only support x4
37
-
38
- # k: hyperparameter to traverse PSNR-FLOPs trade-off. smaller k → larger FLOPs & PSNR. range is about [-1,2].
39
- # adaptive: whether to use automatic decision of k
40
- # no_refinement: whether not to use pixel-wise refinement (postprocessing for reducing artifacts)
41
- # parser.add_argument('--opacity', type=float, default=0.65, help='opacity for colored visualization')
42
- # parser.add_argument('--pixel_batch_size', type=int, default=300000)
43
-
44
- resume_path = 'carn-pcsr-phase1.pth'
45
- sv_file = torch.load(resume_path)
46
- model = models.make(sv_file['model'], load_sd=True).cuda()
47
- model.eval()
48
-
49
- rgb_mean = torch.tensor([0.4488, 0.4371, 0.4040], device='cuda').view(1,3,1,1)
50
- rgb_std = torch.tensor([1.0, 1.0, 1.0], device='cuda').view(1,3,1,1)
51
-
52
- with torch.no_grad():
53
- # prepare inputs
54
- lr = transforms.ToTensor()(Image.open(img_path)).unsqueeze(0).cuda() # (1,3,h,w), range=[0,1]
55
- h,w = lr.shape[-2:]
56
- H,W = h*scale, w*scale
57
- coord = make_coord((H,W), flatten=True, device='cuda').unsqueeze(0)
58
- cell = torch.ones_like(coord)
59
- cell[:,:,0] *= 2/H
60
- cell[:,:,1] *= 2/W
61
- inp_lr = (lr - rgb_mean) / rgb_std
62
-
63
- pred, flag = model(inp_lr, coord=coord, cell=cell, scale=scale, k=0,
64
- pixel_batch_size=300000, adaptive_cluster=True, refinement=True)
65
- flops = get_model_flops(model, inp_lr, coord=coord, cell=cell, scale=scale, k=0,
66
- pixel_batch_size=300000, adaptive_cluster=True, refinement=True)
67
- max_flops = get_model_flops(model, inp_lr, coord=coord, cell=cell, scale=scale, k=-25,
68
- pixel_batch_size=300000, adaptive_cluster=False, refinement=True)
69
- print('flops: {:.1f}G ({:.1f} %) | max_flops: {:.1f}G (100 %)'.format(flops/1e9,
70
- (flops / max_flops)*100, max_flops/1e9))
71
-
72
- pred = pred.transpose(1,2).view(-1,3,H,W)
73
- pred = pred * rgb_std + rgb_mean
74
- pred = tensor2numpy(pred)
75
- Image.fromarray(pred).save(f'output.png')
76
-
77
- flag = flag.view(-1,1,H,W).repeat(1,3,1,1).squeeze(0).detach().cpu()
78
- H,W = pred.shape[:2]
79
- vis_img = np.zeros_like(pred)
80
- vis_img[flag[0] == 0] = np.array([0,255,0])
81
- vis_img[flag[0] == 1] = np.array([255,0,0])
82
- vis_img = vis_img*0.35 + pred*0.65
83
- Image.fromarray(vis_img.astype('uint8')).save('output_vis.png')
84
- ```
85
-
86
- ## Citation
87
- ```
88
- @misc{jeong2024acceleratingimagesuperresolutionnetworks,
89
- title={Accelerating Image Super-Resolution Networks with Pixel-Level Classification},
90
- author={Jinho Jeong and Jinwoo Kim and Younghyun Jo and Seon Joo Kim},
91
- year={2024},
92
- eprint={2407.21448},
93
- archivePrefix={arXiv},
94
- primaryClass={cs.CV},
95
- url={https://arxiv.org/abs/2407.21448},
96
- }
97
- ```
 
1
  ---
2
  tags:
3
+ - pytorch_model_hub_mixin
4
+ - model_hub_mixin
5
  ---
 
 
 
6
 
7
+ This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
8
+ - Library: [More Information Needed]
9
+ - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "classifier_spec": {
3
+ "args": {
4
+ "imnet_spec": {
5
+ "args": {
6
+ "hidden_list": [
7
+ 10,
8
+ 10
9
+ ]
10
+ },
11
+ "name": "mlp"
12
+ }
13
+ },
14
+ "name": "liif-sampler"
15
+ },
16
+ "encoder_spec": {
17
+ "args": {
18
+ "nf": 52,
19
+ "no_upsampling": true
20
+ },
21
+ "name": "carn"
22
+ },
23
+ "heavy_sampler_spec": {
24
+ "args": {
25
+ "imnet_spec": {
26
+ "args": {
27
+ "hidden_list": [
28
+ 74,
29
+ 74,
30
+ 74,
31
+ 74
32
+ ]
33
+ },
34
+ "name": "mlp"
35
+ }
36
+ },
37
+ "name": "liif-sampler"
38
+ },
39
+ "light_sampler_spec": {
40
+ "args": {
41
+ "imnet_spec": {
42
+ "args": {
43
+ "hidden_list": [
44
+ 20,
45
+ 20,
46
+ 20
47
+ ]
48
+ },
49
+ "name": "mlp"
50
+ }
51
+ },
52
+ "name": "liif-sampler"
53
+ }
54
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:120f6168edd5fa6c7d2269527644720a565a57b332aa722c389531e800c70380
3
+ size 691408