From 23d42a127ed10722f1b5308e33fb0a6f1186bef5 Mon Sep 17 00:00:00 2001 From: Chris Dumas Date: Thu, 12 Nov 2026 09:25:24 +0000 Subject: [PATCH] Fix 2D upscale tile boundary rounding --- dumas_h3_latent_upscale_2d.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/dumas_h3_latent_upscale_2d.py b/dumas_h3_latent_upscale_2d.py index 98d2c1d..b6868e6 100644 --- a/dumas_h3_latent_upscale_2d.py +++ b/dumas_h3_latent_upscale_2d.py @@ -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)