Update asymmetric-tiling-sd-webui-3.0/scripts/asymmetric_tiling_UNIFIED.py
Browse files
asymmetric-tiling-sd-webui-3.0/scripts/asymmetric_tiling_UNIFIED.py
CHANGED
|
@@ -1793,57 +1793,75 @@ def custom_padding_forward(input_tensor, weight, bias, stride, padding, dilation
|
|
| 1793 |
else:
|
| 1794 |
req_pad_h = req_pad_w = 0
|
| 1795 |
|
| 1796 |
-
#
|
| 1797 |
-
|
| 1798 |
-
|
| 1799 |
-
|
| 1800 |
-
mode_x = params.get('mode_x', 'Default (Off)')
|
| 1801 |
-
mode_y = params.get('mode_y', 'Default (Off)')
|
| 1802 |
-
|
| 1803 |
-
# Проверяем zoom mode
|
| 1804 |
-
if params.get('use_zoom', False):
|
| 1805 |
-
# Применяем zoom (упрощенно - нужна полная реализация)
|
| 1806 |
-
x = F.pad(input_tensor, (req_pad_w, req_pad_w, req_pad_h, req_pad_h), mode='replicate')
|
| 1807 |
-
else:
|
| 1808 |
-
# Стандартные режимы
|
| 1809 |
-
x = input_tensor
|
| 1810 |
-
|
| 1811 |
-
# Ось Y
|
| 1812 |
-
if mode_y == 'Circular':
|
| 1813 |
-
x = F.pad(x, (0, 0, req_pad_h, req_pad_h), mode='circular')
|
| 1814 |
-
elif mode_y == 'Mirror (Reflect)':
|
| 1815 |
-
x = F.pad(x, (0, 0, req_pad_h, req_pad_h), mode='reflect')
|
| 1816 |
-
else:
|
| 1817 |
-
x = F.pad(x, (0, 0, req_pad_h, req_pad_h), mode='constant', value=0)
|
| 1818 |
-
|
| 1819 |
-
# Ось X
|
| 1820 |
-
if mode_x == 'Circular':
|
| 1821 |
-
x = F.pad(x, (req_pad_w, req_pad_w, 0, 0), mode='circular')
|
| 1822 |
-
elif mode_x == 'Mirror (Reflect)':
|
| 1823 |
-
x = F.pad(x, (req_pad_w, req_pad_w, 0, 0), mode='reflect')
|
| 1824 |
-
else:
|
| 1825 |
-
x = F.pad(x, (req_pad_w, req_pad_w, 0, 0), mode='constant', value=0)
|
| 1826 |
-
|
| 1827 |
-
# ===== ШАГ 6: Применяем свертку с нулевым padding (т.к. уже добавили) =====
|
| 1828 |
-
output = F.conv2d(x, weight, bias, stride, 0, dilation, groups)
|
| 1829 |
|
| 1830 |
-
|
| 1831 |
-
|
| 1832 |
|
| 1833 |
-
return output
|
| 1834 |
-
|
| 1835 |
-
except Exception as e:
|
| 1836 |
-
print(f"[Advanced Tiling] Error in custom_padding_forward_FIXED: {e}")
|
| 1837 |
-
import traceback
|
| 1838 |
-
traceback.print_exc()
|
| 1839 |
-
# Fallback к стандартной свертке
|
| 1840 |
-
return F.conv2d(input_tensor, weight, bias, stride, padding, dilation, groups)
|
| 1841 |
-
|
| 1842 |
# ═══════════════════════════════════════════════════════════════════
|
| 1843 |
-
#
|
| 1844 |
# ═══════════════════════════════════════════════════════════════════
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1845 |
|
| 1846 |
-
# ────────── CUBEMAP ──────────
|
| 1847 |
if mode_x == MODE_CUBEMAP or mode_y == MODE_CUBEMAP:
|
| 1848 |
cubemap_engine = params.get('cubemap_engine', 'A (Fast)')
|
| 1849 |
cubemap_pad_mode = params.get('cubemap_pad_mode', 'replicate')
|
|
@@ -1916,6 +1934,8 @@ def custom_padding_forward(input_tensor, weight, bias, stride, padding, dilation
|
|
| 1916 |
enabled=True
|
| 1917 |
)
|
| 1918 |
|
|
|
|
|
|
|
| 1919 |
return out_cube
|
| 1920 |
|
| 1921 |
# ────────── PANORAMA ──────────
|
|
@@ -1985,6 +2005,8 @@ def custom_padding_forward(input_tensor, weight, bias, stride, padding, dilation
|
|
| 1985 |
enabled=True
|
| 1986 |
)
|
| 1987 |
|
|
|
|
|
|
|
| 1988 |
return out_pano
|
| 1989 |
|
| 1990 |
# Engine B: fast pole-correct padding
|
|
@@ -2027,6 +2049,8 @@ def custom_padding_forward(input_tensor, weight, bias, stride, padding, dilation
|
|
| 2027 |
enabled=True
|
| 2028 |
)
|
| 2029 |
|
|
|
|
|
|
|
| 2030 |
return out_pano
|
| 2031 |
|
| 2032 |
# Engine A (legacy): simple circular wrap
|
|
@@ -2057,6 +2081,8 @@ def custom_padding_forward(input_tensor, weight, bias, stride, padding, dilation
|
|
| 2057 |
enabled=True
|
| 2058 |
)
|
| 2059 |
|
|
|
|
|
|
|
| 2060 |
return out_pano
|
| 2061 |
|
| 2062 |
# ═══════════════════════════════════════════════════════════════════
|
|
@@ -2167,8 +2193,12 @@ def custom_padding_forward(input_tensor, weight, bias, stride, padding, dilation
|
|
| 2167 |
enabled=True
|
| 2168 |
)
|
| 2169 |
|
|
|
|
|
|
|
| 2170 |
return out_final # ← ИСПРАВЛЕНО: возвращаем с multires!
|
| 2171 |
else:
|
|
|
|
|
|
|
| 2172 |
return out_advanced # ← Без multires
|
| 2173 |
|
| 2174 |
except Exception as e:
|
|
@@ -3650,6 +3680,4 @@ class AdvancedTilingScriptV3(scripts.Script):
|
|
| 3650 |
_PANO_GRID_CACHE.clear()
|
| 3651 |
|
| 3652 |
if restored > 0:
|
| 3653 |
-
print(f"✓ Restored {restored} layers to original state")
|
| 3654 |
-
|
| 3655 |
-
|
|
|
|
| 1793 |
else:
|
| 1794 |
req_pad_h = req_pad_w = 0
|
| 1795 |
|
| 1796 |
+
# FIX V3.7: Не выходим рано, если включен ZOOM!
|
| 1797 |
+
if req_pad_h == 0 and req_pad_w == 0 and not params.get('use_zoom', False):
|
| 1798 |
+
return F.conv2d(input_tensor, weight, bias, stride, padding, dilation, groups)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1799 |
|
| 1800 |
+
mode_x = params.get('mode_x', MODE_OFF)
|
| 1801 |
+
mode_y = params.get('mode_y', MODE_OFF)
|
| 1802 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1803 |
# ═══════════════════════════════════════════════════════════════════
|
| 1804 |
+
# ZOOM SYSTEM - обрабатываем первым, т.к. может комбинироваться с другими режимами
|
| 1805 |
# ═══════════════════════════════════════════════════════════════════
|
| 1806 |
+
if params.get('use_zoom', False):
|
| 1807 |
+
try:
|
| 1808 |
+
from advanced_zoom_extension import apply_unified_zoom, validate_zoom_params
|
| 1809 |
+
|
| 1810 |
+
raw_zoom_params = {
|
| 1811 |
+
'zoom_factor': params.get('zoom_factor', 0.0),
|
| 1812 |
+
'zoom_mode': params.get('zoom_mode', ZoomMode.OUTPAINT_ZOOM),
|
| 1813 |
+
'blend_mode': params.get('zoom_blend_mode', BlendMode.CIRCULAR_REFLECT),
|
| 1814 |
+
'center_x': params.get('zoom_center_x', 0.5),
|
| 1815 |
+
'center_y': params.get('zoom_center_y', 0.5),
|
| 1816 |
+
'aspect_ratio_x': params.get('zoom_aspect_ratio_x', 1.0),
|
| 1817 |
+
'aspect_ratio_y': params.get('zoom_aspect_ratio_y', 1.0),
|
| 1818 |
+
'rotation_degrees': params.get('zoom_rotation_degrees', 0.0),
|
| 1819 |
+
'perspective_strength': params.get('zoom_perspective_strength', 0.0),
|
| 1820 |
+
'perspective_angle_x': params.get('zoom_perspective_angle_x', 0.0),
|
| 1821 |
+
'perspective_angle_y': params.get('zoom_perspective_angle_y', 0.0),
|
| 1822 |
+
'blend_width_ratio': params.get('zoom_blend_width_ratio', 0.1),
|
| 1823 |
+
'blend_strength': params.get('zoom_blend_strength', 1.0),
|
| 1824 |
+
'warp_strength': params.get('zoom_warp_strength', 0.0),
|
| 1825 |
+
'warp_frequency': params.get('zoom_warp_frequency', 2.0),
|
| 1826 |
+
'use_adaptive_blend': params.get('zoom_use_adaptive_blend', False),
|
| 1827 |
+
'edge_threshold': params.get('zoom_edge_threshold', 0.1),
|
| 1828 |
+
}
|
| 1829 |
+
|
| 1830 |
+
zoom_params = validate_zoom_params(raw_zoom_params)
|
| 1831 |
+
|
| 1832 |
+
# --- START FIX ---
|
| 1833 |
+
# Move unexpected arguments to extra_params
|
| 1834 |
+
extra_keys = ['spiral_rotation', 'spiral_direction',
|
| 1835 |
+
'gradient_center_x', 'gradient_center_y', 'gradient_radius',
|
| 1836 |
+
'noise_scale', 'noise_octaves']
|
| 1837 |
+
extra_params = {}
|
| 1838 |
+
for key in extra_keys:
|
| 1839 |
+
if key in zoom_params:
|
| 1840 |
+
extra_params[key] = zoom_params.pop(key)
|
| 1841 |
+
# 🔥 ВАЖНАЯ СТРОКА ДЛЯ ЧЕТКОСТИ:
|
| 1842 |
+
extra_params['force_original_size'] = False
|
| 1843 |
+
# -----------------
|
| 1844 |
+
|
| 1845 |
+
x = apply_unified_zoom(
|
| 1846 |
+
input_tensor,
|
| 1847 |
+
pad_h=req_pad_h,
|
| 1848 |
+
pad_w=req_pad_w,
|
| 1849 |
+
extra_params=extra_params, # Pass explicitly
|
| 1850 |
+
**zoom_params
|
| 1851 |
+
)
|
| 1852 |
+
|
| 1853 |
+
output = F.conv2d(x, weight, bias, stride, (0, 0), dilation, groups)
|
| 1854 |
+
|
| 1855 |
+
# ✅ КРИТИЧЕСКОЕ ИСПРАВЛЕНИЕ: корректируем размеры
|
| 1856 |
+
output = ensure_output_size_match(output, expected_out_h, expected_out_w)
|
| 1857 |
+
return output
|
| 1858 |
+
|
| 1859 |
+
except Exception as e:
|
| 1860 |
+
print(f"⚠ Zoom Error: {e}")
|
| 1861 |
+
import traceback
|
| 1862 |
+
traceback.print_exc()
|
| 1863 |
+
return F.conv2d(input_tensor, weight, bias, stride, padding, dilation, groups)
|
| 1864 |
|
|
|
|
| 1865 |
if mode_x == MODE_CUBEMAP or mode_y == MODE_CUBEMAP:
|
| 1866 |
cubemap_engine = params.get('cubemap_engine', 'A (Fast)')
|
| 1867 |
cubemap_pad_mode = params.get('cubemap_pad_mode', 'replicate')
|
|
|
|
| 1934 |
enabled=True
|
| 1935 |
)
|
| 1936 |
|
| 1937 |
+
# ✅ КРИТИЧЕСКОЕ ИСПРАВЛЕНИЕ: корректируем размеры
|
| 1938 |
+
out_cube = ensure_output_size_match(out_cube, expected_out_h, expected_out_w)
|
| 1939 |
return out_cube
|
| 1940 |
|
| 1941 |
# ────────── PANORAMA ──────────
|
|
|
|
| 2005 |
enabled=True
|
| 2006 |
)
|
| 2007 |
|
| 2008 |
+
# ✅ КРИТИЧЕСКОЕ ИСПРАВЛЕНИЕ: корректируем размеры
|
| 2009 |
+
out_pano = ensure_output_size_match(out_pano, expected_out_h, expected_out_w)
|
| 2010 |
return out_pano
|
| 2011 |
|
| 2012 |
# Engine B: fast pole-correct padding
|
|
|
|
| 2049 |
enabled=True
|
| 2050 |
)
|
| 2051 |
|
| 2052 |
+
# ✅ КРИТИЧЕСКОЕ ИСПРАВЛЕНИЕ: корректируем размеры
|
| 2053 |
+
out_pano = ensure_output_size_match(out_pano, expected_out_h, expected_out_w)
|
| 2054 |
return out_pano
|
| 2055 |
|
| 2056 |
# Engine A (legacy): simple circular wrap
|
|
|
|
| 2081 |
enabled=True
|
| 2082 |
)
|
| 2083 |
|
| 2084 |
+
# ✅ КРИТИЧЕСКОЕ ИСПРАВЛЕНИЕ: корректируем размеры
|
| 2085 |
+
out_pano = ensure_output_size_match(out_pano, expected_out_h, expected_out_w)
|
| 2086 |
return out_pano
|
| 2087 |
|
| 2088 |
# ═══════════════════════════════════════════════════════════════════
|
|
|
|
| 2193 |
enabled=True
|
| 2194 |
)
|
| 2195 |
|
| 2196 |
+
# ✅ КРИТИЧЕСКОЕ ИСПРАВЛЕНИЕ: корректируем размеры
|
| 2197 |
+
out_final = ensure_output_size_match(out_final, expected_out_h, expected_out_w)
|
| 2198 |
return out_final # ← ИСПРАВЛЕНО: возвращаем с multires!
|
| 2199 |
else:
|
| 2200 |
+
# ✅ КРИТИЧЕСКОЕ ИСПРАВЛЕНИЕ: корректируем размеры
|
| 2201 |
+
out_advanced = ensure_output_size_match(out_advanced, expected_out_h, expected_out_w)
|
| 2202 |
return out_advanced # ← Без multires
|
| 2203 |
|
| 2204 |
except Exception as e:
|
|
|
|
| 3680 |
_PANO_GRID_CACHE.clear()
|
| 3681 |
|
| 3682 |
if restored > 0:
|
| 3683 |
+
print(f"✓ Restored {restored} layers to original state")
|
|
|
|
|
|