🚀 Janus-Pro
Janus-Pro是一種新穎的自迴歸框架,它將多模態理解和生成統一起來。該框架解決了以往方法的侷限性,通過將視覺編碼解耦為獨立的路徑,同時仍使用單一、統一的Transformer架構進行處理。這種解耦不僅緩解了視覺編碼器在理解和生成任務中的角色衝突,還增強了框架的靈活性。Janus-Pro超越了以往的統一模型,其性能可與特定任務模型相媲美甚至更優。其簡單性、高靈活性和有效性使其成為下一代統一多模態模型的有力候選者。
🚀 快速開始
項目倉庫
Github倉庫
模型示例圖
✨ 主要特性
Janus-Pro是一個統一的理解和生成多模態大語言模型(MLLM),它將用於多模態理解和生成的視覺編碼解耦。Janus-Pro基於DeepSeek-LLM-1.5b-base/DeepSeek-LLM-7b-base構建。
對於多模態理解,它使用 SigLIP-L 作為視覺編碼器,支持384 x 384的圖像輸入。對於圖像生成,Janus-Pro使用 此處 的分詞器,下采樣率為16。
屬性 |
詳情 |
模型類型 |
統一的多模態理解和生成模型 |
視覺編碼器(多模態理解) |
SigLIP-L,支持384 x 384圖像輸入 |
分詞器(圖像生成) |
此處 的分詞器,下采樣率為16 |
基礎模型 |
DeepSeek-LLM-1.5b-base/DeepSeek-LLM-7b-base |
💻 使用示例
基礎用法
單圖像推理
以下是一個使用單圖像進行視覺理解的示例。
import torch
from PIL import Image
import requests
from transformers import JanusForConditionalGeneration, JanusProcessor
model_id = "deepseek-community/Janus-Pro-7B"
messages = [
{
"role": "user",
"content": [
{'type': 'image', 'url': 'http://images.cocodataset.org/val2017/000000039769.jpg'},
{'type': 'text', 'text': "What do you see in this image?"}
]
},
]
processor = JanusProcessor.from_pretrained(model_id)
model = JanusForConditionalGeneration.from_pretrained(
model_id, torch_dtype=torch.bfloat16, device_map="auto"
)
inputs = processor.apply_chat_template(
messages,
add_generation_prompt=True,
generation_mode="text",
tokenize=True,
return_dict=True,
return_tensors="pt"
).to(model.device, dtype=torch.bfloat16)
output = model.generate(**inputs, max_new_tokens=40, generation_mode='text', do_sample=True)
text = processor.decode(output[0], skip_special_tokens=True)
print(text)
高級用法
文本到圖像生成
Janus還可以通過簡單地將生成模式設置為 image
從提示中生成圖像,如下所示。
import torch
from transformers import JanusForConditionalGeneration, JanusProcessor
model_id = "deepseek-community/Janus-Pro-7B"
processor = JanusProcessor.from_pretrained(model_id)
model = JanusForConditionalGeneration.from_pretrained(
model_id, torch_dtype=torch.bfloat16, device_map="auto"
)
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": "A dog running under the rain."}
]
}
]
prompt = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(
text=prompt,
generation_mode="image",
return_tensors="pt"
).to(model.device, dtype=torch.bfloat16)
model.generation_config.num_return_sequences = 2
outputs = model.generate(
**inputs,
generation_mode="image",
do_sample=True,
use_cache=True
)
decoded_image = model.decode_image_tokens(outputs)
images = processor.postprocess(list(decoded_image.float()), return_tensors="PIL.Image.Image")
for i, image in enumerate(images["pixel_values"]):
image.save(f"image{i}.png")
📄 許可證
此代碼倉庫遵循 MIT許可證。Janus-Pro模型的使用需遵循 DeepSeek模型許可證。
📚 詳細文檔
引用信息
@article{chen2025janus,
title={Janus-Pro: Unified Multimodal Understanding and Generation with Data and Model Scaling},
author={Chen, Xiaokang and Wu, Zhiyu and Liu, Xingchao and Pan, Zizheng and Liu, Wen and Xie, Zhenda and Yu, Xingkai and Ruan, Chong},
journal={arXiv preprint arXiv:2501.17811},
year={2025}
}
聯繫我們
如果您有任何問題,請提出問題或通過 service@deepseek.com 與我們聯繫。