From f2a6985c78389b521bca94919f6130b9b21d4fda Mon Sep 17 00:00:00 2001 From: JPPhoto Date: Tue, 15 Nov 2022 17:16:24 +0000 Subject: [PATCH] Added --embiggen_strength option --- ldm/generate.py | 10 ++++++++-- ldm/invoke/args.py | 9 +++++++++ ldm/invoke/server.py | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ldm/generate.py b/ldm/generate.py index 5d4b7a736c..7f2fe0b68c 100644 --- a/ldm/generate.py +++ b/ldm/generate.py @@ -288,8 +288,9 @@ class Generate: strength = None, init_color = None, # these are specific to embiggen (which also relies on img2img args) - embiggen = None, - embiggen_tiles = None, + embiggen = None, + embiggen_tiles = None, + embiggen_strength = None, # these are specific to GFPGAN/ESRGAN gfpgan_strength= 0, facetool = None, @@ -344,6 +345,7 @@ class Generate: perlin // optional 0-1 value to add a percentage of perlin noise to the initial noise embiggen // scale factor relative to the size of the --init_img (-I), followed by ESRGAN upscaling strength (0-1.0), followed by minimum amount of overlap between tiles as a decimal ratio (0 - 1.0) or number of pixels embiggen_tiles // list of tiles by number in order to process and replace onto the image e.g. `0 2 4` + embiggen_strength // strength for embiggen. 0.0 preserves image exactly, 1.0 replaces it completely To use the step callback, define a function that receives two arguments: - Image GPU data @@ -485,6 +487,7 @@ class Generate: perlin=perlin, embiggen=embiggen, embiggen_tiles=embiggen_tiles, + embiggen_strength=embiggen_strength, inpaint_replace=inpaint_replace, mask_blur_radius=mask_blur_radius, safety_checker=checker, @@ -634,6 +637,8 @@ class Generate: # fetch the metadata from the image generator = self.select_generator(embiggen=True) opt.strength = 0.40 + if opt.embiggen_strength is not None: + opt.strength = embiggen_strength print(f'>> Setting img2img strength to {opt.strength} for happy embiggening') generator.generate( prompt, @@ -649,6 +654,7 @@ class Generate: height = opt.height, embiggen = opt.embiggen, embiggen_tiles = opt.embiggen_tiles, + embiggen_strength = opt.embiggen_strength, image_callback = callback, ) elif tool == 'outpaint': diff --git a/ldm/invoke/args.py b/ldm/invoke/args.py index 72b785171e..16e6256879 100644 --- a/ldm/invoke/args.py +++ b/ldm/invoke/args.py @@ -286,6 +286,8 @@ class Args(object): switches.append(f'--embiggen {" ".join([str(u) for u in a["embiggen"]])}') if a['embiggen_tiles']: switches.append(f'--embiggen_tiles {" ".join([str(u) for u in a["embiggen_tiles"]])}') + if a['embiggen_strength']: + switches.append(f'--embiggen_strength {a["embiggen_strength"]}') # outpainting parameters if a['out_direction']: @@ -915,6 +917,13 @@ class Args(object): help='For embiggen, provide list of tiles to process and replace onto the image e.g. `1 3 5`.', default=None, ) + postprocessing_group.add_argument( + '--embiggen_strength', + '-embiggen_strength', + type=float, + help='The strength of the embiggen img2img step, defaults to 0.4', + default=0.4, + ) special_effects_group.add_argument( '--seamless', action='store_true', diff --git a/ldm/invoke/server.py b/ldm/invoke/server.py index 4fe8303960..370e7a7c66 100644 --- a/ldm/invoke/server.py +++ b/ldm/invoke/server.py @@ -30,6 +30,7 @@ def build_opt(post_data, seed, gfpgan_model_exists): # however, this code is here against that eventuality setattr(opt, 'embiggen', None) setattr(opt, 'embiggen_tiles', None) + setattr(opt, 'embiggen_strength', None) setattr(opt, 'facetool_strength', float(post_data['facetool_strength']) if gfpgan_model_exists else 0) setattr(opt, 'upscale', [int(post_data['upscale_level']), float(post_data['upscale_strength'])] if post_data['upscale_level'] != '' else None)