outcrop improvements, hand-added

This commit is contained in:
Lincoln Stein 2022-11-12 16:05:45 +00:00
parent 7ad2355b1d
commit ed943bd6c7
6 changed files with 16 additions and 20 deletions

View File

@ -105,7 +105,7 @@ 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.
`-S<seed>`. A negative seed will generate a new random seed.
A number of caveats:

View File

@ -564,18 +564,11 @@ class Generate:
prompt = None
args = metadata_from_png(image_path)
if opt.seed is not None:
seed = opt.seed
elif args.seed >= 0:
seed = args.seed
else:
seed = opt.seed or args.seed
if seed is None or seed < 0:
seed = random.randrange(0, np.iinfo(np.uint32).max)
if opt.prompt is not None:
prompt = opt.prompt
else:
prompt = args.prompt
prompt = opt.prompt or args.prompt or ''
print(f'>> using seed {seed} and prompt "{prompt}" for {image_path}')
# try to reuse the same filename prefix as the original file.
@ -627,7 +620,7 @@ class Generate:
opt.seed = seed
opt.prompt = prompt
if len(extend_instructions)>0:
if len(extend_instructions) > 0:
restorer = Outcrop(image,self,)
return restorer.process (
extend_instructions,

View File

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

View File

@ -169,7 +169,7 @@ class Inpaint(Img2Img):
# Fill missing areas of original image
init_filled = self.tile_fill_missing(
self.pil_image.copy(),
seed = self.seed,
seed = self.seed if self.seed >= 0 else self.new_seed(),
tile_size = tile_size
)
init_filled.paste(init_image, (0,0), init_image.split()[-1])

View File

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

View File

@ -213,7 +213,10 @@ def main_loop(gen, opt):
setattr(opt,attr,path)
# retrieve previous value of seed if requested
if opt.seed is not None and opt.seed < 0:
# Exception: for postprocess operations negative seed values
# mean "discard the original seed and generate a new one"
# (this is a non-obvious hack and needs to be reworked)
if opt.seed is not None and opt.seed < 0 and operation != 'postprocess':
try:
opt.seed = last_results[opt.seed][1]
print(f'>> Reusing previous seed {opt.seed}')