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

fix bug when using --gfpgan-models-path #13718

Merged

Conversation

avantcontra
Copy link
Contributor

@avantcontra avantcontra commented Oct 21, 2023

Description

  • a simple description of what you're trying to accomplish

    • First, when using --gfpgan-models-path, for example, --gfpgan-models-path D:/custom/webui_models/GFPGAN, and selecting GFPGan as the Face restoration model in Restore faces, the detection_Resnet50_Final.pth file is still being downloaded to the original models\GFPGAN directory. This is because the save_dir parameter in facexlib.detection.load_file_from_url and facexlib.parsing.load_file_from_url is assigned as model_path instead of using the cmd parameter, which is user_path.

    • Second, in modelloader.load_models(), the ext_filter parameter is assigned as ext_filter="GFPGAN" (it should be ext_filter=['.pth']), which also causes the validation fail, resulting in a remote download every time.

    • Third, after fixing the above two issues, if I initially place the GFPGANv1.4.pth, detection_Resnet50_Final.pth, and parsing_parsenet.pth files in the --gfpgan-models-path, it will cause a new problem with gfpgan:

      File "C:\Users\Contra\anaconda3\envs\sd-pytorch2\lib\site-packages\gfpgan-1.3.8-py3.10.egg\gfpgan\utils.py", line 97, in init self.gfpgan.load_state_dict(loadnet[keyname], strict=True)
      KeyError: 'params'

      This is because detection_Resnet50_Final.pth or parsing_parsenet.pth is being mistakenly loaded as GFPGANv1.4.pth.

  • a summary of changes in code

    • Add model_file_path. Because actually the parameter accepted by gfpgan.utils.load_file_from_url is the full path of the model file, not just its directory path.
    • Change ext_filter="GFPGAN" to ext_filter=['.pth'].
    • Add facexlib_path for save_dir of facexlib.detection.load_file_from_url and facexlib.parsing.load_file_from_url. The value depends on whether --gfpgan-models-path exists.
    • Add if 'GFPGAN' in os.path.basename(item) to take the GFPGANv1.4.pth to model_file.
  • which issues it fixes, if any

Screenshots/videos:

Checklist:

@AUTOMATIC1111 AUTOMATIC1111 merged commit 452ab8f into AUTOMATIC1111:dev Nov 3, 2023
3 checks passed
@w-e-w w-e-w mentioned this pull request Dec 4, 2023
@w-e-w w-e-w mentioned this pull request Dec 16, 2023
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

Successfully merging this pull request may close these issues.

2 participants