Finetuning provided model #51

Closed
opened 2026-01-29 21:39:44 +00:00 by claunia · 9 comments
Owner

Originally created by @icoric4 on GitHub (Aug 17, 2021).

Hello and thanks for an awesome project!

I am trying to finetune this model - https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth , but when I have
network_g:
type: GFPGANv1
I get a lot of mismatches between the layers. So I figured the models are different.

Am I right to assume that this ckpt is the GFPGANv1Clean model and if so, how can I finetune it.

When I change the config to:
network_g:
type: GFPGANv1Clean
I get:
KeyError: "No object named 'GFPGANv1Clean' found in 'arch' registry!"

Originally created by @icoric4 on GitHub (Aug 17, 2021). Hello and thanks for an awesome project! I am trying to finetune this model - https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth , but when I have network_g: type: GFPGANv1 I get a lot of mismatches between the layers. So I figured the models are different. Am I right to assume that this ckpt is the GFPGANv1Clean model and if so, how can I finetune it. When I change the config to: network_g: type: GFPGANv1Clean I get: KeyError: "No object named 'GFPGANv1Clean' found in 'arch' registry!"
Author
Owner

@xinntao commented on GitHub (Aug 18, 2021):

@icoric4 Finetuning the https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth has not been supported yet. As this model is converted from another model (which is not released.)

I will add the model, but it may take much time ~

@xinntao commented on GitHub (Aug 18, 2021): @icoric4 Finetuning the https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth has not been supported yet. As this model is converted from another model (which is not released.) I will add the model, but it may take much time ~
Author
Owner

@icoric4 commented on GitHub (Aug 28, 2021):

Thanks!

@icoric4 commented on GitHub (Aug 28, 2021): Thanks!
Author
Owner

@icoric4 commented on GitHub (Sep 1, 2021):

Hello, I have another question.

When training from scratch a model like this one https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth,

could you share the training settings you have used to train it, similar to this?

# training settings
train:
  optim_g:
    type: Adam
    lr: !!float 2e-3
  optim_d:
    type: Adam
    lr: !!float 2e-3
  optim_component:
    type: Adam
    lr: !!float 2e-3

  scheduler:
    type: MultiStepLR
    milestones: [600000, 700000]
    gamma: 0.5

  total_iter: 800000
  warmup_iter: -1  # no warm up

  # losses
  # pixel loss
  pixel_opt:
    type: L1Loss
    loss_weight: !!float 1e-1
    reduction: mean
  # L1 loss used in pyramid loss, component style loss and identity loss
  L1_opt:
    type: L1Loss
    loss_weight: 1
    reduction: mean

  # image pyramid loss
  pyramid_loss_weight: 1
  remove_pyramid_loss: 50000
  # perceptual loss (content and style losses)
  perceptual_opt:
    type: PerceptualLoss
    layer_weights:
      # before relu
      'conv1_2': 0.1
      'conv2_2': 0.1
      'conv3_4': 1
      'conv4_4': 1
      'conv5_4': 1
    vgg_type: vgg19
    use_input_norm: true
    perceptual_weight: !!float 1
    style_weight: 50
    range_norm: true
    criterion: l1
  # gan loss
  gan_opt:
    type: GANLoss
    gan_type: wgan_softplus
    loss_weight: !!float 1e-1
  # r1 regularization for discriminator
  r1_reg_weight: 10
  # facial component loss
  gan_component_opt:
    type: GANLoss
    gan_type: vanilla
    real_label_val: 1.0
    fake_label_val: 0.0
    loss_weight: !!float 1
  comp_style_weight: 200
  # identity loss
  identity_weight: 10

  net_d_iters: 1
  net_d_init_iters: 0
  net_d_reg_every: 16

@icoric4 commented on GitHub (Sep 1, 2021): Hello, I have another question. When training from scratch a model like this one https://github.com/TencentARC/GFPGAN/releases/download/v0.2.0/GFPGANCleanv1-NoCE-C2.pth, could you share the training settings you have used to train it, similar to this? ``` # training settings train: optim_g: type: Adam lr: !!float 2e-3 optim_d: type: Adam lr: !!float 2e-3 optim_component: type: Adam lr: !!float 2e-3 scheduler: type: MultiStepLR milestones: [600000, 700000] gamma: 0.5 total_iter: 800000 warmup_iter: -1 # no warm up # losses # pixel loss pixel_opt: type: L1Loss loss_weight: !!float 1e-1 reduction: mean # L1 loss used in pyramid loss, component style loss and identity loss L1_opt: type: L1Loss loss_weight: 1 reduction: mean # image pyramid loss pyramid_loss_weight: 1 remove_pyramid_loss: 50000 # perceptual loss (content and style losses) perceptual_opt: type: PerceptualLoss layer_weights: # before relu 'conv1_2': 0.1 'conv2_2': 0.1 'conv3_4': 1 'conv4_4': 1 'conv5_4': 1 vgg_type: vgg19 use_input_norm: true perceptual_weight: !!float 1 style_weight: 50 range_norm: true criterion: l1 # gan loss gan_opt: type: GANLoss gan_type: wgan_softplus loss_weight: !!float 1e-1 # r1 regularization for discriminator r1_reg_weight: 10 # facial component loss gan_component_opt: type: GANLoss gan_type: vanilla real_label_val: 1.0 fake_label_val: 0.0 loss_weight: !!float 1 comp_style_weight: 200 # identity loss identity_weight: 10 net_d_iters: 1 net_d_init_iters: 0 net_d_reg_every: 16 ```
Author
Owner

@xinntao commented on GitHub (Sep 1, 2021):

@icoric4
The training setting is similar, but

  1. we remove the component loss
  2. we use more data and data with higher quality
  3. the training network structure is not the same as the inference network structure
@xinntao commented on GitHub (Sep 1, 2021): @icoric4 The training setting is similar, but 1. we remove the component loss 2. we use more data and data with higher quality 3. the training network structure is not the same as the inference network structure
Author
Owner

@timfu248 commented on GitHub (Dec 30, 2021):

你好,如果我想训练 type: GFPGANv1Clean,该怎样获取正确的pre-trained stylegan2 model呢?

如此设置时 decoder_load_path: experiments/pretrained_models/StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth
会报如下错误:

RuntimeError: Error(s) in loading state_dict for StyleGAN2GeneratorCSFT:
Missing key(s) in state_dict: "style_mlp.9.weight", "style_mlp.9.bias", "style_mlp.11.weight", "style_mlp.11.bias", "style_mlp.13.weight", "style_mlp.13.bias", "style_mlp.15.weight", "style_mlp.15.bias", "style_conv1.bias", "style_convs.0.bias", "style_convs.1.bias", "style_convs.2.bias", "style_convs.3.bias", "style_convs.4.bias", "style_convs.5.bias", "style_convs.6.bias", "style_convs.7.bias", "style_convs.8.bias", "style_convs.9.bias", "style_convs.10.bias", "style_convs.11.bias", "style_convs.12.bias", "style_convs.13.bias".
Unexpected key(s) in state_dict: "style_mlp.2.weight", "style_mlp.2.bias", "style_mlp.4.weight", "style_mlp.4.bias", "style_mlp.6.weight", "style_mlp.6.bias", "style_mlp.8.weight", "style_mlp.8.bias", "style_conv1.activate.bias", "style_convs.0.activate.bias", "style_convs.1.activate.bias", "style_convs.2.activate.bias", "style_convs.3.activate.bias", "style_convs.4.activate.bias", "style_convs.5.activate.bias", "style_convs.6.activate.bias", "style_convs.7.activate.bias", "style_convs.8.activate.bias", "style_convs.9.activate.bias", "style_convs.10.activate.bias", "style_convs.11.activate.bias", "style_convs.12.activate.bias", "style_convs.13.activate.bias".

@timfu248 commented on GitHub (Dec 30, 2021): 你好,如果我想训练 type: GFPGANv1Clean,该怎样获取正确的pre-trained stylegan2 model呢? 如此设置时 decoder_load_path: experiments/pretrained_models/StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth 会报如下错误: RuntimeError: Error(s) in loading state_dict for StyleGAN2GeneratorCSFT: Missing key(s) in state_dict: "style_mlp.9.weight", "style_mlp.9.bias", "style_mlp.11.weight", "style_mlp.11.bias", "style_mlp.13.weight", "style_mlp.13.bias", "style_mlp.15.weight", "style_mlp.15.bias", "style_conv1.bias", "style_convs.0.bias", "style_convs.1.bias", "style_convs.2.bias", "style_convs.3.bias", "style_convs.4.bias", "style_convs.5.bias", "style_convs.6.bias", "style_convs.7.bias", "style_convs.8.bias", "style_convs.9.bias", "style_convs.10.bias", "style_convs.11.bias", "style_convs.12.bias", "style_convs.13.bias". Unexpected key(s) in state_dict: "style_mlp.2.weight", "style_mlp.2.bias", "style_mlp.4.weight", "style_mlp.4.bias", "style_mlp.6.weight", "style_mlp.6.bias", "style_mlp.8.weight", "style_mlp.8.bias", "style_conv1.activate.bias", "style_convs.0.activate.bias", "style_convs.1.activate.bias", "style_convs.2.activate.bias", "style_convs.3.activate.bias", "style_convs.4.activate.bias", "style_convs.5.activate.bias", "style_convs.6.activate.bias", "style_convs.7.activate.bias", "style_convs.8.activate.bias", "style_convs.9.activate.bias", "style_convs.10.activate.bias", "style_convs.11.activate.bias", "style_convs.12.activate.bias", "style_convs.13.activate.bias".
Author
Owner

@laodar commented on GitHub (Jul 31, 2023):

你好,如果我想训练 type: GFPGANv1Clean,该怎样获取正确的pre-trained stylegan2 model呢?

如此设置时 decoder_load_path: experiments/pretrained_models/StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth 会报如下错误:

RuntimeError: Error(s) in loading state_dict for StyleGAN2GeneratorCSFT: Missing key(s) in state_dict: "style_mlp.9.weight", "style_mlp.9.bias", "style_mlp.11.weight", "style_mlp.11.bias", "style_mlp.13.weight", "style_mlp.13.bias", "style_mlp.15.weight", "style_mlp.15.bias", "style_conv1.bias", "style_convs.0.bias", "style_convs.1.bias", "style_convs.2.bias", "style_convs.3.bias", "style_convs.4.bias", "style_convs.5.bias", "style_convs.6.bias", "style_convs.7.bias", "style_convs.8.bias", "style_convs.9.bias", "style_convs.10.bias", "style_convs.11.bias", "style_convs.12.bias", "style_convs.13.bias". Unexpected key(s) in state_dict: "style_mlp.2.weight", "style_mlp.2.bias", "style_mlp.4.weight", "style_mlp.4.bias", "style_mlp.6.weight", "style_mlp.6.bias", "style_mlp.8.weight", "style_mlp.8.bias", "style_conv1.activate.bias", "style_convs.0.activate.bias", "style_convs.1.activate.bias", "style_convs.2.activate.bias", "style_convs.3.activate.bias", "style_convs.4.activate.bias", "style_convs.5.activate.bias", "style_convs.6.activate.bias", "style_convs.7.activate.bias", "style_convs.8.activate.bias", "style_convs.9.activate.bias", "style_convs.10.activate.bias", "style_convs.11.activate.bias", "style_convs.12.activate.bias", "style_convs.13.activate.bias".

@timfu248 有解决吗兄弟,目前是不是只能微调GFPGANv1.pth呀

@laodar commented on GitHub (Jul 31, 2023): > 你好,如果我想训练 type: GFPGANv1Clean,该怎样获取正确的pre-trained stylegan2 model呢? > > 如此设置时 decoder_load_path: experiments/pretrained_models/StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth 会报如下错误: > > RuntimeError: Error(s) in loading state_dict for StyleGAN2GeneratorCSFT: Missing key(s) in state_dict: "style_mlp.9.weight", "style_mlp.9.bias", "style_mlp.11.weight", "style_mlp.11.bias", "style_mlp.13.weight", "style_mlp.13.bias", "style_mlp.15.weight", "style_mlp.15.bias", "style_conv1.bias", "style_convs.0.bias", "style_convs.1.bias", "style_convs.2.bias", "style_convs.3.bias", "style_convs.4.bias", "style_convs.5.bias", "style_convs.6.bias", "style_convs.7.bias", "style_convs.8.bias", "style_convs.9.bias", "style_convs.10.bias", "style_convs.11.bias", "style_convs.12.bias", "style_convs.13.bias". Unexpected key(s) in state_dict: "style_mlp.2.weight", "style_mlp.2.bias", "style_mlp.4.weight", "style_mlp.4.bias", "style_mlp.6.weight", "style_mlp.6.bias", "style_mlp.8.weight", "style_mlp.8.bias", "style_conv1.activate.bias", "style_convs.0.activate.bias", "style_convs.1.activate.bias", "style_convs.2.activate.bias", "style_convs.3.activate.bias", "style_convs.4.activate.bias", "style_convs.5.activate.bias", "style_convs.6.activate.bias", "style_convs.7.activate.bias", "style_convs.8.activate.bias", "style_convs.9.activate.bias", "style_convs.10.activate.bias", "style_convs.11.activate.bias", "style_convs.12.activate.bias", "style_convs.13.activate.bias". @timfu248 有解决吗兄弟,目前是不是只能微调GFPGANv1.pth呀
Author
Owner

@qianx77 commented on GitHub (Oct 17, 2024):

你好,如果我想训练 type: GFPGANv1Clean,该怎样获取正确的pre-trained stylegan2 model呢?
如此设置时 decoder_load_path: experiments/pretrained_models/StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth 会报如下错误:
RuntimeError: Error(s) in loading state_dict for StyleGAN2GeneratorCSFT: Missing key(s) in state_dict: "style_mlp.9.weight", "style_mlp.9.bias", "style_mlp.11.weight", "style_mlp.11.bias", "style_mlp.13.weight", "style_mlp.13.bias", "style_mlp.15.weight", "style_mlp.15.bias", "style_conv1.bias", "style_convs.0.bias", "style_convs.1.bias", "style_convs.2.bias", "style_convs.3.bias", "style_convs.4.bias", "style_convs.5.bias", "style_convs.6.bias", "style_convs.7.bias", "style_convs.8.bias", "style_convs.9.bias", "style_convs.10.bias", "style_convs.11.bias", "style_convs.12.bias", "style_convs.13.bias". Unexpected key(s) in state_dict: "style_mlp.2.weight", "style_mlp.2.bias", "style_mlp.4.weight", "style_mlp.4.bias", "style_mlp.6.weight", "style_mlp.6.bias", "style_mlp.8.weight", "style_mlp.8.bias", "style_conv1.activate.bias", "style_convs.0.activate.bias", "style_convs.1.activate.bias", "style_convs.2.activate.bias", "style_convs.3.activate.bias", "style_convs.4.activate.bias", "style_convs.5.activate.bias", "style_convs.6.activate.bias", "style_convs.7.activate.bias", "style_convs.8.activate.bias", "style_convs.9.activate.bias", "style_convs.10.activate.bias", "style_convs.11.activate.bias", "style_convs.12.activate.bias", "style_convs.13.activate.bias".

@timfu248 有解决吗兄弟,目前是不是只能微调GFPGANv1.pth呀

看起来是的

@qianx77 commented on GitHub (Oct 17, 2024): > > 你好,如果我想训练 type: GFPGANv1Clean,该怎样获取正确的pre-trained stylegan2 model呢? > > 如此设置时 decoder_load_path: experiments/pretrained_models/StyleGAN2_512_Cmul1_FFHQ_B12G4_scratch_800k.pth 会报如下错误: > > RuntimeError: Error(s) in loading state_dict for StyleGAN2GeneratorCSFT: Missing key(s) in state_dict: "style_mlp.9.weight", "style_mlp.9.bias", "style_mlp.11.weight", "style_mlp.11.bias", "style_mlp.13.weight", "style_mlp.13.bias", "style_mlp.15.weight", "style_mlp.15.bias", "style_conv1.bias", "style_convs.0.bias", "style_convs.1.bias", "style_convs.2.bias", "style_convs.3.bias", "style_convs.4.bias", "style_convs.5.bias", "style_convs.6.bias", "style_convs.7.bias", "style_convs.8.bias", "style_convs.9.bias", "style_convs.10.bias", "style_convs.11.bias", "style_convs.12.bias", "style_convs.13.bias". Unexpected key(s) in state_dict: "style_mlp.2.weight", "style_mlp.2.bias", "style_mlp.4.weight", "style_mlp.4.bias", "style_mlp.6.weight", "style_mlp.6.bias", "style_mlp.8.weight", "style_mlp.8.bias", "style_conv1.activate.bias", "style_convs.0.activate.bias", "style_convs.1.activate.bias", "style_convs.2.activate.bias", "style_convs.3.activate.bias", "style_convs.4.activate.bias", "style_convs.5.activate.bias", "style_convs.6.activate.bias", "style_convs.7.activate.bias", "style_convs.8.activate.bias", "style_convs.9.activate.bias", "style_convs.10.activate.bias", "style_convs.11.activate.bias", "style_convs.12.activate.bias", "style_convs.13.activate.bias". > > @timfu248 有解决吗兄弟,目前是不是只能微调GFPGANv1.pth呀 看起来是的
Author
Owner

@NetPranav commented on GitHub (Feb 14, 2025):

Hey could you tell me how exactly you configured GFPGAN for the fine tuning as I am new to this and I don't know.
a little hint will help a lot
Thank you

@NetPranav commented on GitHub (Feb 14, 2025): Hey could you tell me how exactly you configured GFPGAN for the fine tuning as I am new to this and I don't know. a little hint will help a lot Thank you
Author
Owner

@qianx77 commented on GitHub (Feb 14, 2025):

Hey could you tell me how exactly you configured GFPGAN for the fine tuning as I am new to this and I don't know. a little hint will help a lot Thank you

you can just finetune GFPGANv1.pth using GFPGANv1. And v1.2 v1.3 v1.4 can't finetune

@qianx77 commented on GitHub (Feb 14, 2025): > Hey could you tell me how exactly you configured GFPGAN for the fine tuning as I am new to this and I don't know. a little hint will help a lot Thank you you can just finetune GFPGANv1.pth using GFPGANv1. And v1.2 v1.3 v1.4 can't finetune
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TencentARC/GFPGAN#51