Skip to content

Commit fd67df9

Browse files
blessedcoolantlstein
authored andcommitted
Remove gfpgan_dir
+ Update GFPGAN Model Path Defaults > Update them to match the new file heirarchy
1 parent 45e5053 commit fd67df9

File tree

8 files changed

+47
-73
lines changed

8 files changed

+47
-73
lines changed

docs/features/CLI.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ overridden on a per-prompt basis (see
9999
| `--sampler <sampler>` | `-A<sampler>` | `k_lms` | Sampler to use. Use `-h` to get list of available samplers. |
100100
| `--seamless` | | `False` | Create interesting effects by tiling elements of the image. |
101101
| `--embedding_path <path>` | | `None` | Path to pre-trained embedding manager checkpoints, for custom models |
102-
| `--gfpgan_dir` | | `src/gfpgan` | Path to where GFPGAN is installed. |
103-
| `--gfpgan_model_path` | | `experiments/pretrained_models/GFPGANv1.4.pth` | Path to GFPGAN model file, relative to `--gfpgan_dir`. |
102+
| `--gfpgan_model_path` | | `experiments/pretrained_models/GFPGANv1.4.pth` | Path to GFPGAN model file. |
104103
| `--free_gpu_mem` | | `False` | Free GPU memory after sampling, to allow image decoding and saving in low VRAM conditions |
105104
| `--precision` | | `auto` | Set model precision, default is selected by device. Options: auto, float32, float16, autocast |
106105

docs/features/POSTPROCESS.md

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,39 @@ title: Postprocessing
66

77
## Intro
88

9-
This extension provides the ability to restore faces and upscale
10-
images.
9+
This extension provides the ability to restore faces and upscale images.
1110

12-
Face restoration and upscaling can be applied at the time you generate
13-
the images, or at any later time against a previously-generated PNG
14-
file, using the [!fix](#fixing-previously-generated-images)
15-
command. [Outpainting and outcropping](OUTPAINTING.md) can only be
16-
applied after the fact.
11+
Face restoration and upscaling can be applied at the time you generate the
12+
images, or at any later time against a previously-generated PNG file, using the
13+
[!fix](#fixing-previously-generated-images) command.
14+
[Outpainting and outcropping](OUTPAINTING.md) can only be applied after the
15+
fact.
1716

1817
## Face Fixing
1918

2019
The default face restoration module is GFPGAN. The default upscale is
21-
Real-ESRGAN. For an alternative face restoration module, see [CodeFormer
22-
Support](#codeformer-support) below.
23-
24-
As of version 1.14, environment.yaml will install the Real-ESRGAN
25-
package into the standard install location for python packages, and
26-
will put GFPGAN into a subdirectory of "src" in the InvokeAI
27-
directory. Upscaling with Real-ESRGAN should "just work" without
28-
further intervention. Simply pass the `--upscale` (`-U`) option on the
29-
`invoke>` command line, or indicate the desired scale on the popup in
30-
the Web GUI.
31-
32-
**GFPGAN** requires a series of downloadable model files to
33-
work. These are loaded when you run `scripts/preload_models.py`. If
34-
GFPAN is failing with an error, please run the following from the
35-
InvokeAI directory:
20+
Real-ESRGAN. For an alternative face restoration module, see
21+
[CodeFormer Support](#codeformer-support) below.
22+
23+
As of version 1.14, environment.yaml will install the Real-ESRGAN package into
24+
the standard install location for python packages, and will put GFPGAN into a
25+
subdirectory of "src" in the InvokeAI directory. Upscaling with Real-ESRGAN
26+
should "just work" without further intervention. Simply pass the `--upscale`
27+
(`-U`) option on the `invoke>` command line, or indicate the desired scale on
28+
the popup in the Web GUI.
29+
30+
**GFPGAN** requires a series of downloadable model files to work. These are
31+
loaded when you run `scripts/preload_models.py`. If GFPAN is failing with an
32+
error, please run the following from the InvokeAI directory:
3633

3734
```bash
3835
python scripts/preload_models.py
3936
```
4037

41-
If you do not run this script in advance, the GFPGAN module will attempt
42-
to download the models files the first time you try to perform facial
38+
If you do not run this script in advance, the GFPGAN module will attempt to
39+
download the models files the first time you try to perform facial
4340
reconstruction.
4441

45-
Alternatively, if you have GFPGAN installed elsewhere, or if you are
46-
using an earlier version of this package which asked you to install
47-
GFPGAN in a sibling directory, you may use the `--gfpgan_dir` argument
48-
with `invoke.py` to set a custom path to your GFPGAN directory. _There
49-
are other GFPGAN related boot arguments if you wish to customize
50-
further._
51-
5242
## Usage
5343

5444
You will now have access to two new prompt arguments.
@@ -119,15 +109,15 @@ actions.
119109
This repo also allows you to perform face restoration using
120110
[CodeFormer](https://github.com/sczhou/CodeFormer).
121111

122-
In order to setup CodeFormer to work, you need to download the models
123-
like with GFPGAN. You can do this either by running
124-
`preload_models.py` or by manually downloading the [model
125-
file](https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth)
112+
In order to setup CodeFormer to work, you need to download the models like with
113+
GFPGAN. You can do this either by running `preload_models.py` or by manually
114+
downloading the
115+
[model file](https://github.com/sczhou/CodeFormer/releases/download/v0.1.0/codeformer.pth)
126116
and saving it to `ldm/invoke/restoration/codeformer/weights` folder.
127117

128-
You can use `-ft` prompt argument to swap between CodeFormer and the
129-
default GFPGAN. The above mentioned `-G` prompt argument will allow
130-
you to control the strength of the restoration effect.
118+
You can use `-ft` prompt argument to swap between CodeFormer and the default
119+
GFPGAN. The above mentioned `-G` prompt argument will allow you to control the
120+
strength of the restoration effect.
131121

132122
### Usage
133123

@@ -157,9 +147,9 @@ situations when there is very little facial data to work with.
157147
## Fixing Previously-Generated Images
158148

159149
It is easy to apply face restoration and/or upscaling to any
160-
previously-generated file. Just use the syntax `!fix path/to/file.png
161-
<options>`. For example, to apply GFPGAN at strength 0.8 and upscale
162-
2X for a file named `./outputs/img-samples/000044.2945021133.png`,
150+
previously-generated file. Just use the syntax
151+
`!fix path/to/file.png <options>`. For example, to apply GFPGAN at strength 0.8
152+
and upscale 2X for a file named `./outputs/img-samples/000044.2945021133.png`,
163153
just run:
164154

165155
```bash

ldm/invoke/args.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -552,14 +552,8 @@ def _create_arg_parser(self):
552552
postprocessing_group.add_argument(
553553
'--gfpgan_model_path',
554554
type=str,
555-
default='./GFPGANv1.4.pth',
556-
help='Indicates the path to the GFPGAN model, relative to --gfpgan_dir.',
557-
)
558-
postprocessing_group.add_argument(
559-
'--gfpgan_dir',
560-
type=str,
561-
default='./models/gfpgan',
562-
help='Indicates the directory containing the GFPGAN code.',
555+
default='./models/gfpgan/GFPGANv1.4.pth',
556+
help='Indicates the path to the GFPGAN model',
563557
)
564558
web_server_group.add_argument(
565559
'--web',

ldm/invoke/restoration/base.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ class Restoration():
22
def __init__(self) -> None:
33
pass
44

5-
def load_face_restore_models(self, gfpgan_dir='./src/gfpgan', gfpgan_model_path='experiments/pretrained_models/GFPGANv1.4.pth'):
5+
def load_face_restore_models(self, gfpgan_model_path='./models/gfpgan/GFPGANv1.4.pth'):
66
# Load GFPGAN
7-
gfpgan = self.load_gfpgan(gfpgan_dir, gfpgan_model_path)
7+
gfpgan = self.load_gfpgan(gfpgan_model_path)
88
if gfpgan.gfpgan_model_exists:
99
print('>> GFPGAN Initialized')
1010
else:
@@ -22,9 +22,9 @@ def load_face_restore_models(self, gfpgan_dir='./src/gfpgan', gfpgan_model_path=
2222
return gfpgan, codeformer
2323

2424
# Face Restore Models
25-
def load_gfpgan(self, gfpgan_dir, gfpgan_model_path):
25+
def load_gfpgan(self, gfpgan_model_path):
2626
from ldm.invoke.restoration.gfpgan import GFPGAN
27-
return GFPGAN(gfpgan_dir, gfpgan_model_path)
27+
return GFPGAN(gfpgan_model_path)
2828

2929
def load_codeformer(self):
3030
from ldm.invoke.restoration.codeformer import CodeFormerRestoration

ldm/invoke/restoration/gfpgan.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,14 @@
1010
class GFPGAN():
1111
def __init__(
1212
self,
13-
gfpgan_dir='models/gfpgan',
14-
gfpgan_model_path='GFPGANv1.4.pth'
15-
) -> None:
13+
gfpgan_model_path='./models/gfpgan/GFPGANv1.4.pth') -> None:
1614

17-
self.model_path = os.path.join(gfpgan_dir, gfpgan_model_path)
15+
self.model_path = os.path.join(gfpgan_model_path)
1816
self.gfpgan_model_exists = os.path.isfile(self.model_path)
1917

2018
if not self.gfpgan_model_exists:
2119
print('## NOT FOUND: GFPGAN model not found at ' + self.model_path)
2220
return None
23-
sys.path.append(os.path.abspath(gfpgan_dir))
2421

2522
def model_exists(self):
2623
return os.path.isfile(self.model_path)
@@ -51,7 +48,7 @@ def process(self, image, strength: float, seed: str = None):
5148
f'>> WARNING: GFPGAN not initialized.'
5249
)
5350
print(
54-
f'>> Download https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth to {self.model_path}, \nor change GFPGAN directory with --gfpgan_dir.'
51+
f'>> Download https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth to {self.model_path}'
5552
)
5653

5754
image = image.convert('RGB')

scripts/invoke.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ def load_face_restoration(opt):
809809
from ldm.invoke.restoration import Restoration
810810
restoration = Restoration()
811811
if opt.restore:
812-
gfpgan, codeformer = restoration.load_face_restore_models(opt.gfpgan_dir, opt.gfpgan_model_path)
812+
gfpgan, codeformer = restoration.load_face_restore_models(opt.gfpgan_model_path)
813813
else:
814814
print('>> Face restoration disabled')
815815
if opt.esrgan:

scripts/legacy_api.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -487,14 +487,8 @@ def create_argv_parser():
487487
parser.add_argument(
488488
'--gfpgan_model_path',
489489
type=str,
490-
default='experiments/pretrained_models/GFPGANv1.3.pth',
491-
help='Indicates the path to the GFPGAN model, relative to --gfpgan_dir.',
492-
)
493-
parser.add_argument(
494-
'--gfpgan_dir',
495-
type=str,
496-
default='./src/gfpgan',
497-
help='Indicates the directory containing the GFPGAN code.',
490+
default='./models/gfpgan/GFPGANv1.4.pth',
491+
help='Indicates the path to the GFPGAN model.',
498492
)
499493
parser.add_argument(
500494
'--web',

scripts/preload_models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,15 +448,15 @@ def download_gfpgan():
448448
for model in (
449449
[
450450
'https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.4.pth',
451-
'models/gfpgan/GFPGANv1.4.pth'
451+
'./models/gfpgan/GFPGANv1.4.pth'
452452
],
453453
[
454454
'https://github.com/xinntao/facexlib/releases/download/v0.1.0/detection_Resnet50_Final.pth',
455-
'models/gfpgan/weights/detection_Resnet50_Final.pth'
455+
'./models/gfpgan/weights/detection_Resnet50_Final.pth'
456456
],
457457
[
458458
'https://github.com/xinntao/facexlib/releases/download/v0.2.2/parsing_parsenet.pth',
459-
'models/gfpgan/weights/parsing_parsenet.pth'
459+
'./models/gfpgan/weights/parsing_parsenet.pth'
460460
],
461461
):
462462
model_url,model_dest = model

0 commit comments

Comments
 (0)