Diffusers documentation
JoyAI-Image-Edit-Plus
JoyAI-Image-Edit-Plus
JoyAI-Image 是一个用于图像理解、文生图以及指令引导图像编辑的统一多模态基础模型。它将一个 8B 多模态大语言模型(MLLM)与一个 16B 多模态扩散 Transformer(MMDiT)相结合。
JoyAI-Image-Edit-Plus 是一个多图像指令引导的编辑模型,它接受多张参考图像和一条文本指令,根据指令生成一张融合参考图像中元素的新图像。每个样本支持 1–5 张参考图像。
| 模型 | 描述 | 下载 |
|---|---|---|
| JoyAI-Image-Edit-Plus | 基于多参考图的元素组合,实现多图指令引导编辑 | Hugging Face |
import torch
from PIL import Image
from diffusers import JoyImageEditPlusPipeline
pipeline = JoyImageEditPlusPipeline.from_pretrained(
"jdopensource/JoyAI-Image-Edit-Plus-Diffusers", dtype=torch.bfloat16
)
pipeline.to("cuda") # or "mps", "xpu", "cpu"
images = [
Image.open("reference_0.png").convert("RGB"),
Image.open("reference_1.png").convert("RGB"),
]
target_h, target_w = pipeline.image_processor.get_default_height_width(images[-1])
output = pipeline(
images=images,
prompt="Combine the person from the second image with the scene from the first image.",
negative_prompt="low quality, blurry, deformed",
height=target_h,
width=target_w,
num_inference_steps=30,
guidance_scale=4.0,
generator=torch.Generator("cuda").manual_seed(42),
).images[0]
output.save("joyimage_edit_plus_output.png")JoyImageEditPlusPipeline
class diffusers.JoyImageEditPlusPipeline
< source >( scheduler: FlowMatchEulerDiscreteSchedulervae: AutoencoderKLWantext_encoder: Qwen3VLForConditionalGenerationtokenizer: Qwen2Tokenizertransformer: JoyImageEditPlusTransformer3DModelprocessor: Qwen3VLProcessortext_token_max_length: int = 2048 )
参数
- scheduler (FlowMatchEulerDiscreteScheduler) —
用于与
transformer配合,对编码后的图像潜变量进行去噪的调度器。 - vae (AutoencoderKLWan) — 变分自编码器(VAE)模型,用于将图像编码为潜在表示,以及从潜在表示解码为图像。
- text_encoder (
Qwen3VLForConditionalGeneration) — 用于提示编码并支持内联图像理解的多模态文本编码器。 - tokenizer (
Qwen2Tokenizer) — 用于文本处理的分词器。 - transformer (JoyImageEditPlusTransformer3DModel) — 用于对编码后的图像潜在变量进行去噪的条件 Transformer (MMDiT) 架构。
- processor (
Qwen3VLProcessor) — 用于多模态输入(文本 + 图像)的处理器。 - text_token_max_length (
int,默认为2048) — 文本编码的最大 token 长度。
使用 JoyImage Edit Plus 进行多图像指令引导编辑的扩散流水线。
支持多张具有不同分辨率的参考图像。每张参考图像会独立进行 VAE 编码和分块(patchify),然后与目标噪声块拼接,用于联合去噪。
__call__
< source >( images: list[PIL.Image.Image] | list[list[PIL.Image.Image]] | None = Noneprompt: str | list[str] = Noneheight: int | None = Nonewidth: int | None = Nonenum_inference_steps: int = 30timesteps: list = Nonesigmas: list = Noneguidance_scale: float = 4.0negative_prompt: str | list[str] | None = Nonegenerator: typing.Union[torch.Generator, list[torch.Generator], NoneType] = Nonelatents: typing.Optional[torch.Tensor] = Noneprompt_embeds: typing.Optional[torch.Tensor] = Noneprompt_embeds_mask: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds: typing.Optional[torch.Tensor] = Nonenegative_prompt_embeds_mask: typing.Optional[torch.Tensor] = Noneoutput_type: str | None = 'pil'return_dict: bool = Truecallback_on_step_end: typing.Union[typing.Callable[[int, int, dict], NoneType], diffusers.callbacks.PipelineCallback, diffusers.callbacks.MultiPipelineCallbacks, NoneType] = Nonecallback_on_step_end_tensor_inputs: list = ['latents']max_sequence_length: int = 4096 ) → JoyImageEditPlusPipelineOutput or tuple
参数
- images (
list[Image.Image]或list[list[Image.Image]],可选) — 用于编辑的参考图像。每幅图像可以具有不同的分辨率。如果提供的是扁平列表, 则将其视为包含多个参考图像的一个样本。 - prompt (
str或list[str],可选) — 用于引导图像生成的提示词或提示词列表。如果未定义,则必须改为传入prompt_embeds。 - height (
int, 可选) — 生成图像的高度(以像素为单位)。如果为None,则根据最后一张参考图像确定。 - width (
int, 可选) — 生成图像的宽度(以像素为单位)。如果为None,则根据最后一张参考图像确定。 - num_inference_steps (
int,可选,默认为30) — 去噪步数。更多的去噪步数通常能生成更高质量的图像,但代价是推理速度变慢。 - timesteps (
list[int],可选) — 用于去噪过程的自定义时间步。如果未定义,则使用等间距。 - sigmas (
list[float],可选) — 用于去噪过程的自定义 sigmas。 - guidance_scale (
float,可选,默认为4.0) — 无分类器引导的缩放系数。较高的值会促使模型生成与prompt更加一致的图片,但会降低图像质量。 - negative_prompt (
str或list[str],可选) — 用于引导图像生成的负面提示词。如果未定义,则使用空白提示词进行无分类器引导。 - generator (
torch.Generator或list[torch.Generator],可选) — 一个或一组 torch 生成器,用于使生成过程具有确定性。 - latents (
torch.Tensor, 可选) — 预生成的含噪潜变量,用作图像生成的输入。 - prompt_embeds (
torch.Tensor, 可选) — 预生成的文本嵌入。可用于轻松调整文本输入。 - prompt_embeds_mask (
torch.Tensor, 可选) — 预生成文本嵌入的注意力掩码。 - negative_prompt_embeds (
torch.Tensor,可选) — 预生成的负向文本嵌入。 - negative_prompt_embeds_mask (
torch.Tensor, 可选) — 预生成的负向文本嵌入的注意力掩码。 - output_type (
str, 可选,默认为"pil") — 生成图像的输出格式。可选"pil"(PIL.Image.Image)、"np"(np.ndarray)、"pt"(torch.Tensor) 或"latent"(原始潜在输出)。 - return_dict (
bool,可选,默认为True) — 是否返回 JoyImageEditPlusPipelineOutput 而不是普通元组。 - callback_on_step_end (
Callable, 可选) — 在每个去噪步骤结束时调用的函数,参数包括:pipeline、步骤索引、timestep,以及一个包含回调张量输入的字典。 - callback_on_step_end_tensor_inputs (
list[str],可选,默认为["latents"]) —callback_on_step_end函数的张量输入列表。 - max_sequence_length (
int,可选,默认为4096) — 文本编码器的最大序列长度。
返回值
JoyImageEditPlusPipelineOutput 或 tuple
如果 return_dict 为 True,则返回 JoyImageEditPlusPipelineOutput;否则返回一个 tuple,其中第一个元素是生成图像的列表。
调用生成 pipeline 时调用的函数。
示例:
>>> import torch
>>> from diffusers import JoyImageEditPlusPipeline
>>> from diffusers.utils import load_image
>>> model_id = "jdopensource/JoyAI-Image-Edit-Plus-Diffusers"
>>> pipe = JoyImageEditPlusPipeline.from_pretrained(model_id, torch_dtype=torch.bfloat16)
>>> pipe.to("cuda")
>>> images = [
... load_image("dog.png"),
... load_image("person.png"),
... ]
>>> output = pipe(
... images=images,
... prompt="Let the person lovingly play with the dog.",
... height=1024,
... width=1024,
... num_inference_steps=30,
... guidance_scale=4.0,
... generator=torch.manual_seed(42),
... )
>>> output.images[0].save("output.png")encode_prompt_multiple_images
< source >( prompt: str | list[str]device: typing.Optional[torch.device] = Noneimages: list[PIL.Image.Image] | None = Nonemax_sequence_length: int | None = None )
通过 Qwen3-VL 处理器对包含内联 <image> 标记的提示词进行编码。
prepare_latents
< source >( batch_size: intnum_channels_latents: intheight: intwidth: intdtype: dtypedevice: devicegenerator: typing.Union[torch.Generator, list[torch.Generator], NoneType]reference_images: list[list[PIL.Image.Image]] | None = Nonelatents: typing.Optional[torch.Tensor] = None ) → padded_latents
准备 6D 填充后的潜在张量,包含目标噪声和参考图像的潜在表示。
JoyImageEditPlusPipelineOutput
class diffusers.JoyImageEditPlusPipelineOutput
< source >( images: typing.Union[typing.List[PIL.Image.Image], numpy.ndarray] )
JoyImage Edit Plus 多图像编辑流水线的输出类。