还在用PS修图吗?这5款开源 AI 图像编辑模型夯爆了

0 阅读4分钟

AI 一天一个样,而开源社区的图像编辑模型也越来越厉害了。过去,AI 绘图更多是随机生成,而现在的模型已经进化到了精准操控阶段。无论是局部替换、风格改写还是复杂的文字排版,通过几行文字指令就能完成。

以下汇总了五款具有代表性的开源模型,并附带详细的部署运行方法。

Step1X-Edit-v1p2:引入思考与反思机制

阶跃星辰发布的 Step1X-Edit-v1p2 是一款强化了推理能力的模型。它在执行编辑指令时,会先通过结构化思考来理解修改意图,并在生成过程中进行反思纠错。这种设计让模型在面对复杂或抽象的指令时,表现出更高的准确度。

部署要点

该模型对环境版本有特定要求,需要Python环境。推荐使用ServBay来进行安装,ServBay能一键就把Python环境安装好,不需要任何命令行,也不用担心环境冲突。

建议安装指定版本的 transformers。

# 安装特定版本的依赖
pip install transformers==4.55.0

# 从指定分支安装 diffusers
git clone -b step1xedit_v1p2 https://github.com/Peyton-Chen/diffusers.git
cd diffusers
pip install -e .

# 可选:安装 RegionE 以提升推理速度
pip install RegionE

运行示例

在代码中开启 enable_thinking_modeenable_reflection_mode 即可启用推理功能。

from diffusers import Step1XEditPipelineV1P2
import torch

pipe = Step1XEditPipelineV1P2.from_pretrained("stepfun-ai/Step1X-Edit-v1p2", torch_dtype=torch.bfloat16)
pipe.to("cuda")

output = pipe(
    image=init_image,
    prompt="给女孩的脖子上加一条红宝石项链",
    enable_thinking_mode=True,
    enable_reflection_mode=True
).final_images[0]

LongCat-Image:高效双语模型

LongCat-Image 仅有 6B 参数规模,但在中文理解和文字渲染上表现突出。它能精准执行“将猫变成狗”这类指令,同时保持非编辑区域的视觉一致性。

部署要点

该模型在处理文字生成任务时,必须将目标文字放在单引号或双引号内,否则无法触发专门的字符编码机制。

conda create -n longcat python=3.10
conda activate longcat
pip install -U diffusers

运行示例

如果追求速度,可以使用其 Turbo 版本,推理步数可缩减至 8 步。

from diffusers import LongCatImageEditPipeline
pipe = LongCatImageEditPipeline.from_pretrained("meituan-longcat/LongCat-Image-Edit-Turbo", torch_dtype=torch.bfloat16)
pipe.enable_model_cpu_offload() # 显存不足时开启,约需 18GB VRAM

image = pipe(img, prompt="将背景换成森林", num_inference_steps=8, guidance_scale=1).images[0]

GLM-Image:混合架构的语义专家

智谱 AI 研发的 GLM-Image 采用自回归生成器与扩散解码器的混合架构。它在知识密集型任务中优势明显,能够理解长文本中复杂的逻辑关系,并准确反映在图像修改中。

部署要点

需要从源码安装最新的 transformers 和 diffusers。

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

运行示例

模型支持多图参考输入,适合进行身份保持或风格迁移。

from diffusers.pipelines.glm_image import GlmImagePipeline
pipe = GlmImagePipeline.from_pretrained("zai-org/GLM-Image", torch_dtype=torch.bfloat16, device_map="cuda")

image = pipe(
    prompt="将雪林背景替换为带有自动扶梯的地铁站",
    image=[init_image],
    height=1056, # 必须手动设置高度和宽度
    width=1024
).images[0]

Qwen-Image:20B 规模的工业级应用

阿里巴巴云推出的 Qwen-Image 2512 是一款 20B 规模的 MMDiT 模型。它在人物真实感和排版渲染上做了深度优化,适合生成专业的商业海报、信息图表或进行复杂的场景编辑。

部署要点

确保 transformers >= 4.51.3 以支持 Qwen 架构。

from diffusers import QwenImageEditPlusPipeline
pipe = QwenImageEditPlusPipeline.from_pretrained("Qwen/Qwen-Image-Edit-2511", torch_dtype=torch.bfloat16).to("cuda")

# 支持多图输入与精准指令遵循
inputs = {
    "image": [image1],
    "prompt": "这个女生看着面前的屏幕,屏幕上写着“阿里巴巴”",
    "num_inference_steps": 40,
    "true_cfg_scale": 4.0
}
output = pipe(**inputs).images[0]

Z-Image-Turbo:亚秒级响应的极速方案

同样来自智谱团队的 Z-Image-Turbo 专注于效率提升。通过 Decoupled-DMD 蒸馏技术,它在 8 步推理下即可达到极高的审美水准,在 H800 等企业级显卡上可实现亚秒级反馈。

部署要点

该模型对 guidance_scale 的设置非常敏感,Turbo 版本通常需设为 0。

from diffusers import ZImagePipeline
pipe = ZImagePipeline.from_pretrained("Tongyi-MAI/Z-Image-Turbo", torch_dtype=torch.bfloat16).to("cuda")

# 8步极速生成
image = pipe(
    prompt="身穿红底汉服的中国少女,细节精致的刺绣",
    num_inference_steps=9, # 实际对应 8 次 DiT 前向计算
    guidance_scale=0.0
).images[0]

总结与选型建议

这些模型虽然都属于图像编辑范畴,但侧重点不同。Step1X 适合需要深层逻辑理解的复杂修改任务。LongCat 和 Qwen 在中文环境和文字渲染上更具优势,且 Qwen 的 20B 规模能提供更丰富的细节。GLM-Image 凭借混合架构在处理信息密度极高的指令时表现更稳。如果应用场景强调实时交互,Z-Image-Turbo 则是目前平衡质量与速度的理想选择。

在部署时,建议优先使用 Conda 环境隔离依赖,并根据显存大小选择开启 enable_model_cpu_offload 或使用 float16 精度运行。