From dc2e5d9d169e5ee16aae5ce7f00b5ae38556103e Mon Sep 17 00:00:00 2001 From: ssit Date: Thu, 18 May 2023 14:59:26 -0400 Subject: [PATCH] Added seam fix parameters, removed gradio dependency Also removed unused imports and variables. --- gradio.py | 1 + modules/processing.py | 3 --- modules/shared.py | 5 +---- nodes.py | 33 ++++++++++++++++++++++++--------- 4 files changed, 26 insertions(+), 16 deletions(-) create mode 100644 gradio.py diff --git a/gradio.py b/gradio.py new file mode 100644 index 0000000..0baca44 --- /dev/null +++ b/gradio.py @@ -0,0 +1 @@ +# Empty gradio module for the ultimate-upscale.py import because gradio is not needed \ No newline at end of file diff --git a/modules/processing.py b/modules/processing.py index 3040279..690f5f1 100644 --- a/modules/processing.py +++ b/modules/processing.py @@ -1,9 +1,6 @@ # Patched classes to adapt from A111 webui for ComfyUI from nodes import common_ksampler, VAEEncode, VAEDecode from utils import pil_to_tensor, tensor_to_pil, get_mask_region, expand_crop_region, resize_image -import modules.shared as shared -import numpy as np -import torch from PIL import Image, ImageFilter diff --git a/modules/shared.py b/modules/shared.py index 6b4f123..d27442f 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -18,7 +18,4 @@ state = State() # Will only ever hold 1 upscaler sd_upscalers = [None] # The upscaler usable by ComfyUI nodes -actual_upscaler = None - -# The resulting image -tiled_image = None \ No newline at end of file +actual_upscaler = None \ No newline at end of file diff --git a/nodes.py b/nodes.py index 16beeaa..4d4d7a8 100644 --- a/nodes.py +++ b/nodes.py @@ -13,12 +13,19 @@ sys.path.insert(0, os.path.join( MAX_RESOLUTION = 8192 -# The modes avaiable for Ultimate SD Upscale +# The modes available for Ultimate SD Upscale MODES = { "Linear": ult.USDUMode.LINEAR, "Chess": ult.USDUMode.CHESS, "None": ult.USDUMode.NONE, } +# The seam fix modes +SEAM_FIX_MODES = { + "None": ult.USDUSFMode.NONE, + "Band Pass": ult.USDUSFMode.BAND_PASS, + "Half Tile": ult.USDUSFMode.HALF_TILE, + "Half Tile + Intersections": ult.USDUSFMode.HALF_TILE_PLUS_INTERSECTIONS, +} class UltimateSDUpscale: @@ -46,6 +53,12 @@ class UltimateSDUpscale: "tile_height": ("INT", {"default": 512, "min": 64, "max": MAX_RESOLUTION, "step": 64}), "mask_blur": ("INT", {"default": 8, "min": 0, "max": 64, "step": 1}), "tile_padding": ("INT", {"default": 32, "min": 0, "max": 128, "step": 1}), + # Seam fix params + "seam_fix_mode": (list(SEAM_FIX_MODES.keys()),), + "seam_fix_denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01}), + "seam_fix_width": ("INT", {"default": 64, "min": 0, "max": 128, "step": 1}), + "seam_fix_mask_blur": ("INT", {"default": 8, "min": 0, "max": 64, "step": 1}), + "seam_fix_padding": ("INT", {"default": 16, "min": 0, "max": 128, "step": 1}), } } @@ -55,7 +68,9 @@ class UltimateSDUpscale: def upscale(self, image, model, positive, negative, vae, upscale_by, seed, steps, cfg, sampler_name, scheduler, denoise, upscale_model, - mode_type, tile_width, tile_height, mask_blur, tile_padding): + mode_type, tile_width, tile_height, mask_blur, tile_padding, + seam_fix_mode, seam_fix_denoise, seam_fix_mask_blur, + seam_fix_width, seam_fix_padding): # # Set up A1111 patches # @@ -65,8 +80,6 @@ class UltimateSDUpscale: shared.sd_upscalers[0] = UpscalerData() # Where the actual upscaler is stored, will be used when the script upscales using the Upscaler in UpscalerData shared.actual_upscaler = upscale_model - # Reset the resulting image - shared.tiled_image = None # Processing sdprocessing = StableDiffusionProcessing(tensor_to_pil(image), @@ -78,11 +91,13 @@ class UltimateSDUpscale: # Running the script # script = ult.Script() - processed = script.run(p=sdprocessing, _=None, tile_width=tile_width, tile_height=tile_height, mask_blur=mask_blur, - padding=tile_padding, seams_fix_width=None, seams_fix_denoise=None, seams_fix_padding=None, - upscaler_index=0, save_upscaled_image=False, redraw_mode=MODES[mode_type], save_seams_fix_image=False, - seams_fix_mask_blur=None, seams_fix_type=ult.USDUSFMode.NONE, target_size_type=2, custom_width=None, - custom_height=None, custom_scale=upscale_by) + processed = script.run(p=sdprocessing, _=None, tile_width=tile_width, tile_height=tile_height, + mask_blur=mask_blur, padding=tile_padding, seams_fix_width=seam_fix_width, + seams_fix_denoise=seam_fix_denoise, seams_fix_padding=seam_fix_padding, + upscaler_index=0, save_upscaled_image=False, redraw_mode=MODES[mode_type], + save_seams_fix_image=False, seams_fix_mask_blur=seam_fix_mask_blur, + seams_fix_type=SEAM_FIX_MODES[seam_fix_mode], target_size_type=2, + custom_width=None, custom_height=None, custom_scale=upscale_by) # Return the resulting image upscaled_image = pil_to_tensor(processed.images[0])