Yi Xie commited on
Commit
20b211e
·
1 Parent(s): 0c3b654
LICENSE ADDED
@@ -0,0 +1,202 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
app.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2023 Yi Xie
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import gradio as gr
17
+
18
+ import glob
19
+ import hashlib
20
+ import logging
21
+ import os
22
+ import shutil
23
+ import subprocess
24
+ import sys
25
+ import yaml
26
+
27
+ OUT_DIR = '/tmp'
28
+
29
+ logging.basicConfig(level=logging.INFO)
30
+ logger = logging.getLogger()
31
+
32
+ known_models_yaml = None
33
+ with open('known_models.yaml', 'r') as f:
34
+ known_models_yaml = yaml.load(f.read(), Loader=yaml.Loader)
35
+
36
+ def convert(input_model):
37
+ last_outputs = glob.glob('*.wifm', root_dir=OUT_DIR) + glob.glob('*.mlpackage', root_dir=OUT_DIR)
38
+ for output in last_outputs:
39
+ try:
40
+ if os.path.isfile(OUT_DIR + '/' + output):
41
+ os.remove(OUT_DIR + '/' + output)
42
+ else:
43
+ shutil.rmtree(OUT_DIR + '/' + output)
44
+ except Exception as e:
45
+ logger.error('Failed to remove last output file: ' + str(e))
46
+
47
+ file = input_model.name
48
+ if not file.endswith('.pth'):
49
+ raise gr.Error('Uploaded file is not PyTorch weights.')
50
+ digest = None
51
+ with open(file, 'rb') as f:
52
+ digest = hashlib.sha256(f.read()).hexdigest()
53
+
54
+ for model in known_models_yaml['models']:
55
+ if digest != model['sha256']:
56
+ continue
57
+ name = model['name']
58
+ out_file = OUT_DIR + '/' + name + '.wifm'
59
+ logger.info('Converting model: %s', name)
60
+ command = [
61
+ 'python', 'converter.py',
62
+ '--type', model['type'],
63
+ '--name', name,
64
+ '--scale', str(model['scale']),
65
+ '--out-dir', OUT_DIR,
66
+ '--description', model['description'],
67
+ '--source', model['source'],
68
+ '--author', model['author'],
69
+ '--license', model['license']
70
+ ]
71
+ if 'cuda' in model and model['cuda']:
72
+ command += ['--has-cuda']
73
+ if 'monochrome' in model and model['monochrome']:
74
+ command += ['--monochrome']
75
+ if 'features' in model:
76
+ command += ['--num-features', str(model['features'])]
77
+ if 'blocks' in model:
78
+ command += ['--num-blocks', str(model['blocks'])]
79
+ if 'convs' in model:
80
+ command += ['--num-convs', str(model['convs'])]
81
+ command += [file]
82
+ logger.debug('Command: %s', command)
83
+ process = subprocess.Popen(command, stdout=subprocess.PIPE)
84
+ for c in iter(lambda: process.stdout.read(1), b''):
85
+ sys.stdout.buffer.write(c)
86
+ sys.stdout.flush()
87
+ process.communicate()
88
+ if process.returncode != 0:
89
+ raise gr.Error('converter.py returned non-zero exit code ' + str(process.returncode))
90
+ if not os.path.exists(out_file):
91
+ raise gr.Error('Unknown error')
92
+ return out_file
93
+
94
+ raise gr.Error('Unknown model. Please create an issue in https://github.com/imxieyi/waifu2x-ios-model-converter if it has a supported architecture.')
95
+
96
+ models_string = ''
97
+ for model in known_models_yaml['models']:
98
+ models_string += '- ' + model['file'].split('/')[-1] + '\n'
99
+
100
+ iface = gr.Interface(
101
+ fn=convert,
102
+ inputs='file',
103
+ outputs='file',
104
+ title='Web waifu2x-ios Model Converter',
105
+ description='''
106
+ Please upload the `.pth` model file on the left. After submitting please wait until the output `.wifm` model file appears on the right. Then simply click `Download` to download converted custom model.
107
+ ''',
108
+ article='''
109
+ Supported models (from [upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)):
110
+ {}
111
+
112
+ Project: https://github.com/imxieyi/waifu2x-ios-model-converter
113
+ Report issues: https://github.com/imxieyi/waifu2x-ios-model-converter/issues
114
+ '''.format(models_string),
115
+ )
116
+ iface.launch()
converter.py ADDED
@@ -0,0 +1,265 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ # Copyright 2023 Yi Xie
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import argparse
17
+ import json
18
+ import logging
19
+ import platform
20
+ import os
21
+ import shutil
22
+ import sys
23
+ import zipfile
24
+
25
+ parser = argparse.ArgumentParser(
26
+ prog=os.path.basename(__file__),
27
+ description='Convert a ML model to waifu2x app custom model',
28
+ )
29
+ parser.add_argument('filename')
30
+ required_args = parser.add_argument_group('required')
31
+ required_args.add_argument('--type', choices=['esrgan_old', 'esrgan_old_lite', 'real_esrgan', 'real_esrgan_compact'], required=True, help='Type of the model')
32
+ required_args.add_argument('--name', type=str, required=True, help='Name of the model')
33
+ required_args.add_argument('--scale', type=int, required=True, help='Scale factor of the model')
34
+ required_args.add_argument('--out-dir', type=str, required=True, help='Output directory')
35
+ optional_args = parser.add_argument_group('optional')
36
+ optional_args.add_argument('--monochrome', action='store_true', help='Input model is monochrome (single channel)')
37
+ optional_args.add_argument('--has-cuda', action='store_true', help='Input model contains CUDA object')
38
+ optional_args.add_argument('--num-features', type=int, help='Override number of features for (Real-)ESRGAN model')
39
+ optional_args.add_argument('--num-blocks', type=int, help='Override number of blocks for (Real-)ESRGAN model')
40
+ optional_args.add_argument('--num-convs', type=int, help='Override number of conv layers for Real-ESRGAN Compact model')
41
+ optional_args.add_argument('--input-size', type=int, default=256, help='Input size (both width and height), default to 256')
42
+ optional_args.add_argument('--shrink-size', type=int, default=20, help='Shrink size (applied to all 4 sides on input), default to 20')
43
+ optional_args.add_argument('--description', type=str, required=False, help='Description of the model, supports Markdown')
44
+ optional_args.add_argument('--source', type=str, required=False, help='Source of the model, supports Markdown')
45
+ optional_args.add_argument('--author', type=str, required=False, help='Author of the model, supports Markdown')
46
+ optional_args.add_argument('--license', type=str, required=False, help='License of the model, supports Markdown')
47
+ optional_args.add_argument('--info-md', type=str, required=False, help='Use custom info.md instead of individual flags')
48
+ optional_args.add_argument('--no-delete-mlmodel', action='store_true', help='Don\'t delete the intermediate Core ML model file')
49
+ args = parser.parse_args()
50
+
51
+ logger = logging.getLogger('converter')
52
+ logger.setLevel(logging.INFO)
53
+ handler = logging.StreamHandler(sys.stdout)
54
+ handler.setLevel(logging.INFO)
55
+ formatter = logging.Formatter('%(levelname)s - %(message)s')
56
+ handler.setFormatter(formatter)
57
+ logger.addHandler(handler)
58
+
59
+ if args.input_size % 4 != 0:
60
+ logger.fatal('Input size must be multiple of 4')
61
+ sys.exit(-1)
62
+
63
+ if args.shrink_size < 0:
64
+ logger.fatal('Shrink size must not be < 0')
65
+ sys.exit(-1)
66
+
67
+ if args.input_size - 2 * args.shrink_size < 4:
68
+ logger.fatal('Input size after shrinking is too small')
69
+ sys.exit(-1)
70
+
71
+ os.makedirs(args.out_dir, exist_ok=True)
72
+
73
+ import coremltools as ct
74
+ import torch
75
+
76
+ torch_model = None
77
+ input_tensor = None
78
+ output_tensor = None
79
+
80
+ device = torch.device('cpu')
81
+ if platform.system() == 'Darwin' and torch.backends.mps.is_available():
82
+ device = torch.device('mps')
83
+ logger.info('Using torch device mps')
84
+ elif torch.cuda.is_available():
85
+ device = torch.device('cuda')
86
+ logger.info('Using torch device cuda')
87
+ else:
88
+ logger.info('Using torch device cpu, please be patient')
89
+
90
+ logger.info('Creating model architecture')
91
+ channels = 3
92
+ if args.monochrome:
93
+ channels = 1
94
+
95
+ num_features = 64
96
+ num_blocks = 23
97
+ num_convs = 16
98
+
99
+ if args.type == 'esrgan_old_lite':
100
+ num_features = 32
101
+ num_blocks = 12
102
+
103
+ if args.num_features is not None:
104
+ num_features = args.num_features
105
+ if args.num_blocks is not None:
106
+ num_blocks = args.num_blocks
107
+ if args.num_convs is not None:
108
+ num_convs = args.num_convs
109
+
110
+ if args.type == 'esrgan_old' or args.type == 'esrgan_old_lite':
111
+ from esrgan_old import architecture
112
+ torch_model = architecture.RRDB_Net(
113
+ channels, channels, num_features, num_blocks, gc=32, upscale=args.scale, norm_type=None,
114
+ act_type='leakyrelu', mode='CNA', res_scale=1, upsample_mode='upconv')
115
+ elif args.type == 'real_esrgan':
116
+ from basicsr.archs.rrdbnet_arch import RRDBNet
117
+ torch_model = RRDBNet(num_in_ch=channels, num_out_ch=channels, num_feat=num_features, num_block=num_blocks, num_grow_ch=32, scale=args.scale)
118
+ elif args.type == 'real_esrgan_compact':
119
+ from basicsr.archs.srvgg_arch import SRVGGNetCompact
120
+ torch_model = SRVGGNetCompact(num_in_ch=channels, num_out_ch=channels, num_feat=num_features, num_conv=num_convs, upscale=args.scale, act_type='prelu')
121
+ else:
122
+ logger.fatal('Unknown model type: %s', args.type)
123
+ sys.exit(-1)
124
+
125
+ logger.info('Loading weights')
126
+ loadnet = None
127
+ if args.has_cuda:
128
+ loadnet = torch.load(args.filename, map_location=device)
129
+ else:
130
+ loadnet = torch.load(args.filename)
131
+
132
+ if 'params_ema' in loadnet:
133
+ loadnet = loadnet['params_ema']
134
+ elif 'params' in loadnet:
135
+ loadnet = loadnet['params']
136
+ torch_model.load_state_dict(loadnet, strict=True)
137
+
138
+ if args.monochrome:
139
+ from torch import nn
140
+ class MonochromeWrapper(nn.Module):
141
+ def __init__(self, model: nn.Module):
142
+ super(MonochromeWrapper, self).__init__()
143
+ self.model = model
144
+ def forward(self, x: torch.Tensor):
145
+ x = torch.mean(x, dim=1, keepdim=True)
146
+ x = self.model(x)
147
+ x = x.repeat([1, 3, 1, 1])
148
+ return x
149
+ torch_model = MonochromeWrapper(torch_model)
150
+
151
+ logger.info('Tracing model, will take a long time and a lot of RAM')
152
+ torch_model.eval()
153
+ torch_model = torch_model.to(device)
154
+ example_input = torch.zeros(1, 3, 16, 16)
155
+ example_input = example_input.to(device)
156
+ traced_model = torch.jit.trace(torch_model, example_input)
157
+ out = traced_model(example_input)
158
+ logger.info('Successfully traced model')
159
+
160
+ input_size = example_input.shape[-1]
161
+ output_size = out.shape[-1]
162
+ if args.scale != output_size / input_size:
163
+ logger.fatal('Expected output scale to be %d, but is actually %.2f', args.scale, output_size / input_size)
164
+ sys.exit(-1)
165
+
166
+ logger.info('Converting to Core ML')
167
+ input_shape = [1, 3, args.input_size, args.input_size]
168
+ output_size = args.input_size * args.scale
169
+ output_shape = [1, 3, output_size, output_size]
170
+ model = ct.convert(
171
+ traced_model,
172
+ convert_to="mlprogram",
173
+ inputs=[ct.TensorType(shape=input_shape)]
174
+ )
175
+ model_name = args.filename.split('/')[-1].split('.')[0]
176
+ mlmodel_file = args.out_dir + '/' + model_name + '.mlpackage'
177
+ model.save(mlmodel_file)
178
+
179
+ logger.info('Packaging model')
180
+ spec = model.get_spec()
181
+ input_name = spec.description.input[0].name
182
+ output_name = spec.description.output[0].name
183
+ logger.debug('Model input name: %s, size: %s', input_name, args.input_size)
184
+ output_size_shrinked = (args.input_size - 2 * args.shrink_size) * args.scale
185
+ logger.debug('Model output name: %s, size: %s, after shrinking: %s', output_name, output_size, output_size_shrinked)
186
+
187
+ manifest = {
188
+ "version": 1,
189
+ "name": args.name,
190
+ "type": "coreml",
191
+ "subModels": {
192
+ "main": {
193
+ "file": mlmodel_file,
194
+ "inputName": input_name,
195
+ "outputName": output_name
196
+ }
197
+ },
198
+ "dataFormat": "nchw",
199
+ "inputShape": input_shape,
200
+ "shrinkSize": args.shrink_size,
201
+ "scale": args.scale,
202
+ "alphaMode": "sameAsMain"
203
+ }
204
+
205
+ info_md = '''
206
+ {}
207
+ ===
208
+ Converted by [waifu2x-ios-model-converter](https://github.com/imxieyi/waifu2x-ios-model-converter).
209
+
210
+ '''.format(args.name)
211
+
212
+ if args.description is not None:
213
+ info_md += '''
214
+ ## Description
215
+ {}
216
+
217
+ '''.format(args.description)
218
+
219
+ if args.author is not None:
220
+ info_md += '''
221
+ ## Author
222
+ {}
223
+
224
+ '''.format(args.author)
225
+
226
+ if args.source is not None:
227
+ info_md += '''
228
+ ## Source
229
+ {}
230
+
231
+ '''.format(args.source)
232
+
233
+ if args.license is not None:
234
+ info_md += '''
235
+ ## License
236
+ {}
237
+
238
+ '''.format(args.license)
239
+
240
+ if len(info_md) > 1024 * 1024:
241
+ logger.fatal('Model info.md too large. Try to reduce license file size, etc.')
242
+ sys.exit(-1)
243
+
244
+ def add_folder_to_zip(folder, zipfile):
245
+ for folderName, subfolders, filenames in os.walk(folder):
246
+ for filename in filenames:
247
+ filePath = os.path.join(folderName, filename)
248
+ zipfile.write(filePath, filePath)
249
+
250
+ zip_file = args.out_dir + '/' + args.name + '.wifm'
251
+ with zipfile.ZipFile(zip_file, 'w', compression=zipfile.ZIP_DEFLATED) as modelzip:
252
+ modelzip.writestr('manifest.json', json.dumps(manifest))
253
+ modelzip.writestr('info.md', info_md)
254
+ if os.path.isfile(mlmodel_file):
255
+ modelzip.write(mlmodel_file)
256
+ else:
257
+ add_folder_to_zip(mlmodel_file, modelzip)
258
+
259
+ if not args.no_delete_mlmodel:
260
+ if os.path.isfile(mlmodel_file):
261
+ os.remove(mlmodel_file)
262
+ else:
263
+ shutil.rmtree(mlmodel_file)
264
+
265
+ logger.info('Successfully converted model: %s', zip_file)
esrgan_old/LICENSE ADDED
@@ -0,0 +1,201 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
esrgan_old/README.md ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ESRGAN (Enhanced SRGAN) [[Paper]](https://arxiv.org/abs/1809.00219) [[BasicSR]](https://github.com/xinntao/BasicSR)
2
+ ## :smiley: Training codes are in [BasicSR](https://github.com/xinntao/BasicSR) repo.
3
+ ### Enhanced Super-Resolution Generative Adversarial Networks
4
+ By Xintao Wang, [Ke Yu](https://yuke93.github.io/), Shixiang Wu, [Jinjin Gu](http://www.jasongt.com/), Yihao Liu, [Chao Dong](https://scholar.google.com.hk/citations?user=OSDCB0UAAAAJ&hl=en), [Yu Qiao](http://mmlab.siat.ac.cn/yuqiao/), [Chen Change Loy](http://personal.ie.cuhk.edu.hk/~ccloy/)
5
+
6
+ This repo only provides simple testing codes, pretrained models and the network strategy demo.
7
+
8
+ ### **For full training and testing codes, please refer to [BasicSR](https://github.com/xinntao/BasicSR).**
9
+
10
+ We won the first place in [PIRM2018-SR competition](https://www.pirm2018.org/PIRM-SR.html) (region 3) and got the best perceptual index.
11
+ The paper is accepted to [ECCV2018 PIRM Workshop](https://pirm2018.org/).
12
+
13
+ :triangular_flag_on_post: Add [Frequently Asked Questions](https://github.com/xinntao/ESRGAN/blob/master/QA.md).
14
+
15
+ > For instance,
16
+ > 1. How to reproduce your results in the PIRM18-SR Challenge (with low perceptual index)?
17
+ > 2. How do you get the perceptual index in your ESRGAN paper?
18
+
19
+ #### BibTeX
20
+ <!--
21
+ @article{wang2018esrgan,
22
+ author={Wang, Xintao and Yu, Ke and Wu, Shixiang and Gu, Jinjin and Liu, Yihao and Dong, Chao and Loy, Chen Change and Qiao, Yu and Tang, Xiaoou},
23
+ title={ESRGAN: Enhanced super-resolution generative adversarial networks},
24
+ journal={arXiv preprint arXiv:1809.00219},
25
+ year={2018}
26
+ }
27
+ -->
28
+ @InProceedings{wang2018esrgan,
29
+ author = {Wang, Xintao and Yu, Ke and Wu, Shixiang and Gu, Jinjin and Liu, Yihao and Dong, Chao and Qiao, Yu and Loy, Chen Change},
30
+ title = {ESRGAN: Enhanced super-resolution generative adversarial networks},
31
+ booktitle = {The European Conference on Computer Vision Workshops (ECCVW)},
32
+ month = {September},
33
+ year = {2018}
34
+ }
35
+
36
+ <p align="center">
37
+ <img src="figures/baboon.jpg">
38
+ </p>
39
+
40
+ The **RRDB_PSNR** PSNR_oriented model trained with DF2K dataset (a merged dataset with [DIV2K](https://data.vision.ee.ethz.ch/cvl/DIV2K/) and [Flickr2K](http://cv.snu.ac.kr/research/EDSR/Flickr2K.tar) (proposed in [EDSR](https://github.com/LimBee/NTIRE2017))) is also able to achive high PSNR performance.
41
+
42
+ | <sub>Method</sub> | <sub>Training dataset</sub> | <sub>Set5</sub> | <sub>Set14</sub> | <sub>BSD100</sub> | <sub>Urban100</sub> | <sub>Manga109</sub> |
43
+ |:---:|:---:|:---:|:---:|:---:|:---:|:---:|
44
+ | <sub>[SRCNN](http://mmlab.ie.cuhk.edu.hk/projects/SRCNN.html)</sub>| <sub>291</sub>| <sub>30.48/0.8628</sub> |<sub>27.50/0.7513</sub>|<sub>26.90/0.7101</sub>|<sub>24.52/0.7221</sub>|<sub>27.58/0.8555</sub>|
45
+ | <sub>[EDSR](https://github.com/thstkdgus35/EDSR-PyTorch)</sub> | <sub>DIV2K</sub> | <sub>32.46/0.8968</sub> | <sub>28.80/0.7876</sub> | <sub>27.71/0.7420</sub> | <sub>26.64/0.8033</sub> | <sub>31.02/0.9148</sub> |
46
+ | <sub>[RCAN](https://github.com/yulunzhang/RCAN)</sub> | <sub>DIV2K</sub> | <sub>32.63/0.9002</sub> | <sub>28.87/0.7889</sub> | <sub>27.77/0.7436</sub> | <sub>26.82/ 0.8087</sub>| <sub>31.22/ 0.9173</sub>|
47
+ |<sub>RRDB(ours)</sub>| <sub>DF2K</sub>| <sub>**32.73/0.9011**</sub> |<sub>**28.99/0.7917**</sub> |<sub>**27.85/0.7455**</sub> |<sub>**27.03/0.8153**</sub> |<sub>**31.66/0.9196**</sub>|
48
+
49
+ ## Quick Test
50
+ #### Dependencies
51
+ - Python 3
52
+ - [PyTorch >= 0.4](https://pytorch.org/) (CUDA version >= 7.5 if installing with CUDA. [More details](https://pytorch.org/get-started/previous-versions/))
53
+ - Python packages: `pip install numpy opencv-python`
54
+
55
+ ### Test models
56
+ 1. Clone this github repo.
57
+ ```
58
+ git clone https://github.com/xinntao/ESRGAN
59
+ cd ESRGAN
60
+ ```
61
+ 2. Place your own **low-resolution images** in `./LR` folder. (There are two sample images - baboon and comic).
62
+ 3. Download pretrained models from [Google Drive](https://drive.google.com/drive/u/0/folders/17VYV_SoZZesU6mbxz2dMAIccSSlqLecY) or [Baidu Drive](https://pan.baidu.com/s/1-Lh6ma-wXzfH8NqeBtPaFQ). Place the models in `./models`. We provide two models with high perceptual quality and high PSNR performance (see [model list](https://github.com/xinntao/ESRGAN/tree/master/models)).
63
+ 4. Run test. We provide ESRGAN model and RRDB_PSNR model.
64
+ ```
65
+ python test.py models/RRDB_ESRGAN_x4.pth
66
+ python test.py models/RRDB_PSNR_x4.pth
67
+ ```
68
+ 5. The results are in `./results` folder.
69
+ ### Network interpolation demo
70
+ You can interpolate the RRDB_ESRGAN and RRDB_PSNR models with alpha in [0, 1].
71
+
72
+ 1. Run `python net_interp.py 0.8`, where *0.8* is the interpolation parameter and you can change it to any value in [0,1].
73
+ 2. Run `python test.py models/interp_08.pth`, where *models/interp_08.pth* is the model path.
74
+
75
+ <p align="center">
76
+ <img height="400" src="figures/43074.gif">
77
+ </p>
78
+
79
+ ## Perceptual-driven SR Results
80
+
81
+ You can download all the resutls from [Google Drive](https://drive.google.com/drive/folders/1iaM-c6EgT1FNoJAOKmDrK7YhEhtlKcLx?usp=sharing). (:heavy_check_mark: included; :heavy_minus_sign: not included; :o: TODO)
82
+
83
+ HR images can be downloaed from [BasicSR-Datasets](https://github.com/xinntao/BasicSR#datasets).
84
+
85
+ | Datasets |LR | [*ESRGAN*](https://arxiv.org/abs/1809.00219) | [SRGAN](https://arxiv.org/abs/1609.04802) | [EnhanceNet](http://openaccess.thecvf.com/content_ICCV_2017/papers/Sajjadi_EnhanceNet_Single_Image_ICCV_2017_paper.pdf) | [CX](https://arxiv.org/abs/1803.04626) |
86
+ |:---:|:---:|:---:|:---:|:---:|:---:|
87
+ | Set5 |:heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:| :o: |
88
+ | Set14 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:| :o: |
89
+ | BSDS100 | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:| :o: |
90
+ | [PIRM](https://pirm.github.io/) <br><sup>(val, test)</sup> | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: | :heavy_check_mark:| :heavy_check_mark: |
91
+ | [OST300](https://arxiv.org/pdf/1804.02815.pdf) |:heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: | :heavy_check_mark:| :o: |
92
+ | urban100 | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: | :heavy_check_mark:| :o: |
93
+ | [DIV2K](https://data.vision.ee.ethz.ch/cvl/DIV2K/) <br><sup>(val, test)</sup> | :heavy_check_mark: | :heavy_check_mark: | :heavy_minus_sign: | :heavy_check_mark:| :o: |
94
+
95
+ ## ESRGAN
96
+ We improve the [SRGAN](https://arxiv.org/abs/1609.04802) from three aspects:
97
+ 1. adopt a deeper model using Residual-in-Residual Dense Block (RRDB) without batch normalization layers.
98
+ 2. employ [Relativistic average GAN](https://ajolicoeur.wordpress.com/relativisticgan/) instead of the vanilla GAN.
99
+ 3. improve the perceptual loss by using the features before activation.
100
+
101
+ In contrast to SRGAN, which claimed that **deeper models are increasingly difficult to train**, our deeper ESRGAN model shows its superior performance with easy training.
102
+
103
+ <p align="center">
104
+ <img height="120" src="figures/architecture.jpg">
105
+ </p>
106
+ <p align="center">
107
+ <img height="180" src="figures/RRDB.png">
108
+ </p>
109
+
110
+ ## Network Interpolation
111
+ We propose the **network interpolation strategy** to balance the visual quality and PSNR.
112
+
113
+ <p align="center">
114
+ <img height="500" src="figures/net_interp.jpg">
115
+ </p>
116
+
117
+ We show the smooth animation with the interpolation parameters changing from 0 to 1.
118
+ Interestingly, it is observed that the network interpolation strategy provides a smooth control of the RRDB_PSNR model and the fine-tuned ESRGAN model.
119
+
120
+ <p align="center">
121
+ <img height="480" src="figures/81.gif">
122
+ &nbsp &nbsp
123
+ <img height="480" src="figures/102061.gif">
124
+ </p>
125
+
126
+ ## Qualitative Results
127
+ PSNR (evaluated on the Y channel) and the perceptual index used in the PIRM-SR challenge are also provided for reference.
128
+
129
+ <p align="center">
130
+ <img src="figures/qualitative_cmp_01.jpg">
131
+ </p>
132
+ <p align="center">
133
+ <img src="figures/qualitative_cmp_02.jpg">
134
+ </p>
135
+ <p align="center">
136
+ <img src="figures/qualitative_cmp_03.jpg">
137
+ </p>
138
+ <p align="center">
139
+ <img src="figures/qualitative_cmp_04.jpg">
140
+ </p>
141
+
142
+ ## Ablation Study
143
+ Overall visual comparisons for showing the effects of each component in
144
+ ESRGAN. Each column represents a model with its configurations in the top.
145
+ The red sign indicates the main improvement compared with the previous model.
146
+ <p align="center">
147
+ <img src="figures/abalation_study.png">
148
+ </p>
149
+
150
+ ## BN artifacts
151
+ We empirically observe that BN layers tend to bring artifacts. These artifacts,
152
+ namely BN artifacts, occasionally appear among iterations and different settings,
153
+ violating the needs for a stable performance over training. We find that
154
+ the network depth, BN position, training dataset and training loss
155
+ have impact on the occurrence of BN artifacts.
156
+ <p align="center">
157
+ <img src="figures/BN_artifacts.jpg">
158
+ </p>
159
+
160
+ ## Useful techniques to train a very deep network
161
+ We find that residual scaling and smaller initialization can help to train a very deep network. More details are in the Supplementary File attached in our [paper](https://arxiv.org/abs/1809.00219).
162
+
163
+ <p align="center">
164
+ <img height="250" src="figures/train_deeper_neta.png">
165
+ <img height="250" src="figures/train_deeper_netb.png">
166
+ </p>
167
+
168
+ ## The influence of training patch size
169
+ We observe that training a deeper network benefits from a larger patch size. Moreover, the deeper model achieves more improvement (∼0.12dB) than the shallower one (∼0.04dB) since larger model capacity is capable of taking full advantage of
170
+ larger training patch size. (Evaluated on Set5 dataset with RGB channels.)
171
+ <p align="center">
172
+ <img height="250" src="figures/patch_a.png">
173
+ <img height="250" src="figures/patch_b.png">
174
+ </p>
esrgan_old/architecture.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import torch
3
+ import torch.nn as nn
4
+ from . import block as B
5
+
6
+
7
+ class RRDB_Net(nn.Module):
8
+ def __init__(self, in_nc, out_nc, nf, nb, gc=32, upscale=4, norm_type=None, act_type='leakyrelu', \
9
+ mode='CNA', res_scale=1, upsample_mode='upconv'):
10
+ super(RRDB_Net, self).__init__()
11
+ n_upscale = int(math.log(upscale, 2))
12
+ if upscale == 3:
13
+ n_upscale = 1
14
+
15
+ fea_conv = B.conv_block(in_nc, nf, kernel_size=3, norm_type=None, act_type=None)
16
+ rb_blocks = [B.RRDB(nf, kernel_size=3, gc=32, stride=1, bias=True, pad_type='zero', \
17
+ norm_type=norm_type, act_type=act_type, mode='CNA') for _ in range(nb)]
18
+ LR_conv = B.conv_block(nf, nf, kernel_size=3, norm_type=norm_type, act_type=None, mode=mode)
19
+
20
+ if upsample_mode == 'upconv':
21
+ upsample_block = B.upconv_blcok
22
+ elif upsample_mode == 'pixelshuffle':
23
+ upsample_block = B.pixelshuffle_block
24
+ else:
25
+ raise NotImplementedError('upsample mode [%s] is not found' % upsample_mode)
26
+ if upscale == 3:
27
+ upsampler = upsample_block(nf, nf, 3, act_type=act_type)
28
+ else:
29
+ upsampler = [upsample_block(nf, nf, act_type=act_type) for _ in range(n_upscale)]
30
+ HR_conv0 = B.conv_block(nf, nf, kernel_size=3, norm_type=None, act_type=act_type)
31
+ HR_conv1 = B.conv_block(nf, out_nc, kernel_size=3, norm_type=None, act_type=None)
32
+
33
+ self.model = B.sequential(fea_conv, B.ShortcutBlock(B.sequential(*rb_blocks, LR_conv)),\
34
+ *upsampler, HR_conv0, HR_conv1)
35
+
36
+ def forward(self, x):
37
+ x = self.model(x)
38
+ return x
esrgan_old/block.py ADDED
@@ -0,0 +1,261 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections import OrderedDict
2
+ import torch
3
+ import torch.nn as nn
4
+
5
+ ####################
6
+ # Basic blocks
7
+ ####################
8
+
9
+
10
+ def act(act_type, inplace=True, neg_slope=0.2, n_prelu=1):
11
+ # helper selecting activation
12
+ # neg_slope: for leakyrelu and init of prelu
13
+ # n_prelu: for p_relu num_parameters
14
+ act_type = act_type.lower()
15
+ if act_type == 'relu':
16
+ layer = nn.ReLU(inplace)
17
+ elif act_type == 'leakyrelu':
18
+ layer = nn.LeakyReLU(neg_slope, inplace)
19
+ elif act_type == 'prelu':
20
+ layer = nn.PReLU(num_parameters=n_prelu, init=neg_slope)
21
+ else:
22
+ raise NotImplementedError('activation layer [%s] is not found' % act_type)
23
+ return layer
24
+
25
+
26
+ def norm(norm_type, nc):
27
+ # helper selecting normalization layer
28
+ norm_type = norm_type.lower()
29
+ if norm_type == 'batch':
30
+ layer = nn.BatchNorm2d(nc, affine=True)
31
+ elif norm_type == 'instance':
32
+ layer = nn.InstanceNorm2d(nc, affine=False)
33
+ else:
34
+ raise NotImplementedError('normalization layer [%s] is not found' % norm_type)
35
+ return layer
36
+
37
+
38
+ def pad(pad_type, padding):
39
+ # helper selecting padding layer
40
+ # if padding is 'zero', do by conv layers
41
+ pad_type = pad_type.lower()
42
+ if padding == 0:
43
+ return None
44
+ if pad_type == 'reflect':
45
+ layer = nn.ReflectionPad2d(padding)
46
+ elif pad_type == 'replicate':
47
+ layer = nn.ReplicationPad2d(padding)
48
+ else:
49
+ raise NotImplementedError('padding layer [%s] is not implemented' % pad_type)
50
+ return layer
51
+
52
+
53
+ def get_valid_padding(kernel_size, dilation):
54
+ kernel_size = kernel_size + (kernel_size - 1) * (dilation - 1)
55
+ padding = (kernel_size - 1) // 2
56
+ return padding
57
+
58
+
59
+ class ConcatBlock(nn.Module):
60
+ # Concat the output of a submodule to its input
61
+ def __init__(self, submodule):
62
+ super(ConcatBlock, self).__init__()
63
+ self.sub = submodule
64
+
65
+ def forward(self, x):
66
+ output = torch.cat((x, self.sub(x)), dim=1)
67
+ return output
68
+
69
+ def __repr__(self):
70
+ tmpstr = 'Identity .. \n|'
71
+ modstr = self.sub.__repr__().replace('\n', '\n|')
72
+ tmpstr = tmpstr + modstr
73
+ return tmpstr
74
+
75
+
76
+ class ShortcutBlock(nn.Module):
77
+ #Elementwise sum the output of a submodule to its input
78
+ def __init__(self, submodule):
79
+ super(ShortcutBlock, self).__init__()
80
+ self.sub = submodule
81
+
82
+ def forward(self, x):
83
+ output = x + self.sub(x)
84
+ return output
85
+
86
+ def __repr__(self):
87
+ tmpstr = 'Identity + \n|'
88
+ modstr = self.sub.__repr__().replace('\n', '\n|')
89
+ tmpstr = tmpstr + modstr
90
+ return tmpstr
91
+
92
+
93
+ def sequential(*args):
94
+ # Flatten Sequential. It unwraps nn.Sequential.
95
+ if len(args) == 1:
96
+ if isinstance(args[0], OrderedDict):
97
+ raise NotImplementedError('sequential does not support OrderedDict input.')
98
+ return args[0] # No sequential is needed.
99
+ modules = []
100
+ for module in args:
101
+ if isinstance(module, nn.Sequential):
102
+ for submodule in module.children():
103
+ modules.append(submodule)
104
+ elif isinstance(module, nn.Module):
105
+ modules.append(module)
106
+ return nn.Sequential(*modules)
107
+
108
+
109
+ def conv_block(in_nc, out_nc, kernel_size, stride=1, dilation=1, groups=1, bias=True,
110
+ pad_type='zero', norm_type=None, act_type='relu', mode='CNA'):
111
+ """
112
+ Conv layer with padding, normalization, activation
113
+ mode: CNA --> Conv -> Norm -> Act
114
+ NAC --> Norm -> Act --> Conv (Identity Mappings in Deep Residual Networks, ECCV16)
115
+ """
116
+ assert mode in ['CNA', 'NAC', 'CNAC'], 'Wong conv mode [%s]' % mode
117
+ padding = get_valid_padding(kernel_size, dilation)
118
+ p = pad(pad_type, padding) if pad_type and pad_type != 'zero' else None
119
+ padding = padding if pad_type == 'zero' else 0
120
+
121
+ c = nn.Conv2d(in_nc, out_nc, kernel_size=kernel_size, stride=stride, padding=padding, \
122
+ dilation=dilation, bias=bias, groups=groups)
123
+ a = act(act_type) if act_type else None
124
+ if 'CNA' in mode:
125
+ n = norm(norm_type, out_nc) if norm_type else None
126
+ return sequential(p, c, n, a)
127
+ elif mode == 'NAC':
128
+ if norm_type is None and act_type is not None:
129
+ a = act(act_type, inplace=False)
130
+ # Important!
131
+ # input----ReLU(inplace)----Conv--+----output
132
+ # |________________________|
133
+ # inplace ReLU will modify the input, therefore wrong output
134
+ n = norm(norm_type, in_nc) if norm_type else None
135
+ return sequential(n, a, p, c)
136
+
137
+
138
+ ####################
139
+ # Useful blocks
140
+ ####################
141
+
142
+
143
+ class ResNetBlock(nn.Module):
144
+ """
145
+ ResNet Block, 3-3 style
146
+ with extra residual scaling used in EDSR
147
+ (Enhanced Deep Residual Networks for Single Image Super-Resolution, CVPRW 17)
148
+ """
149
+
150
+ def __init__(self, in_nc, mid_nc, out_nc, kernel_size=3, stride=1, dilation=1, groups=1, \
151
+ bias=True, pad_type='zero', norm_type=None, act_type='relu', mode='CNA', res_scale=1):
152
+ super(ResNetBlock, self).__init__()
153
+ conv0 = conv_block(in_nc, mid_nc, kernel_size, stride, dilation, groups, bias, pad_type, \
154
+ norm_type, act_type, mode)
155
+ if mode == 'CNA':
156
+ act_type = None
157
+ if mode == 'CNAC': # Residual path: |-CNAC-|
158
+ act_type = None
159
+ norm_type = None
160
+ conv1 = conv_block(mid_nc, out_nc, kernel_size, stride, dilation, groups, bias, pad_type, \
161
+ norm_type, act_type, mode)
162
+ # if in_nc != out_nc:
163
+ # self.project = conv_block(in_nc, out_nc, 1, stride, dilation, 1, bias, pad_type, \
164
+ # None, None)
165
+ # print('Need a projecter in ResNetBlock.')
166
+ # else:
167
+ # self.project = lambda x:x
168
+ self.res = sequential(conv0, conv1)
169
+ self.res_scale = res_scale
170
+
171
+ def forward(self, x):
172
+ res = self.res(x).mul(self.res_scale)
173
+ return x + res
174
+
175
+
176
+ class ResidualDenseBlock_5C(nn.Module):
177
+ """
178
+ Residual Dense Block
179
+ style: 5 convs
180
+ The core module of paper: (Residual Dense Network for Image Super-Resolution, CVPR 18)
181
+ """
182
+
183
+ def __init__(self, nc, kernel_size=3, gc=32, stride=1, bias=True, pad_type='zero', \
184
+ norm_type=None, act_type='leakyrelu', mode='CNA'):
185
+ super(ResidualDenseBlock_5C, self).__init__()
186
+ # gc: growth channel, i.e. intermediate channels
187
+ self.conv1 = conv_block(nc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
188
+ norm_type=norm_type, act_type=act_type, mode=mode)
189
+ self.conv2 = conv_block(nc+gc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
190
+ norm_type=norm_type, act_type=act_type, mode=mode)
191
+ self.conv3 = conv_block(nc+2*gc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
192
+ norm_type=norm_type, act_type=act_type, mode=mode)
193
+ self.conv4 = conv_block(nc+3*gc, gc, kernel_size, stride, bias=bias, pad_type=pad_type, \
194
+ norm_type=norm_type, act_type=act_type, mode=mode)
195
+ if mode == 'CNA':
196
+ last_act = None
197
+ else:
198
+ last_act = act_type
199
+ self.conv5 = conv_block(nc+4*gc, nc, 3, stride, bias=bias, pad_type=pad_type, \
200
+ norm_type=norm_type, act_type=last_act, mode=mode)
201
+
202
+ def forward(self, x):
203
+ x1 = self.conv1(x)
204
+ x2 = self.conv2(torch.cat((x, x1), 1))
205
+ x3 = self.conv3(torch.cat((x, x1, x2), 1))
206
+ x4 = self.conv4(torch.cat((x, x1, x2, x3), 1))
207
+ x5 = self.conv5(torch.cat((x, x1, x2, x3, x4), 1))
208
+ return x5.mul(0.2) + x
209
+
210
+
211
+ class RRDB(nn.Module):
212
+ """
213
+ Residual in Residual Dense Block
214
+ """
215
+
216
+ def __init__(self, nc, kernel_size=3, gc=32, stride=1, bias=True, pad_type='zero', \
217
+ norm_type=None, act_type='leakyrelu', mode='CNA'):
218
+ super(RRDB, self).__init__()
219
+ self.RDB1 = ResidualDenseBlock_5C(nc, kernel_size, gc, stride, bias, pad_type, \
220
+ norm_type, act_type, mode)
221
+ self.RDB2 = ResidualDenseBlock_5C(nc, kernel_size, gc, stride, bias, pad_type, \
222
+ norm_type, act_type, mode)
223
+ self.RDB3 = ResidualDenseBlock_5C(nc, kernel_size, gc, stride, bias, pad_type, \
224
+ norm_type, act_type, mode)
225
+
226
+ def forward(self, x):
227
+ out = self.RDB1(x)
228
+ out = self.RDB2(out)
229
+ out = self.RDB3(out)
230
+ return out.mul(0.2) + x
231
+
232
+
233
+ ####################
234
+ # Upsampler
235
+ ####################
236
+
237
+
238
+ def pixelshuffle_block(in_nc, out_nc, upscale_factor=2, kernel_size=3, stride=1, bias=True,
239
+ pad_type='zero', norm_type=None, act_type='relu'):
240
+ """
241
+ Pixel shuffle layer
242
+ (Real-Time Single Image and Video Super-Resolution Using an Efficient Sub-Pixel Convolutional
243
+ Neural Network, CVPR17)
244
+ """
245
+ conv = conv_block(in_nc, out_nc * (upscale_factor ** 2), kernel_size, stride, bias=bias,
246
+ pad_type=pad_type, norm_type=None, act_type=None)
247
+ pixel_shuffle = nn.PixelShuffle(upscale_factor)
248
+
249
+ n = norm(norm_type, out_nc) if norm_type else None
250
+ a = act(act_type) if act_type else None
251
+ return sequential(conv, pixel_shuffle, n, a)
252
+
253
+
254
+ def upconv_blcok(in_nc, out_nc, upscale_factor=2, kernel_size=3, stride=1, bias=True,
255
+ pad_type='zero', norm_type=None, act_type='relu', mode='nearest'):
256
+ # Up conv
257
+ # described in https://distill.pub/2016/deconv-checkerboard/
258
+ upsample = nn.Upsample(scale_factor=upscale_factor, mode=mode)
259
+ conv = conv_block(in_nc, out_nc, kernel_size, stride, bias=bias,
260
+ pad_type=pad_type, norm_type=norm_type, act_type=act_type)
261
+ return sequential(upsample, conv)
esrgan_old/net_interp.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ import torch
3
+ from collections import OrderedDict
4
+
5
+ alpha = float(sys.argv[1])
6
+
7
+ net_PSNR_path = './models/RRDB_PSNR_x4.pth'
8
+ net_ESRGAN_path = './models/RRDB_ESRGAN_x4.pth'
9
+ net_interp_path = './models/interp_{:02d}.pth'.format(int(alpha*10))
10
+
11
+ net_PSNR = torch.load(net_PSNR_path)
12
+ net_ESRGAN = torch.load(net_ESRGAN_path)
13
+ net_interp = OrderedDict()
14
+
15
+ print('Interpolating with alpha = ', alpha)
16
+
17
+ for k, v_PSNR in net_PSNR.items():
18
+ v_ESRGAN = net_ESRGAN[k]
19
+ net_interp[k] = (1 - alpha) * v_PSNR + alpha * v_ESRGAN
20
+
21
+ torch.save(net_interp, net_interp_path)
known_models.yaml ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ models:
2
+ - name: "AnimeSharp 4x"
3
+ type: esrgan_old
4
+ file: "./torch_models/4x-AnimeSharp.pth"
5
+ sha256: e7a7de2dafd7331c1992862bbbcd9e9712a9f9f8e6303f0aaa59b4341d359bab
6
+ scale: 4
7
+ description: "Anime or Text"
8
+ author: "[Kim2091](https://upscale.wiki/wiki/User:Kim2091)"
9
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
10
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
11
+ - name: "AnimeSharp Lite 4x"
12
+ type: esrgan_old_lite
13
+ file: "./torch_models/4x-AnimeSharp-lite.pth"
14
+ sha256: a0a224521dcc547768e8442e83b68f98f485b3cbcc8bd207a6284fff6636329c
15
+ scale: 4
16
+ description: "Anime"
17
+ author: "[Kim2091](https://upscale.wiki/wiki/User:Kim2091)"
18
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
19
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
20
+ - name: "UltraSharp 4x"
21
+ type: esrgan_old
22
+ file: "./torch_models/4x-UltraSharp.pth"
23
+ sha256: a5812231fc936b42af08a5edba784195495d303d5b3248c24489ef0c4021fe01
24
+ scale: 4
25
+ description: "Universal Upscaler"
26
+ author: "[Kim2091](https://upscale.wiki/wiki/User:Kim2091)"
27
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
28
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
29
+ - name: "NMKD Siax (\"CX\") 4x"
30
+ type: esrgan_old
31
+ file: "./torch_models/4x_NMKD-Siax_200k.pth"
32
+ sha256: 560424d9f68625713fc47e9e7289a98aabe1d744e1cd6a9ae5a35e9957fd127e
33
+ scale: 4
34
+ description: "Universal upscaler for clean and slightly compressed images"
35
+ author: "[Nmkd](https://upscale.wiki/wiki/User:Nmkd)"
36
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
37
+ license: "[WTFPL](http://www.wtfpl.net/)"
38
+ - name: "NMKD Jaywreck3 Lite"
39
+ type: esrgan_old_lite
40
+ file: "./torch_models/1x_NMKD-Jaywreck3-Lite_320k.pth"
41
+ sha256: 3b2654a3bfa6e07bdebde48414d69b89ee3a1d1516ff9b26c3f4c6ee14f7d3f0
42
+ scale: 1
43
+ description: "Restore JPEG compression"
44
+ author: "[Nmkd](https://upscale.wiki/wiki/User:Nmkd)"
45
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
46
+ license: "[WTFPL](http://www.wtfpl.net/)"
47
+ - name: "NMKD Jaywreck3 Soft Lite"
48
+ type: esrgan_old_lite
49
+ file: "./torch_models/1x_NMKD-Jaywreck3-Soft-Lite_320k.pth"
50
+ sha256: bbd1b6e9002ad9cbb4c5049850a361e110b8ed0ae22f5ed0fb49ddf5a6951f53
51
+ scale: 1
52
+ description: "Restore JPEG compression"
53
+ author: "[Nmkd](https://upscale.wiki/wiki/User:Nmkd)"
54
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
55
+ license: "[WTFPL](http://www.wtfpl.net/)"
56
+ - name: "DeGif 2x"
57
+ type: esrgan_old
58
+ file: "./torch_models/2x_NMKD-DeGIF_210000_G.pth"
59
+ sha256: a1c4aad3eb19894afda5dcc12982541ce15f79bd47916137cbeb26e702040626
60
+ scale: 2
61
+ description: "GIF Restoration"
62
+ author: "[Nmkd](https://upscale.wiki/wiki/User:Nmkd)"
63
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
64
+ license: "[WTFPL](http://www.wtfpl.net/)"
65
+ - name: "4x eula digimanga bw v1"
66
+ type: esrgan_old
67
+ file: "./torch_models/4x_eula_digimanga_bw_v1_860k.pth"
68
+ sha256: a3ba78a589cf2f2c39fe77cf3f472173cdcb3ade7dcc77ee5d1cd266d733e3d3
69
+ scale: 4
70
+ description: "Black and white digital manga with halftones."
71
+ author: "end user license agreement#9756"
72
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
73
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
74
+ - name: "4x eula digimanga bw v2 (Monochrome)"
75
+ type: esrgan_old
76
+ file: "./torch_models/4x_eula_digimanga_bw_v2_nc1_307k.pth"
77
+ sha256: 0c3ff9f7b4fc11b21e1262bca06efada0b0723436623db5e2af37fa2291cb750
78
+ scale: 4
79
+ monochrome: true
80
+ cuda: true
81
+ description: "Black and white digital manga with halftones. Vast improvement over v1 in low frequency detail. v1 may still be better in some edge cases."
82
+ author: "end user license agreement#9756"
83
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
84
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
85
+ - name: "ReFocus V3"
86
+ type: esrgan_old
87
+ file: "./torch_models/1x_ReFocus_V3_140000_G.pth"
88
+ sha256: 94d8f38726c7abaa83a3fad27c01863ba961f76a995d8541c173eb3195062547
89
+ scale: 1
90
+ description: "DeBlur, ReFocus, Sharpen Manga, Anime and cartoon style images, but will work on real life images too."
91
+ author: "[Twittman](https://upscale.wiki/wiki/User:Twittman)"
92
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
93
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
94
+ - name: "Realistic Rescaler 4x"
95
+ type: real_esrgan
96
+ file: "./torch_models/4x_RealisticRescaler_100000_G.pth"
97
+ sha256: 7381a1229143c9301a94421b610d95eb312e2555743cc9e80099a0e15ac5bd3b
98
+ scale: 4
99
+ description: "This model was made to upscale realistic low-res textures that are compressed by either JPEG or BC1. From my testing, this works rather well on realistic GameCube textures such as the ones from Shrek Extra Large and the board textures from Mario Party 4. This model could also work on some real life images, especially the ones that are taken outdoors."
100
+ author: "Mutin Choler"
101
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
102
+ license: "[WTFPL](http://www.wtfpl.net/)"
103
+ - name: "Pixel Perfect V4 4x"
104
+ type: esrgan_old
105
+ file: "./torch_models/4x_PixelPerfectV4_137000_G.pth"
106
+ sha256: 52bcda86effc93e07d868036f53dd2f4a38016cdd636b66ebbf6c4525223eb5f
107
+ scale: 4
108
+ description: "Sprite Upscaler"
109
+ author: "Mutin Choler"
110
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
111
+ license: "[WTFPL](http://www.wtfpl.net/)"
112
+ - name: "Anime Undeint"
113
+ type: real_esrgan_compact
114
+ file: "./torch_models/1x_AnimeUndeint_Compact_130k_net_g.pth"
115
+ sha256: f8b2b98c4e5dd3989b836414e2624e0795d74a8eba44e32cba6d18cce181140c
116
+ scale: 1
117
+ description: "This model corrects jagged lines on animation that has been deinterlaced. It handles simple line doubling, line interpolation, and even Yadif-style artifacts. It can also handle sources that were resized after deinterlacing, for example resizing from ntsc to pal resolutions. If a source has been upscaled after deinterlacing, it will need to be downsized before applying this model."
118
+ author: "Zarxrax"
119
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
120
+ license: "[WTFPL](http://www.wtfpl.net/)"
121
+ - name: "Fabric 4x"
122
+ type: esrgan_old
123
+ file: "./torch_models/4x-Fabric.pth"
124
+ sha256: 4a4c7924dfa830aed4dfd1126b1a7ee64a6611260edd03da79e3de842e52024a
125
+ scale: 4
126
+ description: "This model set upscales fabric or cloth textures (works on cats too!). The Alt model is just an earlier iteration version. It may work better on some images.The images need to be minimally compressed or passed through a decompression model first. It works with DDS compression though."
127
+ author: "[Kim2091](https://upscale.wiki/wiki/User:Kim2091)"
128
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
129
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
130
+ - name: "Face Focus 4x"
131
+ type: esrgan_old
132
+ file: "./torch_models/4x_face_focus_275k.pth"
133
+ sha256: a5b0546243a01f98ae63faaa691351be55416bb723271fb4f5147548b8c0b613
134
+ scale: 4
135
+ description: "Face De-blur - slightly out of focus / blurred images of faces. It is aimed at faces / hair"
136
+ author: "[LyonHrt](https://upscale.wiki/wiki/User:LyonHrt"
137
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
138
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
139
+ - name: "FatePlus lite 4x"
140
+ type: esrgan_old_lite
141
+ file: "./torch_models/4x-FatePlus-lite.pth"
142
+ sha256: 959c8d9c39e57092d02cb90d82ad1a8d9297cd57d59e43c0243bea2c9eae83da
143
+ scale: 4
144
+ description: "Anime PSP games, Fate Extra\n\nThis model was trained as a favor to Demon and the Fate Extra community. It leaves a nice grain on the images and upscales lines and details accurately without looking odd. This model works on most anime-style PSP games. Enjoy! It works best on content with dithering and quantization."
145
+ author: "[Kim2091](https://upscale.wiki/wiki/User:Kim2091)"
146
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
147
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
148
+ - name: "Remacri Upscaler 4x"
149
+ type: esrgan_old
150
+ file: "./torch_models/4x_foolhardy_Remacri.pth"
151
+ sha256: e1a73bd89c2da1ae494774746398689048b5a892bd9653e146713f9df8bca86a
152
+ scale: 4
153
+ description: "A creation of BSRGAN with more details and less smoothing, made by interpolating IRL models such as Siax, Superscale, Superscale Artisoft, Pixel Perfect, etc. This was, things like skin and other details don't become mushy and blurry."
154
+ author: "Foolhardy"
155
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
156
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
157
+ - name: "sudo UltraCompact 2x 1.121.175 G"
158
+ type: real_esrgan_compact
159
+ file: "./torch_models/sudo_UltraCompact_2x_1.121.175_G.pth"
160
+ sha256: e53987f0312dee424b4dbd9dce7b2eacbe03fdf1380e44a11f8a4d2ca88c99e3
161
+ scale: 2
162
+ features: 64
163
+ convs: 8
164
+ cuda: true
165
+ description: "Realtime animation restauration and doing stuff like deblur and compression artefact removal"
166
+ author: "sudo"
167
+ source: "[upscale.wiki Model Database](https://upscale.wiki/wiki/Model_Database)"
168
+ license: "[CC BY-NC-SA 4.0](https://creativecommons.org/licenses/by-nc-sa/4.0/)"
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ torch==1.13.1
2
+ torchvision==0.14.1
3
+ basicsr==1.4.2
4
+ coremltools==6.2
5
+ psutil==5.9.0
6
+ chardet==4.0.0