Update sd-webui-hires-i2i/scripts/hires_fix_i2i.py
Browse files
sd-webui-hires-i2i/scripts/hires_fix_i2i.py
CHANGED
|
@@ -38,9 +38,8 @@ class HiresUnified(scripts.Script):
|
|
| 38 |
|
| 39 |
def __init__(self):
|
| 40 |
super().__init__()
|
| 41 |
-
# Кэш апскейла init
|
| 42 |
-
self.
|
| 43 |
-
self._before_cache_img: Optional[Image.Image] = None
|
| 44 |
|
| 45 |
# Отложенный апскейл (режим After / txt2img) — параметры сохраняем в setup()
|
| 46 |
self._defer_after: bool = False
|
|
@@ -187,14 +186,18 @@ class HiresUnified(scripts.Script):
|
|
| 187 |
|
| 188 |
# Если есть init_images И выбран режим "Before" → апскейлим init ДО генерации
|
| 189 |
if getattr(p, "init_images", None) and p.init_images and not process_after:
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 198 |
# Ничего не откладываем на postprocess
|
| 199 |
self._defer_after = False
|
| 200 |
else:
|
|
@@ -245,7 +248,9 @@ class HiresUnified(scripts.Script):
|
|
| 245 |
new_images.append(self._resize_with_upscaler(img, r, name))
|
| 246 |
if new_images:
|
| 247 |
processed.images = new_images
|
|
|
|
|
|
|
| 248 |
if getattr(processed, "extra_generation_params", None) is not None:
|
| 249 |
processed.extra_generation_params.update({
|
| 250 |
"Hires Applied After": True
|
| 251 |
-
})
|
|
|
|
| 38 |
|
| 39 |
def __init__(self):
|
| 40 |
super().__init__()
|
| 41 |
+
# Кэш апскейла init-изображений (режим Before) — dict для поддержки множественных
|
| 42 |
+
self._before_cache: dict[Tuple[int, str, float], Image.Image] = {}
|
|
|
|
| 43 |
|
| 44 |
# Отложенный апскейл (режим After / txt2img) — параметры сохраняем в setup()
|
| 45 |
self._defer_after: bool = False
|
|
|
|
| 186 |
|
| 187 |
# Если есть init_images И выбран режим "Before" → апскейлим init ДО генерации
|
| 188 |
if getattr(p, "init_images", None) and p.init_images and not process_after:
|
| 189 |
+
first_w, first_h = None, None
|
| 190 |
+
for i, init_image in enumerate(p.init_images):
|
| 191 |
+
key = (self._get_image_bytes_key(init_image), upscaler_name, float(ratio))
|
| 192 |
+
if key not in self._before_cache:
|
| 193 |
+
up = self._resize_with_upscaler(init_image, ratio, upscaler_name)
|
| 194 |
+
self._before_cache[key] = up
|
| 195 |
+
p.init_images[i] = self._before_cache[key]
|
| 196 |
+
if i == 0:
|
| 197 |
+
first_w, first_h = p.init_images[i].width, p.init_images[i].height
|
| 198 |
+
if first_w is not None:
|
| 199 |
+
p.width = first_w
|
| 200 |
+
p.height = first_h
|
| 201 |
# Ничего не откладываем на postprocess
|
| 202 |
self._defer_after = False
|
| 203 |
else:
|
|
|
|
| 248 |
new_images.append(self._resize_with_upscaler(img, r, name))
|
| 249 |
if new_images:
|
| 250 |
processed.images = new_images
|
| 251 |
+
processed.image = new_images[0]
|
| 252 |
+
processed.grid = new_images[0]
|
| 253 |
if getattr(processed, "extra_generation_params", None) is not None:
|
| 254 |
processed.extra_generation_params.update({
|
| 255 |
"Hires Applied After": True
|
| 256 |
+
})
|