Added seam fix parameters, removed gradio dependency
Also removed unused imports and variables.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
# Empty gradio module for the ultimate-upscale.py import because gradio is not needed
|
||||
@@ -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
|
||||
|
||||
|
||||
|
||||
+1
-4
@@ -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
|
||||
actual_upscaler = None
|
||||
@@ -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])
|
||||
|
||||
Reference in New Issue
Block a user