From 0202547696a2c8cbe91efbeb30a7b2c689fbe276 Mon Sep 17 00:00:00 2001 From: kaneda2004 Date: Mon, 28 Nov 2022 12:24:53 -0800 Subject: [PATCH 1/3] Update SD Upscaler to include user selectable Scale Factor --- scripts/sd_upscale.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/sd_upscale.py b/scripts/sd_upscale.py index 01074291..4370abe1 100644 --- a/scripts/sd_upscale.py +++ b/scripts/sd_upscale.py @@ -17,13 +17,16 @@ class Script(scripts.Script): return is_img2img def ui(self, is_img2img): - info = gr.HTML("

Will upscale the image to twice the dimensions; use width and height sliders to set tile size

") + info = gr.HTML( + "

Will upscale the image by the selected scale factor; use width and height sliders to set tile size

") overlap = gr.Slider(minimum=0, maximum=256, step=16, label='Tile overlap', value=64) - upscaler_index = gr.Radio(label='Upscaler', choices=[x.name for x in shared.sd_upscalers], value=shared.sd_upscalers[0].name, type="index") + scale_factor = gr.Slider(minimum=0, maximum=4, step=1, label='Scale Factor', value=2) + upscaler_index = gr.Radio(label='Upscaler', choices=[x.name for x in shared.sd_upscalers], + value=shared.sd_upscalers[0].name, type="index") - return [info, overlap, upscaler_index] + return [info, overlap, upscaler_index, scale_factor] - def run(self, p, _, overlap, upscaler_index): + def run(self, p, _, overlap, upscaler_index, scale_factor): processing.fix_seed(p) upscaler = shared.sd_upscalers[upscaler_index] @@ -34,9 +37,9 @@ class Script(scripts.Script): seed = p.seed init_img = p.init_images[0] - - if(upscaler.name != "None"): - img = upscaler.scaler.upscale(init_img, 2, upscaler.data_path) + + if (upscaler.name != "None"): + img = upscaler.scaler.upscale(init_img, scale_factor, upscaler.data_path) else: img = init_img @@ -59,7 +62,8 @@ class Script(scripts.Script): batch_count = math.ceil(len(work) / batch_size) state.job_count = batch_count * upscale_count - print(f"SD upscaling will process a total of {len(work)} images tiled as {len(grid.tiles[0][2])}x{len(grid.tiles)} per upscale in a total of {state.job_count} batches.") + print( + f"SD upscaling will process a total of {len(work)} images tiled as {len(grid.tiles[0][2])}x{len(grid.tiles)} per upscale in a total of {state.job_count} batches.") result_images = [] for n in range(upscale_count): @@ -69,7 +73,7 @@ class Script(scripts.Script): work_results = [] for i in range(batch_count): p.batch_size = batch_size - p.init_images = work[i*batch_size:(i+1)*batch_size] + p.init_images = work[i * batch_size:(i + 1) * batch_size] state.job = f"Batch {i + 1 + n * batch_count} out of {state.job_count}" processed = processing.process_images(p) @@ -83,15 +87,17 @@ class Script(scripts.Script): image_index = 0 for y, h, row in grid.tiles: for tiledata in row: - tiledata[2] = work_results[image_index] if image_index < len(work_results) else Image.new("RGB", (p.width, p.height)) + tiledata[2] = work_results[image_index] if image_index < len(work_results) else Image.new("RGB", ( + p.width, p.height)) image_index += 1 combined_image = images.combine_grid(grid) result_images.append(combined_image) if opts.samples_save: - images.save_image(combined_image, p.outpath_samples, "", start_seed, p.prompt, opts.samples_format, info=initial_info, p=p) + images.save_image(combined_image, p.outpath_samples, "", start_seed, p.prompt, opts.samples_format, + info=initial_info, p=p) processed = Processed(p, result_images, seed, initial_info) - return processed + return processed \ No newline at end of file From 91226829f8cef93fd3ec5ae979ec2e694f741a27 Mon Sep 17 00:00:00 2001 From: kaneda2004 Date: Mon, 28 Nov 2022 12:28:22 -0800 Subject: [PATCH 2/3] Update SD Upscaler to include user selectable Scale Factor --- scripts/sd_upscale.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/scripts/sd_upscale.py b/scripts/sd_upscale.py index 4370abe1..dff54f0a 100644 --- a/scripts/sd_upscale.py +++ b/scripts/sd_upscale.py @@ -17,12 +17,10 @@ class Script(scripts.Script): return is_img2img def ui(self, is_img2img): - info = gr.HTML( - "

Will upscale the image by the selected scale factor; use width and height sliders to set tile size

") + info = gr.HTML("

Will upscale the image by the selected scale factor; use width and height sliders to set tile size

") overlap = gr.Slider(minimum=0, maximum=256, step=16, label='Tile overlap', value=64) scale_factor = gr.Slider(minimum=0, maximum=4, step=1, label='Scale Factor', value=2) - upscaler_index = gr.Radio(label='Upscaler', choices=[x.name for x in shared.sd_upscalers], - value=shared.sd_upscalers[0].name, type="index") + upscaler_index = gr.Radio(label='Upscaler', choices=[x.name for x in shared.sd_upscalers], value=shared.sd_upscalers[0].name, type="index") return [info, overlap, upscaler_index, scale_factor] @@ -62,8 +60,7 @@ class Script(scripts.Script): batch_count = math.ceil(len(work) / batch_size) state.job_count = batch_count * upscale_count - print( - f"SD upscaling will process a total of {len(work)} images tiled as {len(grid.tiles[0][2])}x{len(grid.tiles)} per upscale in a total of {state.job_count} batches.") + print(f"SD upscaling will process a total of {len(work)} images tiled as {len(grid.tiles[0][2])}x{len(grid.tiles)} per upscale in a total of {state.job_count} batches.") result_images = [] for n in range(upscale_count): @@ -87,17 +84,15 @@ class Script(scripts.Script): image_index = 0 for y, h, row in grid.tiles: for tiledata in row: - tiledata[2] = work_results[image_index] if image_index < len(work_results) else Image.new("RGB", ( - p.width, p.height)) + tiledata[2] = work_results[image_index] if image_index < len(work_results) else Image.new("RGB", (p.width, p.height)) image_index += 1 combined_image = images.combine_grid(grid) result_images.append(combined_image) if opts.samples_save: - images.save_image(combined_image, p.outpath_samples, "", start_seed, p.prompt, opts.samples_format, - info=initial_info, p=p) + images.save_image(combined_image, p.outpath_samples, "", start_seed, p.prompt, opts.samples_format, info=initial_info, p=p) processed = Processed(p, result_images, seed, initial_info) - return processed \ No newline at end of file + return processed From 950d9c739ea523652c653e32c09a37c64074c38f Mon Sep 17 00:00:00 2001 From: kaneda2004 Date: Mon, 28 Nov 2022 12:29:49 -0800 Subject: [PATCH 3/3] Update SD Upscaler to include user selectable Scale Factor --- scripts/sd_upscale.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sd_upscale.py b/scripts/sd_upscale.py index dff54f0a..28bd96b3 100644 --- a/scripts/sd_upscale.py +++ b/scripts/sd_upscale.py @@ -19,7 +19,7 @@ class Script(scripts.Script): def ui(self, is_img2img): info = gr.HTML("

Will upscale the image by the selected scale factor; use width and height sliders to set tile size

") overlap = gr.Slider(minimum=0, maximum=256, step=16, label='Tile overlap', value=64) - scale_factor = gr.Slider(minimum=0, maximum=4, step=1, label='Scale Factor', value=2) + scale_factor = gr.Slider(minimum=1, maximum=4, step=1, label='Scale Factor', value=2) upscaler_index = gr.Radio(label='Upscaler', choices=[x.name for x in shared.sd_upscalers], value=shared.sd_upscalers[0].name, type="index") return [info, overlap, upscaler_index, scale_factor]