Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Klanly opened this issue Oct 8, 2020 · 0 comments
Open

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

Klanly opened this issue Oct 8, 2020 · 0 comments

Comments

@Klanly
Copy link

Klanly commented Oct 8, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant