🚀 Janus-1.3B ONNX 模型
本項目將 deepseek-ai/Janus-1.3B 模型轉換為 ONNX 權重,以兼容 Transformers.js 庫。它支持多種跨模態任務,如文本到圖像、圖像到文本、圖像文本到文本等。
🚀 快速開始
本項目將 deepseek-ai/Janus-1.3B 模型轉換為 ONNX 權重,使其與 Transformers.js 兼容,可用於執行多種跨模態任務。
📦 安裝指南
如果你還沒有安裝 Transformers.js JavaScript 庫,可以使用以下命令從 NPM 進行安裝:
npm i @huggingface/transformers
💻 使用示例
基礎用法
示例:圖像+文本到文本
import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
const model_id = "onnx-community/Janus-1.3B-ONNX";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await MultiModalityCausalLM.from_pretrained(model_id);
const conversation = [
{
role: "User",
content: "<image_placeholder>\nConvert the formula into latex code.",
images: ["https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/quadratic_formula.png"],
},
];
const inputs = await processor(conversation);
const outputs = await model.generate({
...inputs,
max_new_tokens: 150,
do_sample: false,
});
const new_tokens = outputs.slice(null, [inputs.input_ids.dims.at(-1), null]);
const decoded = processor.batch_decode(new_tokens, { skip_special_tokens: true });
console.log(decoded[0]);
示例輸出:
Sure, here is the LaTeX code for the given formula:
x = \frac{-b \pm \sqrt{b^2 - 4a c}}{2a}
This code represents the mathematical expression for the variable \( x \).
示例:文本到圖像
import { AutoProcessor, MultiModalityCausalLM } from "@huggingface/transformers";
const model_id = "onnx-community/Janus-1.3B-ONNX";
const processor = await AutoProcessor.from_pretrained(model_id);
const model = await MultiModalityCausalLM.from_pretrained(model_id);
const conversation = [
{
role: "User",
content: "A cute and adorable baby fox with big brown eyes, autumn leaves in the background enchanting,immortal,fluffy, shiny mane,Petals,fairyism,unreal engine 5 and Octane Render,highly detailed, photorealistic, cinematic, natural colors.",
},
];
const inputs = await processor(conversation, { chat_template: "text_to_image" });
const num_image_tokens = processor.num_image_tokens;
const outputs = await model.generate_images({
...inputs,
min_new_tokens: num_image_tokens,
max_new_tokens: num_image_tokens,
do_sample: true,
});
await outputs[0].save("test.png");
示例輸出:
如果你想在線體驗該模型,可以訪問 在線 WebGPU 演示。
📄 許可證
本項目使用其他許可證。
屬性 |
詳情 |
基礎模型 |
deepseek-ai/Janus-1.3B |
任務類型 |
任意到任意 |
庫名稱 |
transformers.js |
標籤 |
文本到圖像、圖像到文本、圖像文本到文本 |