Skip to content
代码片段 群组 项目
未验证 提交 dd5b57e3 编辑于 作者: DenOfEquity's avatar DenOfEquity 提交者: GitHub
浏览文件

fix for SAG with Kohya HRFix/ Deep Shrink (#5546)

now works with arbitrary downscale factors
上级 75a818c7
No related branches found
No related tags found
无相关合并请求
......@@ -57,12 +57,17 @@ def create_blur_map(x0, attn, sigma=3.0, threshold=1.0):
attn = attn.reshape(b, -1, hw1, hw2)
# Global Average Pool
mask = attn.mean(1, keepdim=False).sum(1, keepdim=False) > threshold
ratio = 2**(math.ceil(math.sqrt(lh * lw / hw1)) - 1).bit_length()
mid_shape = [math.ceil(lh / ratio), math.ceil(lw / ratio)]
f = float(lh) / float(lw)
fh = f ** 0.5
fw = (1/f) ** 0.5
S = mask.size(1) ** 0.5
w = int(0.5 + S * fw)
h = int(0.5 + S * fh)
# Reshape
mask = (
mask.reshape(b, *mid_shape)
mask.reshape(b, h, w)
.unsqueeze(1)
.type(attn.dtype)
)
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册