Skip to content

Commit

Permalink
install GFPGAN inside SD repository in order to fix 'dark cast' issue i…
Browse files Browse the repository at this point in the history
  • Loading branch information
lstein committed Sep 11, 2022
1 parent 9a29d44 commit 16f6a67
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 2 additions & 0 deletions environment-mac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ dependencies:
- opencv==4.6.0
- pudb==2022.1
- pytorch-lightning==1.6.5
- realesrgan==0.2.5.0
- scipy==1.9.1
- streamlit==1.12.2
- sympy==1.10.1
Expand All @@ -47,6 +48,7 @@ dependencies:
- -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
- -e git+https://github.com/openai/CLIP.git@main#egg=clip
- -e git+https://github.com/Birch-san/k-diffusion.git@mps#egg=k_diffusion
- -e git+https://github.com/lstein/GFPGAN@fix-dark-cast-images#egg=gfpgan
- -e .
variables:
PYTORCH_ENABLE_MPS_FALLBACK: 1
5 changes: 3 additions & 2 deletions environment.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ldm
name: sd-ldm
channels:
- pytorch
- defaults
Expand All @@ -11,7 +11,7 @@ dependencies:
- numpy=1.19.2
- pip:
- albumentations==0.4.3
- opencv-python==4.1.2.30
- opencv-python==4.5.5.64
- pudb==2019.2
- imageio==2.9.0
- imageio-ffmpeg==0.4.2
Expand All @@ -28,4 +28,5 @@ dependencies:
- -e git+https://github.com/openai/CLIP.git@main#egg=clip
- -e git+https://github.com/CompVis/taming-transformers.git@master#egg=taming-transformers
- -e git+https://github.com/lstein/k-diffusion.git@master#egg=k-diffusion
- -e git+https://github.com/lstein/GFPGAN@fix-dark-cast-images#egg=gfpgan
- -e .
13 changes: 8 additions & 5 deletions ldm/gfpgan/gfpgan_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
from scripts.dream import create_argv_parser

arg_parser = create_argv_parser()
opt = arg_parser.parse_args()

model_path = os.path.join(opt.gfpgan_dir, opt.gfpgan_model_path)
gfpgan_model_exists = os.path.isfile(model_path)
opt = arg_parser.parse_args()

def run_gfpgan(image, strength, seed, upsampler_scale=4):
print(f'>> GFPGAN - Restoring Faces for image seed:{seed}')
gfpgan = None
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
warnings.filterwarnings('ignore', category=UserWarning)

model_path = os.path.join(opt.gfpgan_dir, opt.gfpgan_model_path)
gfpgan_model_exists = os.path.isfile(model_path)

try:
if not gfpgan_model_exists:
Expand Down Expand Up @@ -46,7 +46,10 @@ def run_gfpgan(image, strength, seed, upsampler_scale=4):

if gfpgan is None:
print(
f'>> GFPGAN not initialized. Their packages must be installed as siblings to the "stable-diffusion" folder, or set explicitly using the --gfpgan_dir option.'
f'>> WARNING: GFPGAN not initialized.'
)
print(
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.'
)
return image

Expand Down
4 changes: 2 additions & 2 deletions scripts/dream.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def main_loop(t2i, outdir, prompt_as_dir, parser, infile):
if len(opt.prompt) == 0:
print('Try again with a prompt!')
continue
if opt.init_img is not None and re.match('^-\d+$',opt.init_img): # retrieve previous value!
if opt.init_img is not None and re.match('^-\\d+$',opt.init_img): # retrieve previous value!
try:
opt.init_img = last_results[int(opt.init_img)][0]
print(f'>> Reusing previous image {opt.init_img}')
Expand Down Expand Up @@ -478,7 +478,7 @@ def create_argv_parser():
parser.add_argument(
'--gfpgan_dir',
type=str,
default='../GFPGAN',
default='./src/gfpgan',
help='Indicates the directory containing the GFPGAN code.',
)
parser.add_argument(
Expand Down

0 comments on commit 16f6a67

Please sign in to comment.