ComfyUIでRefiner を利用した txt2img 画像生成をする

ジャスミン
質問: リファイナー(Refiner)
SDXLではRefinerを利用した画像生成方法があると聞きました。どのように実行するのでしょうか?

この記事では、ComfyUIを利用してRefinerを利用した画像生成の手順を紹介します。

事前準備: ComfyUIのインストール

ComfyUIをインストールします。手順の詳細はこちらの記事を参照してください。

ワークフロー

以下のワークフローを作成します。
ComfyUIでRefiner を利用した txt2img 画像生成をする:画像1

[Kサンプラー (高度)]のノードを2つ利用します。一つ目の[Kサンプラー (高度)]のノードの出力が、 二つ目の[Kサンプラー (高度)]のノードの入力になります。

Kサンプラーの設定は以下になります。

商品価格
設定項目 Kサンプラー(BASE) 1段目 Kサンプラー(REFINER) 2段目 補足
ノイズ追加 enable disable
ノイズシード 乱数 0
ステップ 25 25 好みに応じて増減可能
CFG 8.0 8.0 好みに応じて増減可能
サンプラー名 eular eualr 好みに応じて変更可能
スケジューラー normal normal 好みに応じてKarrasなどに変更可能
ステップ開始 0 20 前段のステップ終了が後段のステップ開始になります
ステップ終了 20 10000
残りのノイズと一緒に返す enable disable

ComfyUIでRefiner を利用した txt2img 画像生成をする:画像2

画像生成

プロンプトを入力して、[実行する]ボタンをクリックします。右側の画像を保存ノードに画像生成結果が表示されます。

ComfyUIでRefiner を利用した txt2img 画像生成をする:画像3

どの程度の違いがあるのか

Refinerありの場合となしの場合の画像生成結果が下図です。
BaseとRefinerに同じモデルを利用した場合は、ほとんど差がないと考えてよい状況です。 気持ち、Refinerあり版のほうが細部が描画されている印象もあります。

Refinerなし

ComfyUIでRefiner を利用した txt2img 画像生成をする:画像4
ComfyUIでRefiner を利用した txt2img 画像生成をする:画像5
ComfyUIでRefiner を利用した txt2img 画像生成をする:画像6
ComfyUIでRefiner を利用した txt2img 画像生成をする:画像7

Refinerあり

ComfyUIでRefiner を利用した txt2img 画像生成をする:画像8
ComfyUIでRefiner を利用した txt2img 画像生成をする:画像9
ComfyUIでRefiner を利用した txt2img 画像生成をする:画像10
ComfyUIでRefiner を利用した txt2img 画像生成をする:画像11

参考: JSONワークフロー

JSONのワークフローです。

{
  "id": "0d2b4953-d295-4844-8ee5-a33e69da13d7",
  "revision": 0,
  "last_node_id": 54,
  "last_link_id": 48,
  "nodes": [
    {
      "id": 5,
      "type": "EmptyLatentImage",
      "pos": [
        -221.6652889964057,
        -724.4757915302819
      ],
      "size": [
        360,
        144
      ],
      "flags": {},
      "order": 0,
      "mode": 0,
      "inputs": [],
      "outputs": [
        {
          "name": "LATENT",
          "type": "LATENT",
          "slot_index": 0,
          "links": [
            27
          ]
        }
      ],
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "EmptyLatentImage"
      },
      "widgets_values": [
        1024,
        1024,
        1
      ],
      "color": "#323",
      "bgcolor": "#535"
    },
    {
      "id": 4,
      "type": "CheckpointLoaderSimple",
      "pos": [
        -182.9231202764538,
        -73.38463630692513
      ],
      "size": [
        420,
        130.65625
      ],
      "flags": {},
      "order": 1,
      "mode": 0,
      "inputs": [],
      "outputs": [
        {
          "name": "MODEL",
          "type": "MODEL",
          "slot_index": 0,
          "links": [
            10
          ]
        },
        {
          "name": "CLIP",
          "type": "CLIP",
          "slot_index": 1,
          "links": [
            3,
            5
          ]
        },
        {
          "name": "VAE",
          "type": "VAE",
          "slot_index": 2,
          "links": []
        }
      ],
      "title": "Load Checkpoint - BASE",
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "CheckpointLoaderSimple",
        "models": [
          {
            "name": "sd_xl_base_1.0.safetensors",
            "url": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors?download=true",
            "directory": "checkpoints"
          }
        ]
      },
      "widgets_values": [
        "sdxl\\novaAnimeXL_ilV140.safetensors"
      ],
      "color": "#323",
      "bgcolor": "#535"
    },
    {
      "id": 45,
      "type": "PrimitiveNode",
      "pos": [
        -117.51212518430634,
        -526.334898914597
      ],
      "size": [
        252,
        80
      ],
      "flags": {},
      "order": 2,
      "mode": 0,
      "inputs": [],
      "outputs": [
        {
          "name": "INT",
          "type": "INT",
          "widget": {
            "name": "steps"
          },
          "links": [
            38,
            41
          ]
        }
      ],
      "title": "steps",
      "properties": {
        "Run widget replace on values": false
      },
      "widgets_values": [
        25,
        "fixed"
      ],
      "color": "#432",
      "bgcolor": "#653"
    },
    {
      "id": 47,
      "type": "PrimitiveNode",
      "pos": [
        -118.21595756611714,
        -395.8377879119929
      ],
      "size": [
        252,
        80
      ],
      "flags": {},
      "order": 3,
      "mode": 0,
      "inputs": [],
      "outputs": [
        {
          "name": "INT",
          "type": "INT",
          "widget": {
            "name": "end_at_step"
          },
          "slot_index": 0,
          "links": [
            43,
            44
          ]
        }
      ],
      "title": "end_at_step",
      "properties": {
        "Run widget replace on values": false
      },
      "widgets_values": [
        20,
        "fixed"
      ],
      "color": "#432",
      "bgcolor": "#653"
    },
    {
      "id": 17,
      "type": "VAEDecode",
      "pos": [
        1300.0701314262692,
        463.55194660072664
      ],
      "size": [
        240,
        72
      ],
      "flags": {},
      "order": 13,
      "mode": 0,
      "inputs": [
        {
          "name": "samples",
          "type": "LATENT",
          "link": 25
        },
        {
          "name": "vae",
          "type": "VAE",
          "link": 34
        }
      ],
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "slot_index": 0,
          "links": [
            28
          ]
        }
      ],
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "VAEDecode"
      },
      "widgets_values": [],
      "color": "#332922",
      "bgcolor": "#593930"
    },
    {
      "id": 7,
      "type": "CLIPTextEncode",
      "pos": [
        314.51074265423495,
        124.27638695529436
      ],
      "size": [
        477.0625,
        125
      ],
      "flags": {},
      "order": 9,
      "mode": 0,
      "inputs": [
        {
          "name": "clip",
          "type": "CLIP",
          "link": 5
        },
        {
          "name": "text",
          "type": "STRING",
          "widget": {
            "name": "text"
          },
          "link": 46
        }
      ],
      "outputs": [
        {
          "name": "CONDITIONING",
          "type": "CONDITIONING",
          "slot_index": 0,
          "links": [
            12
          ]
        }
      ],
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "CLIPTextEncode"
      },
      "widgets_values": [
        "text, watermark"
      ],
      "color": "#322",
      "bgcolor": "#533"
    },
    {
      "id": 6,
      "type": "CLIPTextEncode",
      "pos": [
        311.48512040864193,
        -79.72360678468954
      ],
      "size": [
        486.109375,
        125
      ],
      "flags": {},
      "order": 7,
      "mode": 0,
      "inputs": [
        {
          "name": "clip",
          "type": "CLIP",
          "link": 3
        },
        {
          "name": "text",
          "type": "STRING",
          "widget": {
            "name": "text"
          },
          "link": 45
        }
      ],
      "outputs": [
        {
          "name": "CONDITIONING",
          "type": "CONDITIONING",
          "slot_index": 0,
          "links": [
            11
          ]
        }
      ],
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "CLIPTextEncode"
      },
      "widgets_values": [
        "evening sunset scenery blue sky nature, glass bottle with a galaxy in it"
      ],
      "color": "#232",
      "bgcolor": "#353"
    },
    {
      "id": 10,
      "type": "KSamplerAdvanced",
      "pos": [
        878.937419086526,
        -99.52575897819906
      ],
      "size": [
        360,
        418.625
      ],
      "flags": {},
      "order": 11,
      "mode": 0,
      "inputs": [
        {
          "name": "model",
          "type": "MODEL",
          "link": 10
        },
        {
          "name": "positive",
          "type": "CONDITIONING",
          "link": 11
        },
        {
          "name": "negative",
          "type": "CONDITIONING",
          "link": 12
        },
        {
          "name": "latent_image",
          "type": "LATENT",
          "link": 27
        },
        {
          "name": "steps",
          "type": "INT",
          "widget": {
            "name": "steps"
          },
          "link": 41
        },
        {
          "name": "end_at_step",
          "type": "INT",
          "widget": {
            "name": "end_at_step"
          },
          "link": 43
        }
      ],
      "outputs": [
        {
          "name": "LATENT",
          "type": "LATENT",
          "slot_index": 0,
          "links": [
            13
          ]
        }
      ],
      "title": "KSampler (Advanced) - BASE",
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "KSamplerAdvanced"
      },
      "widgets_values": [
        "enable",
        965442598677472,
        "randomize",
        25,
        8,
        "euler",
        "normal",
        0,
        20,
        "enable"
      ]
    },
    {
      "id": 15,
      "type": "CLIPTextEncode",
      "pos": [
        322.51735323115787,
        466.4643689765279
      ],
      "size": [
        469.90625,
        125
      ],
      "flags": {},
      "order": 8,
      "mode": 0,
      "inputs": [
        {
          "name": "clip",
          "type": "CLIP",
          "link": 19
        },
        {
          "name": "text",
          "type": "STRING",
          "widget": {
            "name": "text"
          },
          "link": 47
        }
      ],
      "outputs": [
        {
          "name": "CONDITIONING",
          "type": "CONDITIONING",
          "slot_index": 0,
          "links": [
            23
          ]
        }
      ],
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "CLIPTextEncode"
      },
      "widgets_values": [
        "evening sunset scenery blue sky nature, glass bottle with a galaxy in it"
      ],
      "color": "#232",
      "bgcolor": "#353"
    },
    {
      "id": 16,
      "type": "CLIPTextEncode",
      "pos": [
        327.5062730027926,
        673.1060894793321
      ],
      "size": [
        466.25,
        125
      ],
      "flags": {},
      "order": 10,
      "mode": 0,
      "inputs": [
        {
          "name": "clip",
          "type": "CLIP",
          "link": 20
        },
        {
          "name": "text",
          "type": "STRING",
          "widget": {
            "name": "text"
          },
          "link": 48
        }
      ],
      "outputs": [
        {
          "name": "CONDITIONING",
          "type": "CONDITIONING",
          "slot_index": 0,
          "links": [
            24
          ]
        }
      ],
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "CLIPTextEncode"
      },
      "widgets_values": [
        "text, watermark"
      ],
      "color": "#322",
      "bgcolor": "#533"
    },
    {
      "id": 11,
      "type": "KSamplerAdvanced",
      "pos": [
        883.9310839503081,
        461.20376450938045
      ],
      "size": [
        360,
        418.625
      ],
      "flags": {},
      "order": 12,
      "mode": 0,
      "inputs": [
        {
          "name": "model",
          "type": "MODEL",
          "link": 14
        },
        {
          "name": "positive",
          "type": "CONDITIONING",
          "link": 23
        },
        {
          "name": "negative",
          "type": "CONDITIONING",
          "link": 24
        },
        {
          "name": "latent_image",
          "type": "LATENT",
          "link": 13
        },
        {
          "name": "steps",
          "type": "INT",
          "widget": {
            "name": "steps"
          },
          "link": 38
        },
        {
          "name": "start_at_step",
          "type": "INT",
          "widget": {
            "name": "start_at_step"
          },
          "link": 44
        }
      ],
      "outputs": [
        {
          "name": "LATENT",
          "type": "LATENT",
          "slot_index": 0,
          "links": [
            25
          ]
        }
      ],
      "title": "KSampler (Advanced) - REFINER",
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "KSamplerAdvanced"
      },
      "widgets_values": [
        "disable",
        0,
        "fixed",
        25,
        8,
        "euler",
        "normal",
        20,
        10000,
        "disable"
      ]
    },
    {
      "id": 12,
      "type": "CheckpointLoaderSimple",
      "pos": [
        -172.38480271836073,
        471.923102950887
      ],
      "size": [
        390.5625,
        130.65625
      ],
      "flags": {},
      "order": 4,
      "mode": 0,
      "inputs": [],
      "outputs": [
        {
          "name": "MODEL",
          "type": "MODEL",
          "slot_index": 0,
          "links": [
            14
          ]
        },
        {
          "name": "CLIP",
          "type": "CLIP",
          "slot_index": 1,
          "links": [
            19,
            20
          ]
        },
        {
          "name": "VAE",
          "type": "VAE",
          "slot_index": 2,
          "links": [
            34
          ]
        }
      ],
      "title": "Load Checkpoint - REFINER",
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33",
        "Node name for S&R": "CheckpointLoaderSimple",
        "models": [
          {
            "name": "sd_xl_refiner_1.0.safetensors",
            "url": "https://huggingface.co/stabilityai/stable-diffusion-xl-refiner-1.0/resolve/main/sd_xl_refiner_1.0.safetensors?download=true",
            "directory": "checkpoints"
          }
        ]
      },
      "widgets_values": [
        "sdxl\\novaAnimeXL_ilV140.safetensors"
      ],
      "color": "#323",
      "bgcolor": "#535"
    },
    {
      "id": 51,
      "type": "PrimitiveNode",
      "pos": [
        -648.4359470492894,
        -659.2259511606903
      ],
      "size": [
        360,
        132
      ],
      "flags": {},
      "order": 5,
      "mode": 0,
      "inputs": [],
      "outputs": [
        {
          "name": "STRING",
          "type": "STRING",
          "widget": {
            "name": "text"
          },
          "slot_index": 0,
          "links": [
            45,
            47
          ]
        }
      ],
      "title": "Positive Prompt (Text)",
      "properties": {
        "Run widget replace on values": false
      },
      "widgets_values": [
        "evening sunset scenery blue sky nature, glass bottle with a galaxy in it"
      ],
      "color": "#232",
      "bgcolor": "#353"
    },
    {
      "id": 50,
      "type": "PrimitiveNode",
      "pos": [
        -645.602613715956,
        -474.6108638960674
      ],
      "size": [
        360,
        132
      ],
      "flags": {},
      "order": 6,
      "mode": 0,
      "inputs": [],
      "outputs": [
        {
          "name": "STRING",
          "type": "STRING",
          "widget": {
            "name": "text"
          },
          "slot_index": 0,
          "links": [
            46,
            48
          ]
        }
      ],
      "title": "Negative Prompt (Text)",
      "properties": {
        "Run widget replace on values": false
      },
      "widgets_values": [
        "text, watermark"
      ],
      "color": "#322",
      "bgcolor": "#533"
    },
    {
      "id": 19,
      "type": "SaveImage",
      "pos": [
        1621.679425046525,
        -160.5100337521767
      ],
      "size": [
        508.265625,
        610.265625
      ],
      "flags": {},
      "order": 14,
      "mode": 0,
      "inputs": [
        {
          "name": "images",
          "type": "IMAGE",
          "link": 28
        }
      ],
      "outputs": [],
      "properties": {
        "cnr_id": "comfy-core",
        "ver": "0.3.33"
      },
      "widgets_values": [
        "ComfyUI"
      ]
    }
  ],
  "links": [
    [
      3,
      4,
      1,
      6,
      0,
      "CLIP"
    ],
    [
      5,
      4,
      1,
      7,
      0,
      "CLIP"
    ],
    [
      10,
      4,
      0,
      10,
      0,
      "MODEL"
    ],
    [
      11,
      6,
      0,
      10,
      1,
      "CONDITIONING"
    ],
    [
      12,
      7,
      0,
      10,
      2,
      "CONDITIONING"
    ],
    [
      13,
      10,
      0,
      11,
      3,
      "LATENT"
    ],
    [
      14,
      12,
      0,
      11,
      0,
      "MODEL"
    ],
    [
      19,
      12,
      1,
      15,
      0,
      "CLIP"
    ],
    [
      20,
      12,
      1,
      16,
      0,
      "CLIP"
    ],
    [
      23,
      15,
      0,
      11,
      1,
      "CONDITIONING"
    ],
    [
      24,
      16,
      0,
      11,
      2,
      "CONDITIONING"
    ],
    [
      25,
      11,
      0,
      17,
      0,
      "LATENT"
    ],
    [
      27,
      5,
      0,
      10,
      3,
      "LATENT"
    ],
    [
      28,
      17,
      0,
      19,
      0,
      "IMAGE"
    ],
    [
      34,
      12,
      2,
      17,
      1,
      "VAE"
    ],
    [
      38,
      45,
      0,
      11,
      4,
      "INT"
    ],
    [
      41,
      45,
      0,
      10,
      4,
      "INT"
    ],
    [
      43,
      47,
      0,
      10,
      5,
      "INT"
    ],
    [
      44,
      47,
      0,
      11,
      5,
      "INT"
    ],
    [
      45,
      51,
      0,
      6,
      1,
      "STRING"
    ],
    [
      46,
      50,
      0,
      7,
      1,
      "STRING"
    ],
    [
      47,
      51,
      0,
      15,
      1,
      "STRING"
    ],
    [
      48,
      50,
      0,
      16,
      1,
      "STRING"
    ]
  ],
  "groups": [
    {
      "id": 10,
      "title": "Text Prompts",
      "bounding": [
        -667.5702971629603,
        -746.9290414663459,
        405.0564102564103,
        431.6564102564104
      ],
      "color": "#3f789e",
      "font_size": 24,
      "flags": {}
    },
    {
      "id": 12,
      "title": "Refiner",
      "bounding": [
        -216.94794679299358,
        374.7739526993206,
        1486.0714450726744,
        523.1923076923072
      ],
      "color": "#3f789e",
      "font_size": 24,
      "flags": {}
    },
    {
      "id": 11,
      "title": "Base",
      "bounding": [
        -218.83330252880188,
        -192.57446581927076,
        1489.7021725385575,
        540.7050269493689
      ],
      "color": "#3f789e",
      "font_size": 24,
      "flags": {}
    }
  ],
  "config": {},
  "extra": {
    "ds": {
      "scale": 0.6446280991735549,
      "offset": [
        783.4741883912207,
        858.9294908992364
      ]
    },
    "frontendVersion": "1.36.14",
    "workflowRendererVersion": "Vue"
  },
  "version": 0.4
}
AuthorPortraitAlt
著者
iPentecのメインデザイナー
Webページ、Webクリエイティブのデザインを担当。PhotoshopやIllustratorの作業もする。 最近は生成AIの画像生成の沼に沈んでいる。
作成日: 2025-01-18