Skip to content

Commit 16f6a67

Browse files
committed
install GFPGAN inside SD repository in order to fix 'dark cast' issue basujindal#169
1 parent 9a29d44 commit 16f6a67

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

environment-mac.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies:
3535
- opencv==4.6.0
3636
- pudb==2022.1
3737
- pytorch-lightning==1.6.5
38+
- realesrgan==0.2.5.0
3839
- scipy==1.9.1
3940
- streamlit==1.12.2
4041
- sympy==1.10.1
@@ -47,6 +48,7 @@ dependencies:
4748
- -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
4849
- -e git+https://github.com/openai/CLIP.git@main#egg=clip
4950
- -e git+https://github.com/Birch-san/k-diffusion.git@mps#egg=k_diffusion
51+
- -e git+https://github.com/lstein/GFPGAN@fix-dark-cast-images#egg=gfpgan
5052
- -e .
5153
variables:
5254
PYTORCH_ENABLE_MPS_FALLBACK: 1

environment.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: ldm
1+
name: sd-ldm
22
channels:
33
- pytorch
44
- defaults
@@ -11,7 +11,7 @@ dependencies:
1111
- numpy=1.19.2
1212
- pip:
1313
- albumentations==0.4.3
14-
- opencv-python==4.1.2.30
14+
- opencv-python==4.5.5.64
1515
- pudb==2019.2
1616
- imageio==2.9.0
1717
- imageio-ffmpeg==0.4.2
@@ -28,4 +28,5 @@ dependencies:
2828
- -e git+https://github.com/openai/CLIP.git@main#egg=clip
2929
- -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
3030
- -e git+https://github.com/lstein/k-diffusion.git@master#egg=k-diffusion
31+
- -e git+https://github.com/lstein/GFPGAN@fix-dark-cast-images#egg=gfpgan
3132
- -e .

ldm/gfpgan/gfpgan_tools.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@
88
from scripts.dream import create_argv_parser
99

1010
arg_parser = create_argv_parser()
11-
opt = arg_parser.parse_args()
12-
13-
model_path = os.path.join(opt.gfpgan_dir, opt.gfpgan_model_path)
14-
gfpgan_model_exists = os.path.isfile(model_path)
11+
opt = arg_parser.parse_args()
1512

1613
def run_gfpgan(image, strength, seed, upsampler_scale=4):
1714
print(f'>> GFPGAN - Restoring Faces for image seed:{seed}')
1815
gfpgan = None
1916
with warnings.catch_warnings():
2017
warnings.filterwarnings('ignore', category=DeprecationWarning)
2118
warnings.filterwarnings('ignore', category=UserWarning)
19+
20+
model_path = os.path.join(opt.gfpgan_dir, opt.gfpgan_model_path)
21+
gfpgan_model_exists = os.path.isfile(model_path)
2222

2323
try:
2424
if not gfpgan_model_exists:
@@ -46,7 +46,10 @@ def run_gfpgan(image, strength, seed, upsampler_scale=4):
4646

4747
if gfpgan is None:
4848
print(
49-
f'>> GFPGAN not initialized. Their packages must be installed as siblings to the "stable-diffusion" folder, or set explicitly using the --gfpgan_dir option.'
49+
f'>> WARNING: GFPGAN not initialized.'
50+
)
51+
print(
52+
f'>> Download https://github.com/TencentARC/GFPGAN/releases/download/v1.3.0/GFPGANv1.3.pth to {model_path}, \nor change GFPGAN directory with --gfpgan_dir.'
5053
)
5154
return image
5255

scripts/dream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def main_loop(t2i, outdir, prompt_as_dir, parser, infile):
183183
if len(opt.prompt) == 0:
184184
print('Try again with a prompt!')
185185
continue
186-
if opt.init_img is not None and re.match('^-\d+$',opt.init_img): # retrieve previous value!
186+
if opt.init_img is not None and re.match('^-\\d+$',opt.init_img): # retrieve previous value!
187187
try:
188188
opt.init_img = last_results[int(opt.init_img)][0]
189189
print(f'>> Reusing previous image {opt.init_img}')
@@ -478,7 +478,7 @@ def create_argv_parser():
478478
parser.add_argument(
479479
'--gfpgan_dir',
480480
type=str,
481-
default='../GFPGAN',
481+
default='./src/gfpgan',
482482
help='Indicates the directory containing the GFPGAN code.',
483483
)
484484
parser.add_argument(

0 commit comments

Comments
 (0)