☰
ComfyUI Ultimate SD Upscale (No Upscale) 节点实战:对已放大图像的瓦片重绘与接缝修复
2026/10/14 22:03:21 网站建设 项目流程
  • 人工智能
  • 计算机视觉
  • 图像处理
  • 媒体生成

【免费下载链接】ComfyUI_UltimateSDUpscale

ComfyUI nodes for the Ultimate Stable Diffusion Upscale script by Coyote-A.

项目地址:https://gitcode.com/gh_mirrors/co/ComfyUI_UltimateSDUpscale
点击查看免费下载

本篇技术指南围绕 ComfyUI_UltimateSDUpscale 仓库中的Ultimate SD Upscale (No Upscale)节点展开。该节点跳过基于放大模型的初始放大步骤,直接对一张"已经放大好的图像"执行分块(tiled)image-to-image 重绘与接缝修复(seam fix)。读完后,你将掌握该节点的完整输入参数体系、redraw 与 seam fix 两阶段处理流程、平铺模式与接缝修复策略的选择方法,以及从源码层面理解每个参数如何影响分块采样、VAE 解码与边缘合成的实现细节。

上图来自仓库的basic-usdu模板工作流(见 示例工作流),展示的是同族主节点UltimateSDUpscale的标准用法;Ultimate SD Upscale (No Upscale)是它的变体,工作流接入方式一致,只是输入端不需要UpscaleModelLoader,而是直接喂入一张已放大的图像。节点在 ComfyUI 节点菜单中位于image/upscaling分类下。

节点定位:只做精修,不做放大

Ultimate SD Upscale (No Upscale)对一张已经放大的图像应用分块 image-to-image 处理,用于增强细节和修复接缝,但不执行基于 upscale model 的初始放大步骤。

官方文档(js/docs/UltimateSDUpscaleNoUpscale.md)明确的设计目标是:当你已经拥有一张放大好的图像,只想应用 tiled redraw(分块重绘)和 seam fix(接缝修复)步骤时,使用这个节点变体。典型场景包括:

  • 你已经用其他方法或上采样器放大了图像,想利用 USDU 的分块精修能力来补充细节、消除伪影;
  • 你希望将"放大"与"精修"解耦,对两个阶段分别拥有更细的控制(例如放大用算法插值或另一个模型完成,精修才用扩散模型);
  • 你不想占用一个 upscale model,而是先用 Lanczos、Nearest Neighbor 这类算法完成简单放大,再用本节点做细节增强。

源码层面的实现:一个"瘦身版"主节点

从 usdu_nodes.py 的源码结构看,UltimateSDUpscaleNoUpscale并不是独立实现,而是UltimateSDUpscale主节点类的子类,通过重写INPUT_TYPES与upscale两个方法完成"瘦身":

class UltimateSDUpscaleNoUpscale(UltimateSDUpscale): @classmethod def INPUT_TYPES(s): required, optional = USDU_base_inputs() remove_input(required, "upscale_model") remove_input(required, "upscale_by") rename_input(required, "image", "upscaled_image") return prepare_inputs(required, optional) def upscale(self, upscaled_image, model, positive, negative, vae, seed, ...): upscale_by = 1.0 ... return super().upscale(upscaled_image, model, positive, negative, vae, upscale_by, seed, steps, cfg, sampler_name, scheduler, denoise, None, mode_type, tile_width, tile_height, mask_blur, tile_padding, seam_fix_mode, seam_fix_denoise, seam_fix_mask_blur, seam_fix_width, seam_fix_padding, force_uniform_tiles, tiled_decode, batch_size)

(见 usdu_nodes.py)

这段代码完整印证了文档中的两个核心事实:

  1. 不做放大:输入端移除了upscale_model和upscale_by两个参数,图像输入被重命名为upscaled_image,并把upscale_by硬编码为1.0、upscale_model传None给父类——因此节点内部根本不会发生尺寸变化,输入尺寸即输出尺寸;
  2. 复用了主节点的全部精修管线:除放大外的所有参数(采样参数、平铺参数、seam fix 参数、force_uniform_tiles、tiled_decode)与主节点完全一致,走同一条底层处理链。

两个节点共享的输入定义集中在 USDU_base_inputs 函数中,这也是下一节参数表的来源。

处理流程:redraw 与 seam fix 两个阶段

redraw 阶段(分块重绘)

当平铺顺序(tiling order,即mode_type参数)没有设置为 "None" 时,图像会进入 redraw 步骤:按照平铺顺序和节点上的 tile 参数从图像中选取一块 tile;以该 tile 作为 image-to-image 过程的输入,使用节点上的采样相关参数(seed、steps、cfg、sampler、scheduler、denoise)执行一次采样;然后把结果 tile 按正确位置贴回图像。如此循环,直到所有 tile 处理完毕。

seam fix 阶段(接缝修复)

redraw 完成后,如果启用了接缝修复(seam_fix_mode不为 "None"),还会执行 seam fix 步骤。seam fix 支持多种策略,由seam_fix_mode参数定义。它与 redraw 使用同一个image-to-image 过程,只是作用区域换成了 redraw 阶段 tile 之间的缝隙区域。

每个 tile 的底层处理链

从 modules/processing.py 中process_images函数的源码结构看,每一个 tile(无论属于 redraw 还是 seam fix)都会经历如下管线(见 modules/processing.py):

  1. 确定裁剪区域:在整图尺寸的掩码上定位当前 tile 的白色矩形区域,并加上tile_padding/seam fix padding;
  2. 尺寸策略分支(force_uniform_tiles生效点):
    • 启用时,调用expand_crop将裁剪区域向外扩展、并按图像宽高比调整,最终统一缩放到(tile_width + tile_padding) x (tile_height + tile_padding)的规整尺寸——这正是文档中"与 A1111 Web UI 行为一致"的来源;
    • 禁用时,取能装下掩码的最小尺寸(向上取整到 8 的倍数),tile 尺寸不规整,采样可能更快,但模型未必在该尺寸上训练过;
  3. 掩码模糊:若mask_blur > 0,对掩码做高斯模糊(ImageFilter.GaussianBlur(p.mask_blur)),模糊半径越大,贴回时 tile 边缘附近保留的原始图像越多;
  4. VAE 编码:把裁剪出的 tile 转成张量并批量编码为 latent;
  5. 采样:调用 ComfyUI 的common_ksampler(或自定义 sampler/sigmas、guider),以该 tile 的 latent 为初始图像做 image-to-image;
  6. VAE 解码(tiled_decode生效点):
    if not p.tiled_decode: (decoded,) = p.vae_decoder.decode(p.vae, samples) else: (decoded,) = p.vae_decoder_tiled.decode(p.vae, samples, 512) # Default tile size is 512

    (modules/processing.py)即正常解码或 512 像素瓦片解码二选一;

  7. 贴回合成:解码出的 tile 用 LANCZOS 缩放回裁剪区域原始尺寸,粘贴到全透明画布上对应位置,再以模糊后的掩码作为 alpha 通道做alpha_composite合成回原图——这就是 tile 边缘能够平滑融入原图、不出现硬边的手段。

此外,usdu_patch.py 中对原始 USDU 脚本的 monkey patch 会把目标尺寸p.width/p.height通过round_length取整到 8 的倍数,保证分块布局规整、VAE 编解码尺寸合法。

输入参数完整参考

以下表格完整继承自官方文档 js/docs/UltimateSDUpscaleNoUpscale.md,取值范围与默认值与 usdu_nodes.py 中USDU_base_inputs的定义一致。

ParameterData TypeInput MethodDefaultRangeDescription
upscaled_imageIMAGEImage InputNone-The already upscaled image to refine with tiled processing.(已放大的、待分块精修的输入图像)
modelMODELModel SelectionNone-The model to use for image-to-image processing on each tile.(每个 tile 做 image-to-image 时使用的模型)
positiveCONDITIONINGConditioning InputNone-The positive conditioning for each tile during the redraw step.(redraw 阶段每个 tile 的正向条件)
negativeCONDITIONINGConditioning InputNone-The negative conditioning for each tile during the redraw step.(redraw 阶段每个 tile 的负向条件)
vaeVAEModel SelectionNone-The VAE model to use for encoding and decoding tiles.(tile 编解码使用的 VAE 模型)
seedINTNumber Input00-18446744073709551615The seed to use for image-to-image processing, ensuring reproducible results.(i2i 采样随机种子,保证结果可复现)
stepsINTNumber Input201-10000The number of sampling steps to use for each tile during the redraw step and seam fix step.(redraw 与 seam fix 每个 tile 的采样步数)
cfgFLOATSlider8.00.0-100.0The CFG (Classifier Free Guidance) scale to use for each tile. Higher values make the output follow the prompt more closely. The recommended values depend on the model.(每个 tile 的 CFG 强度,越高越贴近提示词,推荐值取决于模型)
sampler_nameCOMBODropdown-Available samplersThe sampler to use for each tile during the image-to-image process.(i2i 过程使用的采样器,选项来自 ComfyUI 内置列表)
schedulerCOMBODropdown-Available schedulersThe scheduler to use for each tile during the sampling process.(采样调度器)
denoiseFLOATSlider0.20.0-1.0 (step 0.01)The denoising strength to use for each tile. Higher values allow more creative changes, but more chance of seams.(每个 tile 的去噪强度;越高创造性变化越多,但也更容易出现接缝)
mode_typeCOMBODropdown-Linear, Chess, NoneThe tiling order to use for the redraw step. Linear processes tiles row by row, Chess uses a checkerboard pattern, and None skips the redraw step.(redraw 的平铺顺序:Linear 逐行处理,Chess 棋盘格隔块处理,None 跳过 redraw)
tile_widthINTNumber Input51264-8192 (step 8)The base width of each tile during the redraw step.(redraw tile 的基础宽度)
tile_heightINTNumber Input51264-8192 (step 8)The base height of each tile during the redraw step.(redraw tile 的基础高度)
mask_blurINTNumber Input80-64The blur radius for the mask applied to tiles, helping blend tiles seamlessly. A higher value means more of the original image is retained near the seams when pasting the refined tiles back on the upscaled image.(tile 掩码的高斯模糊半径;越高,贴回时接缝附近保留的原始图像越多)
tile_paddingINTNumber Input320-8192 (step 8)The padding to apply to tiles, providing more context for better blending. Adds to tile size (e.g. (tile_width+tile_padding)x(tile_height+tile_padding)).(tile 向外扩展的 padding,提供更多上下文;实际处理尺寸为(tile_width + tile_padding) x (tile_height + tile_padding))
seam_fix_modeCOMBODropdown-None, Band Pass, Half Tile, Half Tile + IntersectionsThe seam fix mode to use. Different modes apply different strategies to fix visible seams between tiles.(接缝修复模式,不同模式采用不同策略)
seam_fix_denoiseFLOATSlider1.00.0-1.0 (step 0.01)The denoising strength to use for the seam fix step.(seam fix 步骤的去噪强度)
seam_fix_widthINTNumber Input640-8192 (step 8)The width of the bands used for the Band Pass seam fix mode.(Band Pass 模式下条带(band)的宽度)
seam_fix_mask_blurINTNumber Input80-64The blur radius for the seam fix mask, ensuring smooth blending.(seam fix 掩码的模糊半径,保证平滑融合)
seam_fix_paddingINTNumber Input160-8192 (step 8)The padding to apply for the seam fix step. Adds to tile size.(seam fix tile 的 padding,会计入处理尺寸)
force_uniform_tilesBOOLEANToggleTrueTrue/FalseIf enabled, tiles that would be cut off by the edges of the image will expand using context around the tile to keep the same tile size determined bytile_width,tile_height, andtile_padding. This is what happens in the A1111 Web UI. If disabled, the minimal size for tiles will be used, which may make the sampling faster but may cause artifacts due to irregular tile sizes.(启用时,被图像边缘截断的 tile 会用周围上下文扩展,保持统一 tile 尺寸,与 A1111 行为一致;禁用时使用最小 tile 尺寸,采样可能更快,但尺寸不规整可能引入伪影)
tiled_decodeBOOLEANToggleFalseTrue/FalseWhether to use tiled decoding when decoding tiles. Useful when you know the ComfyUI engine will attempt a normal decode and run into an Out Of Memory error, and resorts to tiled decoding anyway.(解码 tile 时是否使用分块解码;当你预见到 ComfyUI 会先尝试正常解码并触发 OOM 再回退到分块解码时,可提前开启)

源码中额外暴露的batch_size参数

从 usdu_nodes.py 的USDU_base_inputs定义看,节点实际还包含一个文档表格未列出的batch_size参数(INT,默认 1,范围 1-4096):它控制一次批量处理多少张 tile,更大的值可以减少处理时间但占用更多 VRAM,且产生与逐块处理不同的结果,只影响主 redraw 步骤、不影响 seam fix 步骤。同时源码中存在一条断言约束(usdu_nodes.py):batch_size大于 1 时要求force_uniform_tiles为True,因为批量中所有 tile 必须同尺寸。配置batch_size时需遵循这一前提。

输出

Output NameData TypeDescription
IMAGEIMAGEThe final refined image.(精修后的最终图像;尺寸与upscaled_image输入完全一致)

使用技巧

以下技巧完整继承自官方文档,并补充了源码依据。

1. 何时使用这个节点

  • 你已经用其他上采样器放大了图像,想补充细节;
  • 你想修复一张已有高分辨率图像中的接缝或伪影;
  • 你想把"放大"与"精修"解耦,对每一步获得更多控制;
  • 你想跳过 upscale model,先用 Lanczos、Nearest Neighbor 这类算法做一次简单放大,再用本节点精修。

2. 基本用法

  • 典型的 tile 尺寸应参考模型训练时的分辨率,例如 SD1.5 模型常用 512x512。如果你能在该分辨率下生成连贯的图像,那它大概率也是合适的 tile 尺寸;
  • 由于本节点输出尺寸等于输入尺寸,若你需要指定精确的输出分辨率,文档建议的路径是:单独完成放大(例如ImageUpscaleWithModel->ImageScale),再送入本节点——这正是 test/test_main_workflow.py 中test_upscale_no_upscale测试所验证的调用链:先用ImageScaleBy节点以 lanczos 方式放大 2 倍,再调用UltimateSDUpscaleNoUpscale(steps=5、cfg=8、denoise=0.7、mode_type="Chess"、512x512 tile、seam_fix_mode="None"、force_uniform_tiles=True),最后对输出做 MAE 相似度断言。该测试同时覆盖了batch_size=1与batch_size=2两种情况,可作为 API 级调用该节点的可靠参数模板。

3. 平铺模式(mode_type)

  • Linear:按行顺序逐块处理 tile;
  • Chess:棋盘格模式,先处理隔开的 tile。可以有助于降低可见接缝;
  • None:完全跳过 redraw 步骤。当你只想用 seam fix 步骤修复可见接缝、不想新增细节时很有用。

从源码看,三种模式对应usdu.USDUMode.LINEAR / CHESS / NONE枚举(usdu_nodes.py);当mode_type为 None 时,StableDiffusionProcessing初始化阶段也不会把 redraw tile 计入进度条总量(modules/processing.py)。

4. Denoise 设置

  • 使用较低 denoise(0.05-0.2)来让放大后的图像变得更清晰,同时避免接缝和幻觉(hallucination);
  • 更高的 denoise 值只有在配合 ControlNet tile 模型之类的约束时才可用,否则容易出现 tile 边界和接缝。

这与文档对denoise参数的描述一致:"Higher values allow more creative changes, but more chance of seams."

5. 接缝修复模式(seam_fix_mode)

  • None:不做任何接缝修复;
  • Band Pass:对 tile 之间的条带状区域(宽度由seam_fix_width控制)做处理;
  • Half Tile:处理半 tile 大小的重叠区域;
  • Half Tile + Intersections:最彻底,处理半 tile 区域及其交叉点。

源码中这四种策略对应USDUSFMode枚举NONE / BAND_PASS / HALF_TILE / HALF_TILE_PLUS_INTERSECTIONS(modules/processing.py),且StableDiffusionProcessing会按模式精确估算 seam fix 需要额外处理的块数用于进度条:Band Pass 增加(rows-1)+(cols-1)条带,Half Tile 增加(rows-1)*cols + (cols-1)*rows个半块,Half Tile + Intersections 再额外加上(rows-1)*(cols-1)个交叉块(modules/processing.py)。这组公式直观解释了为什么"更彻底的接缝修复模式处理时间更长"。

6. 性能优化

  • 开启tiled_decode:当解码阶段 VRAM 不足时,可以跳过 ComfyUI"先尝试正常解码、OOM 后再回退分块解码"的默认行为,直接走分块解码(对应 modules/processing.py 中VAEDecodeTiled分支,内部瓦片尺寸固定为 512);
  • 使用模型和 VRAM 能处理的最大 tile 尺寸,减少所需 tile 数量;
  • 关闭force_uniform_tiles,只解码贴回后真正可见的区域。这能节省处理时间,但模型可能未在得到的(更小、不规整的)tile 尺寸上训练过,且会丢失启用该选项时本可以获得的 tile 周围上下文。

7. 重要说明

  • 该节点不做任何放大;它期望输入就是一张已经放大的图像;
  • 输出尺寸由输入尺寸决定(不会做任何缩放)。这与源码中upscale_by = 1.0的硬编码一致(usdu_nodes.py);
  • seam fix 步骤会显著增加处理时间。如果接缝是主要问题,不妨优先尝试降低 denoise 或增大 tile 尺寸来规避接缝,而不是依赖 seam fix。

配套说明:脚本依赖与进度条配置

Ultimate SD Upscale (No Upscale)的 redraw / seam fix 调度逻辑最终委托给 Coyote-A 的原始 Ultimate SD Upscale 脚本(usdu.Script().run(...),见 usdu_nodes.py)。该脚本不随本仓库内置,首次加载插件时init.py 会自动从上游仓库下载并解压到repositories/ultimate_sd_upscale/目录,因此首次运行需要有可用的网络环境。

另外,仓库根目录的 config.json.example 展示了一个可选的config.json({"per_tile_progress": true})。从 modules/processing.py 的源码结构看,该配置控制进度条是"按 tile 逐个推进"还是整个流程只显示一条总进度条;将其复制为config.json并修改per_tile_progress即可调整。

参考路径汇总

内容路径
本节点官方文档js/docs/UltimateSDUpscaleNoUpscale.md
主节点文档(参数对照)js/docs/UltimateSDUpscale.md
节点定义(含 NoUpscale 类)usdu_nodes.py
每 tile 处理管线modules/processing.py
尺寸取整 monkey patchusdu_patch.py
条件裁剪工具usdu_utils.py
NoUpscale 集成测试test/test_main_workflow.py
进度条配置示例config.json.example
模板工作流example_workflows/basic-usdu.json
  • 人工智能
  • 计算机视觉
  • 图像处理
  • 媒体生成

【免费下载链接】ComfyUI_UltimateSDUpscale

ComfyUI nodes for the Ultimate Stable Diffusion Upscale script by Coyote-A.

项目地址:https://gitcode.com/gh_mirrors/co/ComfyUI_UltimateSDUpscale
点击查看免费下载

相关推荐

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询