如何提升網(wǎng)站訪問速度文章推廣平臺
文章目錄
- 一、模型介紹
- 二、預(yù)期用途
- 1. 視覺問答(VQA)與視覺推理
- 2. 文檔視覺問答(DocVQA)
- 3. 圖像字幕
- 4. 圖像-文本檢索
- 5. 視覺接地
- 三、本地部署
- 1. 下載模型
- 2. 模型大小
- 3. 運行代碼
- 四、ollama部署
- 1. 安裝ollama
- 2. 安裝 Llama 3.2 Vision 模型
- 3. 運行 Llama 3.2-Vision
- 五、效果展示
一、模型介紹
Llama 3.2-Vision 是一系列多模態(tài)大語言模型(LLM),包括預(yù)訓(xùn)練和指令調(diào)優(yōu)的圖像推理生成模型大小分別為11B和90B(輸入為文本+圖像/輸出為文本)。Lama 3.2-Vision 指令調(diào)優(yōu)模型針對視覺識別、圖像推理、字幕生成以及回答關(guān)于圖像的一般問題進(jìn)行了優(yōu)化。這些模型在常見的行業(yè)基準(zhǔn)測試中表現(xiàn)優(yōu)于許多可用的開源和閉源多模態(tài)模型,
模型開發(fā)者: Meta
模型架構(gòu): Llama 3.2-Vision 基于 Lama 3.1 文本模型構(gòu)建,后者是一個使用優(yōu)化的Transformer架構(gòu)的自回歸語言模型。調(diào)優(yōu)版本使用有監(jiān)督的微調(diào)(SFT)和基于人類反饋的強化學(xué)習(xí)(RLHF)來與人類對有用性和安全性的偏好保持一致。為了支持圖像識別任務(wù),Llama 3.2-Vision 模型使用了單獨訓(xùn)練的視覺適配器,該適配器與預(yù)訓(xùn)練的 Llama 3.1 語言模型集成。適配器由一系列交叉注意力層組成,將圖像編碼器表示傳遞給核心LLM。
支持的語言:對于純文本任務(wù),官方支持英語、德語、法語、意大利語、葡萄牙語、印地語、西班牙語和泰語。Llama3.2的訓(xùn)練數(shù)據(jù)集包含了比這八種語言更廣泛的語言。注意,對于圖像+文本應(yīng)用,僅支持英語。
開發(fā)者可以在遵守 Llama 3.2 社區(qū)許可證和可接受使用政策的前提下,對 Lama 3.2 模型進(jìn)行其他語言的微調(diào)。開發(fā)者始終應(yīng)確保其部署,包括涉及額外語言的部署,是安全且負(fù)責(zé)任的。
模型發(fā)布日期:2024年9月25日
二、預(yù)期用途
預(yù)期用途案例: Llama 3.2-Vision旨在用于商業(yè)和研究用途。經(jīng)過指令調(diào)優(yōu)的模型適用于視覺識別、圖像推理、字幕添加以及帶有圖像的助手式聊天,而預(yù)訓(xùn)練模型可以適應(yīng)多種圖像推理任務(wù)。此外,由于Llama 3.2-Vision能夠接受圖像和文本作為輸入,因此還可能包括以下用途:
1. 視覺問答(VQA)與視覺推理
想象一臺機(jī)器能夠査看圖片并理解您對其提出的問題。
2. 文檔視覺問答(DocVQA)
想象計算機(jī)能夠理解文檔(如地圖或合同)中的文本和布局,并直接從圖像中回答問題。
3. 圖像字幕
圖像字幕架起了視覺與語言之間的橋梁,提取細(xì)節(jié),理解場景,然后構(gòu)造一兩句講述故事的話。
4. 圖像-文本檢索
圖像-文本檢索就像是為圖像及其描述做媒人。類似于搜索引擎,但這種引擎既理解圖片也理解文字。
5. 視覺接地
視覺接地就像將我們所見與所說連接起來。它關(guān)乎于理解語言如何引用圖像中的特定部分,允許AI模型基于自然語言描述來精確定位對象或區(qū)域。
三、本地部署
1. 下載模型
#模型下載
from modelscope import snapshot_download model_dir = snapshot_download('AI-ModelScope/Llama-3.2-11B-Vision-Instruct-GGUF')
2. 模型大小
3. 運行代碼
在運行代碼前先確保安裝了transformers包
pip install --upgrade transformers
import requests
import torch
from PIL import Image
from transformers import MllamaForConditionalGeneration, AutoProcessor
from modelscope import snapshot_download
model_id = "LLM-Research/Llama-3.2-11B-Vision-Instruct"
model_dir = snapshot_download(model_id, ignore_file_pattern=['*.pth'])model = MllamaForConditionalGeneration.from_pretrained(model_dir,torch_dtype=torch.bfloat16,device_map="auto",
)
processor = AutoProcessor.from_pretrained(model_dir)url = "https://www.modelscope.cn/models/LLM-Research/Llama-3.2-11B-Vision/resolve/master/rabbit.jpg"
image = Image.open(requests.get(url, stream=True).raw)messages = [{"role": "user", "content": [{"type": "image"},{"type": "text", "text": "If I had to write a haiku for this one, it would be: "}]}
]
input_text = processor.apply_chat_template(messages, add_generation_prompt=True)
inputs = processor(image, input_text, return_tensors="pt").to(model.device)output = model.generate(**inputs, max_new_tokens=30)
print(processor.decode(output[0]))
四、ollama部署
ollama部署模型最為方便,不需要寫運行代碼,也不需要安裝各種庫,ollama安裝好后,run相應(yīng)模型,它會自動下載,然后直接可以進(jìn)行提問,不需要運行什么代碼。
1. 安裝ollama
#o11ama版本需大于等于0.4.0
curl -fsSL https://ollama.com/install.sh | sh
#查看o1lama版本
ollama --version
2. 安裝 Llama 3.2 Vision 模型
o1lama run 1lama3.2-vision:1lb
3. 運行 Llama 3.2-Vision
將 images.png替換為自己的圖像路徑。模型將分析圖像并根據(jù)其理解提供響應(yīng)。
ollama run x/llama3.2-vision:latest "which era does this piece belong to? Give details about the era: images.png
五、效果展示
給大模型一張圖片,然后附帶問題是:這件作品屬于哪個時代?詳細(xì)介紹那個時代。下面是模型輸出
The piece is a painting of a woman in a red dress, surrounded by gold and white ornate details.The woman is depicted in mid-air, with her arms outstretched and her legs bent at the knees. Sheis holding a bouquet of flowers in her right hand and a fruit in her left hand.
The background of the painting is a light blue sky with pink clouds, and there are also some pinkflowers and green leaves surrounding the woman. The overall atmosphere of the painting is oneof joy and celebration, as if the woman is dancing or celebrating something.
This piece belongs to the Rococo era, which was a style of art and architecture that emerged inEurope in the 18th century. The Rococo style is characterized by its use of pastel colors, curvedlines, and ornate details. lt was popularized during the reign of King Louis XV of France, who ruledfrom 1715 to 1774.
為更直觀翻譯下,可以看到基本把圖片細(xì)節(jié)都描述很清楚,同事也給出了大致時代。