开源图像编辑模型Flux Kontext的本地部署与入门教程
再也不需要到处去寻找很复杂、后期难于维护的各种工作流和下载种类繁多的大模型。只需要一次性的硬件成本支出,就可以随时按照自己的需求来生图,无需额外计算与支付算力、网络、存储等费用,长期使用后边际成本更低。所有的数据处理都在本地设备完成,避免敏感内容(个人图片、商业素材竺)外传到公网。无需调用收费api,不受调用次数的限制,适合高频次、批量处理图像的场景(如自媒体内容制作)。
开源图像编辑模型Flux Kontext Dev的本地部署与入门教程
本地部署的优点
维护简单
再也不需要到处去寻找很复杂、后期难于维护的各种工作流和下载种类繁多的大模型。
更低的成本
只需要一次性的硬件成本支出,就可以随时按照自己的需求来生图,无需额外计算与支付算力、网络、存储等费用,长期使用后边际成本更低。
数据隐私与安全
所有的数据处理都在本地设备完成,避免敏感内容(个人图片、商业素材等)外传到公网。
开源可控
无需调用收费api,不受调用次数的限制,适合高频次、批量处理图像的场景(如自媒体内容制作)。
本地部署准备
由于Flux Kontext Dev 于昨天 6月27日才正式开源,ComfyUI也于昨天才提交了支持Flux Kontext Dev模型的PR。下载6月27日之后的ComfyUI才能正确打开ComfyUI官方的Flux Kontext Dev工作流。
依次打开菜单栏 Workflow -> Browse Templates -> Flux -> Flux Kontext Dev(Basic)。这个工作流新增加了两个节点FluxKontextImageScale和ReferenceLatent,而旧版本ComfyUI没有这两个节点,旧版本的ComfyUI如果从ComfyUI-Manager查找缺失的节点插件,可以找到有一个名为COmfyUI-ADIC的插件提供了这两个节点,我发现这个插件也是昨天才提交了这两个节点的PR,并且过了几个小时又将它们重新修改成另外的节点名称(可能是为了避免与新版本ComfyUI的节点命名冲突),但我测试使用这个插件的那两个节点并没有能够成功出图,所以为了能够正确使用Flux Kontext Dev模型,我建议使用旧版本ComfyUI的用户,将ComfyUI升级到6月27日之后的版本。
ComfyUI官方地址
ComfyUI安装
本地需要先安装好Git、Python开发环境、CUDA驱动和Conda管理工具( 这里我使用conda管理Python虚拟环境
),如果是普通用户就下载ComfyUI的完整离线安装包(网址https://github.com/comfyanonymous/ComfyUI/releases中有离线安装包ComfyUI_windows_portable_nvidia.7z),省略了前述工具软件的安装步骤。以下是ComfyUI的安装和启动的完整命令:
# 下载源码
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI
# 创建Python虚拟环境
conda create -n comfyenv python=3.10.16
# 激活Python虚拟环境
conda activate comfyenv
# 非50系的显卡,可以安装Stable版本的PyTorch(安装Nightly版本也适用)
pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu128
# 50系的显卡,必须安装Nightly版本的PyTorch:
pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128
# 安装依赖软件包
pip install -r requirements.txt
# 启动ComfyUI
python main.py
模型下载
diffusion model
- flux1-dev-kontext_fp8_scaled.safetensors(11.0GB)
https://hf-mirror.com/Comfy-Org/flux1-kontext-dev_ComfyUI/resolve/main/split_files/diffusion_models/flux1-dev-kontext_fp8_scaled.safetensors
vae
- ae.safetensors(319MB)
https://hf-mirror.com/Comfy-Org/Lumina_Image_2.0_Repackaged/blob/main/split_files/vae/ae.safetensors
text encoder
- clip_l.safetensors(234MB)
https://hf-mirror.com/comfyanonymous/flux_text_encoders/blob/main/clip_l.safetensors - t5xxl_fp8_e4m3fn_scaled.safetensors(非满血版 4.8GB)
https://hf-mirror.com/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp8_e4m3fn_scaled.safetensors
或者
t5xxl_fp16.safetensors(满血版 9.11GB)
https://hf-mirror.com/comfyanonymous/flux_text_encoders/resolve/main/t5xxl_fp16.safetensors
本地模型结构
📂 ComfyUI/
├── 📂 models/
│ ├── 📂 diffusion_models/
│ │ └── flux1-dev-kontext_fp8_scaled.safetensors
│ ├── 📂 vae/
│ │ └── ae.safetensor
│ └── 📂 text_encoders/
│ ├── clip_l.safetensors
│ └── t5xxl_fp8_e4m3fn_scaled.safetensors 或者 t5xxl_fp16.safetensors
ComfyUI关于Flux-Kontext-dev的官方文档说明
https://docs.comfy.org/tutorials/flux/flux-1-kontext-dev
English Tutorial | 中文教程
提示词示例
1.单图模式
参考工作流与下载: https://www.runninghub.cn/post/1938422713163649026
-
将画面变成落日时分,柔和的光线,保持人物细节和特征不变
Change the scene to sunset, with soft lighting, turn the clothes into a skirt, while keeping the character’s details and features unchanged. -
将女孩的衣服修改为西装,保持人物细节和特征不变
Modify the girl’s clothes into a suit while keeping the character’s details and features unchanged -
把这个女孩的衣服换成蓝色 T 恤,并在她的耳朵上戴上耳环。
Change the girl’s clothes into a blue T-shirt and put earrings on her ears -
将衣服修改为维京战士,保持人物细节和特征不变
Change the clothes to be a viking warrior while keeping the character’s details and features unchanged
(以下的提示词在某些图片上没有上面的好,没有做到人物一致性)
Change the clothes to be a viking warrior while preserving facial features -
给这个图像的风格变成吉卜力风格
Change the style of this image to a Ghibli style. -
给这个图像的风格变成二次元动漫风格
Change the style of this image to anime-style. -
提取图片的线条图,用平滑的黑白线条表达,保留轮廓、白色背景,保持图片中人物的面部特征、服装细节和姿势不变
Extract the line drawing of the image, expressed with smooth black and white lines, retaining the outline, white background, and keeping the facial features, clothing details, and posture of the character in the image unchanged.
2.双图模式
参考工作流与下载: https://www.runninghub.cn/post/1938432790901755906
-
图1女人背着图2这个包,背景在公园,保持人物细节不改变
The woman in Figure 1 is carrying the bag in Figure 2, set against a park background, while keeping the character details unchanged. -
图1女人在图2的沙滩上散步,保持人物细节不改变
The woman in Figure 1 is walking on the beach in Figure 2, while keeping the character details unchanged.
3.删除指定物体
参考工作流与下载: https://www.runninghub.cn/post/1938583929945251841
- 删除黑色区域
Remove the black area
出图成功率
有时候不同的图片使用相同的提示词会有不一样的结果,这就需要换另一套更加准确的提示词来生图了。
示例:
- 将衣服修改为维京战士,保持人物细节和特征不变
Change the clothes to be a viking warrior while keeping the character’s details and features unchanged
(以下的提示词在某些图片上没有上面的好,没有做到人物一致性) - 将衣服修改为维京战士,保留人物的面部特征
Change the clothes to be a viking warrior while preserving facial features
Flux Kontext 提示词技巧
使用英文
1. 基础修改
- 简单直接:
"Change the car color to red"
- 保持风格:
"Change to daytime while maintaining the same style of the painting"
2. 风格转换
原则:
- 明确命名风格:
"Transform to Bauhaus art style"
- 描述特征:
"Transform to oil painting with visible brushstrokes, thick paint texture"
- 保留构图:
"Change to Bauhaus style while maintaining the original composition"
3. 角色一致性
框架:
- 具体描述:
"The woman with short black hair"
而非"她"
- 保留特征:
"while maintaining the same facial features, hairstyle, and expression"
- 分步修改:先改背景,再改动作
4. 文本编辑
- 使用引号:
"Replace 'joy' with 'BFL'"
- 保持格式:
"Replace text while maintaining the same font style"
常见问题解决
角色变化过大
❌ 错误:"Transform the person into a Viking"
✅ 正确:"Change the clothes to be a viking warrior while preserving facial features"
构图位置改变
❌ 错误:"Put him on a beach"
✅ 正确:"Change the background to a beach while keeping the person in the exact same position, scale, and pose"
风格应用不准确
❌ 错误:"Make it a sketch"
✅ 正确:"Convert to pencil sketch with natural graphite lines, cross-hatching, and visible paper texture"
核心原则
- 具体明确 - 使用精确描述,避免模糊词汇
- 分步编辑 - 复杂修改分为多个简单步骤
- 明确保留 - 说明哪些要保持不变
- 动词选择 - 用"更改"、“替换"而非"转换”
最佳实践模板
对象修改:"Change [object] to [new state], keep [content to preserve] unchanged"
风格转换:"Transform to [specific style], while maintaining [composition/character/other] unchanged"
背景替换:"Change the background to [new background], keep the subject in the exact same position and pose"
文本编辑:"Replace '[original text]' with '[new text]', maintain the same font style"
记住: 越具体越好,Kontext 擅长理解详细指令并保持一致性。
更多推荐
所有评论(0)