diff --git a/dumas_h3_latent_upscale.py b/dumas_h3_latent_upscale.py index 89f1b04..2b92cf8 100644 --- a/dumas_h3_latent_upscale.py +++ b/dumas_h3_latent_upscale.py @@ -634,9 +634,18 @@ def _upscale_video_model_tiled(video, param): spatial_h_overlap = max(0, int(param.get("spatial_h_overlap", overlap) or overlap)) min_tile_size = max(0, int(param.get("min_tile_size", 0) or 0)) + def _fit_overlap(value, tile): + value = max(0, int(value or 0)) + tile = max(0, int(tile or 0)) + if tile <= 32: + return 0 + return min(value, ((tile - 1) // 32) * 32) + if mode == "rows_cols": tile_w = max(32, int(round(w_out / float(grid_cols) / 32.0)) * 32) tile_h = max(32, int(round(h_out / float(grid_rows) / 32.0)) * 32) + spatial_w_overlap = _fit_overlap(spatial_w_overlap, tile_w) + spatial_h_overlap = _fit_overlap(spatial_h_overlap, tile_h) min_tile_size = min(min_tile_size, tile_w, tile_h) rows, cols, trows, tcols, row_ovl, col_ovl = _compute_spatial_grid( h_out, w_out, tile_h, tile_w, spatial_h_overlap, spatial_w_overlap, min_tile_size, min_tile_size @@ -648,6 +657,7 @@ def _upscale_video_model_tiled(video, param): if value % 32 != 0: raise ValueError(f"'{name}' must be a multiple of 32 pixels; got {value}.") min_tile_size = min(min_tile_size, tile_w, tile_h) + overlap = _fit_overlap(overlap, min(tile_w, tile_h)) rows, cols, trows, tcols, row_ovl, col_ovl = _compute_spatial_grid( h_out, w_out, tile_h, tile_w, overlap, overlap, min_tile_size, min_tile_size )