avans06 commited on
Commit
69d49d2
·
1 Parent(s): cc44a11

Referring to the Spandrel project, the hyperparameter settings of the upscale model have been updated.

Browse files
Files changed (1) hide show
  1. app.py +270 -209
app.py CHANGED
@@ -6,6 +6,7 @@ import numpy as np
6
  import gradio as gr
7
  import torch
8
  import traceback
 
9
  from collections import defaultdict
10
  from facexlib.utils.misc import download_from_url
11
  from basicsr.utils.realesrganer import RealESRGANer
@@ -68,50 +69,50 @@ upscale_models = {
68
 
69
  "4xLSDIRCompact.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact/4xLSDIRCompact.pth",
70
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact",
71
- """Upscale small good quality photos to 4x their size. This is my first ever released self-trained sisr upscaling model."""],
72
 
73
  "4xLSDIRCompactC.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactC.pth",
74
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
75
- """4x photo upscaler that handler jpg compression. Trying to extend my previous model to be able to handle compression (JPG 100-30) by manually altering the training dataset, since 4xLSDIRCompact cant handle compression. Use this instead of 4xLSDIRCompact if your photo has compression (like an image from the web)."""],
76
 
77
  "4xLSDIRCompactR.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactR.pth",
78
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
79
- """4x photo uspcaler that handles jpg compression, noise and slight. Extending my last 4xLSDIRCompact model to Real-ESRGAN, meaning trained on synthetic data instead to handle more kinds of degradations, it should be able to handle compression, noise, and slight blur."""],
80
 
81
  "4xLSDIRCompactN.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
82
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
83
- """Upscale good quality input photos to x4 their size. The original 4xLSDIRCompact a bit more trained, cannot handle degradation.
84
  I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
85
 
86
  "4xLSDIRCompactC3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
87
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
88
- """Upscale compressed photos to x4 their size. Able to handle JPG compression (30-100).
89
  I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
90
 
91
  "4xLSDIRCompactR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactR3.pth",
92
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
93
- """Upscale (degraded) photos to x4 their size. Trained on synthetic data, meant to handle more degradations.
94
  I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
95
 
96
  "4xLSDIRCompactCR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactCR3.pth",
97
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
98
- """I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
99
 
100
  "2xParimgCompact.pth": ["https://github.com/Phhofm/models/releases/download/2xParimgCompact/2xParimgCompact.pth",
101
  "https://github.com/Phhofm/models/releases/tag/2xParimgCompact",
102
- """A 2x photo upscaling compact model based on Microsoft's ImagePairs. This was one of the earliest models I started training and finished it now for release. As can be seen in the examples, this model will affect colors."""],
103
 
104
  "1xExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xExposureCorrection_compact.pth",
105
  "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
106
- """This model is meant as an experiment to see if compact can be used to train on photos to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
107
 
108
  "1xUnderExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xUnderExposureCorrection_compact.pth",
109
  "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
110
- """This model is meant as an experiment to see if compact can be used to train on underexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
111
 
112
  "1xOverExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xOverExposureCorrection_compact.pth",
113
  "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
114
- """This model is meant as an experiment to see if compact can be used to train on overexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
115
 
116
  # RRDBNet
117
  "RealESRGAN_x4plus_anime_6B.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
@@ -159,17 +160,17 @@ I aimed for perceptual quality without zooming in like 400%. Since RealESRGAN is
159
 
160
  "4xNomos2_otf_esrgan.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_otf_esrgan/4xNomos2_otf_esrgan.pth",
161
  "https://github.com/Phhofm/models/releases/tag/4xNomos2_otf_esrgan",
162
- """Purpose: Restoration, 4x ESRGAN model for photography, trained using the Real-ESRGAN otf degradation pipeline."""],
163
 
164
  "4xNomosWebPhoto_esrgan.pth": ["https://github.com/Phhofm/models/releases/download/4xNomosWebPhoto_esrgan/4xNomosWebPhoto_esrgan.pth",
165
  "https://github.com/Phhofm/models/releases/tag/4xNomosWebPhoto_esrgan",
166
- """Purpose: Restoration, 4x ESRGAN model for photography, trained with realistic noise, lens blur, jpg and webp re-compression.
167
  ESRGAN version of 4xNomosWebPhoto_RealPLKSR, trained on the same dataset and in the same way."""],
168
 
169
  # DATNet
170
  "4xNomos8kDAT.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos8kDAT/4xNomos8kDAT.pth",
171
  "https://openmodeldb.info/models/4x-Nomos8kDAT",
172
- """A 4x photo upscaler with otf jpg compression, blur and resize, trained on musl's Nomos8k_sfw dataset for realisic sr, this time based on the DAT arch, as a finetune on the official 4x DAT model."""],
173
 
174
  "4x-DWTP-DS-dat2-v3.pth" : ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-DWTP-DS-dat2-v3.pth",
175
  "https://openmodeldb.info/models/4x-DWTP-DS-dat2-v3",
@@ -177,23 +178,19 @@ ESRGAN version of 4xNomosWebPhoto_RealPLKSR, trained on the same dataset and in
177
 
178
  "4xBHI_dat2_real.pth" : ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_real/4xBHI_dat2_real.pth",
179
  "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_real",
180
- """Purpose: 4x upscaling images. Handles realistic noise, some realistic blur, and webp and jpg (re)compression.
181
- Description: 4x dat2 upscaling model for web and realistic images. It handles realistic noise, some realistic blur, and webp and jpg (re)compression. Trained on my BHI dataset (390'035 training tiles) with degraded LR subset."""],
182
 
183
  "4xBHI_dat2_otf.pth" : ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_otf/4xBHI_dat2_otf.pth",
184
  "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_otf",
185
- """Purpose: 4x upscaling images, handles noise and jpg compression
186
- Description: 4x dat2 upscaling model, trained with the real-esrgan otf pipeline on my bhi dataset. Handles noise and compression."""],
187
 
188
  "4xBHI_dat2_multiblur.pth" : ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_multiblurjpg/4xBHI_dat2_multiblur.pth",
189
  "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_multiblurjpg",
190
- """Purpose: 4x upscaling images, handles jpg compression
191
- Description: 4x dat2 upscaling model, trained with down_up,linear, cubic_mitchell, lanczos, gauss and box scaling algos, some average, gaussian and anisotropic blurs and jpg compression. Trained on my BHI sisr dataset."""],
192
 
193
  "4xBHI_dat2_multiblurjpg.pth" : ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_multiblurjpg/4xBHI_dat2_multiblurjpg.pth",
194
  "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_multiblurjpg",
195
- """Purpose: 4x upscaling images, handles jpg compression
196
- Description: 4x dat2 upscaling model, trained with down_up,linear, cubic_mitchell, lanczos, gauss and box scaling algos, some average, gaussian and anisotropic blurs and jpg compression. Trained on my BHI sisr dataset."""],
197
 
198
  "4x_IllustrationJaNai_V1_DAT2_190k.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1qpioSqBkB_IkSBhEAewSSNFt6qgkBimP",
199
  "https://openmodeldb.info/models/4x-IllustrationJaNai-V1-DAT2",
@@ -201,45 +198,64 @@ Description: 4x dat2 upscaling model, trained with down_up,linear, cubic_mitchel
201
  Model for color images including manga covers and color illustrations, digital art, visual novel art, artbooks, and more.
202
  DAT2 version is the highest quality version but also the slowest. See the ESRGAN version for faster performance."""],
203
 
 
 
 
 
 
 
 
 
 
204
  # HAT
205
  "4xNomos8kSCHAT-L.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCHAT/4xNomos8kSCHAT-L.pth",
206
  "https://openmodeldb.info/models/4x-Nomos8kSCHAT-L",
207
- """4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr. Since this is a big model, upscaling might take a while."""],
208
 
209
  "4xNomos8kSCHAT-S.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCHAT/4xNomos8kSCHAT-S.pth",
210
  "https://openmodeldb.info/models/4x-Nomos8kSCHAT-S",
211
- """4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr. HAT-S version/model."""],
212
 
213
  "4xNomos8kHAT-L_otf.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kHAT-L_otf/4xNomos8kHAT-L_otf.pth",
214
  "https://openmodeldb.info/models/4x-Nomos8kHAT-L-otf",
215
- """4x photo upscaler trained with otf"""],
 
 
 
 
 
 
 
216
 
217
  # RealPLKSR_dysample
218
  "4xHFA2k_ludvae_realplksr_dysample.pth": ["https://github.com/Phhofm/models/releases/download/4xHFA2k_ludvae_realplksr_dysample/4xHFA2k_ludvae_realplksr_dysample.pth",
219
  "https://openmodeldb.info/models/4x-HFA2k-ludvae-realplksr-dysample",
220
- """A Dysample RealPLKSR 4x upscaling model for anime single-image resolution."""],
221
 
222
  "4xArtFaces_realplksr_dysample.pth" : ["https://github.com/Phhofm/models/releases/download/4xArtFaces_realplksr_dysample/4xArtFaces_realplksr_dysample.pth",
223
  "https://openmodeldb.info/models/4x-ArtFaces-realplksr-dysample",
224
- """A Dysample RealPLKSR 4x upscaling model for art / painted faces."""],
225
 
226
- "4x-PBRify_RPLKSRd_V3.pth" : ["https://github.com/Kim2091/Kim2091-Models/releases/download/4x-PBRify_RPLKSRd_V3/4x-PBRify_RPLKSRd_V3.pth", "https://openmodeldb.info/models/4x-PBRify-RPLKSRd-V3",
227
- """This model is roughly 8x faster than the current DAT2 model, while being higher quality. It produces far more natural detail, resolves lines and edges more smoothly, and cleans up compression artifacts better."""],
 
 
 
228
 
229
  "4xNomos2_realplksr_dysample.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos2_realplksr_dysample/4xNomos2_realplksr_dysample.pth",
230
  "https://openmodeldb.info/models/4x-Nomos2-realplksr-dysample",
231
- """Description: A Dysample RealPLKSR 4x upscaling model that was trained with / handles jpg compression down to 70 on the Nomosv2 dataset, preserves DoF.
232
  This model affects / saturate colors, which can be counteracted a bit by using wavelet color fix, as used in these examples."""],
233
 
234
  # RealPLKSR
235
  "2x-AnimeSharpV2_RPLKSR_Sharp.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_RPLKSR_Sharp.pth",
236
- "https://openmodeldb.info/models/2x-AnimeSharpV2-RPLKSR-Sharp",
237
  """Kim2091: This is my first anime model in years. Hopefully you guys can find a good use-case for it.
238
  RealPLKSR (Higher quality, slower) Sharp: For heavily degraded sources. Sharp models have issues depth of field but are best at removing artifacts
239
  """],
240
 
241
  "2x-AnimeSharpV2_RPLKSR_Soft.pth" : ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_RPLKSR_Soft.pth",
242
- "https://openmodeldb.info/models/2x-AnimeSharpV2-RPLKSR-Soft",
243
  """Kim2091: This is my first anime model in years. Hopefully you guys can find a good use-case for it.
244
  RealPLKSR (Higher quality, slower) Soft: For cleaner sources. Soft models preserve depth of field but may not remove other artifacts as well"""],
245
 
@@ -268,25 +284,62 @@ Optimized primarily for PAL resolution (NTSC might work good as well)."""],
268
 
269
  "4xNomosWebPhoto_RealPLKSR.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomosWebPhoto_RealPLKSR/4xNomosWebPhoto_RealPLKSR.pth",
270
  "https://openmodeldb.info/models/4x-NomosWebPhoto-RealPLKSR",
271
- """4x RealPLKSR model for photography, trained with realistic noise, lens blur, jpg and webp re-compression."""],
272
 
273
  # DRCT
274
  "4xNomos2_hq_drct-l.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_drct-l/4xNomos2_hq_drct-l.pth",
275
  "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_drct-l",
276
- """An drct-l 4x upscaling model, similiar to the 4xNomos2_hq_atd, 4xNomos2_hq_dat2 and 4xNomos2_hq_mosr models, trained and for usage on non-degraded input to give good quality output.
277
  """],
278
 
279
  # ATD
280
  "4xNomos2_hq_atd.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_atd/4xNomos2_hq_atd.pth",
281
  "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_atd",
282
- """An atd 4x upscaling model, similiar to the 4xNomos2_hq_dat2 or 4xNomos2_hq_mosr models, trained and for usage on non-degraded input to give good quality output.
283
  """],
284
 
285
  # MoSR
286
  "4xNomos2_hq_mosr.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_mosr/4xNomos2_hq_mosr.pth",
287
  "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_mosr",
288
- """A 4x MoSR upscaling model, meant for non-degraded input, since this model was trained on non-degraded input to give good quality output.
 
 
 
 
 
 
289
  """],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  }
291
 
292
  example_list = ["images/a01.jpg", "images/a02.jpg", "images/a03.jpg", "images/a04.jpg", "images/bus.jpg", "images/zidane.jpg",
@@ -300,6 +353,12 @@ def get_model_type(model_name):
300
  model_type = "other"
301
  if any(value in model_name.lower() for value in ("4x-animesharp.pth", "sudo-realesrgan")):
302
  model_type = "ESRGAN"
 
 
 
 
 
 
303
  elif any(value in model_name.lower() for value in ("realesrgan", "realesrnet")):
304
  model_type = "RRDB"
305
  elif any(value in model_name.lower() for value in ("realesr", "exposurecorrection", "parimgcompact", "lsdircompact")):
@@ -310,10 +369,6 @@ def get_model_type(model_name):
310
  model_type = "DAT"
311
  elif "hat" in model_name.lower():
312
  model_type = "HAT"
313
- elif ("realplksr" in model_name.lower() and "dysample" in model_name.lower()) or "rplksrd" in model_name.lower():
314
- model_type = "RealPLKSR_dysample"
315
- elif any(value in model_name.lower() for value in ("realplksr", "rplksr", "realplskr")):
316
- model_type = "RealPLKSR"
317
  elif "drct" in model_name.lower():
318
  model_type = "DRCT"
319
  elif "atd" in model_name.lower():
@@ -352,124 +407,212 @@ class Upscale:
352
  download_from_url(upscale_models[upscale_model][0], upscale_model, os.path.join("weights", "upscale"))
353
  modelInUse = f"_{os.path.splitext(upscale_model)[0]}"
354
 
355
- self.netscale = 1 if any(sub in upscale_model for sub in ("x1", "1x")) else (2 if any(sub in upscale_model for sub in ("x2", "2x")) else 4)
356
  model = None
357
  is_auto_split_upscale = True
358
  half = True if torch.cuda.is_available() else False
359
  if upscale_type:
 
 
360
  from basicsr.archs.rrdbnet_arch import RRDBNet
361
- # background enhancer with upscale model
362
- if any(value == upscale_type for value in ("SRVGG", "RRDB", "ESRGAN")):
363
- loadnet_origin = torch.load(os.path.join("weights", "upscale", upscale_model), map_location=torch.device('cpu'), weights_only=True)
364
- if 'params_ema' in loadnet_origin or 'params' in loadnet_origin:
365
- loadnet_origin = loadnet_origin['params_ema'] if 'params_ema' in loadnet_origin else loadnet_origin['params']
366
  if upscale_type == "SRVGG":
367
  from basicsr.archs.srvgg_arch import SRVGGNetCompact
368
- body_max_num = self.find_max_numbers(loadnet_origin, "body")
369
- num_feat = loadnet_origin["body.0.weight"].shape[0]
370
- num_in_ch = loadnet_origin["body.0.weight"].shape[1]
371
- num_conv = body_max_num // 2 - 1 #16 if any(value in upscale_model for value in ("animevideov3", "ExposureCorrection", "ParimgCompact", "LSDIRCompact")) else 32
372
- model = SRVGGNetCompact(num_in_ch=num_in_ch, num_out_ch=3, num_feat=num_feat, num_conv=num_conv, upscale=self.netscale, act_type='prelu')
373
  elif upscale_type == "RRDB" or upscale_type == "ESRGAN":
374
  if upscale_type == "RRDB":
375
- num_block = 1 + self.find_max_numbers(loadnet_origin, "body")
376
- num_feat = loadnet_origin["conv_first.weight"].shape[0]
377
  else:
378
- num_block = self.find_max_numbers(loadnet_origin, "model.1.sub")
379
- num_feat = loadnet_origin["model.0.weight"].shape[0]
380
  model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=num_feat, num_block=num_block, num_grow_ch=32, scale=self.netscale, is_real_esrgan=upscale_type == "RRDB")
381
  elif upscale_type == "DAT":
382
  from basicsr.archs.dat_arch import DAT
383
  half = False
384
- expansion_factor = 2. if "dat2" in upscale_model.lower() else 4.
385
- model = DAT(img_size=64, in_chans=3, embed_dim=180, split_size=[8,32], depth=[6,6,6,6,6,6], num_heads=[6,6,6,6,6,6], expansion_factor=expansion_factor, upscale=self.netscale)
386
- # # Speculate on the parameters.
387
- # loadnet_origin = torch.load(os.path.join("weights", "upscale", upscale_model), map_location=torch.device('cpu'), weights_only=True)
388
- # inferred_params = self.infer_parameters_from_state_dict_for_dat(loadnet_origin, self.netscale)
389
- # for param, value in inferred_params.items():
390
- # print(f"{param}: {value}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391
  elif upscale_type == "HAT":
392
  half = False
393
  from basicsr.archs.hat_arch import HAT
394
- # The parameters are derived from the XPixelGroup project files: HAT-L_SRx4_ImageNet-pretrain.yml and HAT-S_SRx4.yml.
395
- # https://github.com/XPixelGroup/HAT/tree/main/options/test
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  if "hat-l" in upscale_model.lower():
397
- window_size = 16
398
  compress_ratio = 3
399
  squeeze_factor = 30
400
- depths = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
401
- embed_dim = 180
402
- num_heads = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
403
- mlp_ratio = 2
404
- upsampler = "pixelshuffle"
405
  elif "hat-s" in upscale_model.lower():
406
- window_size = 16
407
  compress_ratio = 24
408
  squeeze_factor = 24
409
- depths = [6, 6, 6, 6, 6, 6]
410
- embed_dim = 144
411
- num_heads = [6, 6, 6, 6, 6, 6]
412
- mlp_ratio = 2
413
- upsampler = "pixelshuffle"
414
- model = HAT(img_size=64, patch_size=1, in_chans=3, embed_dim=embed_dim, depths=depths, num_heads=num_heads, window_size=window_size, compress_ratio=compress_ratio,
415
- squeeze_factor=squeeze_factor, conv_scale=0.01, overlap_ratio=0.5, mlp_ratio=mlp_ratio, upsampler=upsampler, upscale=self.netscale,)
416
  elif "RealPLKSR" in upscale_type:
417
  from basicsr.archs.realplksr_arch import realplksr
418
- if upscale_type == "RealPLKSR_dysample":
419
- model = realplksr(dim=64, n_blocks=28, kernel_size=17, split_ratio=0.25, upscaling_factor=self.netscale, dysample=True)
420
- elif upscale_type == "RealPLKSR":
421
- half = False if "RealPLSKR" in upscale_model else half
422
- model = realplksr(dim=64, n_blocks=28, kernel_size=17, split_ratio=0.25, upscaling_factor=self.netscale)
 
 
 
 
 
423
  elif upscale_type == "DRCT":
424
  half = False
425
  from basicsr.archs.DRCT_arch import DRCT
426
- window_size = 16
427
- compress_ratio = 3
428
- squeeze_factor = 30
429
- depths = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
430
- embed_dim = 180
431
- num_heads = [6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6]
432
- mlp_ratio = 2
433
- upsampler = "pixelshuffle"
434
- model = DRCT(upscale=self.netscale, in_chans=3, img_size= 64, window_size=window_size, compress_ratio=compress_ratio,squeeze_factor=squeeze_factor,
435
- conv_scale= 0.01, overlap_ratio= 0.5, img_range= 1., depths=depths,
436
- embed_dim=embed_dim, num_heads=num_heads, gc= 32,
437
- mlp_ratio=mlp_ratio, upsampler=upsampler, resi_connection= '1conv')
 
 
 
 
 
 
 
 
 
 
 
438
  elif upscale_type == "ATD":
439
  half = False
440
  from basicsr.archs.atd_arch import ATD
441
- window_size = 16
442
- depths=[6, 6, 6, 6, 6, 6,]
443
- embed_dim=210
444
- num_heads=[6, 6, 6, 6, 6, 6,]
445
- mlp_ratio=2
446
- upsampler='pixelshuffle'
447
- model = ATD(upscale=self.netscale,
448
- embed_dim=embed_dim,
449
- depths=depths,
450
- num_heads=num_heads,
451
- window_size=window_size,
452
- category_size=256,
453
- num_tokens=128,
454
- reducted_dim=20,
455
- convffn_kernel_size=5,
456
- mlp_ratio=mlp_ratio,
457
- upsampler=upsampler,
458
- use_checkpoint=False,
459
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  elif upscale_type == "MoSR":
461
  from basicsr.archs.mosr_arch import mosr
462
- model = mosr(in_ch = 3,
463
- out_ch = 3,
464
- upscale = self.netscale,
465
- n_block = 24,
466
- dim = 64,
467
- upsampler = "ps", # "ps" "ds"
468
- drop_path = 0.0,
469
- kernel_size = 7,
470
- expansion_ratio = 1.5,
471
- conv_ratio = 1.0
472
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
473
 
474
  self.upsampler = None
475
  if model:
@@ -623,83 +766,6 @@ class Upscale:
623
 
624
  return tuple(max_values[findkey] for findkey in findkeys) if len(findkeys) > 1 else max_values[findkeys[0]]
625
 
626
- def infer_parameters_from_state_dict_for_dat(self, state_dict, upscale=4):
627
- if "params" in state_dict:
628
- state_dict = state_dict["params"]
629
- elif "params_ema" in state_dict:
630
- state_dict = state_dict["params_ema"]
631
-
632
- inferred_params = {}
633
-
634
- # Speculate on the depth.
635
- depth = {}
636
- for key in state_dict.keys():
637
- if "blocks" in key:
638
- layer = int(key.split(".")[1])
639
- block = int(key.split(".")[3])
640
- depth[layer] = max(depth.get(layer, 0), block + 1)
641
- inferred_params["depth"] = [depth[layer] for layer in sorted(depth.keys())]
642
-
643
- # Speculate on the number of num_heads per layer.
644
- # ex.
645
- # layers.0.blocks.1.attn.temperature: torch.Size([6, 1, 1])
646
- # layers.5.blocks.5.attn.temperature: torch.Size([6, 1, 1])
647
- # The shape of temperature is [num_heads, 1, 1].
648
- num_heads = []
649
- for layer in range(len(inferred_params["depth"])):
650
- for block in range(inferred_params["depth"][layer]):
651
- key = f"layers.{layer}.blocks.{block}.attn.temperature"
652
- if key in state_dict:
653
- num_heads_layer = state_dict[key].shape[0]
654
- num_heads.append(num_heads_layer)
655
- break
656
-
657
- inferred_params["num_heads"] = num_heads
658
-
659
- # Speculate on embed_dim.
660
- # ex. layers.0.blocks.0.attn.qkv.weight: torch.Size([540, 180])
661
- for key in state_dict.keys():
662
- if "attn.qkv.weight" in key:
663
- qkv_weight = state_dict[key]
664
- embed_dim = qkv_weight.shape[1] # Note: The in_features of qkv corresponds to embed_dim.
665
- inferred_params["embed_dim"] = embed_dim
666
- break
667
-
668
- # Speculate on split_size.
669
- # ex.
670
- # layers.0.blocks.0.attn.attns.0.rpe_biases: torch.Size([945, 2])
671
- # layers.0.blocks.0.attn.attns.0.relative_position_index: torch.Size([256, 256])
672
- # layers.0.blocks.2.attn.attn_mask_0: torch.Size([16, 256, 256])
673
- # layers.0.blocks.2.attn.attn_mask_1: torch.Size([16, 256, 256])
674
- for key in state_dict.keys():
675
- if "relative_position_index" in key:
676
- relative_position_size = state_dict[key].shape[0]
677
- # Determine split_size[0] and split_size[1] based on the provided data.
678
- split_size_0, split_size_1 = 8, relative_position_size // 8 # 256 = 8 * 32
679
- inferred_params["split_size"] = [split_size_0, split_size_1]
680
- break
681
-
682
- # Speculate on the expansion_factor.
683
- # ex.
684
- # layers.0.blocks.0.ffn.fc1.weight: torch.Size([360, 180])
685
- # layers.5.blocks.5.ffn.fc1.weight: torch.Size([360, 180])
686
- if "embed_dim" in inferred_params:
687
- for key in state_dict.keys():
688
- if "ffn.fc1.weight" in key:
689
- fc1_weight = state_dict[key]
690
- expansion_factor = fc1_weight.shape[0] // inferred_params["embed_dim"]
691
- inferred_params["expansion_factor"] = expansion_factor
692
- break
693
-
694
- inferred_params["img_size"] = 64
695
- inferred_params["in_chans"] = 3 # Assume an RGB image.
696
-
697
- for key in state_dict.keys():
698
- print(f"{key}: {state_dict[key].shape}")
699
-
700
- return inferred_params
701
-
702
-
703
  def imwriteUTF8(self, save_path, image): # `cv2.imwrite` does not support writing files to UTF-8 file paths.
704
  img_name = os.path.basename(save_path)
705
  _, extension = os.path.splitext(img_name)
@@ -727,11 +793,6 @@ def main():
727
  Practically, the aforementioned algorithm is used to restore your **old photos** or improve **AI-generated faces**.<br>
728
  To use it, simply just upload the concerned image.<br>
729
  """
730
- article = r"""
731
- [![download](https://img.shields.io/github/downloads/TencentARC/GFPGAN/total.svg)](https://github.com/TencentARC/GFPGAN/releases)
732
- [![GitHub Stars](https://img.shields.io/github/stars/TencentARC/GFPGAN?style=social)](https://github.com/TencentARC/GFPGAN)
733
- [![arXiv](https://img.shields.io/badge/arXiv-Paper-<COLOR>.svg)](https://arxiv.org/abs/2101.04061)
734
- """
735
 
736
  upscale = Upscale()
737
 
@@ -741,7 +802,7 @@ def main():
741
  for key, _ in typed_upscale_models.items():
742
  upscale_type, upscale_model = key.split(", ", 1)
743
  if tmptype and tmptype != upscale_type:#RRDB ESRGAN
744
- speed = "Fast" if tmptype == "SRVGG" else ("Slow" if any(value == tmptype for value in ("DAT", "HAT", "DRCT", "ATD")) else "Normal")
745
  upscale_model_header = f"| Upscale Model | Info, Type: {tmptype}, Model execution speed: {speed} | Download URL |\n|------------|------|--------------|"
746
  upscale_model_tables.append(upscale_model_header + "\n" + "\n".join(rows))
747
  rows.clear()
@@ -749,7 +810,7 @@ def main():
749
  value = upscale_models[upscale_model]
750
  row = f"| [{upscale_model}]({value[1]}) | " + value[2].replace("\n", "<br>") + " | [download]({value[0]}) |"
751
  rows.append(row)
752
- speed = "Fast" if tmptype == "SRVGG" else ("Slow" if any(value == tmptype for value in ("DAT", "HAT", "DRCT", "ATD")) else "Normal")
753
  upscale_model_header = f"| Upscale Model Name | Info, Type: {tmptype}, Model execution speed: {speed} | Download URL |\n|------------|------|--------------|"
754
  upscale_model_tables.append(upscale_model_header + "\n" + "\n".join(rows))
755
 
 
6
  import gradio as gr
7
  import torch
8
  import traceback
9
+ import math
10
  from collections import defaultdict
11
  from facexlib.utils.misc import download_from_url
12
  from basicsr.utils.realesrganer import RealESRGANer
 
69
 
70
  "4xLSDIRCompact.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact/4xLSDIRCompact.pth",
71
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact",
72
+ """Phhofm: Upscale small good quality photos to 4x their size. This is my first ever released self-trained sisr upscaling model."""],
73
 
74
  "4xLSDIRCompactC.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactC.pth",
75
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
76
+ """Phhofm: 4x photo upscaler that handler jpg compression. Trying to extend my previous model to be able to handle compression (JPG 100-30) by manually altering the training dataset, since 4xLSDIRCompact cant handle compression. Use this instead of 4xLSDIRCompact if your photo has compression (like an image from the web)."""],
77
 
78
  "4xLSDIRCompactR.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompactC/4xLSDIRCompactR.pth",
79
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompactC",
80
+ """Phhofm: 4x photo uspcaler that handles jpg compression, noise and slight. Extending my last 4xLSDIRCompact model to Real-ESRGAN, meaning trained on synthetic data instead to handle more kinds of degradations, it should be able to handle compression, noise, and slight blur."""],
81
 
82
  "4xLSDIRCompactN.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
83
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
84
+ """Phhofm: Upscale good quality input photos to x4 their size. The original 4xLSDIRCompact a bit more trained, cannot handle degradation.
85
  I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
86
 
87
  "4xLSDIRCompactC3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactC3.pth",
88
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
89
+ """Phhofm: Upscale compressed photos to x4 their size. Able to handle JPG compression (30-100).
90
  I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
91
 
92
  "4xLSDIRCompactR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactR3.pth",
93
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
94
+ """Phhofm: Upscale (degraded) photos to x4 their size. Trained on synthetic data, meant to handle more degradations.
95
  I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
96
 
97
  "4xLSDIRCompactCR3.pth": ["https://github.com/Phhofm/models/releases/download/4xLSDIRCompact3/4xLSDIRCompactCR3.pth",
98
  "https://github.com/Phhofm/models/releases/tag/4xLSDIRCompact3",
99
+ """Phhofm: I am releasing the Series 3 from my 4xLSDIRCompact models. In general my suggestion is, if you have good quality input images use 4xLSDIRCompactN3, otherwise try 4xLSDIRCompactC3 which will be able to handle jpg compression and a bit of blur, or then 4xLSDIRCompactCR3, which is an interpolation between C3 and R3 to be able to handle a bit of noise additionally."""],
100
 
101
  "2xParimgCompact.pth": ["https://github.com/Phhofm/models/releases/download/2xParimgCompact/2xParimgCompact.pth",
102
  "https://github.com/Phhofm/models/releases/tag/2xParimgCompact",
103
+ """Phhofm: A 2x photo upscaling compact model based on Microsoft's ImagePairs. This was one of the earliest models I started training and finished it now for release. As can be seen in the examples, this model will affect colors."""],
104
 
105
  "1xExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xExposureCorrection_compact.pth",
106
  "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
107
+ """Phhofm: This model is meant as an experiment to see if compact can be used to train on photos to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
108
 
109
  "1xUnderExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xUnderExposureCorrection_compact.pth",
110
  "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
111
+ """Phhofm: This model is meant as an experiment to see if compact can be used to train on underexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
112
 
113
  "1xOverExposureCorrection_compact.pth": ["https://github.com/Phhofm/models/releases/download/1xExposureCorrection_compact/1xOverExposureCorrection_compact.pth",
114
  "https://github.com/Phhofm/models/releases/tag/1xExposureCorrection_compact",
115
+ """Phhofm: This model is meant as an experiment to see if compact can be used to train on overexposed images to exposure correct those using the pixel, perceptual, color, color and ldl losses. There is no brightness loss. Still it seems to kinda work."""],
116
 
117
  # RRDBNet
118
  "RealESRGAN_x4plus_anime_6B.pth": ["https://github.com/xinntao/Real-ESRGAN/releases/download/v0.2.2.4/RealESRGAN_x4plus_anime_6B.pth",
 
160
 
161
  "4xNomos2_otf_esrgan.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos2_otf_esrgan/4xNomos2_otf_esrgan.pth",
162
  "https://github.com/Phhofm/models/releases/tag/4xNomos2_otf_esrgan",
163
+ """Phhofm: Restoration, 4x ESRGAN model for photography, trained using the Real-ESRGAN otf degradation pipeline."""],
164
 
165
  "4xNomosWebPhoto_esrgan.pth": ["https://github.com/Phhofm/models/releases/download/4xNomosWebPhoto_esrgan/4xNomosWebPhoto_esrgan.pth",
166
  "https://github.com/Phhofm/models/releases/tag/4xNomosWebPhoto_esrgan",
167
+ """Phhofm: Restoration, 4x ESRGAN model for photography, trained with realistic noise, lens blur, jpg and webp re-compression.
168
  ESRGAN version of 4xNomosWebPhoto_RealPLKSR, trained on the same dataset and in the same way."""],
169
 
170
  # DATNet
171
  "4xNomos8kDAT.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos8kDAT/4xNomos8kDAT.pth",
172
  "https://openmodeldb.info/models/4x-Nomos8kDAT",
173
+ """Phhofm: A 4x photo upscaler with otf jpg compression, blur and resize, trained on musl's Nomos8k_sfw dataset for realisic sr, this time based on the DAT arch, as a finetune on the official 4x DAT model."""],
174
 
175
  "4x-DWTP-DS-dat2-v3.pth" : ["https://objectstorage.us-phoenix-1.oraclecloud.com/n/ax6ygfvpvzka/b/open-modeldb-files/o/4x-DWTP-DS-dat2-v3.pth",
176
  "https://openmodeldb.info/models/4x-DWTP-DS-dat2-v3",
 
178
 
179
  "4xBHI_dat2_real.pth" : ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_real/4xBHI_dat2_real.pth",
180
  "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_real",
181
+ """Phhofm: 4x dat2 upscaling model for web and realistic images. It handles realistic noise, some realistic blur, and webp and jpg (re)compression. Trained on my BHI dataset (390'035 training tiles) with degraded LR subset."""],
 
182
 
183
  "4xBHI_dat2_otf.pth" : ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_otf/4xBHI_dat2_otf.pth",
184
  "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_otf",
185
+ """Phhofm: 4x dat2 upscaling model, trained with the real-esrgan otf pipeline on my bhi dataset. Handles noise and compression."""],
 
186
 
187
  "4xBHI_dat2_multiblur.pth" : ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_multiblurjpg/4xBHI_dat2_multiblur.pth",
188
  "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_multiblurjpg",
189
+ """Phhofm: 4x dat2 upscaling model, trained with down_up,linear, cubic_mitchell, lanczos, gauss and box scaling algos, some average, gaussian and anisotropic blurs and jpg compression. Trained on my BHI sisr dataset."""],
 
190
 
191
  "4xBHI_dat2_multiblurjpg.pth" : ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_multiblurjpg/4xBHI_dat2_multiblurjpg.pth",
192
  "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_multiblurjpg",
193
+ """Phhofm: 4x dat2 upscaling model, trained with down_up,linear, cubic_mitchell, lanczos, gauss and box scaling algos, some average, gaussian and anisotropic blurs and jpg compression. Trained on my BHI sisr dataset."""],
 
194
 
195
  "4x_IllustrationJaNai_V1_DAT2_190k.pth": ["https://drive.google.com/uc?export=download&confirm=1&id=1qpioSqBkB_IkSBhEAewSSNFt6qgkBimP",
196
  "https://openmodeldb.info/models/4x-IllustrationJaNai-V1-DAT2",
 
198
  Model for color images including manga covers and color illustrations, digital art, visual novel art, artbooks, and more.
199
  DAT2 version is the highest quality version but also the slowest. See the ESRGAN version for faster performance."""],
200
 
201
+ "4x-PBRify_UpscalerDAT2_V1.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/4x-PBRify_UpscalerDAT2_V1/4x-PBRify_UpscalerDAT2_V1.pth",
202
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/4x-PBRify_UpscalerDAT2_V1",
203
+ """Kim2091: Yet another model in the PBRify_Remix series. This is a new upscaler to replace the previous 4x-PBRify_UpscalerSIR-M_V2 model.
204
+ This model far exceeds the quality of the previous, with far more natural detail generation and better reconstruction of lines and edges."""],
205
+
206
+ "4xBHI_dat2_otf_nn.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_dat2_otf_nn/4xBHI_dat2_otf_nn.pth",
207
+ "https://github.com/Phhofm/models/releases/tag/4xBHI_dat2_otf_nn",
208
+ """Phhofm: 4x dat2 upscaling model, trained with the real-esrgan otf pipeline but without noise, on my bhi dataset. Handles resizes, and jpg compression."""],
209
+
210
  # HAT
211
  "4xNomos8kSCHAT-L.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCHAT/4xNomos8kSCHAT-L.pth",
212
  "https://openmodeldb.info/models/4x-Nomos8kSCHAT-L",
213
+ """Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr. Since this is a big model, upscaling might take a while."""],
214
 
215
  "4xNomos8kSCHAT-S.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCHAT/4xNomos8kSCHAT-S.pth",
216
  "https://openmodeldb.info/models/4x-Nomos8kSCHAT-S",
217
+ """Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr. HAT-S version/model."""],
218
 
219
  "4xNomos8kHAT-L_otf.pth": ["https://github.com/Phhofm/models/releases/download/4xNomos8kHAT-L_otf/4xNomos8kHAT-L_otf.pth",
220
  "https://openmodeldb.info/models/4x-Nomos8kHAT-L-otf",
221
+ """Phhofm: 4x photo upscaler trained with otf"""],
222
+
223
+ "4xBHI_small_hat-l.pth": ["https://github.com/Phhofm/models/releases/download/4xBHI_small_hat-l/4xBHI_small_hat-l.pth",
224
+ "https://github.com/Phhofm/models/releases/tag/4xBHI_small_hat-l",
225
+ """Phhofm: 4x hat-l upscaling model for good quality input. This model does not handle any degradations.
226
+ This model is rather soft, I tried to balance sharpness and faithfulness/non-artifacts.
227
+ For a bit sharper output, but can generate a bit of artifacts, you can try the 4xBHI_small_hat-l_sharp version,
228
+ also included in this release, which might still feel soft if you are used to sharper outputs."""],
229
 
230
  # RealPLKSR_dysample
231
  "4xHFA2k_ludvae_realplksr_dysample.pth": ["https://github.com/Phhofm/models/releases/download/4xHFA2k_ludvae_realplksr_dysample/4xHFA2k_ludvae_realplksr_dysample.pth",
232
  "https://openmodeldb.info/models/4x-HFA2k-ludvae-realplksr-dysample",
233
+ """Phhofm: A Dysample RealPLKSR 4x upscaling model for anime single-image resolution."""],
234
 
235
  "4xArtFaces_realplksr_dysample.pth" : ["https://github.com/Phhofm/models/releases/download/4xArtFaces_realplksr_dysample/4xArtFaces_realplksr_dysample.pth",
236
  "https://openmodeldb.info/models/4x-ArtFaces-realplksr-dysample",
237
+ """Phhofm: A Dysample RealPLKSR 4x upscaling model for art / painted faces."""],
238
 
239
+ "4x-PBRify_RPLKSRd_V3.pth" : ["https://github.com/Kim2091/Kim2091-Models/releases/download/4x-PBRify_RPLKSRd_V3/4x-PBRify_RPLKSRd_V3.pth",
240
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/4x-PBRify_RPLKSRd_V3",
241
+ """Kim2091: This update brings a new upscaling model, 4x-PBRify_RPLKSRd_V3. This model is roughly 8x faster than the current DAT2 model, while being higher quality.
242
+ It produces far more natural detail, resolves lines and edges more smoothly, and cleans up compression artifacts better.
243
+ As a result of those improvements, PBR is also much improved. It tends to be clearer with less defined artifacts."""],
244
 
245
  "4xNomos2_realplksr_dysample.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos2_realplksr_dysample/4xNomos2_realplksr_dysample.pth",
246
  "https://openmodeldb.info/models/4x-Nomos2-realplksr-dysample",
247
+ """Phhofm: A Dysample RealPLKSR 4x upscaling model that was trained with / handles jpg compression down to 70 on the Nomosv2 dataset, preserves DoF.
248
  This model affects / saturate colors, which can be counteracted a bit by using wavelet color fix, as used in these examples."""],
249
 
250
  # RealPLKSR
251
  "2x-AnimeSharpV2_RPLKSR_Sharp.pth": ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_RPLKSR_Sharp.pth",
252
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
253
  """Kim2091: This is my first anime model in years. Hopefully you guys can find a good use-case for it.
254
  RealPLKSR (Higher quality, slower) Sharp: For heavily degraded sources. Sharp models have issues depth of field but are best at removing artifacts
255
  """],
256
 
257
  "2x-AnimeSharpV2_RPLKSR_Soft.pth" : ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_RPLKSR_Soft.pth",
258
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
259
  """Kim2091: This is my first anime model in years. Hopefully you guys can find a good use-case for it.
260
  RealPLKSR (Higher quality, slower) Soft: For cleaner sources. Soft models preserve depth of field but may not remove other artifacts as well"""],
261
 
 
284
 
285
  "4xNomosWebPhoto_RealPLKSR.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomosWebPhoto_RealPLKSR/4xNomosWebPhoto_RealPLKSR.pth",
286
  "https://openmodeldb.info/models/4x-NomosWebPhoto-RealPLKSR",
287
+ """Phhofm: 4x RealPLKSR model for photography, trained with realistic noise, lens blur, jpg and webp re-compression."""],
288
 
289
  # DRCT
290
  "4xNomos2_hq_drct-l.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_drct-l/4xNomos2_hq_drct-l.pth",
291
  "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_drct-l",
292
+ """Phhofm: An drct-l 4x upscaling model, similiar to the 4xNomos2_hq_atd, 4xNomos2_hq_dat2 and 4xNomos2_hq_mosr models, trained and for usage on non-degraded input to give good quality output.
293
  """],
294
 
295
  # ATD
296
  "4xNomos2_hq_atd.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_atd/4xNomos2_hq_atd.pth",
297
  "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_atd",
298
+ """Phhofm: An atd 4x upscaling model, similiar to the 4xNomos2_hq_dat2 or 4xNomos2_hq_mosr models, trained and for usage on non-degraded input to give good quality output.
299
  """],
300
 
301
  # MoSR
302
  "4xNomos2_hq_mosr.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos2_hq_mosr/4xNomos2_hq_mosr.pth",
303
  "https://github.com/Phhofm/models/releases/tag/4xNomos2_hq_mosr",
304
+ """Phhofm: A 4x MoSR upscaling model, meant for non-degraded input, since this model was trained on non-degraded input to give good quality output.
305
+ """],
306
+
307
+ "2x-AnimeSharpV2_MoSR_Sharp.pth" : ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_MoSR_Sharp.pth",
308
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
309
+ """Kim2091: This is my first anime model in years. Hopefully you guys can find a good use-case for it.
310
+ MoSR (Lower quality, faster), Sharp: For heavily degraded sources. Sharp models have issues depth of field but are best at removing artifacts
311
  """],
312
+
313
+ "2x-AnimeSharpV2_MoSR_Soft.pth" : ["https://github.com/Kim2091/Kim2091-Models/releases/download/2x-AnimeSharpV2_Set/2x-AnimeSharpV2_MoSR_Soft.pth",
314
+ "https://github.com/Kim2091/Kim2091-Models/releases/tag/2x-AnimeSharpV2_Set",
315
+ """Kim2091: This is my first anime model in years. Hopefully you guys can find a good use-case for it.
316
+ MoSR (Lower quality, faster), Soft: For cleaner sources. Soft models preserve depth of field but may not remove other artifacts as well
317
+ """],
318
+
319
+ # SRFormer
320
+ "4xNomos8kSCSRFormer.pth" : ["https://github.com/Phhofm/models/releases/download/4xNomos8kSCSRFormer/4xNomos8kSCSRFormer.pth",
321
+ "https://github.com/Phhofm/models/releases/tag/4xNomos8kSCSRFormer",
322
+ """Phhofm: 4x photo upscaler with otf jpg compression and blur, trained on musl's Nomos8k_sfw dataset for realisic sr.
323
+ """],
324
+
325
+ # "4xFrankendata_FullDegradation_g_460000.pth" : ["https://drive.google.com/uc?export=download&confirm=1&id=1PZrj-8ofxhORv_OgTVSoRt3dYi-BtiDj",
326
+ # "https://openmodeldb.info/models/4x-Frankendata-FullDegradation-SRFormer",
327
+ # """Description: 4x realistic upscaler that may also work for general purpose usage.
328
+ # It was trained with OTF random degradation with a very low to very high range of degradations, including blur, noise, and compression.
329
+ # Trained with the same Frankendata dataset that I used for the pretrain model.
330
+ # """],
331
+
332
+ # "FrankendataPretrainer_SRFormer400K_g.pth" : ["https://drive.google.com/uc?export=download&confirm=1&id=1SaKvpYYIm2Vj2m9GifUMlNCbmkE6JZmr",
333
+ # "https://openmodeldb.info/models/4x-FrankendataPretainer-SRFormer",
334
+ # """Description: 4x realistic upscaler that may also work for general purpose usage.
335
+ # It was trained with OTF random degradation with a very low to very high range of degradations, including blur, noise, and compression.
336
+ # Trained with the same Frankendata dataset that I used for the pretrain model.
337
+ # """],
338
+
339
+ # "1xFrankenfixer_SRFormerLight_g.pth" : ["https://drive.google.com/uc?export=download&confirm=1&id=1UJ0iyFn4IGNhPIgNgrQrBxYsdDloFc9I",
340
+ # "https://openmodeldb.info/models/1x-Frankenfixer-SRFormerLight",
341
+ # """A 1x model designed to reduce artifacts and restore detail to images upscaled by 4xFrankendata_FullDegradation_SRFormer. It could possibly work with other upscaling models too.
342
+ # """],
343
  }
344
 
345
  example_list = ["images/a01.jpg", "images/a02.jpg", "images/a03.jpg", "images/a04.jpg", "images/bus.jpg", "images/zidane.jpg",
 
353
  model_type = "other"
354
  if any(value in model_name.lower() for value in ("4x-animesharp.pth", "sudo-realesrgan")):
355
  model_type = "ESRGAN"
356
+ elif "srformer" in model_name.lower():
357
+ model_type = "SRFormer"
358
+ elif ("realplksr" in model_name.lower() and "dysample" in model_name.lower()) or "rplksrd" in model_name.lower():
359
+ model_type = "RealPLKSR_dysample"
360
+ elif any(value in model_name.lower() for value in ("realplksr", "rplksr", "realplskr")):
361
+ model_type = "RealPLKSR"
362
  elif any(value in model_name.lower() for value in ("realesrgan", "realesrnet")):
363
  model_type = "RRDB"
364
  elif any(value in model_name.lower() for value in ("realesr", "exposurecorrection", "parimgcompact", "lsdircompact")):
 
369
  model_type = "DAT"
370
  elif "hat" in model_name.lower():
371
  model_type = "HAT"
 
 
 
 
372
  elif "drct" in model_name.lower():
373
  model_type = "DRCT"
374
  elif "atd" in model_name.lower():
 
407
  download_from_url(upscale_models[upscale_model][0], upscale_model, os.path.join("weights", "upscale"))
408
  modelInUse = f"_{os.path.splitext(upscale_model)[0]}"
409
 
410
+ self.netscale = 1 if any(sub in upscale_model.lower() for sub in ("x1", "1x")) else (2 if any(sub in upscale_model.lower() for sub in ("x2", "2x")) else 4)
411
  model = None
412
  is_auto_split_upscale = True
413
  half = True if torch.cuda.is_available() else False
414
  if upscale_type:
415
+ # The values of the following hyperparameters are based on the research findings of the Spandrel project.
416
+ # https://github.com/chaiNNer-org/spandrel/tree/main/libs/spandrel/spandrel/architectures
417
  from basicsr.archs.rrdbnet_arch import RRDBNet
418
+ loadnet = torch.load(os.path.join("weights", "upscale", upscale_model), map_location=torch.device('cpu'), weights_only=True)
419
+ if 'params_ema' in loadnet or 'params' in loadnet:
420
+ loadnet = loadnet['params_ema'] if 'params_ema' in loadnet else loadnet['params']
421
+ # for key in loadnet_origin.keys():
422
+ # print(f"{key}, {loadnet_origin[key].shape}")
423
  if upscale_type == "SRVGG":
424
  from basicsr.archs.srvgg_arch import SRVGGNetCompact
425
+ body_max_num = self.find_max_numbers(loadnet, "body")
426
+ num_feat = loadnet["body.0.weight"].shape[0]
427
+ num_in_ch = loadnet["body.0.weight"].shape[1]
428
+ num_conv = body_max_num // 2 - 1
429
+ model = SRVGGNetCompact(num_in_ch=num_in_ch, num_out_ch=3, num_feat=num_feat, num_conv=num_conv, upscale=self.netscale, act_type='prelu')
430
  elif upscale_type == "RRDB" or upscale_type == "ESRGAN":
431
  if upscale_type == "RRDB":
432
+ num_block = self.find_max_numbers(loadnet, "body") + 1
433
+ num_feat = loadnet["conv_first.weight"].shape[0]
434
  else:
435
+ num_block = self.find_max_numbers(loadnet, "model.1.sub")
436
+ num_feat = loadnet["model.0.weight"].shape[0]
437
  model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=num_feat, num_block=num_block, num_grow_ch=32, scale=self.netscale, is_real_esrgan=upscale_type == "RRDB")
438
  elif upscale_type == "DAT":
439
  from basicsr.archs.dat_arch import DAT
440
  half = False
441
+
442
+ in_chans = loadnet["conv_first.weight"].shape[1]
443
+ embed_dim = loadnet["conv_first.weight"].shape[0]
444
+ num_layers = self.find_max_numbers(loadnet, "layers") + 1
445
+ depth = [6] * num_layers
446
+ num_heads = [6] * num_layers
447
+ for i in range(num_layers):
448
+ depth[i] = self.find_max_numbers(loadnet, f"layers.{i}.blocks") + 1
449
+ num_heads[i] = loadnet[f"layers.{i}.blocks.1.attn.temperature"].shape[0] if depth[i] >= 2 else \
450
+ loadnet[f"layers.{i}.blocks.0.attn.attns.0.pos.pos3.2.weight"].shape[0] * 2
451
+
452
+ upsampler = "pixelshuffle" if "conv_last.weight" in loadnet else "pixelshuffledirect"
453
+ resi_connection = "1conv" if "conv_after_body.weight" in loadnet else "3conv"
454
+ qkv_bias = "layers.0.blocks.0.attn.qkv.bias" in loadnet
455
+ expansion_factor = float(loadnet["layers.0.blocks.0.ffn.fc1.weight"].shape[0] / embed_dim)
456
+
457
+ img_size = 64
458
+ if "layers.0.blocks.2.attn.attn_mask_0" in loadnet:
459
+ attn_mask_0_x, attn_mask_0_y, _attn_mask_0_z = loadnet["layers.0.blocks.2.attn.attn_mask_0"].shape
460
+ img_size = int(math.sqrt(attn_mask_0_x * attn_mask_0_y))
461
+
462
+ split_size = [2, 4]
463
+ if "layers.0.blocks.0.attn.attns.0.rpe_biases" in loadnet:
464
+ split_sizes = loadnet["layers.0.blocks.0.attn.attns.0.rpe_biases"][-1] + 1
465
+ split_size = [int(x) for x in split_sizes]
466
+
467
+ model = DAT(img_size=img_size, in_chans=in_chans, embed_dim=embed_dim, split_size=split_size, depth=depth, num_heads=num_heads, expansion_factor=expansion_factor,
468
+ qkv_bias=qkv_bias, resi_connection=resi_connection, upsampler=upsampler, upscale=self.netscale)
469
  elif upscale_type == "HAT":
470
  half = False
471
  from basicsr.archs.hat_arch import HAT
472
+ in_chans = loadnet["conv_first.weight"].shape[1]
473
+ embed_dim = loadnet["conv_first.weight"].shape[0]
474
+ window_size = int(math.sqrt(loadnet["relative_position_index_SA"].shape[0]))
475
+ num_layers = self.find_max_numbers(loadnet, "layers") + 1
476
+ depths = [6] * num_layers
477
+ num_heads = [6] * num_layers
478
+ for i in range(num_layers):
479
+ depths[i] = self.find_max_numbers(loadnet, f"layers.{i}.residual_group.blocks") + 1
480
+ num_heads[i] = loadnet[f"layers.{i}.residual_group.overlap_attn.relative_position_bias_table"].shape[1]
481
+ resi_connection = "1conv" if "conv_after_body.weight" in loadnet else "identity"
482
+
483
+ qkv_bias = "layers.0.residual_group.blocks.0.attn.qkv.bias" in loadnet
484
+ patch_norm = "patch_embed.norm.weight" in loadnet
485
+ ape = "absolute_pos_embed" in loadnet
486
+
487
+ mlp_hidden_dim = int(loadnet["layers.0.residual_group.blocks.0.mlp.fc1.weight"].shape[0])
488
+ mlp_ratio = mlp_hidden_dim / embed_dim
489
+ upsampler = "pixelshuffle"
490
+
491
  if "hat-l" in upscale_model.lower():
 
492
  compress_ratio = 3
493
  squeeze_factor = 30
 
 
 
 
 
494
  elif "hat-s" in upscale_model.lower():
 
495
  compress_ratio = 24
496
  squeeze_factor = 24
497
+ model = HAT(img_size=64, patch_size=1, in_chans=in_chans, embed_dim=embed_dim, depths=depths, num_heads=num_heads, window_size=window_size, compress_ratio=compress_ratio,
498
+ squeeze_factor=squeeze_factor, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, ape=ape, patch_norm=patch_norm,
499
+ upsampler=upsampler, resi_connection=resi_connection, upscale=self.netscale,)
 
 
 
 
500
  elif "RealPLKSR" in upscale_type:
501
  from basicsr.archs.realplksr_arch import realplksr
502
+ half = False if "RealPLSKR" in upscale_model else half
503
+ use_ea = "feats.1.attn.f.0.weight" in loadnet
504
+ dim = loadnet["feats.0.weight"].shape[0]
505
+ num_feats = self.find_max_numbers(loadnet, "feats") + 1
506
+ n_blocks = num_feats - 3
507
+ kernel_size = loadnet["feats.1.lk.conv.weight"].shape[2]
508
+ split_ratio = loadnet["feats.1.lk.conv.weight"].shape[0] / dim
509
+ use_dysample = "to_img.init_pos" in loadnet
510
+
511
+ model = realplksr(upscaling_factor=self.netscale, dim=dim, n_blocks=n_blocks, kernel_size=kernel_size, split_ratio=split_ratio, use_ea=use_ea, dysample=use_dysample)
512
  elif upscale_type == "DRCT":
513
  half = False
514
  from basicsr.archs.DRCT_arch import DRCT
515
+
516
+ in_chans = loadnet["conv_first.weight"].shape[1]
517
+ embed_dim = loadnet["conv_first.weight"].shape[0]
518
+ num_layers = self.find_max_numbers(loadnet, "layers") + 1
519
+ depths = (6,) * num_layers
520
+ num_heads = []
521
+ for i in range(num_layers):
522
+ num_heads.append(loadnet[f"layers.{i}.swin1.attn.relative_position_bias_table"].shape[1])
523
+
524
+ mlp_ratio = loadnet["layers.0.swin1.mlp.fc1.weight"].shape[0] / embed_dim
525
+ window_square = loadnet["layers.0.swin1.attn.relative_position_bias_table"].shape[0]
526
+ window_size = (math.isqrt(window_square) + 1) // 2
527
+ upsampler = "pixelshuffle" if "conv_last.weight" in loadnet else ""
528
+ resi_connection = "1conv" if "conv_after_body.weight" in loadnet else ""
529
+ qkv_bias = "layers.0.swin1.attn.qkv.bias" in loadnet
530
+ gc_adjust1 = loadnet["layers.0.adjust1.weight"].shape[0]
531
+ patch_norm = "patch_embed.norm.weight" in loadnet
532
+ ape = "absolute_pos_embed" in loadnet
533
+
534
+ model = DRCT(in_chans=in_chans, img_size= 64, window_size=window_size, compress_ratio=3,squeeze_factor=30,
535
+ conv_scale= 0.01, overlap_ratio= 0.5, img_range= 1., depths=depths, embed_dim=embed_dim, num_heads=num_heads,
536
+ mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, ape=ape, patch_norm=patch_norm, use_checkpoint=False,
537
+ upscale=self.netscale, upsampler=upsampler, resi_connection=resi_connection, gc =gc_adjust1,)
538
  elif upscale_type == "ATD":
539
  half = False
540
  from basicsr.archs.atd_arch import ATD
541
+ in_chans = loadnet["conv_first.weight"].shape[1]
542
+ embed_dim = loadnet["conv_first.weight"].shape[0]
543
+ window_size = math.isqrt(loadnet["relative_position_index_SA"].shape[0])
544
+ num_layers = self.find_max_numbers(loadnet, "layers") + 1
545
+ depths = [6] * num_layers
546
+ num_heads = [6] * num_layers
547
+ for i in range(num_layers):
548
+ depths[i] = self.find_max_numbers(loadnet, f"layers.{i}.residual_group.layers") + 1
549
+ num_heads[i] = loadnet[f"layers.{i}.residual_group.layers.0.attn_win.relative_position_bias_table"].shape[1]
550
+ num_tokens = loadnet["layers.0.residual_group.layers.0.attn_atd.scale"].shape[0]
551
+ reducted_dim = loadnet["layers.0.residual_group.layers.0.attn_atd.wq.weight"].shape[0]
552
+ convffn_kernel_size = loadnet["layers.0.residual_group.layers.0.convffn.dwconv.depthwise_conv.0.weight"].shape[2]
553
+ mlp_ratio = (loadnet["layers.0.residual_group.layers.0.convffn.fc1.weight"].shape[0] / embed_dim)
554
+ qkv_bias = "layers.0.residual_group.layers.0.wqkv.bias" in loadnet
555
+ ape = "absolute_pos_embed" in loadnet
556
+ patch_norm = "patch_embed.norm.weight" in loadnet
557
+ resi_connection = "1conv" if "layers.0.conv.weight" in loadnet else "3conv"
558
+
559
+ if "conv_up1.weight" in loadnet:
560
+ upsampler = "nearest+conv"
561
+ elif "conv_before_upsample.0.weight" in loadnet:
562
+ upsampler = "pixelshuffle"
563
+ elif "conv_last.weight" in loadnet:
564
+ upsampler = ""
565
+ else:
566
+ upsampler = "pixelshuffledirect"
567
+
568
+ is_light = upsampler == "pixelshuffledirect" and embed_dim == 48
569
+ category_size = 128 if is_light else 256
570
+
571
+ model = ATD(in_chans=in_chans, embed_dim=embed_dim, depths=depths, num_heads=num_heads, window_size=window_size, category_size=category_size,
572
+ num_tokens=num_tokens, reducted_dim=reducted_dim, convffn_kernel_size=convffn_kernel_size, mlp_ratio=mlp_ratio, qkv_bias=qkv_bias, ape=ape,
573
+ patch_norm=patch_norm, use_checkpoint=False, upscale=self.netscale, upsampler=upsampler, resi_connection='1conv',)
574
  elif upscale_type == "MoSR":
575
  from basicsr.archs.mosr_arch import mosr
576
+ n_block = self.find_max_numbers(loadnet, "gblocks") - 5
577
+ in_ch = loadnet["gblocks.0.weight"].shape[1]
578
+ out_ch = loadnet["upsampler.end_conv.weight"].shape[0] if "upsampler.init_pos" in loadnet else in_ch
579
+ dim = loadnet["gblocks.0.weight"].shape[0]
580
+ expansion_ratio = (loadnet["gblocks.1.fc1.weight"].shape[0] / loadnet["gblocks.1.fc1.weight"].shape[1]) / 2
581
+ conv_ratio = loadnet["gblocks.1.conv.weight"].shape[0] / dim
582
+ kernel_size = loadnet["gblocks.1.conv.weight"].shape[2]
583
+ upsampler = "dys" if "upsampler.init_pos" in loadnet else ("gps" if "upsampler.in_to_k.weight" in loadnet else "ps")
584
+
585
+ model = mosr(in_ch = in_ch, out_ch = out_ch, upscale = self.netscale, n_block = n_block, dim = dim,
586
+ upsampler = upsampler, kernel_size = kernel_size, expansion_ratio = expansion_ratio, conv_ratio = conv_ratio,)
587
+ elif upscale_type == "SRFormer":
588
+ half = False
589
+ from basicsr.archs.srformer_arch import SRFormer
590
+ in_chans = loadnet["conv_first.weight"].shape[1]
591
+ embed_dim = loadnet["conv_first.weight"].shape[0]
592
+ ape = "absolute_pos_embed" in loadnet
593
+ patch_norm = "patch_embed.norm.weight" in loadnet
594
+ qkv_bias = "layers.0.residual_group.blocks.0.attn.q.bias" in loadnet
595
+ mlp_ratio = float(loadnet["layers.0.residual_group.blocks.0.mlp.fc1.weight"].shape[0] / embed_dim)
596
+
597
+ num_layers = self.find_max_numbers(loadnet, "layers") + 1
598
+ depths = [6] * num_layers
599
+ num_heads = [6] * num_layers
600
+ for i in range(num_layers):
601
+ depths[i] = self.find_max_numbers(loadnet, f"layers.{i}.residual_group.blocks") + 1
602
+ num_heads[i] = loadnet[f"layers.{i}.residual_group.blocks.0.attn.relative_position_bias_table"].shape[1]
603
+
604
+ if "conv_hr.weight" in loadnet:
605
+ upsampler = "nearest+conv"
606
+ elif "conv_before_upsample.0.weight" in loadnet:
607
+ upsampler = "pixelshuffle"
608
+ elif "upsample.0.weight" in loadnet:
609
+ upsampler = "pixelshuffledirect"
610
+ resi_connection = "1conv" if "conv_after_body.weight" in loadnet else "3conv"
611
+
612
+ window_size = int(math.sqrt(loadnet["layers.0.residual_group.blocks.0.attn.relative_position_bias_table"].shape[0])) + 1
613
+
614
+ model = SRFormer(img_size=64, in_chans=in_chans, embed_dim=embed_dim, depths=depths, num_heads=num_heads, window_size=window_size, mlp_ratio=mlp_ratio,
615
+ qkv_bias=qkv_bias, qk_scale=None, ape=ape, patch_norm=patch_norm, upscale=self.netscale, upsampler=upsampler, resi_connection=resi_connection,)
616
 
617
  self.upsampler = None
618
  if model:
 
766
 
767
  return tuple(max_values[findkey] for findkey in findkeys) if len(findkeys) > 1 else max_values[findkeys[0]]
768
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
769
  def imwriteUTF8(self, save_path, image): # `cv2.imwrite` does not support writing files to UTF-8 file paths.
770
  img_name = os.path.basename(save_path)
771
  _, extension = os.path.splitext(img_name)
 
793
  Practically, the aforementioned algorithm is used to restore your **old photos** or improve **AI-generated faces**.<br>
794
  To use it, simply just upload the concerned image.<br>
795
  """
 
 
 
 
 
796
 
797
  upscale = Upscale()
798
 
 
802
  for key, _ in typed_upscale_models.items():
803
  upscale_type, upscale_model = key.split(", ", 1)
804
  if tmptype and tmptype != upscale_type:#RRDB ESRGAN
805
+ speed = "Fast" if tmptype == "SRVGG" else ("Slow" if any(value == tmptype for value in ("DAT", "HAT", "DRCT", "ATD", "SRFormer")) else "Normal")
806
  upscale_model_header = f"| Upscale Model | Info, Type: {tmptype}, Model execution speed: {speed} | Download URL |\n|------------|------|--------------|"
807
  upscale_model_tables.append(upscale_model_header + "\n" + "\n".join(rows))
808
  rows.clear()
 
810
  value = upscale_models[upscale_model]
811
  row = f"| [{upscale_model}]({value[1]}) | " + value[2].replace("\n", "<br>") + " | [download]({value[0]}) |"
812
  rows.append(row)
813
+ speed = "Fast" if tmptype == "SRVGG" else ("Slow" if any(value == tmptype for value in ("DAT", "HAT", "DRCT", "ATD", "SRFormer")) else "Normal")
814
  upscale_model_header = f"| Upscale Model Name | Info, Type: {tmptype}, Model execution speed: {speed} | Download URL |\n|------------|------|--------------|"
815
  upscale_model_tables.append(upscale_model_header + "\n" + "\n".join(rows))
816