JoyAI-Image-Edit 是一款专注于指令引导图像编辑的多模态基础模型。它凭借强大的空间理解能力(包括场景解析、关系定位和指令分解),实现精确且可控的编辑,可将复杂修改准确应用于指定区域。
环境要求:Python >= 3.10,支持 CUDA 的 GPU
注意:JoyImageEditPipeline 将在 diffusers 的下一个官方版本(>0.38.0)中包含。在此之前,请按上述方法从源码安装。
pip install torch transformers torchvision
pip install git+https://github.com/huggingface/diffusers.gitimport torch
from PIL import Image
from diffusers import JoyImageEditPipeline
pipeline = JoyImageEditPipeline.from_pretrained("jdopensource/JoyAI-Image-Edit-Diffusers")
pipeline.to(torch.bfloat16)
pipeline.to("cuda")
pipeline.set_progress_bar_config(disable=None)
print("pipeline loaded")
img_path = "./test_images/input.png"
prompt = "Remove the construction structure from the top of the crane."
image = Image.open(img_path).convert("RGB")
inputs = {
"image": image,
"prompt": prompt,
"generator": torch.manual_seed(0),
"num_inference_steps": 40,
"guidance_scale": 4.0,
}
print("run pipeline...")
with torch.inference_mode():
output = pipeline(**inputs)
image = output.images[0]
image.save("joyai_image_edit_output.png")
print("image saved.")JoyAI-Image 支持三种空间编辑提示模式:物体移动、物体旋转和相机控制。为获得最稳定的效果,建议尽可能严格遵循以下提示模板。
当您希望将目标物体移动到指定区域时,使用此模式。
提示模板:
Move the <object> into the red box and finally remove the red box.规则:
<object> 替换为待移动目标对象的清晰描述。示例:
Move the board into the red box and finally remove the red box.
当你希望将物体旋转至特定标准视角时,可使用此模式。
提示词模板:
Rotate the <object> to show the <view> side view.支持的 <view> 值:
frontrightleftrearfront rightfront leftrear rightrear left规则:
<object>。<view>。示例:
Rotate the dog to show the left side view.
当你希望仅更改相机视角而保持3D场景本身不变时,请使用此模式。
提示词模板:
Move the camera.
- Camera rotation: Yaw {y_rotation}°, Pitch {p_rotation}°.
- Camera zoom: in/out/unchanged.
- Keep the 3D scene static; only change the viewpoint.规则:
{y_rotation} 指定偏航旋转角度(以度为单位)。
{p_rotation} 指定俯仰旋转角度(以度为单位)。
相机缩放 必须是以下选项之一:
in(放大)out(缩小)unchanged(不变)最后一行至关重要:它明确告知模型保留 3D 场景内容和几何结构,仅调整相机视角。
示例:
Move the camera.
- Camera rotation: Yaw 0.0°, Pitch -15.0°.
- Camera zoom: unchanged.
- Keep the 3D scene static; only change the viewpoint.
JoyAI-Image 基于 Apache 2.0 许可协议授权。
我们正积极招聘研究科学家、AI 基础设施工程师和实习生,加入我们共同构建下一代生成式基础模型并将其应用于实际场景。如果您感兴趣,请将简历发送至:huanghaoyang.ocean@jd.com