跳到正文
DEV Community· hao jia·· 7 小時前AI 評分58

Real-ESRGAN General x4v3 分塊放大測試:填充量由 0 增至 34,最大差異由 149 降至 0

Tile padding for 4x upscaling: six lines of output, max difference 149 down to 0

AI 導讀

作者測試 Real-ESRGAN General x4v3 的 4 倍分塊放大,96 像素 tile 的填充量由 0 增至 34 時,輸出相對整圖推理的最大差異由 149 降至 0。

正文

If you run a 4x upscaler in tiles, you have probably seen the seam: a faint grid where the blocks meet. The usual fix is "add some overlap", with no number attached. This post reads one real run of a pad-and-crop loop line by line, so you can get that number for your own model.

The setup: Python with onnxruntime on CPU, Real-ESRGAN General x4v3, a 480×480 crop of a CC0 landscape photo from Wikimedia Commons (author Bonnie Moreland) in, a 1920×1920 image out. Tile size 96. For each tile, the loop sends the tile plus N extra pixels on every side into the model, crops the extra ring off the output and pastes only the middle back. N is the padding. The reference is the same model fed the whole image at once.

The six lines

The output of that run, quoted as printed:

整图一次   1.53s
块 96 上下文  0   2.75s  与整图一次的最大差 149  不同的像素值 2197281
块 96 上下文  4   3.14s  与整图一次的最大差  58  不同的像素值 1439588
块 96 上下文 12   3.98s  与整图一次的最大差  10  不同的像素值 485258
块 96 上下文 24   5.16s  与整图一次的最大差   2  不同的像素值 29057
块 96 上下文 34   6.22s  与整图一次的最大差   0  不同的像素值 0

The labels are Chinese: 整图一次 is "whole image, one pass", 块 is tile, 上下文 is context (the padding), 最大差 is max difference, and 不同的像素值 is the number of differing pixel values.

Line one is the reference, the cheapest line. Line two is padding 0, the plain "cut, infer, paste" version. The worst pixel is off by 149 on the 0–255 scale, and 2,197,281 of the 11,059,200 values (1920 × 1920 × 3 channels) differ, about a fifth.

Lines three and four: padding 4 gives 58, padding 12 gives 10. At 12 the differing count is 485,258, about 4% of all values (percentages here are divided from the printed counts, not measured separately).

Line five, padding 24, leaves a max difference of 2 and 29,057 differing values, under 0.3%.

Line six, padding 34, is identical to the reference: max difference 0, zero differing values. A finer scan from 28 to 33 px still leaves between a few thousand and three values off by one level.

Two caveats on this log. This script did not pin the thread count, so it ran with the default, and the timings do not compare with the 4-thread tables below. In that setup, medians of five runs, whole-image inference took 1.60 s and tile 96 with padding 12 took 2.28 s, against 3.98 s here. And 149 is the max taken per colour channel; a table that averages the three channels first lists 145 for padding 0, so the two numbers are not in conflict.

What was measured

Cost is the other side. For Real-ESRGAN General x4v3, a 480×480 input and 4 CPU threads, with 5-run medians, tile 96 gets 15%, 43%, 94% and 155% slower than padding 0 at padding 4, 12, 24 and 36, while tile 160 gets 8%, 23%, 47% and 74% slower. Smaller tiles pay more for the same padding.

Where the seam hurts differs by content. In a self-made 480×480 test image with four regions, tile 96 and no padding, the worst pixel differences sat on straight lines and text crossing a block edge (max 249 and 227). The gradient sky had a max of 19, yet its seam is the easiest to notice, since nothing hides the straight step.

What is inferred

The 34 is probably not a coincidence. This model is 34 stacked 3×3 convolutions, and each layer reaches one pixel further, so an output pixel can depend on at most 34 pixels of input around it. With 34 pixels of padding, every kept pixel would see the same input as in a whole-image pass. That is an inference from the architecture; the run only confirms the zero. It would apply to plain convolutional models only; SwinIR and HAT, which use attention, were not run, so nothing is claimed about them.

The Real-ESRGAN README, read on 2026-11-20 and not run here, says of its portable executable that tiling "may introduce block inconsistency".

Use it on your own model

Run the same comparison: whole image once, then tiles at growing padding, and read the max difference and the differing count. Take the smallest padding where both are acceptable. For a browser example, ImgIng https://imging.ai/ runs its fast upscale tier in a worker with tile 160 and overlap 12. Three 256×256 samples, CC0 photos (portrait by William Stitt, landscape by Bonnie Moreland) aged by script, so not real old photos, were upscaled 4x once each; against whole-image inference with the same model file, the output differed by at most 2 levels, and 16 on the scratched one. That difference also mixes browser GPU and CPU rounding, so not all of it is seam.

Matching a whole-image pass only shows that tiling adds no error. The detail the model draws is its own guess, so neither result is fit for IDs, forensics or checking OCR text; keep the original.

來源:DEV Community · dev.to