
Deepseek 推出 Janus-pro:超越 Dall-e 3 和稳定扩散技术、改变游戏规则的 Ai 图像生成器
- Rifx.Online
- Generative AI , Computer Vision , AI Applications
- 23 Feb, 2025
DeepSeek的Janus-Pro模型概述
DeepSeek的R-1模型在过去几天内在全球引起了广泛关注。它是OpenAI的o1模型的一个开源和经济实惠的替代品。然而,在R-1的热度尚未平息之前,这家中国初创公司又推出了一款名为Janus-Pro的开源AI图像模型。
DeepSeek表示,Janus-Pro 7B在多个基准测试中优于OpenAI的Dall-E 3和Stable Diffusion。但它真的那么好吗?它是否兑现了这些声明,还是仅仅是另一个跟随AI热潮的模型?
让我们来看看。
简单来说,Janus-Pro是一个强大的AI模型,能够理解图像和文本,并且可以根据文本描述生成图像。
Janus-Pro是Janus模型的增强版,旨在实现统一的多模态理解和生成。它具有更好的训练方法、更多的数据和更大的模型。它还为短提示提供了更稳定的输出,具有更好的视觉质量、更丰富的细节,并能够生成简单的文本。
看看下面的一些示例:
Prompt: 一位美丽女孩的面孔
这个新模型在渲染文本方面也更具能力。
Prompt: 一幅清晰的黑板图像,表面干净、深绿色,中央用粗体白色粉笔字写着“Hello”,字迹清晰可辨。
Janus-Pro系列包括两种模型大小:10亿和70亿,展示了视觉编码和解码方法的可扩展性。两个模型生成的图像分辨率为384 × 384。
在商业许可方面,该模型提供了一个宽松的许可,适用于学术和商业用途。
Janus-Pro的技术细节
Janus-Pro使用独立的视觉编码方法来处理多模态理解和视觉生成任务。此设计旨在减轻这两项任务之间的冲突并提高整体性能。
对于多模态理解,Janus-Pro使用SigLIP encoder从图像中提取高维语义特征,然后通过理解适配器将这些特征映射到LLM的输入空间。
对于视觉生成,该模型使用VQ tokenizer将图像转换为离散ID,然后通过生成适配器将这些ID映射到LLM的输入空间。
在文本到图像的指令遵循中,Janus-Pro-7B在GenEval benchmark上得分为0.80,超过了其他模型,如OpenAI的Dall-E 3和Stability AI的Stable Diffusion 3 Medium。
此外,Janus-Pro-7B在DPG-Bench上获得了84.19的分数,超越了所有其他方法,展示了其在文本到图像生成中遵循密集指令的能力。
Janus-Pro 是否优于 Dall-E 3 或 Stable Diffusion?
根据 DeepSeek 的内部基准测试,Dall-E 3 和 Stable Diffusion 模型在 GenEval 和 DPG-Bench 基准测试中的得分均较低。
但我对此信息持保留态度,因为样本图像的效果。证明这一点的最佳方法是进行我自己的测试。让我们看看以下一些例子:
Prompt: A photo of a herd of red sheep on a green field.
左图 (Janus-Pro),右图 (Dall-E 3)
Prompt: A beautiful 35 year old woman of average build wearing a pink tulle dress sits on the ground in front of the Eiffel Tower. Soft light illuminates her face as she poses for a photo with Paris in the background in Chanel style. Her shoulder length brown hair is styled in loose waves that fall to one side.
左图 (Janus-Pro),右图 (Dall-E 3)
Prompt: An image of a little boy holding a white board with the text “AI is awesome!”
左图 (Janus-Pro),右图 (Dall-E 3)
根据以上示例,Dall-E 3 显然表现优于 Janus-Pro。Janus-Pro 输出中的面部和身体比例明显不准确,文本渲染示例也表明它在这一领域存在困难。
话虽如此,我可能遗漏了一些内容——可能需要特定的参数或 fine-tuning 来改善结果。然而,在默认设置下,输出效果令人失望。
图像由 Jim Clyde Monge 提供
如何访问 Janus-Pro?
DeepSeek 在 HuggingFace 上向公众发布了 Janus,以支持学术和商业社区内更广泛和多样化的研究。
- Janus-1.3B: Hugging Face 链接
- JanusFlow-1.3B: Hugging Face 链接
- Janus-Pro-1B: Hugging Face 链接
- Janus-Pro-7B: Hugging Face 链接
请注意,具有 70 亿参数的 Janus-Pro 模型几乎会占用您内部内存的 15GB。
如果您不想在自己的硬件上运行该模型,可以简单地在 HuggingFace 上运行 Gradio 演示。
使用起来非常简单。只需描述您想要生成的图像,然后点击“生成图像”按钮。生成的速度取决于同时使用该应用程序的用户数量。
您还可以通过上传图像并要求 AI 进行解释来尝试多模态理解功能。以下是一个示例:
提示:解释这个 meme
这张图是对两种视觉编码方法的幽默比较,使用了流行的“buff Doge vs. Cheems” meme 格式。
- 这很准确,我认为它是一个很好的自动字幕或为照片添加 alt 文本的工具。
对于开发者,您可以下载模型并在本地磁盘上运行。以下是一个示例推理代码片段,用于从文本生成图像:
import os
import PIL.Image
import torch
import numpy as np
from transformers import AutoModelForCausalLM
from janus.models import MultiModalityCausalLM, VLChatProcessor
model_path = "deepseek-ai/Janus-Pro-7B"
vl_chat_processor: VLChatProcessor = VLChatProcessor.from_pretrained(model_path)
tokenizer = vl_chat_processor.tokenizer
vl_gpt: MultiModalityCausalLM = AutoModelForCausalLM.from_pretrained(
model_path, trust_remote_code=True
)
vl_gpt = vl_gpt.to(torch.bfloat16).cuda().eval()
conversation = [
{
"role": "<|User|>",
"content": "A stunning princess from kabul in red, white traditional clothing, blue eyes, brown hair",
},
{"role": "<|Assistant|>", "content": ""},
]
sft_format = vl_chat_processor.apply_sft_template_for_multi_turn_prompts(
conversations=conversation,
sft_format=vl_chat_processor.sft_format,
system_prompt="",
)
prompt = sft_format + vl_chat_processor.image_start_tag
@torch.inference_mode()
def generate(
mmgpt: MultiModalityCausalLM,
vl_chat_processor: VLChatProcessor,
prompt: str,
temperature: float = 1,
parallel_size: int = 16,
cfg_weight: float = 5,
image_token_num_per_image: int = 576,
img_size: int = 384,
patch_size: int = 16,
):
input_ids = vl_chat_processor.tokenizer.encode(prompt)
input_ids = torch.LongTensor(input_ids)
tokens = torch.zeros((parallel_size*2, len(input_ids)), dtype=torch.int).cuda()
for i in range(parallel_size*2):
tokens[i, :] = input_ids
if i % 2 != 0:
tokens[i, 1:-1] = vl_chat_processor.pad_id
inputs_embeds = mmgpt.language_model.get_input_embeddings()(tokens)
generated_tokens = torch.zeros((parallel_size, image_token_num_per_image), dtype=torch.int).cuda()
for i in range(image_token_num_per_image):
outputs = mmgpt.language_model.model(inputs_embeds=inputs_embeds, use_cache=True, past_key_values=outputs.past_key_values if i != 0 else None)
hidden_states = outputs.last_hidden_state
logits = mmgpt.gen_head(hidden_states[:, -1, :])
logit_cond = logits[0::2, :]
logit_uncond = logits[1::2, :]
logits = logit_uncond + cfg_weight * (logit_cond-logit_uncond)
probs = torch.softmax(logits / temperature, dim=-1)
next_token = torch.multinomial(probs, num_samples=1)
generated_tokens[:, i] = next_token.squeeze(dim=-1)
next_token = torch.cat([next_token.unsqueeze(dim=1), next_token.unsqueeze(dim=1)], dim=1).view(-1)
img_embeds = mmgpt.prepare_gen_img_embeds(next_token)
inputs_embeds = img_embeds.unsqueeze(dim=1)
dec = mmgpt.gen_vision_model.decode_code(generated_tokens.to(dtype=torch.int), shape=[parallel_size, 8, img_size//patch_size, img_size//patch_size])
dec = dec.to(torch.float32).cpu().numpy().transpose(0, 2, 3, 1)
dec = np.clip((dec + 1) / 2 * 255, 0, 255)
visual_img = np.zeros((parallel_size, img_size, img_size, 3), dtype=np.uint8)
visual_img[:, :, :] = dec
os.makedirs('generated_samples', exist_ok=True)
for i in range(parallel_size):
save_path = os.path.join('generated_samples', "img_{}.jpg".format(i))
PIL.Image.fromarray(visual_img[i]).save(save_path)
generate(
vl_gpt,
vl_chat_processor,
prompt,
)
最后的思考
我理解人们对这个新图像模型的热议。有人声称它是 Dall-E 3 的一个不错替代品,但我并不认同。我自己试过 Janus-Pro,但图像的质量并没有我想象中那么令人印象深刻。
一个关键的限制是输入分辨率限制为 384 × 384。此外,文本到图像生成的相对低分辨率,加上来自视觉 tokenizer 的重建损失,可能导致图像缺乏许多用户所期望的细节水平。
尽管如此,像 Janus-Pro 这样的开源模型的快速出现表明 DeepSeek 已经在 AI 竞争中定位自己为一个强有力的颠覆者。尽管目前的质量限制,他们对可访问、开放创新的推动无疑让行业领导者们忙于适应。
此故事发布于 Generative AI。