ComfyUI 全流程指南:安装、配置、插件与模型选型

作者:吴业亮

博客:wuyeliang.blog.csdn.net

一、ComfyUI 简介及后端原理

1. 什么是 ComfyUI

ComfyUI 是一款功能强大的 Stable Diffusion 可视化节点编辑器,允许用户通过拖拽节点的方式构建图像生成流程,提供了比传统 UI 更灵活、更精细的控制能力。它适用于需要自定义生成流程的开发者和高级用户,支持各种扩散模型、插件扩展和工作流自动化。

2. 后端原理

ComfyUI 后端基于 Python 构建,核心原理如下:

  • 节点式架构:将图像生成的各个环节(如模型加载、文本编码、图像解码等)封装为独立节点,通过节点间的连接构建完整工作流
  • PyTorch 集成:底层依赖 PyTorch 框架进行模型推理,支持 CPU/GPU 计算,通过 CUDA 加速实现高效的图像生成
  • 异步处理:采用异步任务处理机制,支持批量生成和后台任务运行
  • 模块化设计:通过插件系统支持功能扩展,允许开发者自定义节点和工作流逻辑
  • 模型管理:支持多种扩散模型(如 Stable Diffusion、SDXL 等)及配套组件(VAE、LoRA 等)的加载与管理

二、ComfyUI 安装步骤

1. 克隆仓库

  • GitHub 直接克隆

    bash 复制代码
    cd /data
    git clone https://github.com/comfyanonymous/ComfyUI.git
  • 国内镜像克隆(加速访问)

    bash 复制代码
    git clone https://mirror.ghproxy.com/https://github.com/comfyanonymous/ComfyUI.git
  • 进入项目目录

    bash 复制代码
    cd ComfyUI/

2. 创建运行环境

  • 建立 Conda 虚拟环境

    bash 复制代码
    conda create -n comfyui python=3.11
    conda activate comfyui
  • 安装依赖库

    bash 复制代码
    pip install -r requirements.txt
  • 针对 CUDA 11.8 的特殊配置

    编辑 requirements.txt,移除以下行:

    复制代码
    torch
    torchvision
    torchaudio

    然后执行专用安装命令:

    bash 复制代码
    pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

3. 启动与配置

  • 自定义端口启动(示例使用 80 端口)

    bash 复制代码
    python main.py --port 80 --listen 0.0.0.0
  • 解决 CUDA 相关错误

    若出现 RuntimeError: CUDA error: operation not supported,使用以下命令启动:

    bash 复制代码
    python main.py --port 80 --listen 0.0.0.0 --disable-cuda-malloc
  • 配置系统服务(开机自启)

    1. 创建服务文件

      bash 复制代码
      vi /etc/systemd/system/ComfyUI.service
    2. 写入以下内容

      ini 复制代码
      [Unit]
      Description=ComfyUI Service
      After=network.target
      
      [Service]
      Type=simple
      User=root
      StandardOutput=file:/var/log/ComfyUI.log
      StandardError=file:/var/log/ComfyUI.log
      WorkingDirectory=/data/ComfyUI/
      ExecStart=/bin/bash -c 'source /root/miniconda3/bin/activate && conda activate comfyui && python main.py --port 8080 --listen 0.0.0.0 --disable-cuda-malloc'
      Restart=on-failure
      
      [Install]
      WantedBy=multi-user.target
    3. 启用并启动服务

      bash 复制代码
      systemctl daemon-reload
      systemctl enable ComfyUI.service
      systemctl restart ComfyUI.service

三、推荐插件

插件功能 安装命令
设备管理器 git clone https://mirror.ghproxy.com/https://github.com/11cafe/comfyui-workspace-manager.git
界面汉化 git clone https://mirror.ghproxy.com/https://github.com/AIGODLIKE/AIGODLIKE-ComfyUI-Translation.git
自动补全 git clone https://mirror.ghproxy.com/https://github.com/pythongosssss/ComfyUI-Custom-Scripts.git
提示词翻译 git clone https://mirror.ghproxy.com/https://github.com/AlekPet/ComfyUI_Custom_Nodes_AlekPet.git
节点管理器 git clone https://github.com/ltdrdata/ComfyUI-Manager
环境信息提示器 git clone https://mirror.ghproxy.com/https://github.com/crystian/ComfyUI-Crystools.git 额外依赖:pip install split_image facexlib ultralytics wget deepdiff pynvml transparent_background supervision aiohttp_cors webcolors

四、常用差异化节点

复制代码
ComfyUI-AnimateAnyone-Evolved/      # 动画生成节点
ComfyUI-BrushNet/                  # 画笔控制节点
ComfyUI_CatVTON_Wrapper/           # 虚拟试衣节点
ComfyUI-CogVideoXWrapper/          # 视频生成节点
ComfyUI-Gemini/                    # Gemini 模型集成
ComfyUI-GGUF/                      # GGUF 格式模型支持
ComfyUI-InstantID/                 # 人脸特征控制
ComfyUI-layerdiffuse/              # 分层扩散节点
ComfyUI-Marigold/                  # 深度估计节点
ComfyUI-MimicMotionWrapper/        # 动作模仿节点
ComfyUI-MingNodes/                 # 通用功能扩展节点
ComfyUI_OmniGen_Wrapper/           # OmniGen 模型封装
ComfyUI-PhotoMaker-ZHO/            # 照片生成节点
comfyui_segment_anything/          # 图像分割节点
ComfyUI-SUPIR/                     # 超分辨率节点
ComfyUI_toyxyz_test_nodes/         # 测试节点集
ComfyUI-YoloWorld-EfficientSAM/    # 目标检测节点
eden_comfy_pipelines/              # 预设工作流
facerestore_cf/                    # 人脸修复节点
NodeGPT/                           # GPT 集成节点

五、推荐 VAE 模型

模型名称 适用场景 下载链接
vae-ft-mse-840000-ema-pruned 通用 Stable Diffusion 版本 下载
kl-f8-anime2 动漫风格图像 下载
sdxl_vae.safetensors SDXL 模型专用 下载
orangemix.vae.pt Anything V3/V4 模型 下载
clearvae_v2.2.safetensors 提高图像清晰度 下载

提示:不同 VAE 模型会影响图像生成质量和风格,建议根据具体需求测试选择最合适的模型。

相关推荐
love530love2 小时前
Python 3.12 解决 MediaPipe “no attribute ‘solutions‘” 终极方案:基于全版本硬核实测的避坑指南
开发语言·人工智能·windows·python·comfyui·mediapipe·solutions
Rubin智造社2 天前
04月27日AI每日参考:Sora正式关闭,小米机器人开源,DeepSeek再降价
comfyui·github copilot·cohere·sora关闭·aleph alpha·deepseek降价·小米机器人
阿钱真强道3 天前
23 ComfyUI 实战:AnimateDiff + OpenPose Walking 姿态驱动视频生成
openpose·animatediff·controlnet·comfyui·姿态·walking·动作控制
阿钱真强道4 天前
21 ComfyUI 实战:IP-Adapter + ControlNet 实现人物表情编辑,为什么降权重后更容易“笑出来”
aigc·stable-diffusion·controlnet·comfyui·softedge·ip-adapter·人物表情编辑
Rubin智造社4 天前
04月25日AI每日参考:谷歌豪掷400亿押注Anthropic,DeepSeek V4横空出世
大数据·人工智能·物联网·comfyui·deepseek v4·谷歌anthropic投资·meta亚马逊芯片
阿钱真强道5 天前
20 ComfyUI 实战:用 ControlNet 实现人物表情编辑,让人物“笑起来”的工作流解析
aigc·stable-diffusion·controlnet·comfyui·softedge·ip-adapter·人物表情编辑
阿钱真强道5 天前
19 基于 ComfyUI 工作流学习 AnimateDiff:单图生成视频的入门实践与问题分析
aigc·animatediff·stable-diffusion·comfyui·视频生成·图生视频·单图转视频
阿钱真强道6 天前
17 ComfyUI AnimateDiff 新手教程:最小文生视频工作流搭建与原理解析
animatediff·文生视频·stable-diffusion·comfyui·新手入门·工作流教程
阿钱真强道6 天前
18 AnimateDiff 简介:它在 AI 视频生成领域处于什么位置?
animatediff·stable-diffusion·comfyui·工作流·ai视频·新手教程
宁南山7 天前
比迪丽LoRA模型AE做片段视频素材生成:动态背景与元素创作
stable diffusion·ai绘画·lora模型·视频素材生成