Commit ·
fd2ee05
1
Parent(s): a62e7c1
fix: resize to original
Browse files
logic.py
CHANGED
|
@@ -70,25 +70,31 @@ class WatermarkRemover:
|
|
| 70 |
"painting, mirror artifact, blurry, distorted, deformed, low quality, noise, grain"
|
| 71 |
)
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
with torch.inference_mode():
|
| 80 |
result = self.inpainting_pipe(
|
| 81 |
prompt=prompt,
|
| 82 |
negative_prompt=negative_prompt,
|
| 83 |
-
image=
|
| 84 |
-
mask_image=
|
| 85 |
num_inference_steps=30,
|
| 86 |
guidance_scale=7.5,
|
| 87 |
-
# 👇 Явно передаем оригинальные размеры
|
| 88 |
-
width=original_width,
|
| 89 |
-
height=original_height,
|
| 90 |
).images[0]
|
| 91 |
|
|
|
|
|
|
|
|
|
|
| 92 |
return np.array(result)
|
| 93 |
|
| 94 |
# ===================================================================
|
|
|
|
| 70 |
"painting, mirror artifact, blurry, distorted, deformed, low quality, noise, grain"
|
| 71 |
)
|
| 72 |
|
| 73 |
+
logger.info("Запуск Stable Diffusion Inpainting с 30 шагами...")
|
| 74 |
+
|
| 75 |
+
# --- 🔹 Сохраняем оригинальный размер
|
| 76 |
+
orig_size = image.size # (width, height)
|
| 77 |
+
|
| 78 |
+
# --- 🔹 Resize до кратного 8 (иначе модель может ругаться)
|
| 79 |
+
new_w = (orig_size[0] // 8) * 8
|
| 80 |
+
new_h = (orig_size[1] // 8) * 8
|
| 81 |
+
resized_image = image.resize((new_w, new_h), Image.LANCZOS)
|
| 82 |
+
resized_mask = mask.resize((new_w, new_h), Image.LANCZOS)
|
| 83 |
+
|
| 84 |
+
# --- 🔹 Инференс
|
| 85 |
with torch.inference_mode():
|
| 86 |
result = self.inpainting_pipe(
|
| 87 |
prompt=prompt,
|
| 88 |
negative_prompt=negative_prompt,
|
| 89 |
+
image=resized_image,
|
| 90 |
+
mask_image=resized_mask,
|
| 91 |
num_inference_steps=30,
|
| 92 |
guidance_scale=7.5,
|
|
|
|
|
|
|
|
|
|
| 93 |
).images[0]
|
| 94 |
|
| 95 |
+
# --- 🔹 Возвращаем к оригинальному размеру
|
| 96 |
+
result = result.resize(orig_size, Image.LANCZOS)
|
| 97 |
+
|
| 98 |
return np.array(result)
|
| 99 |
|
| 100 |
# ===================================================================
|