fix bug when using --gfpgan-models-path #13718
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, thedetection_Resnet50_Final.pth
file is still being downloaded to the originalmodels\GFPGAN
directory. This is because thesave_dir
parameter infacexlib.detection.load_file_from_url
andfacexlib.parsing.load_file_from_url
is assigned asmodel_path
instead of using the cmd parameter, which isuser_path
.Second, in
modelloader.load_models()
, theext_filter
parameter is assigned asext_filter="GFPGAN"
(it should beext_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
, andparsing_parsenet.pth
files in the--gfpgan-models-path
, it will cause a new problem with gfpgan:This is because
detection_Resnet50_Final.pth
orparsing_parsenet.pth
is being mistakenly loaded asGFPGANv1.4.pth
.a summary of changes in code
model_file_path
. Because actually the parameter accepted bygfpgan.utils.load_file_from_url
is the full path of the model file, not just its directory path.ext_filter="GFPGAN"
toext_filter=['.pth']
.facexlib_path
forsave_dir
offacexlib.detection.load_file_from_url
andfacexlib.parsing.load_file_from_url
. The value depends on whether--gfpgan-models-path
exists.if 'GFPGAN' in os.path.basename(item)
to take theGFPGANv1.4.pth
tomodel_file
.which issues it fixes, if any
Screenshots/videos:
Checklist: