Skip to content

feice-huang/joyai-image-edit-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

JoyAI-Image-Edit (Diffusers) ComfyUI 自定义节点安装指南


1. 效果展示与设备要求

1.1 效果展示

JoyAI-Image-Edit 是京东开源的指令驱动图像编辑模型,支持以下能力:

  • 通用图像编辑(改变颜色、添加/移除物体等)
  • 空间编辑(物体移动、旋转、相机控制)
  • 文生图(Text-to-Image)

工作流运行效果

ComfyUI 中 JoyAI-Image-Edit 节点工作流的截图

示例效果展示(点击展开)

物体移动

Prompt: Move the board into the red box and finally remove the red box.

输入图像 输出图像
编辑输入 编辑输出

旋转

Prompt: Rotate the dog to show the left side view.

输入图像 输出图像
编辑输入 编辑输出

相机控制

Prompt:

Move the camera.
- Camera rotation: Yaw 0.0°, Pitch -15.0°.
- Camera zoom: unchanged.
- Keep the 3D scene static; only change the viewpoint.
输入图像 输出图像
编辑输入 编辑输出

1.2 设备性能要求

项目 最低要求(开启 CPU Offload) 推荐配置(关闭 CPU Offload)
GPU 显存 35GB(如 A100-40GB) 55GB(如 A100-80GB)

说明:

  • 模型权重总计约 47GB(BF16精度),其中 Transformer 31GB、Text Encoder 17GB、VAE 243MB
  • 开启 cpu_offload 模式时,任意时刻仅一个大模块在 GPU 上,峰值显存实测约 33GiB(建议预留 35GB+)
  • 关闭 cpu_offload 时全部模型同时加载到 GPU,需要 55GB 显存
  • 如果显存不足 35GB,后续我们会发布量化版本权重,敬请期待

2. 下载

2.1 下载模型权重

模型权重需要放置在 ComfyUI 的 models/diffusers/ 目录下。

方法一:使用 huggingface-cli 下载

# 安装 huggingface_hub(如未安装)
pip install huggingface_hub

# 下载到 ComfyUI/models/diffusers/ 目录
huggingface-cli download jdopensource/JoyAI-Image-Edit-Diffusers \
  --local-dir /path/to/ComfyUI/models/diffusers/JoyAI-Image-Edit-Diffusers

方法二:使用 modelscope 下载

modelscope download --model jd-opensource/JoyAI-Image-Edit-Diffusers \
  --local_dir /path/to/ComfyUI/models/diffusers/JoyAI-Image-Edit-Diffusers

下载完成后 ComfyUI/models/diffusers/JoyAI-Image-Edit-Diffusers/ 目录的文件列表

ComfyUI/models/diffusers/
└── JoyAI-Image-Edit-Diffusers/
    ├── model_index.json
    ├── transformer/         # ~31GB, 核心扩散模型
    ├── text_encoder/        # ~17GB, Qwen3VL 文本编码器
    ├── tokenizer/           # ~16MB
    ├── processor/           # ~16MB
    ├── vae/                 # ~243MB
    └── scheduler/           # ~1KB

2.2 下载节点代码

将自定义节点代码克隆或复制到 ComfyUI 的 custom_nodes/ 目录中。

方法一:从 GitHub 克隆并提取

cd /path/to/ComfyUI/custom_nodes/

# 克隆仓库
git clone https://github.com/jd-opensource/JoyAI-Image.git

# 提取 diffusers 版 ComfyUI 节点
cp -r JoyAI-Image/joyai_image_diffusers_comfyui ./

# 清理(可选)
rm -rf JoyAI-Image

方法二:手动复制

如果你已经有代码文件,确保 custom_nodes/ 下存在如下结构:

ComfyUI/custom_nodes/
└── joyai_image_diffusers_comfyui/
    ├── __init__.py
    ├── nodes.py
    ├── joyai-image-edit-workflow.json    # 预置工作流
    └── README.md

3. 配置(安装依赖)

3.1 安装 Python 依赖

本节点依赖以下关键包:

包名 版本要求 说明
diffusers >= 0.39.0.dev0(源码安装) 包含 JoyImageEditPipeline 支持
transformers >= 4.57.0 Qwen3VL 文本编码器支持
torch >= 2.8 PyTorch

安装 diffusers(从源码)

重要:截至 diffusers 0.38.0 正式版,JoyImageEditPipeline 已合并到主分支,但尚未包含在 release 中。需从源码安装:

# 进入 ComfyUI 使用的 Python 环境
# 如果 ComfyUI 用的 conda 环境:
# conda activate comfyui

pip install git+https://github.com/huggingface/diffusers.git

安装/升级 transformers

pip install transformers>=4.57.0

验证安装

python -c "
from diffusers import JoyImageEditPipeline, JoyImageEditTransformer3DModel
from transformers import Qwen3VLForConditionalGeneration
print('All imports successful!')
"

如果输出 All imports successful! 表示安装成功。

3.2 验证 ComfyUI 识别节点

  1. 重启 ComfyUI
  2. 在节点搜索中搜索 "JoyAI"

应该能看到以下 4 个节点:

节点名 显示名称 分类
JoyAIImageEditDiffusersTransformerLoader Load JoyAI Transformer (Diffusers) loaders/joyai
JoyAIImageEditDiffusersTextEncoderLoader Load JoyAI Text Encoder (Diffusers) loaders/joyai
JoyAIImageEditDiffusersVAELoader Load JoyAI VAE (Diffusers) loaders/joyai
JoyAIImageEditDiffusersPipeline JoyAI Image Edit Pipeline (Diffusers) image/joyai

ComfyUI 中搜索 "JoyAI" 显示 4 个节点

4. 使用工作流

4.1 加载预置工作流

  1. 打开 ComfyUI
  2. custom_nodes/joyai_image_diffusers_comfyui/joyai-image-edit-workflow.json 拖入画布,或通过菜单 Load 导入

4.2 配置节点

  1. 在三个 Loader 节点中选择模型路径:下拉列表中应出现 JoyAI-Image-Edit-Diffusers
  2. 连接输入图像:使用 Load Image 节点加载待编辑图片
  3. 设置 Prompt:在 Pipeline 节点的 prompt 框中输入编辑指令(英文)

4.3 参数说明

参数 默认值 说明
prompt "" 编辑指令(英文),例如 "Turn the plate blue"
height / width 0 输出尺寸,0 表示自动匹配输入图像
steps 40 去噪步数,越多质量越高但越慢
guidance_scale 0.0 引导强度,>1.0 启用 CFG
num_images_per_prompt 1 每次生成的图片数
seed 0 随机种子,用于复现结果
cpu_offload True 分阶段 CPU 卸载,开启可以降低峰值显存

4.4 运行

点击 Run 运行工作流。

首次运行时模型加载需要较长时间(约1-3分钟,取决于磁盘速度)。后续运行若模型已缓存则会快很多。


5. 常见问题排查

Q1: 搜索不到 JoyAI 节点

原因:ComfyUI 未正确加载节点包

解决方案

  1. 确认目录名正确:custom_nodes/joyai_image_diffusers_comfyui/
  2. 检查 ComfyUI 启动日志是否有 import 错误
  3. 确认 diffuserstransformers 已正确安装到 ComfyUI 使用的 Python 环境中

Q2: 模型下拉列表为空

原因:模型权重目录未正确放置

解决方案

  1. 确认 ComfyUI/models/diffusers/JoyAI-Image-Edit-Diffusers/ 目录存在
  2. 确认该目录下包含 model_index.json 文件
  3. 如果 ComfyUI 配置了自定义路径,检查 extra_model_paths.yaml

Q3: ImportError - No module named 'diffusers.pipelines.joyimage'

原因:diffusers 版本过低,未包含 JoyImageEditPipeline

解决方案

pip install git+https://github.com/huggingface/diffusers.git

Q4: CUDA Out of Memory

原因:显存不足

解决方案

  1. 确保 Pipeline 节点中 cpu_offload 设为 True
  2. 降低输出分辨率(height/width)
  3. num_images_per_prompt 设为 1
  4. 关闭其他占用显存的程序

Q5: 运行极慢

可能原因

  • 开启了 cpu_offload,模型在 CPU/GPU 间来回搬运正常会慢一些
  • 磁盘 I/O 瓶颈

优化建议

  • 如有充足显存(80GB),关闭 cpu_offload
  • 使用 NVMe SSD 存放模型权重

6. 提示词参考

通用编辑

Turn the plate blue.
Add sunglasses to the person.
Remove the background.
Make it look like a painting.

空间编辑 - 物体移动

Move the apple into the red box and finally remove the red box.

(需要在输入图像上标注红色方框表示目标位置)

空间编辑 - 物体旋转

Rotate the chair to show the front side view.
Rotate the car to show the rear left side view.

支持的方向:front, right, left, rear, front right, front left, rear right, rear left

空间编辑 - 相机控制

Move the camera.
- Camera rotation: Yaw 45°, Pitch 0°.
- Camera zoom: in.
- Keep the 3D scene static; only change the viewpoint.

附录:CPU Offload 工作原理

开启 cpu_offload=True 时,推理分为 4 个阶段,每个阶段仅有一个大模型在 GPU 上:

阶段1: Text Encoder → GPU   编码文本提示   → 卸载到 CPU
阶段2: VAE         → GPU   编码参考图像   → 卸载到 CPU
阶段3: Transformer → GPU   去噪循环       → 卸载到 CPU
阶段4: VAE         → GPU   解码输出图像   → 卸载到 CPU

这使得峰值显存占用仅为最大单模块的大小加上中间张量(实测峰值约 33GiB)。

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors