mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
ready for merge after documentation added
This commit is contained in:
parent
0eb07b7488
commit
aa785c3ef1
@ -428,10 +428,11 @@ class Generate:
|
|||||||
fit=fit,
|
fit=fit,
|
||||||
text_mask=text_mask,
|
text_mask=text_mask,
|
||||||
invert_mask=invert_mask,
|
invert_mask=invert_mask,
|
||||||
|
force_outpaint=force_outpaint,
|
||||||
)
|
)
|
||||||
|
|
||||||
# TODO: Hacky selection of operation to perform. Needs to be refactored.
|
# TODO: Hacky selection of operation to perform. Needs to be refactored.
|
||||||
generator = self.select_generator(init_image, mask_image, embiggen, hires_fix)
|
generator = self.select_generator(init_image, mask_image, embiggen, hires_fix, force_outpaint)
|
||||||
|
|
||||||
generator.set_variation(
|
generator.set_variation(
|
||||||
self.seed, variation_amount, with_variations
|
self.seed, variation_amount, with_variations
|
||||||
@ -649,6 +650,7 @@ class Generate:
|
|||||||
mask_image:Image.Image=None,
|
mask_image:Image.Image=None,
|
||||||
embiggen:bool=False,
|
embiggen:bool=False,
|
||||||
hires_fix:bool=False,
|
hires_fix:bool=False,
|
||||||
|
force_outpaint:bool=False,
|
||||||
):
|
):
|
||||||
inpainting_model_in_use = self.sampler.uses_inpainting_model()
|
inpainting_model_in_use = self.sampler.uses_inpainting_model()
|
||||||
|
|
||||||
@ -678,6 +680,7 @@ class Generate:
|
|||||||
fit=False,
|
fit=False,
|
||||||
text_mask=None,
|
text_mask=None,
|
||||||
invert_mask=False,
|
invert_mask=False,
|
||||||
|
force_outpaint=False,
|
||||||
):
|
):
|
||||||
init_image = None
|
init_image = None
|
||||||
init_mask = None
|
init_mask = None
|
||||||
@ -691,7 +694,7 @@ class Generate:
|
|||||||
|
|
||||||
# if image has a transparent area and no mask was provided, then try to generate mask
|
# if image has a transparent area and no mask was provided, then try to generate mask
|
||||||
if self._has_transparency(image):
|
if self._has_transparency(image):
|
||||||
self._transparency_check_and_warning(image, mask)
|
self._transparency_check_and_warning(image, mask, force_outpaint)
|
||||||
init_mask = self._create_init_mask(image, width, height, fit=fit)
|
init_mask = self._create_init_mask(image, width, height, fit=fit)
|
||||||
|
|
||||||
if (image.width * image.height) > (self.width * self.height) and self.size_matters:
|
if (image.width * image.height) > (self.width * self.height) and self.size_matters:
|
||||||
@ -1005,11 +1008,11 @@ class Generate:
|
|||||||
colored += 1
|
colored += 1
|
||||||
return colored == 0
|
return colored == 0
|
||||||
|
|
||||||
def _transparency_check_and_warning(self,image, mask):
|
def _transparency_check_and_warning(self,image, mask, force_outpaint=False):
|
||||||
if not mask:
|
if not mask:
|
||||||
print(
|
print(
|
||||||
'>> Initial image has transparent areas. Will inpaint in these regions.')
|
'>> Initial image has transparent areas. Will inpaint in these regions.')
|
||||||
if self._check_for_erasure(image):
|
if (not force_outpaint) and self._check_for_erasure(image):
|
||||||
print(
|
print(
|
||||||
'>> WARNING: Colors underneath the transparent region seem to have been erased.\n',
|
'>> WARNING: Colors underneath the transparent region seem to have been erased.\n',
|
||||||
'>> Inpainting will be suboptimal. Please preserve the colors when making\n',
|
'>> Inpainting will be suboptimal. Please preserve the colors when making\n',
|
||||||
|
@ -177,13 +177,16 @@ class Args(object):
|
|||||||
else:
|
else:
|
||||||
# no initial quote, so get everything up to the first thing
|
# no initial quote, so get everything up to the first thing
|
||||||
# that looks like a switch
|
# that looks like a switch
|
||||||
|
if cmd_string.startswith('-'):
|
||||||
|
prompt = ''
|
||||||
|
switches = cmd_string
|
||||||
|
else:
|
||||||
match = re.match('^(.+?)\s(--?[a-zA-Z].+)',cmd_string)
|
match = re.match('^(.+?)\s(--?[a-zA-Z].+)',cmd_string)
|
||||||
if match:
|
if match:
|
||||||
prompt,switches = match.groups()
|
prompt,switches = match.groups()
|
||||||
else:
|
else:
|
||||||
prompt = cmd_string
|
prompt = cmd_string
|
||||||
switches = ''
|
switches = ''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._cmd_switches = self._cmd_parser.parse_args(shlex.split(switches))
|
self._cmd_switches = self._cmd_parser.parse_args(shlex.split(switches))
|
||||||
setattr(self._cmd_switches,'prompt',prompt)
|
setattr(self._cmd_switches,'prompt',prompt)
|
||||||
@ -566,9 +569,12 @@ class Args(object):
|
|||||||
)
|
)
|
||||||
render_group = parser.add_argument_group('General rendering')
|
render_group = parser.add_argument_group('General rendering')
|
||||||
img2img_group = parser.add_argument_group('Image-to-image and inpainting')
|
img2img_group = parser.add_argument_group('Image-to-image and inpainting')
|
||||||
|
inpainting_group = parser.add_argument_group('Inpainting')
|
||||||
|
outpainting_group = parser.add_argument_group('Outpainting and outcropping')
|
||||||
variation_group = parser.add_argument_group('Creating and combining variations')
|
variation_group = parser.add_argument_group('Creating and combining variations')
|
||||||
postprocessing_group = parser.add_argument_group('Post-processing')
|
postprocessing_group = parser.add_argument_group('Post-processing')
|
||||||
special_effects_group = parser.add_argument_group('Special effects')
|
special_effects_group = parser.add_argument_group('Special effects')
|
||||||
|
deprecated_group = parser.add_argument_group('Deprecated options')
|
||||||
render_group.add_argument(
|
render_group.add_argument(
|
||||||
'--prompt',
|
'--prompt',
|
||||||
default='',
|
default='',
|
||||||
@ -699,17 +705,6 @@ class Args(object):
|
|||||||
type=str,
|
type=str,
|
||||||
help='Path to input image for img2img mode (supersedes width and height)',
|
help='Path to input image for img2img mode (supersedes width and height)',
|
||||||
)
|
)
|
||||||
img2img_group.add_argument(
|
|
||||||
'-M',
|
|
||||||
'--init_mask',
|
|
||||||
type=str,
|
|
||||||
help='Path to input mask for inpainting mode (supersedes width and height)',
|
|
||||||
)
|
|
||||||
img2img_group.add_argument(
|
|
||||||
'--invert_mask',
|
|
||||||
action='store_true',
|
|
||||||
help='Invert the mask',
|
|
||||||
)
|
|
||||||
img2img_group.add_argument(
|
img2img_group.add_argument(
|
||||||
'-tm',
|
'-tm',
|
||||||
'--text_mask',
|
'--text_mask',
|
||||||
@ -737,29 +732,68 @@ class Args(object):
|
|||||||
help='Strength for noising/unnoising. 0.0 preserves image exactly, 1.0 replaces it completely',
|
help='Strength for noising/unnoising. 0.0 preserves image exactly, 1.0 replaces it completely',
|
||||||
default=0.75,
|
default=0.75,
|
||||||
)
|
)
|
||||||
img2img_group.add_argument(
|
inpainting_group.add_argument(
|
||||||
'-D',
|
'-M',
|
||||||
'--out_direction',
|
'--init_mask',
|
||||||
nargs='+',
|
|
||||||
type=str,
|
type=str,
|
||||||
metavar=('direction', 'pixels'),
|
help='Path to input mask for inpainting mode (supersedes width and height)',
|
||||||
help='Direction to extend the given image (left|right|top|bottom). If a distance pixel value is not specified it defaults to half the image size'
|
|
||||||
)
|
)
|
||||||
img2img_group.add_argument(
|
inpainting_group.add_argument(
|
||||||
'-c',
|
'--invert_mask',
|
||||||
'--outcrop',
|
action='store_true',
|
||||||
nargs='+',
|
help='Invert the mask',
|
||||||
type=str,
|
|
||||||
metavar=('direction','pixels'),
|
|
||||||
help='Outcrop the image with one or more direction/pixel pairs: -c top 64 bottom 128 left 64 right 64',
|
|
||||||
)
|
)
|
||||||
img2img_group.add_argument(
|
inpainting_group.add_argument(
|
||||||
'-r',
|
'-r',
|
||||||
'--inpaint_replace',
|
'--inpaint_replace',
|
||||||
type=float,
|
type=float,
|
||||||
default=0.0,
|
default=0.0,
|
||||||
help='when inpainting, adjust how aggressively to replace the part of the picture under the mask, from 0.0 (a gentle merge) to 1.0 (replace entirely)',
|
help='when inpainting, adjust how aggressively to replace the part of the picture under the mask, from 0.0 (a gentle merge) to 1.0 (replace entirely)',
|
||||||
)
|
)
|
||||||
|
outpainting_group.add_argument(
|
||||||
|
'-c',
|
||||||
|
'--outcrop',
|
||||||
|
nargs='+',
|
||||||
|
type=str,
|
||||||
|
metavar=('direction','pixels'),
|
||||||
|
help='Outcrop the image with one or more direction/pixel pairs: e.g. -c top 64 bottom 128 left 64 right 64',
|
||||||
|
)
|
||||||
|
outpainting_group.add_argument(
|
||||||
|
'--force_outpaint',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='Force outpainting if you have no inpainting mask to pass',
|
||||||
|
)
|
||||||
|
outpainting_group.add_argument(
|
||||||
|
'--seam_size',
|
||||||
|
type=int,
|
||||||
|
default=0,
|
||||||
|
help='When outpainting, size of the mask around the seam between original and outpainted image',
|
||||||
|
)
|
||||||
|
outpainting_group.add_argument(
|
||||||
|
'--seam_blur',
|
||||||
|
type=int,
|
||||||
|
default=0,
|
||||||
|
help='When outpainting, the amount to blur the seam inwards',
|
||||||
|
)
|
||||||
|
outpainting_group.add_argument(
|
||||||
|
'--seam_strength',
|
||||||
|
type=float,
|
||||||
|
default=0.7,
|
||||||
|
help='When outpainting, the img2img strength to use when filling the seam. Values around 0.7 work well',
|
||||||
|
)
|
||||||
|
outpainting_group.add_argument(
|
||||||
|
'--seam_steps',
|
||||||
|
type=int,
|
||||||
|
default=10,
|
||||||
|
help='When outpainting, the number of steps to use to fill the seam. Low values (~10) work well',
|
||||||
|
)
|
||||||
|
outpainting_group.add_argument(
|
||||||
|
'--tile_size',
|
||||||
|
type=int,
|
||||||
|
default=32,
|
||||||
|
help='When outpainting, the tile size to use for filling outpaint areas',
|
||||||
|
)
|
||||||
postprocessing_group.add_argument(
|
postprocessing_group.add_argument(
|
||||||
'-ft',
|
'-ft',
|
||||||
'--facetool',
|
'--facetool',
|
||||||
@ -843,7 +877,14 @@ class Args(object):
|
|||||||
dest='use_mps_noise',
|
dest='use_mps_noise',
|
||||||
help='Simulate noise on M1 systems to get the same results'
|
help='Simulate noise on M1 systems to get the same results'
|
||||||
)
|
)
|
||||||
|
deprecated_group.add_argument(
|
||||||
|
'-D',
|
||||||
|
'--out_direction',
|
||||||
|
nargs='+',
|
||||||
|
type=str,
|
||||||
|
metavar=('direction', 'pixels'),
|
||||||
|
help='Older outcropping system. Direction to extend the given image (left|right|top|bottom). If a distance pixel value is not specified it defaults to half the image size'
|
||||||
|
)
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def format_metadata(**kwargs):
|
def format_metadata(**kwargs):
|
||||||
|
@ -42,6 +42,8 @@ class Omnibus(Img2Img,Txt2Img):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if isinstance(init_image, Image.Image):
|
if isinstance(init_image, Image.Image):
|
||||||
|
if init_image.mode != 'RGB':
|
||||||
|
init_image = init_image.convert('RGB')
|
||||||
init_image = self._image_to_tensor(init_image)
|
init_image = self._image_to_tensor(init_image)
|
||||||
|
|
||||||
if isinstance(mask_image, Image.Image):
|
if isinstance(mask_image, Image.Image):
|
||||||
|
@ -172,9 +172,8 @@ def main_loop(gen, opt):
|
|||||||
except (OSError, AttributeError, KeyError):
|
except (OSError, AttributeError, KeyError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# if len(opt.prompt) == 0:
|
if len(opt.prompt) == 0:
|
||||||
# print('\nTry again with a prompt!')
|
opt.prompt = ''
|
||||||
# continue
|
|
||||||
|
|
||||||
# width and height are set by model if not specified
|
# width and height are set by model if not specified
|
||||||
if not opt.width:
|
if not opt.width:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user