Skip to content

add a --no-patchmatch option to disable patchmatch loading #1598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ldm/invoke/CLI.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ldm/invoke/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
14 changes: 10 additions & 4 deletions ldm/invoke/generator/inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
4 changes: 4 additions & 0 deletions ldm/invoke/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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