jixiaozhong / RealSR

Real-World Super-Resolution via Kernel Estimation and Noise Injection
Apache License 2.0
740 stars 102 forks source link

Rename state_dict names, make it compatible with original ESRGAN #23

Open Klanly opened 3 years ago

Klanly commented 3 years ago

So the generator network of this is EXACTLY esrgan but with different layer(?) naming. I made a state_dict name converting func like this:

def renamelayerz(state_dict):
  from collections import OrderedDict
  import rsrlayers
  new_state_dict = OrderedDict()

  for key, value in state_dict.items():
    new_key = rsrlayers.rsr2esr[key]
    new_state_dict[new_key] = value

  return new_state_dict

def mkESRGAN(model_path,scale,isRSR=False):

  if not os.path.isfile(model_path):
    model_path = '/content/drive/My Drive/TFMLz/ESRGAN_oldarch/models/'+model_path+'.pth'

  model = arch.RRDB_Net(3, 3, 64, 23, gc=32, upscale=scale, norm_type=None, act_type='leakyrelu', \
                        mode='CNA', res_scale=1, upsample_mode='upconv')
  dick=torch.load(model_path)

  if isRSR:
    dick = renamelayerz(dick)

  model.load_state_dict(dick, strict=True)
  model.eval()
  for k, v in model.named_parameters():
      v.requires_grad = False
  return model

rsrlayers.py.txt

And it works (with original ESRGAN scripts).

Can you revert those names back to original esrgan ones? It will make this easier to be adopted by other esrgan applications.