ComfyUI使用InstantID实现根据图片生成相似图片,类似换脸,AI摄影

ComfyUI-InstantID:https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID

进入 ComfyUI\custom_nodes

git clone https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID.git
cd ComfyUI-InstantID
pip install -r requirements.txt

需要下载的模型

下载 https://huggingface.co/InstantX/InstantID/tree/main/ControlNetModel 中的 config.json 和 diffusion_pytorch_model.safetensors ,将模型填入 ComfyUI/custom_nodes/ComfyUI-InstantID/checkpoints/controlnet

下载 https://huggingface.co/InstantX/InstantID/tree/main 中的 ip-adapter.bin ,将模型填入 ComfyUI/custom_nodes/ComfyUI-InstantID/checkpoints

下载 https://huggingface.co/DIAMONIK7777/antelopev2/tree/main 中的所有模型,将其放入 ComfyUI//custom_nodes/ComfyUI-InstantID/models/antelopev2 中

放置结果如下



如果报错本地没有openai/clip-vit-large-patch14或者CLIP-ViT-bigG-14-laion2B-39B-b160k

需要把它们下载到本地hanggingface的cache内,可以使用huggingface_hub下载,之前我写过 https://www.cnblogs.com/qcy-blog/p/18165717

据我测试,clip-vit-large-patch14需要全部下载,CLIP-ViT-bigG-14-laion2B-39B-b160k只需要下载一部分

地址 https://hf-mirror.com/laion/CLIP-ViT-bigG-14-laion2B-39B-b160k/commits/main
地址 https://hf-mirror.com/openai/clip-vit-large-patch14/tree/main

工作流 https://github.com/ZHO-ZHO-ZHO/ComfyUI-InstantID/blob/main/INSTANTID WORKFLOWS/V2.0 InstantID_locally_pose_ref【Zho】.json

注意这两个要改成绝对路径,就是上面放好的模型路径,基础模型得是SDXL,要用较低的CFG和步数,推荐CFG=3-5,Steps=20-40,这个越大越像


结果

或者使用这个工作流

{
  "last_node_id": 33,
  "last_link_id": 62,
  "nodes": [
    {
      "id": 30,
      "type": "CLIPTextEncode",
      "pos": [
        772,
        221
      ],
      "size": {
        "0": 291.9967346191406,
        "1": 128.62518310546875
      },
      "flags": {
        "collapsed": false
      },
      "order": 9,
      "mode": 0,
      "inputs": [
        {
          "name": "clip",
          "type": "CLIP",
          "link": 59,
          "label": "CLIP"
        },
        {
          "name": "text",
          "type": "STRING",
          "link": 57,
          "widget": {
            "name": "text"
          },
          "label": "文本"
        }
      ],
      "outputs": [
        {
          "name": "CONDITIONING",
          "type": "CONDITIONING",
          "links": [
            61
          ],
          "shape": 3,
          "slot_index": 0,
          "label": "条件"
        }
      ],
      "properties": {
        "Node name for S&R": "CLIPTextEncode"
      },
      "widgets_values": [
        "1girl,(8k, RAW photo, best quality, masterpiece:1.3),(realistic,photo-realistic:1.37),soft light,(extremely beautiful face:1.1),big eyes,an extremely delicate and beautiful girl,depth of field,blurry background,delicate,beautiful,beautiful face,beautiful eyes,beautiful girl,delicate face,delicate girl,8k wallpaper,(best quality:1.12),(ultra-detailed:1.12),(highres:1.12),hyper detailed,ultra-detailed,high resolution illustration,colorful,8k wallpaper,highres,Cinematic light,ray tracing,(8k, RAW photo, best quality, masterpiece, ultra highres, ultra detailed:1.2),(realistic, photo-realistic:),outdoors,forest,butterfly,green glowing plants,long_sleeves,(blond hair:1.2),(lolita:1.2),dress,lace,spirit,lace,ribbon,hair_ribbon,nature,Dreamy forest,cowboy_shot,flowers meadows,senlin,leaf,fairy,elf ears,"
      ]
    },
    {
      "id": 31,
      "type": "CLIPTextEncode",
      "pos": [
        770,
        409
      ],
      "size": {
        "0": 286.3603515625,
        "1": 112.35245513916016
      },
      "flags": {
        "collapsed": false
      },
      "order": 10,
      "mode": 0,
      "inputs": [
        {
          "name": "clip",
          "type": "CLIP",
          "link": 60,
          "label": "CLIP"
        },
        {
          "name": "text",
          "type": "STRING",
          "link": 58,
          "widget": {
            "name": "text"
          },
          "label": "文本"
        }
      ],
      "outputs": [
        {
          "name": "CONDITIONING",
          "type": "CONDITIONING",
          "links": [
            62
          ],
          "shape": 3,
          "slot_index": 0,
          "label": "条件"
        }
      ],
      "properties": {
        "Node name for S&R": "CLIPTextEncode"
      },
      "widgets_values": [
        "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry"
      ]
    },
    {
      "id": 4,
      "type": "CheckpointLoaderSimple",
      "pos": [
        100,
        253
      ],
      "size": {
        "0": 480.5506286621094,
        "1": 98
      },
      "flags": {},
      "order": 0,
      "mode": 0,
      "outputs": [
        {
          "name": "MODEL",
          "type": "MODEL",
          "links": [
            38
          ],
          "slot_index": 0,
          "label": "模型"
        },
        {
          "name": "CLIP",
          "type": "CLIP",
          "links": [
            59,
            60
          ],
          "slot_index": 1,
          "label": "CLIP"
        },
        {
          "name": "VAE",
          "type": "VAE",
          "links": [
            3
          ],
          "slot_index": 2,
          "label": "VAE"
        }
      ],
      "properties": {
        "Node name for S&R": "CheckpointLoaderSimple"
      },
      "widgets_values": [
        "XL写实 realvisxlV40_v40LightningBakedvae.safetensors"
      ]
    },
    {
      "id": 29,
      "type": "LoadImage",
      "pos": [
        1149,
        240
      ],
      "size": {
        "0": 293.4960021972656,
        "1": 392.0699768066406
      },
      "flags": {},
      "order": 1,
      "mode": 0,
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "links": [
            56
          ],
          "shape": 3,
          "label": "图像"
        },
        {
          "name": "MASK",
          "type": "MASK",
          "links": null,
          "shape": 3,
          "label": "遮罩"
        }
      ],
      "properties": {
        "Node name for S&R": "LoadImage"
      },
      "widgets_values": [
        "未标222题-1.jpg",
        "image"
      ]
    },
    {
      "id": 14,
      "type": "ControlNetLoader",
      "pos": [
        979,
        84
      ],
      "size": {
        "0": 409.7744445800781,
        "1": 82.64219665527344
      },
      "flags": {},
      "order": 2,
      "mode": 0,
      "outputs": [
        {
          "name": "CONTROL_NET",
          "type": "CONTROL_NET",
          "links": [
            37
          ],
          "shape": 3,
          "label": "ControlNet",
          "slot_index": 0
        }
      ],
      "properties": {
        "Node name for S&R": "ControlNetLoader"
      },
      "widgets_values": [
        "diffusion_pytorch_model.safetensors"
      ]
    },
    {
      "id": 15,
      "type": "InstantIDFaceAnalysis",
      "pos": [
        1036,
        -32
      ],
      "size": {
        "0": 315,
        "1": 58
      },
      "flags": {},
      "order": 3,
      "mode": 0,
      "outputs": [
        {
          "name": "FACEANALYSIS",
          "type": "FACEANALYSIS",
          "links": [
            36
          ],
          "shape": 3,
          "label": "FACEANALYSIS",
          "slot_index": 0
        }
      ],
      "properties": {
        "Node name for S&R": "InstantIDFaceAnalysis"
      },
      "widgets_values": [
        "CUDA"
      ]
    },
    {
      "id": 13,
      "type": "InstantIDModelLoader",
      "pos": [
        1041,
        -141
      ],
      "size": {
        "0": 315,
        "1": 58
      },
      "flags": {},
      "order": 4,
      "mode": 0,
      "outputs": [
        {
          "name": "INSTANTID",
          "type": "INSTANTID",
          "links": [
            35
          ],
          "shape": 3,
          "label": "INSTANTID",
          "slot_index": 0
        }
      ],
      "properties": {
        "Node name for S&R": "InstantIDModelLoader"
      },
      "widgets_values": [
        "ip-adapter.bin"
      ]
    },
    {
      "id": 19,
      "type": "ApplyInstantIDAdvanced",
      "pos": [
        1484,
        -46
      ],
      "size": {
        "0": 315,
        "1": 338
      },
      "flags": {},
      "order": 11,
      "mode": 0,
      "inputs": [
        {
          "name": "instantid",
          "type": "INSTANTID",
          "link": 35,
          "label": "instantid"
        },
        {
          "name": "insightface",
          "type": "FACEANALYSIS",
          "link": 36,
          "label": "insightface"
        },
        {
          "name": "control_net",
          "type": "CONTROL_NET",
          "link": 37,
          "label": "control_net"
        },
        {
          "name": "image",
          "type": "IMAGE",
          "link": 34,
          "label": "image",
          "slot_index": 3
        },
        {
          "name": "model",
          "type": "MODEL",
          "link": 38,
          "label": "model",
          "slot_index": 4
        },
        {
          "name": "positive",
          "type": "CONDITIONING",
          "link": 61,
          "label": "positive"
        },
        {
          "name": "negative",
          "type": "CONDITIONING",
          "link": 62,
          "label": "negative"
        },
        {
          "name": "image_kps",
          "type": "IMAGE",
          "link": 56,
          "label": "image_kps",
          "slot_index": 7
        },
        {
          "name": "mask",
          "type": "MASK",
          "link": null,
          "label": "mask"
        }
      ],
      "outputs": [
        {
          "name": "MODEL",
          "type": "MODEL",
          "links": [
            40
          ],
          "shape": 3,
          "label": "MODEL",
          "slot_index": 0
        },
        {
          "name": "positive",
          "type": "CONDITIONING",
          "links": [
            41
          ],
          "shape": 3,
          "label": "positive",
          "slot_index": 1
        },
        {
          "name": "negative",
          "type": "CONDITIONING",
          "links": [
            42
          ],
          "shape": 3,
          "label": "negative",
          "slot_index": 2
        }
      ],
      "properties": {
        "Node name for S&R": "ApplyInstantIDAdvanced"
      },
      "widgets_values": [
        0.1,
        0.85,
        0,
        1,
        0,
        "average"
      ]
    },
    {
      "id": 24,
      "type": "EmptyLatentImage",
      "pos": [
        1565,
        354
      ],
      "size": {
        "0": 210,
        "1": 106
      },
      "flags": {},
      "order": 5,
      "mode": 0,
      "outputs": [
        {
          "name": "LATENT",
          "type": "LATENT",
          "links": [
            54
          ],
          "shape": 3,
          "label": "Latent",
          "slot_index": 0
        }
      ],
      "properties": {
        "Node name for S&R": "EmptyLatentImage"
      },
      "widgets_values": [
        1016,
        1016,
        1
      ]
    },
    {
      "id": 1,
      "type": "KSampler",
      "pos": [
        1849,
        34
      ],
      "size": {
        "0": 267.6806945800781,
        "1": 534.6439208984375
      },
      "flags": {},
      "order": 12,
      "mode": 0,
      "inputs": [
        {
          "name": "model",
          "type": "MODEL",
          "link": 40,
          "label": "模型",
          "slot_index": 0
        },
        {
          "name": "positive",
          "type": "CONDITIONING",
          "link": 41,
          "label": "正面条件"
        },
        {
          "name": "negative",
          "type": "CONDITIONING",
          "link": 42,
          "label": "负面条件"
        },
        {
          "name": "latent_image",
          "type": "LATENT",
          "link": 54,
          "label": "Latent",
          "slot_index": 3
        }
      ],
      "outputs": [
        {
          "name": "LATENT",
          "type": "LATENT",
          "links": [
            1
          ],
          "shape": 3,
          "label": "Latent",
          "slot_index": 0
        }
      ],
      "properties": {
        "Node name for S&R": "KSampler"
      },
      "widgets_values": [
        898106851306632,
        "randomize",
        4,
        1.5,
        "dpmpp_sde",
        "karras",
        1
      ]
    },
    {
      "id": 2,
      "type": "VAEDecode",
      "pos": [
        2153,
        74
      ],
      "size": {
        "0": 210,
        "1": 46
      },
      "flags": {},
      "order": 13,
      "mode": 0,
      "inputs": [
        {
          "name": "samples",
          "type": "LATENT",
          "link": 1,
          "label": "Latent"
        },
        {
          "name": "vae",
          "type": "VAE",
          "link": 3,
          "label": "VAE",
          "slot_index": 1
        }
      ],
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "links": [
            2
          ],
          "shape": 3,
          "label": "图像",
          "slot_index": 0
        }
      ],
      "properties": {
        "Node name for S&R": "VAEDecode"
      }
    },
    {
      "id": 3,
      "type": "SaveImage",
      "pos": [
        1532,
        723
      ],
      "size": {
        "0": 742.4053344726562,
        "1": 825.8528442382812
      },
      "flags": {},
      "order": 14,
      "mode": 0,
      "inputs": [
        {
          "name": "images",
          "type": "IMAGE",
          "link": 2,
          "label": "图像"
        }
      ],
      "properties": {
        "Node name for S&R": "SaveImage"
      },
      "widgets_values": [
        "ComfyUI"
      ]
    },
    {
      "id": 16,
      "type": "LoadImage",
      "pos": [
        928,
        798
      ],
      "size": {
        "0": 543.4951782226562,
        "1": 643.7646484375
      },
      "flags": {},
      "order": 6,
      "mode": 0,
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "links": [
            34
          ],
          "shape": 3,
          "label": "图像",
          "slot_index": 0
        },
        {
          "name": "MASK",
          "type": "MASK",
          "links": null,
          "shape": 3,
          "label": "遮罩"
        }
      ],
      "properties": {
        "Node name for S&R": "LoadImage"
      },
      "widgets_values": [
        "未2222标111题-1 (9).jpg",
        "image"
      ]
    },
    {
      "id": 33,
      "type": "LoadImage",
      "pos": [
        2325,
        715
      ],
      "size": {
        "0": 771.886962890625,
        "1": 855.3436889648438
      },
      "flags": {},
      "order": 7,
      "mode": 0,
      "outputs": [
        {
          "name": "IMAGE",
          "type": "IMAGE",
          "links": null,
          "shape": 3,
          "label": "图像"
        },
        {
          "name": "MASK",
          "type": "MASK",
          "links": null,
          "shape": 3,
          "label": "遮罩"
        }
      ],
      "properties": {
        "Node name for S&R": "LoadImage"
      },
      "widgets_values": [
        "ComfyUI_01673_.png",
        "image"
      ]
    },
    {
      "id": 32,
      "type": "SDXLPromptStyler",
      "pos": [
        225,
        413
      ],
      "size": {
        "0": 458.0843811035156,
        "1": 476.97576904296875
      },
      "flags": {},
      "order": 8,
      "mode": 0,
      "outputs": [
        {
          "name": "text_positive",
          "type": "STRING",
          "links": [
            57
          ],
          "shape": 3,
          "label": "正面条件",
          "slot_index": 0
        },
        {
          "name": "text_negative",
          "type": "STRING",
          "links": [
            58
          ],
          "shape": 3,
          "label": "负面条件",
          "slot_index": 1
        }
      ],
      "properties": {
        "Node name for S&R": "SDXLPromptStyler"
      },
      "widgets_values": [
        "looking_at_viewer,1woman,Asia,thin,portrait,Thirty-five years old",
        "lowres, low quality, worst quality:1.2, text:1.2, watermark, painting, drawing, glitch, deformed, mutated, ugly, Letters, Freckles, Wrinkles, Pimples, illustration",
        "game-cyberpunk game",
        true,
        true,
        true
      ],
      "color": "#233",
      "bgcolor": "#355"
    }
  ],
  "links": [
    [
      1,
      1,
      0,
      2,
      0,
      "LATENT"
    ],
    [
      2,
      2,
      0,
      3,
      0,
      "IMAGE"
    ],
    [
      3,
      4,
      2,
      2,
      1,
      "VAE"
    ],
    [
      34,
      16,
      0,
      19,
      3,
      "IMAGE"
    ],
    [
      35,
      13,
      0,
      19,
      0,
      "INSTANTID"
    ],
    [
      36,
      15,
      0,
      19,
      1,
      "FACEANALYSIS"
    ],
    [
      37,
      14,
      0,
      19,
      2,
      "CONTROL_NET"
    ],
    [
      38,
      4,
      0,
      19,
      4,
      "MODEL"
    ],
    [
      40,
      19,
      0,
      1,
      0,
      "MODEL"
    ],
    [
      41,
      19,
      1,
      1,
      1,
      "CONDITIONING"
    ],
    [
      42,
      19,
      2,
      1,
      2,
      "CONDITIONING"
    ],
    [
      54,
      24,
      0,
      1,
      3,
      "LATENT"
    ],
    [
      56,
      29,
      0,
      19,
      7,
      "IMAGE"
    ],
    [
      57,
      32,
      0,
      30,
      1,
      "STRING"
    ],
    [
      58,
      32,
      1,
      31,
      1,
      "STRING"
    ],
    [
      59,
      4,
      1,
      30,
      0,
      "CLIP"
    ],
    [
      60,
      4,
      1,
      31,
      0,
      "CLIP"
    ],
    [
      61,
      30,
      0,
      19,
      5,
      "CONDITIONING"
    ],
    [
      62,
      31,
      0,
      19,
      6,
      "CONDITIONING"
    ]
  ],
  "groups": [],
  "config": {},
  "extra": {},
  "version": 0.4
}
posted @ 2024-05-20 16:26  朝阳1  阅读(146)  评论(0编辑  收藏  举报