Revert "Outcrop improvements" (#1449)

Reverts invoke-ai/InvokeAI#1414

- missed review comments from @Kyle0654
This commit is contained in:
Lincoln Stein 2022-11-11 15:38:02 -05:00 committed by GitHub
commit 0a88243911
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 57 deletions

View File

@ -92,21 +92,6 @@ The new image is larger than the original (576x704) because 64 pixels were added
to the top and right sides. You will need enough VRAM to process an image of to the top and right sides. You will need enough VRAM to process an image of
this size. this size.
#### Outcropping non-InvokeAI images
You can outcrop an arbitrary image that was not generated by InvokeAI,
but your results will vary. The `inpainting-1.5` model is highly
recommended, but if not feasible, then you may be able to improve the
output by conditioning the outcropping with a text prompt that
describes the scene using the `--new_prompt` argument:
```bash
invoke> !fix images/vacation.png --outcrop top 128 --new_prompt "family vacation"
```
You may also provide a different seed for outcropping to use by passing
`-S<seed>`. A seed of "0" will generate a new random seed.
A number of caveats: A number of caveats:
1. Although you can specify any pixel values, they will be rounded up to the 1. Although you can specify any pixel values, they will be rounded up to the

View File

@ -561,22 +561,17 @@ class Generate:
): ):
# retrieve the seed from the image; # retrieve the seed from the image;
seed = None seed = None
image_metadata = None
prompt = None prompt = None
args = metadata_from_png(image_path) args = metadata_from_png(image_path)
if opt.seed is not None: seed = args.seed
seed = opt.seed prompt = args.prompt
elif args.seed >= 0: print(f'>> retrieved seed {seed} and prompt "{prompt}" from {image_path}')
seed = args.seed
else:
seed = random.randrange(0, np.iinfo(np.uint32).max)
if opt.prompt is not None: if not seed:
prompt = opt.prompt print('* Could not recover seed for image. Replacing with 42. This will not affect image quality')
else: seed = 42
prompt = args.prompt
print(f'>> using seed {seed} and prompt "{prompt}" for {image_path}')
# try to reuse the same filename prefix as the original file. # try to reuse the same filename prefix as the original file.
# we take everything up to the first period # we take everything up to the first period
@ -623,10 +618,6 @@ class Generate:
extend_instructions[direction]=int(pixels) extend_instructions[direction]=int(pixels)
except ValueError: except ValueError:
print(f'** invalid extension instruction. Use <directions> <pixels>..., as in "top 64 left 128 right 64 bottom 64"') print(f'** invalid extension instruction. Use <directions> <pixels>..., as in "top 64 left 128 right 64 bottom 64"')
opt.seed = seed
opt.prompt = prompt
if len(extend_instructions)>0: if len(extend_instructions)>0:
restorer = Outcrop(image,self,) restorer = Outcrop(image,self,)
return restorer.process ( return restorer.process (

View File

@ -864,11 +864,6 @@ class Args(object):
default=32, default=32,
help='When outpainting, the tile size to use for filling outpaint areas', help='When outpainting, the tile size to use for filling outpaint areas',
) )
postprocessing_group.add_argument(
'--new_prompt',
type=str,
help='Change the text prompt applied during postprocessing (default, use original generation prompt)',
)
postprocessing_group.add_argument( postprocessing_group.add_argument(
'-ft', '-ft',
'--facetool', '--facetool',

View File

@ -63,7 +63,7 @@ class Generator():
**kwargs **kwargs
) )
results = [] results = []
seed = seed if seed is not None and seed > 0 else self.new_seed() seed = seed if seed is not None else self.new_seed()
first_seed = seed first_seed = seed
seed, initial_noise = self.generate_initial_noise(seed, width, height) seed, initial_noise = self.generate_initial_noise(seed, width, height)

View File

@ -636,7 +636,7 @@ def split_weighted_subprompts(text, skip_normalize=False)->list:
weight_sum = sum(map(lambda x: x[1], parsed_prompts)) weight_sum = sum(map(lambda x: x[1], parsed_prompts))
if weight_sum == 0: if weight_sum == 0:
print( print(
"* Warning: Subprompt weights add up to zero. Discarding and using even weights instead.") "Warning: Subprompt weights add up to zero. Discarding and using even weights instead.")
equal_weight = 1 / max(len(parsed_prompts), 1) equal_weight = 1 / max(len(parsed_prompts), 1)
return [(x[0], equal_weight) for x in parsed_prompts] return [(x[0], equal_weight) for x in parsed_prompts]
return [(x[0], x[1] / weight_sum) for x in parsed_prompts] return [(x[0], x[1] / weight_sum) for x in parsed_prompts]

View File

@ -28,12 +28,11 @@ class Outcrop(object):
self.generate._set_sampler() self.generate._set_sampler()
def wrapped_callback(img,seed,**kwargs): def wrapped_callback(img,seed,**kwargs):
preferred_seed = orig_opt.seed if orig_opt.seed> 0 else seed image_callback(img,orig_opt.seed,use_prefix=prefix,**kwargs)
image_callback(img,preferred_seed,use_prefix=prefix,**kwargs)
result= self.generate.prompt2image( result= self.generate.prompt2image(
opt.prompt, orig_opt.prompt,
seed = opt.seed if opt.seed else orig_opt.seed, seed = orig_opt.seed, # uncomment to make it deterministic
sampler = self.generate.sampler, sampler = self.generate.sampler,
steps = opt.steps, steps = opt.steps,
cfg_scale = opt.cfg_scale, cfg_scale = opt.cfg_scale,

View File

@ -29,7 +29,6 @@ infile = None
def main(): def main():
"""Initialize command-line parsers and the diffusion model""" """Initialize command-line parsers and the diffusion model"""
global infile global infile
print('* Initializing, be patient...')
opt = Args() opt = Args()
args = opt.parse_args() args = opt.parse_args()
@ -47,6 +46,7 @@ def main():
print('--max_loaded_models must be >= 1; using 1') print('--max_loaded_models must be >= 1; using 1')
args.max_loaded_models = 1 args.max_loaded_models = 1
print('* Initializing, be patient...')
from ldm.generate import Generate from ldm.generate import Generate
# these two lines prevent a horrible warning message from appearing # these two lines prevent a horrible warning message from appearing
@ -282,7 +282,7 @@ def main_loop(gen, opt):
filename = f'{prefix}.{use_prefix}.{seed}.png' filename = f'{prefix}.{use_prefix}.{seed}.png'
tm = opt.text_mask[0] tm = opt.text_mask[0]
th = opt.text_mask[1] if len(opt.text_mask)>1 else 0.5 th = opt.text_mask[1] if len(opt.text_mask)>1 else 0.5
formatted_dream_prompt = f'!mask {opt.input_file_path} -tm {tm} {th}' formatted_dream_prompt = f'!mask {opt.prompt} -tm {tm} {th}'
path = file_writer.save_image_and_prompt_to_png( path = file_writer.save_image_and_prompt_to_png(
image = image, image = image,
dream_prompt = formatted_dream_prompt, dream_prompt = formatted_dream_prompt,
@ -322,7 +322,7 @@ def main_loop(gen, opt):
tool = re.match('postprocess:(\w+)',opt.last_operation).groups()[0] tool = re.match('postprocess:(\w+)',opt.last_operation).groups()[0]
add_postprocessing_to_metadata( add_postprocessing_to_metadata(
opt, opt,
opt.input_file_path, opt.prompt,
filename, filename,
tool, tool,
formatted_dream_prompt, formatted_dream_prompt,
@ -620,16 +620,10 @@ def do_textmask(gen, opt, callback):
) )
def do_postprocess (gen, opt, callback): def do_postprocess (gen, opt, callback):
file_path = opt.prompt # treat the prompt as the file pathname file_path = opt.prompt # treat the prompt as the file pathname
if opt.new_prompt is not None:
opt.prompt = opt.new_prompt
else:
opt.prompt = None
if os.path.dirname(file_path) == '': #basename given if os.path.dirname(file_path) == '': #basename given
file_path = os.path.join(opt.outdir,file_path) file_path = os.path.join(opt.outdir,file_path)
opt.input_file_path = file_path
tool=None tool=None
if opt.facetool_strength > 0: if opt.facetool_strength > 0:
tool = opt.facetool tool = opt.facetool
@ -668,10 +662,7 @@ def do_postprocess (gen, opt, callback):
def add_postprocessing_to_metadata(opt,original_file,new_file,tool,command): def add_postprocessing_to_metadata(opt,original_file,new_file,tool,command):
original_file = original_file if os.path.exists(original_file) else os.path.join(opt.outdir,original_file) original_file = original_file if os.path.exists(original_file) else os.path.join(opt.outdir,original_file)
new_file = new_file if os.path.exists(new_file) else os.path.join(opt.outdir,new_file) new_file = new_file if os.path.exists(new_file) else os.path.join(opt.outdir,new_file)
try: meta = retrieve_metadata(original_file)['sd-metadata']
meta = retrieve_metadata(original_file)['sd-metadata']
except AttributeError:
meta = retrieve_metadata(new_file)['sd-metadata']
if 'image' not in meta: if 'image' not in meta:
meta = metadata_dumps(opt,seeds=[opt.seed])['image'] meta = metadata_dumps(opt,seeds=[opt.seed])['image']
meta['image'] = {} meta['image'] = {}
@ -719,7 +710,7 @@ def prepare_image_metadata(
elif len(prior_variations) > 0: elif len(prior_variations) > 0:
formatted_dream_prompt = opt.dream_prompt_str(seed=first_seed) formatted_dream_prompt = opt.dream_prompt_str(seed=first_seed)
elif operation == 'postprocess': elif operation == 'postprocess':
formatted_dream_prompt = '!fix '+opt.dream_prompt_str(seed=seed,prompt=opt.input_file_path) formatted_dream_prompt = '!fix '+opt.dream_prompt_str(seed=seed)
else: else:
formatted_dream_prompt = opt.dream_prompt_str(seed=seed) formatted_dream_prompt = opt.dream_prompt_str(seed=seed)
return filename,formatted_dream_prompt return filename,formatted_dream_prompt