mirror of
https://github.com/jags111/efficiency-nodes-comfyui.git
synced 2026-03-24 14:42:12 -03:00
Merge pull request #128 from LucianoCirino/HiResFix-and-VAEtiled-Patch
HiResFix and VAEtiled Patch
This commit is contained in:
@@ -525,7 +525,7 @@ class TSC_KSampler:
|
|||||||
|
|
||||||
#---------------------------------------------------------------------------------------------------------------
|
#---------------------------------------------------------------------------------------------------------------
|
||||||
def vae_decode_latent(vae, samples, vae_decode):
|
def vae_decode_latent(vae, samples, vae_decode):
|
||||||
return VAEDecodeTiled.decode_tiled(vae,samples)[0] if "tiled" in vae_decode else VAEDecode().decode(vae,samples)[0]
|
return VAEDecodeTiled().decode(vae,samples,512)[0] if "tiled" in vae_decode else VAEDecode().decode(vae,samples)[0]
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------------------------------
|
||||||
def sample_latent_image(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
|
def sample_latent_image(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
|
||||||
@@ -3945,14 +3945,13 @@ if os.path.exists(sd_latent_upscaler_path):
|
|||||||
class TSC_HighRes_Fix:
|
class TSC_HighRes_Fix:
|
||||||
|
|
||||||
default_upscale_methods = LatentUpscaleBy.INPUT_TYPES()["required"]["upscale_method"][0]
|
default_upscale_methods = LatentUpscaleBy.INPUT_TYPES()["required"]["upscale_method"][0]
|
||||||
|
city96_upscale_methods = list()
|
||||||
|
|
||||||
latent_versions = []
|
|
||||||
if comfy_latent_upscaler:
|
if comfy_latent_upscaler:
|
||||||
latent_versions = comfy_latent_upscaler.LatentUpscaler.INPUT_TYPES()["required"]["latent_ver"][0]
|
city96_upscale_methods = ["SD-Latent-Upscaler." + ver for ver in comfy_latent_upscaler.LatentUpscaler.INPUT_TYPES()["required"]["latent_ver"][0]]
|
||||||
latent_versions_updated = ["SD-Latent-Upscaler." + ver for ver in latent_versions]
|
city96_scalings_raw = comfy_latent_upscaler.LatentUpscaler.INPUT_TYPES()["required"]["scale_factor"][0]
|
||||||
allowed_scalings_raw = comfy_latent_upscaler.LatentUpscaler.INPUT_TYPES()["required"]["scale_factor"][0]
|
city96_scalings_float = [float(scale) for scale in city96_scalings_raw]
|
||||||
allowed_scalings = [float(scale) for scale in allowed_scalings_raw]
|
upscale_methods = default_upscale_methods + city96_upscale_methods
|
||||||
upscale_methods = default_upscale_methods + latent_versions_updated
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def INPUT_TYPES(cls):
|
def INPUT_TYPES(cls):
|
||||||
@@ -3979,36 +3978,41 @@ class TSC_HighRes_Fix:
|
|||||||
|
|
||||||
if iterations > 0:
|
if iterations > 0:
|
||||||
# For latent methods from SD-Latent-Upscaler
|
# For latent methods from SD-Latent-Upscaler
|
||||||
if latent_upscale_method in self.latent_versions_updated:
|
if latent_upscale_method in self.city96_upscale_methods:
|
||||||
# Remove extra characters added
|
# Remove extra characters added
|
||||||
latent_upscale_method = latent_upscale_method.replace("SD-Latent-Upscaler.", "")
|
latent_upscale_method = latent_upscale_method.replace("SD-Latent-Upscaler.", "")
|
||||||
|
|
||||||
# Set function to comfy_latent_upscaler.LatentUpscaler.upscale()
|
# Set function to comfy_latent_upscaler.LatentUpscaler.upscale()
|
||||||
upscale_function = comfy_latent_upscaler.LatentUpscaler
|
upscale_function = comfy_latent_upscaler.LatentUpscaler
|
||||||
|
|
||||||
# Find the nearest valid scaling in allowed_scalings
|
# Find the nearest valid scaling in city96_scalings_float
|
||||||
nearest_scaling = min(self.allowed_scalings, key=lambda x: abs(x - upscale_by))
|
nearest_scaling = min(self.city96_scalings_float, key=lambda x: abs(x - upscale_by))
|
||||||
|
|
||||||
# Retrieve the index of the nearest scaling
|
# Retrieve the index of the nearest scaling
|
||||||
nearest_scaling_index = self.allowed_scalings.index(nearest_scaling)
|
nearest_scaling_index = self.city96_scalings_float.index(nearest_scaling)
|
||||||
|
|
||||||
# Use the index to get the raw string representation
|
# Use the index to get the raw string representation
|
||||||
nearest_scaling_raw = self.allowed_scalings_raw[nearest_scaling_index]
|
nearest_scaling_raw = self.city96_scalings_raw[nearest_scaling_index]
|
||||||
|
|
||||||
upscale_by = float_to_string(upscale_by)
|
upscale_by = float_to_string(upscale_by)
|
||||||
|
|
||||||
# Check if the input upscale_by value was different from the nearest valid value
|
# Check if the input upscale_by value was different from the nearest valid value
|
||||||
if upscale_by != nearest_scaling_raw:
|
if upscale_by != nearest_scaling_raw:
|
||||||
print(f"{warning('HighRes-Fix Warning:')} "
|
print(f"{warning('HighRes-Fix Warning:')} "
|
||||||
f"When using 'SD-Latent-Upscaler.{latent_upscale_method}', 'upscale_by' must be one of {self.allowed_scalings_raw}.\n"
|
f"When using 'SD-Latent-Upscaler.{latent_upscale_method}', 'upscale_by' must be one of {self.city96_scalings_raw}.\n"
|
||||||
f"Rounding to the nearest valid value ({nearest_scaling_raw}).\033[0m")
|
f"Rounding to the nearest valid value ({nearest_scaling_raw}).\033[0m")
|
||||||
upscale_by = nearest_scaling_raw
|
upscale_by = nearest_scaling_raw
|
||||||
|
|
||||||
# For default upscale methods
|
# For default upscale methods
|
||||||
elif latent_upscale_method in self.default_upscale_methods:
|
elif latent_upscale_method in self.default_upscale_methods:
|
||||||
# Set function to LatentUpscaleBy.upscale()
|
|
||||||
upscale_function = LatentUpscaleBy
|
upscale_function = LatentUpscaleBy
|
||||||
|
|
||||||
|
else: # Default
|
||||||
|
upscale_function = LatentUpscaleBy
|
||||||
|
latent_upscale_method = self.default_upscale_methods[0]
|
||||||
|
print(f"{warning('HiResFix Script Warning:')} Chosen latent upscale method not found! "
|
||||||
|
f"defaulting to '{latent_upscale_method}'.\n")
|
||||||
|
|
||||||
# Construct the script output
|
# Construct the script output
|
||||||
script = script or {}
|
script = script or {}
|
||||||
script["hiresfix"] = (latent_upscale_method, upscale_by, hires_steps, denoise, iterations, upscale_function)
|
script["hiresfix"] = (latent_upscale_method, upscale_by, hires_steps, denoise, iterations, upscale_function)
|
||||||
|
|||||||
Reference in New Issue
Block a user