输入
| 参数名 | 描述 | 数据类型 | 是否必填 | 默认值 | 范围/选项 |
|---|---|---|---|---|---|
Model | 用于去噪过程的输入模型 | checkpoint | 是 | 无 | - |
种子 | 用于生成随机噪声,使用相同的“种子”将生成相同的图像 | Int | 是 | 0 | 0 ~ 18446744073709551615 |
步数 | 去噪过程中使用的步数,步数越多,结果越精确 | Int | 是 | 20 | 1 ~ 10000 |
cfg | 控制生成图像与输入条件的匹配程度,建议值为 6-8 | float | 是 | 8.0 | 0.0 ~ 100.0 |
采样器名称 | 选择用于去噪的采样器,影响生成速度和风格 | UI Option | 是 | 无 | 多种算法 |
调度器 | 控制噪声的移除方式,影响生成过程 | UI Option | 是 | 无 | 多种调度器 |
Positive | 引导去噪的正向条件,即你希望在图像中出现的内容 | conditioning | 是 | 无 | - |
Negative | 引导去噪的负向条件,即你不希望在图像中出现的内容 | conditioning | 是 | 无 | - |
Latent_Image | 用于去噪的潜空间图像 | Latent | 是 | 无 | - |
降噪 | 决定噪声移除比例,值越低,与输入图像的关联性越小 | float | 否 | 1.0 | 0.0 ~ 1.0 |
生成后的控制 | 提供在每次提示后更改种子的能力 | UI Option | 否 | 无 | Random/Inc/Dec/Keep |
输出
| 参数 | 功能 |
|---|---|
| Latent | 输出采样器去噪后的潜空间数据 |
源代码
[更新于 2025 年 5 月 15 日]
def common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent, denoise=1.0, disable_noise=False, start_step=None, last_step=None, force_full_denoise=False):
latent_image = latent["samples"]
latent_image = comfy.sample.fix_empty_latent_channels(model, latent_image)
if disable_noise:
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
else:
batch_inds = latent["batch_index"] if "batch_index" in latent else None
noise = comfy.sample.prepare_noise(latent_image, seed, batch_inds)
noise_mask = None
if "noise_mask" in latent:
noise_mask = latent["noise_mask"]
callback = latent_preview.prepare_callback(model, steps)
disable_pbar = not comfy.utils.PROGRESS_BAR_ENABLED
samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
denoise=denoise, disable_noise=disable_noise, start_step=start_step, last_step=last_step,
force_full_denoise=force_full_denoise, noise_mask=noise_mask, callback=callback, disable_pbar=disable_pbar, seed=seed)
out = latent.copy()
out["samples"] = samples
return (out, )
class KSampler:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"model": ("MODEL", {"tooltip": "用于对输入潜空间数据进行去噪的模型。"}),
"seed": ("INT", {"default": 0, "min": 0, "max": 0xffffffffffffffff, "control_after_generate": True, "tooltip": "用于创建噪声的随机种子。"}),
"steps": ("INT", {"default": 20, "min": 1, "max": 10000, "tooltip": "去噪过程中使用的步数。"}),
"cfg": ("FLOAT", {"default": 8.0, "min": 0.0, "max": 100.0, "step":0.1, "round": 0.01, "tooltip": "无分类器引导比例,用于平衡创造性与对提示词的遵循程度。值越高,生成的图像与提示词越匹配,但过高会负面影响质量。"}),
"sampler_name": (comfy.samplers.KSampler.SAMPLERS, {"tooltip": "采样时使用的算法,会影响生成结果的质量、速度和风格。"}),
"scheduler": (comfy.samplers.KSampler.SCHEDULERS, {"tooltip": "调度器控制如何逐步移除噪声以形成图像。"}),
"positive": ("CONDITIONING", {"tooltip": "描述你希望在图像中包含的属性的条件。"}),
"negative": ("CONDITIONING", {"tooltip": "描述你希望从图像中排除的属性的条件。"}),
"latent_image": ("LATENT", {"tooltip": "要去噪的潜空间图像。"}),
"denoise": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 1.0, "step": 0.01, "tooltip": "应用的去噪程度,较低的值将保持初始图像的结构,允许进行图生图采样。"}),
}
}
RETURN_TYPES = ("LATENT",)
OUTPUT_TOOLTIPS = ("去噪后的潜空间数据。",)
FUNCTION = "sample"
CATEGORY = "sampling"
DESCRIPTION = "使用提供的模型、正向和负向条件对潜空间图像进行去噪。"
def sample(self, model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=1.0):
return common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)
本文档由 AI 生成。如果您发现任何错误或有改进建议,欢迎贡献! 在 GitHub 上编辑