From c193e6261e5a242d8373921a523e4d660564566a Mon Sep 17 00:00:00 2001 From: Lincoln Stein Date: Mon, 28 Nov 2022 18:27:56 +0000 Subject: [PATCH] add a --no-patchmatch option to disable patchmatch loading This feature was added to prevent the CI Macintosh tests from erroring out when patchmatch is unable to retrieve its shared library from github assets. --- ldm/invoke/CLI.py | 4 +++- ldm/invoke/args.py | 6 ++++++ ldm/invoke/generator/inpaint.py | 14 ++++++++++---- ldm/invoke/globals.py | 4 ++++ 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ldm/invoke/CLI.py b/ldm/invoke/CLI.py index d5687602d9e..e6bbb2e1436 100644 --- a/ldm/invoke/CLI.py +++ b/ldm/invoke/CLI.py @@ -44,8 +44,10 @@ def main(): print('--max_loaded_models must be >= 1; using 1') args.max_loaded_models = 1 - # alert - setting a global here + # alert - setting globals here Globals.root = os.path.expanduser(args.root_dir or os.environ.get('INVOKEAI_ROOT') or os.path.abspath('.')) + Globals.try_patchmatch = args.patchmatch + print(f'>> InvokeAI runtime directory is "{Globals.root}"') # loading here to avoid long delays on startup diff --git a/ldm/invoke/args.py b/ldm/invoke/args.py index 330220b7ea5..1e7bd48471c 100644 --- a/ldm/invoke/args.py +++ b/ldm/invoke/args.py @@ -465,6 +465,12 @@ def _create_arg_parser(self): action='store_true', help='Check for and blur potentially NSFW images', ) + model_group.add_argument( + '--patchmatch', + action=argparse.BooleanOptionalAction, + default=True, + help='Load the patchmatch extension for outpainting. Use --no-patchmatch to disable.', + ) file_group.add_argument( '--from_file', dest='infile', diff --git a/ldm/invoke/generator/inpaint.py b/ldm/invoke/generator/inpaint.py index ae1e4a946bb..3a250ebc4b8 100644 --- a/ldm/invoke/generator/inpaint.py +++ b/ldm/invoke/generator/inpaint.py @@ -17,13 +17,19 @@ from ldm.models.diffusion.ksampler import KSampler from ldm.invoke.generator.base import downsampling from ldm.util import debug_image -from patchmatch import patch_match - +from ldm.invoke.globals import Globals infill_methods: list[str] = list() -if patch_match.patchmatch_available: - infill_methods.append('patchmatch') +if Globals.try_patchmatch: + from patchmatch import patch_match + if patch_match.patchmatch_available: + print('>> Patchmatch initialized') + infill_methods.append('patchmatch') + else: + print('>> Patchmatch not loaded, please see https://github.com/invoke-ai/InvokeAI/blob/patchmatch-install-docs/docs/installation/INSTALL_PATCHMATCH.md') +else: + print('>> Patchmatch loading disabled') infill_methods.append('tile') diff --git a/ldm/invoke/globals.py b/ldm/invoke/globals.py index 877d618e3a9..9989fe82f5a 100644 --- a/ldm/invoke/globals.py +++ b/ldm/invoke/globals.py @@ -18,3 +18,7 @@ # Where to look for the initialization file Globals.initfile = os.path.expanduser('~/.invokeai') + +# Awkward workaround to disable attempted loading of pypatchmatch +# which is causing CI tests to error out. +Globals.try_patchmatch = True