Fix 2D upscale tile boundary rounding
This commit is contained in:
@@ -135,19 +135,20 @@ class DumasMMH3LatentUpscale2D:
|
||||
yi0, yi1 = max(0, y0 - tile_overlap), min(h, y1 + tile_overlap)
|
||||
xi0, xi1 = max(0, x0 - tile_overlap), min(w, x1 + tile_overlap)
|
||||
tile = (src[:, :, :, yi0:yi1, xi0:xi1] - mean) / std
|
||||
sy, sx = out_h / h, out_w / w
|
||||
tile_y0, tile_y1 = int(round(yi0 * sy)), int(round(yi1 * sy))
|
||||
tile_x0, tile_x1 = int(round(xi0 * sx)), int(round(xi1 * sx))
|
||||
tile_out = model(
|
||||
tile, scale=1.0,
|
||||
target_hw=(int(round((yi1 - yi0) * out_h / h)),
|
||||
int(round((xi1 - xi0) * out_w / w))),
|
||||
target_hw=(tile_y1 - tile_y0, tile_x1 - tile_x0),
|
||||
enable_chunking=False,
|
||||
tier=(int(sharpness) if getattr(model.resizer, "tier_dim", 0) else None),
|
||||
)
|
||||
sy, sx = out_h / h, out_w / w
|
||||
oy0, oy1 = int(round((y0 - yi0) * sy)), int(round((y1 - yi0) * sy))
|
||||
ox0, ox1 = int(round((x0 - xi0) * sx)), int(round((x1 - xi0) * sx))
|
||||
dy0, dy1 = int(round(y0 * sy)), int(round(y1 * sy))
|
||||
dx0, dx1 = int(round(x0 * sx)), int(round(x1 * sx))
|
||||
result[:, :, :, dy0:dy1, dx0:dx1] += tile_out[:, :, :, oy0:oy1, ox0:ox1]
|
||||
dh, dw = dy1 - dy0, dx1 - dx0
|
||||
oy0, ox0 = dy0 - tile_y0, dx0 - tile_x0
|
||||
result[:, :, :, dy0:dy1, dx0:dx1] += tile_out[:, :, :, oy0:oy0 + dh, ox0:ox0 + dw]
|
||||
weights[:, :, :, dy0:dy1, dx0:dx1] += 1
|
||||
del tile, tile_out
|
||||
out = (result / weights.clamp_min(1) * std + mean).to("cpu", dtype=source.dtype)
|
||||
|
||||
Reference in New Issue
Block a user