Fluxi AI Small Vision
Fluxi AI 是一款基於 Qwen2-VL-7B-Instruct 的多模態智能助手,具備文本、圖像和視頻處理能力,特別優化了葡萄牙語支持。
下載量 25
發布時間 : 2/1/2025
模型概述
全能AI助手,能夠處理文本、圖像和視頻的多模態交互,支持函數調用、檢索增強生成(RAG)和系統引導式交互。
模型特點
多模態智能
支持文本、圖像和視頻的多模態交互與理解。
多語言理解
特別優化了葡萄牙語能力,同時支持多種歐洲和亞洲語言。
函數執行能力
支持預定義函數的調用與執行,優化了葡萄牙語函數調用。
高級RAG技術
檢索增強生成技術,優化了葡萄牙語內容檢索與整合。
自然友好的交互體驗
提供角色化應答和增強的上下文理解能力。
模型能力
文本生成與理解
圖像分析與解讀
視頻理解
函數調用
檢索增強生成(RAG)
系統引導式交互
使用案例
多模態交互
圖像描述
根據輸入的圖像生成詳細的描述文本。
生成準確且詳細的圖像描述。
視頻內容分析
分析視頻內容並生成描述或摘要。
生成視頻內容的詳細描述或摘要。
函數調用
聯繫人創建
根據用戶輸入創建聯繫人記錄。
生成結構化聯繫人信息並調用相關函數。
檢索增強生成
信息查詢
根據提供的文檔上下文回答用戶問題。
生成基於文檔的準確回答。
🚀 Fluxi AI - 小型視覺模型 🤖✨
Fluxi AI - 小型視覺模型是一款多功能的人工智能助手,能夠處理文本、圖像和視頻等多模態交互。它支持函數調用、增強檢索生成(RAG)和系統引導交互,尤其在葡萄牙語方面進行了優化,具有自然友好的交互體驗。
🚀 快速開始
安裝依賴
Qwen2-VL 的代碼可在最新版本的 Hugging Face Transformers 中獲取,建議使用以下命令從源代碼進行構建:
pip install git+https://github.com/huggingface/transformers
否則,可能會遇到以下錯誤:
KeyError: 'qwen2_vl'
我們還提供了一套工具,可更方便地處理各種視覺輸入,包括 base64、URL 以及交錯的圖像和視頻。可以使用以下命令進行安裝:
pip install qwen-vl-utils
代碼示例
以下是使用 transformers
和 qwen_vl_utils
調用聊天模型的代碼示例:
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
from qwen_vl_utils import process_vision_info
# 加載模型到可用設備
model = Qwen2VLForConditionalGeneration.from_pretrained(
"JJhooww/Fluxi_AI_Small_Vision", torch_dtype="auto", device_map="auto"
)
# 建議啟用 flash_attention_2 以獲得更好的加速和內存節省,特別是在處理多圖像和視頻的場景中。
# model = Qwen2VLForConditionalGeneration.from_pretrained(
# "JJhooww/Fluxi_AI_Small_Vision",
# torch_dtype=torch.bfloat16,
# attn_implementation="flash_attention_2",
# device_map="auto",
# )
# 默認處理器
processor = AutoProcessor.from_pretrained("JJhooww/Fluxi_AI_Small_Vision")
# 模型中每個圖像的視覺令牌數量的默認範圍是 4 - 16384。您可以根據需要配置 min_pixels 和 max_pixels,例如將令牌計數範圍設置為 256 - 1280,以平衡速度和內存使用。
# min_pixels = 256*28*28
# max_pixels = 1280*28*28
# processor = AutoProcessor.from_pretrained("JJhooww/Fluxi_AI_Small_Vision", min_pixels=min_pixels, max_pixels=max_pixels)
messages = [
{
"role": "user",
"content": [
{
"type": "image",
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
},
{"type": "text", "text": "描述這張圖片。"},
],
}
]
# 推理準備
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# 推理:生成輸出
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
不使用 qwen_vl_utils
from PIL import Image
import requests
import torch
from torchvision import io
from typing import Dict
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessor
# 以降低精度加載模型到可用設備
model = Qwen2VLForConditionalGeneration.from_pretrained(
"JJhooww/Fluxi_AI_Small_Vision", torch_dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained("JJhooww/Fluxi_AI_Small_Vision")
# 圖像
url = "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg"
image = Image.open(requests.get(url, stream=True).raw)
conversation = [
{
"role": "user",
"content": [
{
"type": "image",
},
{"type": "text", "text": "描述這張圖片。"},
],
}
]
# 輸入預處理
text_prompt = processor.apply_chat_template(conversation, add_generation_prompt=True)
# 預期輸出: '<|im_start|>system\n您是一個有用的助手。<|im_end|>\n<|im_start|>user\n<|vision_start|><|image_pad|><|vision_end|>描述這張圖片。<|im_end|>\n<|im_start|>assistant\n'
inputs = processor(
text=[text_prompt], images=[image], padding=True, return_tensors="pt"
)
inputs = inputs.to("cuda")
# 推理:生成輸出
output_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids = [
output_ids[len(input_ids) :]
for input_ids, output_ids in zip(inputs.input_ids, output_ids)
]
output_text = processor.batch_decode(
generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
)
print(output_text)
多圖像推理
# 包含多張圖像和文本查詢的消息
messages = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/image1.jpg"},
{"type": "image", "image": "file:///path/to/image2.jpg"},
{"type": "text", "text": "找出這些圖像中的相似之處。"},
],
}
]
# 推理準備
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# 推理
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
視頻推理
# 包含圖像列表作為視頻和文本查詢的消息
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": [
"file:///path/to/frame1.jpg",
"file:///path/to/frame2.jpg",
"file:///path/to/frame3.jpg",
"file:///path/to/frame4.jpg",
],
"fps": 1.0,
},
{"type": "text", "text": "描述這個視頻。"},
],
}
]
# 包含視頻和文本查詢的消息
messages = [
{
"role": "user",
"content": [
{
"type": "video",
"video": "file:///path/to/video1.mp4",
"max_pixels": 360 * 420,
"fps": 1.0,
},
{"type": "text", "text": "描述這個視頻。"},
],
}
]
# 推理準備
text = processor.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=[text],
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# 推理
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_text = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_text)
批量推理
# 批量推理的示例消息
messages1 = [
{
"role": "user",
"content": [
{"type": "image", "image": "file:///path/to/image1.jpg"},
{"type": "image", "image": "file:///path/to/image2.jpg"},
{"type": "text", "text": "這些圖像中的共同元素有哪些?"},
],
}
]
messages2 = [
{"role": "system", "content": "您是一個有用的助手。"},
{"role": "user", "content": "你是誰?"}
]
# 組合消息進行批量處理
messages = [messages1, messages1]
# 批量推理準備
texts = [
processor.apply_chat_template(msg, tokenize=False, add_generation_prompt=True)
for msg in messages
]
image_inputs, video_inputs = process_vision_info(messages)
inputs = processor(
text=texts,
images=image_inputs,
videos=video_inputs,
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
# 批量推理
generated_ids = model.generate(**inputs, max_new_tokens=128)
generated_ids_trimmed = [
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
]
output_texts = processor.batch_decode(
generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
)
print(output_texts)
✨ 主要特性
- 多模態智能:具備處理文本、圖像和視頻等多模態信息的能力。
- 多語言理解:支持多種語言,尤其在葡萄牙語上有優化表現。
- 函數執行能力:能夠執行預定義的函數,處理結構化的輸入輸出。
- 高級 RAG 功能:結合文檔上下文,提供更準確的回答。
- 自然友好交互:提供自然流暢的交互體驗。
📦 安裝指南
安裝 Transformers
pip install git+https://github.com/huggingface/transformers
安裝工具包
pip install qwen-vl-utils
💻 使用示例
基礎用法
函數調用示例
# 函數調用數據集結構
messages = [
{
"role": "system",
"content": [{
"type": "text",
"text": """# 工具
您可以調用一個或多個函數來輔助用戶查詢。
您會在 XML 標籤 <tools></tools> 中收到函數簽名:
<tools>
{
"type": "function",
"function": {
"name": "criar_contato",
"description": "創建一個新聯繫人",
"parameters": {
"type": "object",
"properties": {
"nome": {"type": "string", "description": "聯繫人的姓名"},
"email": {"type": "string", "description": "聯繫人的電子郵件地址"}
},
"required": ["nome", "email"]
}
}
}
</tools>"""
}]
},
{
"role": "user",
"content": [{
"type": "text",
"text": "我需要為我的朋友 John Doe 創建一個新聯繫人。他的電子郵件是 johndoe@example.com。"
}]
}
]
# 助手響應
response = {
"role": "assistant",
"content": [{
"type": "text",
"text": "<tool_call>\n{'name': 'criar_contato', 'arguments': {'nome': 'John Doe', 'email': 'johndoe@example.com'}}</tool_call>"
}]
}
RAG 實現示例
# RAG 數據集結構
messages = [
{
"role": "user",
"content": [{
"type": "text",
"text": "訪問巴西的外國遊客主要來自哪些國家?"
}]
},
{
"role": "system",
"content": [{
"type": "text",
"text": "{'doc04': {'text': '巴西接待了超過 600 萬外國遊客,主要來自阿根廷、美國、巴拉圭、智利、烏拉圭和法國...'}}"
}]
}
]
# 助手響應
response = {
"role": "assistant",
"content": [{
"type": "text",
"text": "訪問巴西的外國遊客主要來自以下國家:\n\n- 阿根廷\n- 美國\n- 巴拉圭\n- 智利\n- 烏拉圭\n- 法國"
}]
}
系統引導代理示例
# 系統引導代理配置
messages = [
{
"role": "system",
"content": [{
"type": "text",
"text": "您是多個科學學科的專家,包括物理、化學和生物學。請以引人入勝且易懂的方式解釋科學概念、理論和現象。"
}]
},
{
"role": "user",
"content": [{
"type": "text",
"text": "你能幫我寫一篇關於森林砍伐的文章嗎?"
}]
}
]
📚 詳細文檔
模型概述
該 AI 助手基於 Qwen2-VL-7B-Instruct 模型構建,這是由 Qwen 開發的強大多模態語言模型。主要特點包括:
- 70 億參數:提供更強大的語言處理能力。
- 先進的視覺和語言架構:支持多模態信息處理。
- 多圖像分辨率支持:適應不同的圖像輸入。
- 視頻處理能力:能夠理解視頻內容。
- 多模態任務優化:針對多模態任務進行了專門優化。
主要功能
多模態處理
- 文本生成與理解:能夠生成和理解自然語言文本。
- 圖像分析與理解:對圖像進行分析和解讀。
- 視頻理解:支持長達 20 分鐘以上的視頻理解。
- 多種輸入格式支持:包括本地文件、Base64 圖像、URL 以及圖像和視頻的組合。
多語言支持
模型能夠理解和處理多種語言,包括:
- 葡萄牙語(優化支持)
- 英語
- 西班牙語、法語、德語等歐洲語言
- 日語和韓語
- 阿拉伯語和越南語
主要特性
函數調用
- 執行預定義函數:具備執行預定義函數的能力。
- 結構化輸入輸出處理:處理結構化的輸入輸出。
- 複雜參數支持:支持複雜的函數參數。
- 葡萄牙語優化:針對葡萄牙語使用場景進行了優化。
增強檢索生成(RAG)
- 文檔上下文整合:結合文檔上下文提供更準確的回答。
- 相關信息提取:提取相關的信息。
- 上下文自適應回答:根據上下文生成合適的回答。
- 葡萄牙語優化:針對葡萄牙語內容進行了優化。
系統引導交互
- 基於角色和功能的回答:根據角色和功能生成回答。
- 領域知識適應:適應不同的領域知識。
- 增強的上下文理解:更好地理解上下文信息。
- 葡萄牙語代理優化:針對葡萄牙語代理進行了優化。
葡萄牙語優化
函數調用
- 葡萄牙語函數名稱和描述:函數名稱和描述使用葡萄牙語。
- 巴西命名約定:遵循巴西的參數命名約定。
- 本地化錯誤消息和響應:提供本地化的錯誤消息和響應。
- 基於巴西用例的函數選擇:根據巴西的用例選擇合適的函數。
增強 RAG
- 葡萄牙語內容檢索優化:優化葡萄牙語內容的檢索。
- 巴西上下文優先:優先考慮巴西的上下文信息。
- 本地信息提取精度提高:提高本地信息提取的精度。
- 語言模式識別改進:改進對葡萄牙語語言模式的識別。
代理特定增強
- 增強的巴西文化背景:融入更多的巴西文化背景信息。
- 區域知識整合:整合區域知識。
- 葡萄牙語細微差別理解提升:更好地理解葡萄牙語的細微差別。
- 巴西特定領域優化:針對巴西特定領域進行優化。
模型侷限性
- 不支持音頻:目前模型不支持音頻輸入和處理。
- 數據截止日期:數據庫信息截止到 2023 年 6 月。
- 個體和品牌識別受限:對個體和品牌的識別能力有限。
- 多步驟複雜任務性能下降:在處理多步驟複雜任務時性能可能會下降。
- 物體精確計數困難:難以精確計數物體。
- 3D 空間推理有限:3D 空間推理能力有限。
🔧 技術細節
本模型基於 Qwen2-VL-7B-Instruct 構建,該模型具有先進的多模態處理架構,能夠有效地處理文本、圖像和視頻信息。通過優化的訓練算法和大量的多模態數據訓練,模型在多語言理解和多模態交互方面表現出色。在葡萄牙語優化方面,採用了特定的語言處理技術和數據增強方法,提高了模型在葡萄牙語環境下的性能。
📄 許可證
本項目採用 Apache-2.0 許可證。
📚 引用
基礎模型引用
@article{Qwen2VL,
title={Qwen2-VL: Enhancing Vision-Language Model's Perception of the World at Any Resolution},
author={Wang, Peng and Bai, Shuai and Tan, Sinan and Wang, Shijie and Fan, Zhihao and Bai, Jinze and Chen, Keqin and Liu, Xuejing and Wang, Jialin and Ge, Wenbin and Fan, Yang and Dang, Kai and Du, Mengfei and Ren, Xuancheng and Men, Rui and Liu, Dayiheng and Zhou, Chang and Zhou, Jingren and Lin, Junyang},
journal={arXiv preprint arXiv:2409.12191},
year={2024}
}
@article{Qwen-VL,
title={Qwen-VL: A Versatile Vision-Language Model for Understanding, Localization, Text Reading, and Beyond},
author={Bai, Jinze and Bai, Shuai and Yang, Shusheng and Wang, Shijie and Tan, Sinan and Wang, Peng and Lin, Junyang and Zhou, Chang and Zhou, Jingren},
journal={arXiv preprint arXiv:2308.12966},
year={2023}
}
📋 信息表格
屬性 | 詳情 |
---|---|
模型類型 | Fluxi AI - 小型視覺模型 |
訓練數據 | JJhooww/system_chat_portuguese、JJhooww/rag_agente、JJhooww/chamada_de_funcao、JJhooww/open_perfect_ptbr_sharegpt_multiturn |
基礎模型 | Qwen/Qwen2-VL-7B-Instruct |
許可證 | Apache-2.0 |
Clip Vit Large Patch14
CLIP是由OpenAI開發的視覺-語言模型,通過對比學習將圖像和文本映射到共享的嵌入空間,支持零樣本圖像分類
圖像生成文本
C
openai
44.7M
1,710
Clip Vit Base Patch32
CLIP是由OpenAI開發的多模態模型,能夠理解圖像和文本之間的關係,支持零樣本圖像分類任務。
圖像生成文本
C
openai
14.0M
666
Siglip So400m Patch14 384
Apache-2.0
SigLIP是基於WebLi數據集預訓練的視覺語言模型,採用改進的sigmoid損失函數,優化了圖像-文本匹配任務。
圖像生成文本
Transformers

S
google
6.1M
526
Clip Vit Base Patch16
CLIP是由OpenAI開發的多模態模型,通過對比學習將圖像和文本映射到共享的嵌入空間,實現零樣本圖像分類能力。
圖像生成文本
C
openai
4.6M
119
Blip Image Captioning Base
Bsd-3-clause
BLIP是一個先進的視覺-語言預訓練模型,擅長圖像描述生成任務,支持條件式和非條件式文本生成。
圖像生成文本
Transformers

B
Salesforce
2.8M
688
Blip Image Captioning Large
Bsd-3-clause
BLIP是一個統一的視覺-語言預訓練框架,擅長圖像描述生成任務,支持條件式和無條件式圖像描述生成。
圖像生成文本
Transformers

B
Salesforce
2.5M
1,312
Openvla 7b
MIT
OpenVLA 7B是一個基於Open X-Embodiment數據集訓練的開源視覺-語言-動作模型,能夠根據語言指令和攝像頭圖像生成機器人動作。
圖像生成文本
Transformers 英語

O
openvla
1.7M
108
Llava V1.5 7b
LLaVA 是一款開源多模態聊天機器人,基於 LLaMA/Vicuna 微調,支持圖文交互。
圖像生成文本
Transformers

L
liuhaotian
1.4M
448
Vit Gpt2 Image Captioning
Apache-2.0
這是一個基於ViT和GPT2架構的圖像描述生成模型,能夠為輸入圖像生成自然語言描述。
圖像生成文本
Transformers

V
nlpconnect
939.88k
887
Blip2 Opt 2.7b
MIT
BLIP-2是一個視覺語言模型,結合了圖像編碼器和大型語言模型,用於圖像到文本的生成任務。
圖像生成文本
Transformers 英語

B
Salesforce
867.78k
359
精選推薦AI模型
Llama 3 Typhoon V1.5x 8b Instruct
專為泰語設計的80億參數指令模型,性能媲美GPT-3.5-turbo,優化了應用場景、檢索增強生成、受限生成和推理任務
大型語言模型
Transformers 支持多種語言

L
scb10x
3,269
16
Cadet Tiny
Openrail
Cadet-Tiny是一個基於SODA數據集訓練的超小型對話模型,專為邊緣設備推理設計,體積僅為Cosmo-3B模型的2%左右。
對話系統
Transformers 英語

C
ToddGoldfarb
2,691
6
Roberta Base Chinese Extractive Qa
基於RoBERTa架構的中文抽取式問答模型,適用於從給定文本中提取答案的任務。
問答系統 中文
R
uer
2,694
98