🚀 Janus-Pro
Janus-Pro是一種新穎的自迴歸框架,它將多模態理解和生成進行了統一。該框架通過將視覺編碼解耦為獨立的路徑,同時仍使用單一、統一的Transformer架構進行處理,解決了以往方法的侷限性。這種解耦不僅緩解了視覺編碼器在理解和生成任務中的角色衝突,還增強了框架的靈活性。Janus-Pro超越了以往的統一模型,其性能與特定任務模型相當甚至更優。它的簡單性、高靈活性和有效性使其成為下一代統一多模態模型的有力候選者。
🚀 快速開始
Janus-Pro是一個統一的多模態理解和生成模型,它將視覺編碼解耦,用於多模態理解和生成任務。它基於DeepSeek-LLM-1.5b-base/DeepSeek-LLM-7b-base構建。
Github倉庫
✨ 主要特性
- 統一多模態理解和生成,解決了以往方法的侷限性。
- 通過解耦視覺編碼,緩解了視覺編碼器在理解和生成任務中的角色衝突,增強了框架的靈活性。
- 超越了以往的統一模型,性能與特定任務模型相當甚至更優。
💻 使用示例
基礎用法
單圖像推理
以下是使用單圖像進行視覺理解的示例:
import torch
from PIL import Image
import requests
from transformers import JanusForConditionalGeneration, JanusProcessor
model_id = "deepseek-community/Janus-Pro-1B"
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-1B"
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模型許可證。
📚 詳細文檔
模型概述
屬性 |
詳情 |
模型類型 |
統一的多模態理解和生成模型 |
構建基礎 |
DeepSeek-LLM-1.5b-base/DeepSeek-LLM-7b-base |
多模態理解視覺編碼器 |
SigLIP-L,支持384 x 384圖像輸入 |
圖像生成分詞器 |
來自此處,下采樣率為16 |
引用信息
@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}
}
聯繫我們
如果您有任何問題,請提出issue或通過service@deepseek.com與我們聯繫。