0% read

如何用 Gemma 4 分析圖片(多模態指南)

Apr 7, 2026

大多數 Gemma 4 教學只展示如何將它用於文字。但重點是——多模態是 Gemma 4 相對於之前版本最大的升級。每個 Gemma 4 模型都能理解圖片,較小的 E2B/E4B 模型甚至能處理音訊。如果你沒有在傳送圖片給 Gemma 4,你只用了一半的模型。

讓我們修正這個。

Gemma 4 能「看到」什麼?

Gemma 4 的視覺能力涵蓋很多領域:

  • 照片 — 描述場景、識別物件、讀取標誌
  • 截圖 — 提取文字、分析 UI 佈局
  • 圖表和圖形 — 解釋資料視覺化
  • 文件 — 讀取印刷或掃描文字(OCR)
  • 手寫 — 讀取手寫筆記(品質取決於可讀性)
  • 影片影格 — 分析影片中的個別影格
  • 示意圖 — 理解流程圖、架構圖、線框圖
  • 程式碼截圖 — 從圖片中讀取並解釋程式碼

要理解的一件重要的事:Gemma 4 做的是圖片理解,不是圖片生成。它可以看一張圖片並告訴你裡面有什麼,但它不能創造圖片。如果你想要圖片生成,那是完全不同的模型(像 Imagen)。

透過 Ollama CLI 傳送圖片

如果你有 Ollama 在本機執行,傳送圖片超級簡單:

ollama run gemma4 "Describe this image in detail" --image /path/to/photo.jpg

多張圖片也行:

ollama run gemma4 "Compare these two screenshots" --image before.png --image after.png

就這樣。一個旗標。Ollama 在背後處理編碼和其他一切。

透過 API 傳送圖片(Python)

要以程式方式使用,你需要將圖片 base64 編碼並包含在 API 呼叫中。以下是用 Ollama 本機 API 的做法:

import requests
import base64

# 讀取並編碼圖片
with open("screenshot.png", "rb") as f:
    image_data = base64.b64encode(f.read()).decode("utf-8")

response = requests.post("http://localhost:11434/api/generate", json={
    "model": "gemma4",
    "prompt": "What text is visible in this screenshot?",
    "images": [image_data],
    "stream": False
})

print(response.json()["response"])

搭配圖片使用 Chat API

用於關於圖片的多輪對話:

import requests
import base64

with open("chart.png", "rb") as f:
    image_data = base64.b64encode(f.read()).decode("utf-8")

response = requests.post("http://localhost:11434/api/chat", json={
    "model": "gemma4",
    "messages": [
        {
            "role": "user",
            "content": "What trends do you see in this chart?",
            "images": [image_data]
        }
    ],
    "stream": False
})

print(response.json()["message"]["content"])

使用 Google AI Studio SDK

import google.generativeai as genai
from pathlib import Path

genai.configure(api_key="YOUR_API_KEY")
model = genai.GenerativeModel("gemma-4-27b-it")

image = genai.upload_file(Path("diagram.png"))
response = model.generate_content([
    "Explain this architecture diagram. What are the main components and how do they connect?",
    image
])

print(response.text)

更多 API 選項,查看我們的完整 API 教學

5 個實用使用場景(含範例提示詞)

1. OCR:從截圖提取文字

Extract all visible text from this screenshot. Format it as plain text, preserving the layout as much as possible.

這對 App 截圖、網頁、收據和名片效果出奇地好。它對非常小的文字或不尋常的字型不完美,但對大多數使用場景能完成任務。

2. 圖表與資料分析

Analyze this chart. What type of chart is it? What are the key data points? What trends or patterns do you notice? Summarize the main takeaway in one sentence.

Gemma 4 可以讀取長條圖、折線圖、圓餅圖和散佈圖。它會識別軸、標籤和大約值。很適合快速理解資料視覺化而不用挖原始資料。

3. UI 設計審查

Review this UI screenshot as a UX designer. Identify: 1) Visual hierarchy issues, 2) Accessibility concerns (contrast, text size), 3) Layout inconsistencies, 4) Suggestions for improvement. Be specific and reference exact elements.

這是個真正有用的工作流程。丟進你 App 的截圖就能得到快速的設計評論。它會抓到像是對比度差、間距不一致和不明確的 CTA 等問題。

4. 照片描述(無障礙)

Write a detailed alt-text description for this image suitable for screen readers. Include: the main subject, setting, colors, mood, and any text visible. Keep it under 150 words.

適合為網站生成 alt 文字。它不能替代關鍵內容的手寫描述,但適合批量處理。

5. 手寫筆記轉寫

Transcribe the handwritten text in this image. If any words are unclear, indicate them with [unclear]. Preserve the original structure (bullet points, numbered lists, etc.).

品質嚴重取決於手寫。乾淨的印刷風格字跡效果不錯。凌亂的草寫?難說。但即使不完美的轉寫也比重新打字快。

哪些模型支援什麼?

功能E2BE4B26B31B
文字輸入
圖片輸入
音訊輸入
影片影格
圖片生成

要注意的關鍵事項:

  • 所有模型都支援圖片輸入。 即使最小的 E2B 也能分析圖片。
  • 音訊輸入僅限 E2B/E4B。 較大的模型不原生支援音訊。
  • 無圖片生成。 Gemma 4 是理解模型,不是生成圖片的模型。
  • 影片 = 影格。 你傳送個別影格,不是影片檔。先提取關鍵影格再以圖片方式傳送。

更好的圖片分析技巧

在你的提示詞中要具體。 「描述這張圖片」給你通用輸出。「列出貨架上每個可見的產品及大約價格」給你有用的資料。

圖片品質很重要。 模糊的照片給模糊的答案。傳送前裁剪到相關區域——雜訊越少結果越好。

使用合適的模型大小。 對簡單 OCR,E2B 就夠了。對複雜的場景理解或細微分析,26B 或 31B 模型明顯更好。

多張圖片可行。 你可以傳送 2-3 張圖片並要求比較、差異或組合分析。但別太瘋狂——更多圖片意味著更多處理時間和記憶體使用。

限制

  • 無圖片生成。 無法繪製、創造或編輯圖片。
  • 會有幻覺。 Gemma 4 可能「讀到」不存在的文字或誤認物件。一律驗證關鍵資訊。
  • 小文字很難。 如果你幾乎讀不到,Gemma 4 大概也讀不到。放大並裁剪。
  • 複雜示意圖。 有很多重疊元素的超密集技術圖可能讓模型困惑。如有需要就拆成部分。

下一步

gemma4 — interact

Stop reading. Start building.

~/gemma4 $ Get hands-on with the models discussed in this guide. No deployment, no friction, 100% free playground.

Launch Playground />
Gemma 4 AI

Gemma 4 AI

Related Guides

如何用 Gemma 4 分析圖片(多模態指南) | 部落格