Skip to content
Guides6 min read

使用視覺 AI 加速影像和影片標註

使用 YOLO、Ollama、OpenAI 和 Claude 為影像和影片任務設定 AI 驅動的目標檢測、預標註和分類。

Potato Team

Potato 2.1 引入了視覺 AI 支援,將 AI 驅動的輔助功能直接帶入影像和影片標註工作流。您可以讓 YOLO 自動檢測目標然後稽核其建議,或者讓視覺語言模型對影像進行分類並解釋其推理,而不必從頭標註每個邊界框。

本指南將逐步介紹每個視覺 AI 端點的設定、不同輔助模式的配置,以及如何將視覺 AI 與 Potato 的文本 AI 功能相結合。

您將學到

  • 設定 YOLO 進行快速本地目標檢測
  • 執行 Ollama Vision 模型進行本地影像理解
  • 使用 OpenAI 和 Anthropic 雲視覺 API
  • 配置檢測、預標註、分類和提示模式
  • 在單個項目中結合視覺和文本 AI 端點
  • 稽核 AI 建議的接受/拒絕工作流

前提條件

您需要 Potato 2.1.0 或更高版本:

bash
pip install --upgrade potato-annotation

根據您選擇的端點,還需要以下之一:

  • YOLOpip install ultralytics opencv-python
  • Ollama:從 ollama.ai 安裝並拉取視覺模型
  • OpenAI:具有 GPT-4o 訪問許可權的 API 金鑰
  • Anthropic:具有 Claude 視覺模型訪問許可權的 API 金鑰

選項 1:使用 YOLO 進行目標檢測

當您需要完全在本地機器上執行快速、精確的邊界框檢測時,YOLO 是最佳選擇。它擅長檢測常見目標(人、車、動物、傢俱),可以在毫秒內處理影像。

設定

bash
pip install ultralytics opencv-python

配置

yaml
annotation_task_name: "Object Detection with YOLO"
 
data_files:
  - data/images.json
 
item_properties:
  id_key: id
  text_key: image_url
 
instance_display:
  fields:
    - key: image_url
      type: image
      display_options:
        max_width: 800
        zoomable: true
 
annotation_schemes:
  - annotation_type: image_annotation
    name: objects
    description: "Detect and label objects"
    source_field: "image_url"
    tools:
      - bbox
    labels:
      - name: "person"
        color: "#FF6B6B"
      - name: "car"
        color: "#4ECDC4"
      - name: "dog"
        color: "#45B7D1"
      - name: "cat"
        color: "#96CEB4"
 
    ai_support:
      enabled: true
      features:
        detection: true
        pre_annotate: true
        hint: true
 
ai_support:
  enabled: true
  endpoint_type: "yolo"
  ai_config:
 
output_annotation_dir: "annotation_output/"
user_config:
  allow_all_users: true

資料格式

以 JSONL 格式建立 data/images.json(每行一個 JSON 物件):

json
{"id": "img_001", "image_url": "images/street_scene_1.jpg"}
{"id": "img_002", "image_url": "images/park_photo.jpg"}
{"id": "img_003", "image_url": "https://example.com/images/office.jpg"}

選擇 YOLO 模型

模型大小速度精度最適合
yolov8n.pt6 MB最快較低快速原型
yolov8s.pt22 MB良好均衡工作負載
yolov8m.pt50 MB中等較好通用場景
yolov8l.pt84 MB較慢精度優先
yolov8x.pt131 MB最慢最高最大精度

對於檢測不在 YOLO 內建類別中的目標,使用 YOLO-World 進行開放詞彙檢測:

yaml
ai_config:
  model: "yolo-world"
  confidence_threshold: 0.3

調整檢測

如果 YOLO 遺漏了目標,降低置信度閾值:

yaml
ai_config:
  confidence_threshold: 0.3  # More detections, more false positives

如果誤檢太多,提高閾值:

yaml
ai_config:
  confidence_threshold: 0.7  # Fewer detections, higher precision

選項 2:使用 Ollama Vision 的本地視覺語言模型

Ollama Vision 讓您能夠在本地執行視覺語言模型。與 YOLO 不同,這些模型可以理解影像上下文、分類場景並生成文本解釋 — 所有這些都無需將資料傳送到雲 API。

設定

bash
# Install Ollama
curl -fsSL https://ollama.ai/install.sh | sh
 
# Pull a vision model
ollama pull llava
 
# Or for better performance:
ollama pull qwen2.5-vl:7b

配置

yaml
annotation_task_name: "Image Classification with Ollama Vision"
 
data_files:
  - data/images.json
 
item_properties:
  id_key: id
  text_key: image_url
 
instance_display:
  fields:
    - key: image_url
      type: image
      display_options:
        max_width: 600
        zoomable: true
 
annotation_schemes:
  - annotation_type: radio
    name: scene_type
    description: "What type of scene is shown?"
    labels:
      - indoor
      - outdoor_urban
      - outdoor_nature
      - aerial
      - underwater
 
 
ai_support:
  enabled: true
  endpoint_type: "ollama_vision"
  ai_config:
 
output_annotation_dir: "annotation_output/"
user_config:
  allow_all_users: true

支援的模型

模型參數量優勢
llava:7b7B快速,通用理解良好
llava:13b13B更好的準確性
llava-llama38B強推理能力
bakllava7B視覺細節好
llama3.2-vision:11b11B最新 Llama 視覺模型
qwen2.5-vl:7b7B強多語言 + 視覺
moondream1.8B非常快速,輕量級

選項 3:OpenAI Vision

OpenAI Vision 通過 GPT-4o 提供高品質的影像理解。當您需要最強大的視覺模型且不介意雲 API 成本時最為合適。

配置

yaml
ai_support:
  enabled: true
  endpoint_type: "openai_vision"
  ai_config:
    api_key: "${OPENAI_API_KEY}"
    model: "gpt-4o"
    max_tokens: 1000
    detail: "auto"  # "low" for faster/cheaper, "high" for detail

設定您的 API 金鑰:

bash
export OPENAI_API_KEY="sk-..."

detail 參數控制傳送到 API 的影像解析度:

  • low — 更快、更便宜,適合分類
  • high — 全解析度,更適合查詢小目標
  • auto — 讓 API 自行決定

選項 4:Anthropic Vision

Claude 的視覺能力在理解影像上下文和提供詳細解釋方面表現出色。

配置

yaml
ai_support:
  enabled: true
  endpoint_type: "anthropic_vision"
  ai_config:
    api_key: "${ANTHROPIC_API_KEY}"
    model: "claude-sonnet-4-20250514"
    max_tokens: 1024
bash
export ANTHROPIC_API_KEY="sk-ant-..."

AI 輔助模式

每個視覺 AI 端點支援不同的輔助模式。為每個標註方案僅啟用所需的模式。

檢測模式

查詢與您配置的標籤匹配的目標,並以虛線邊界框疊加層顯示:

yaml
ai_support:
  enabled: true
  features:
    detection: true

標註者點選"檢測"後,AI 建議以虛線疊加層形式出現在影像上。雙擊接受,右擊拒絕。

預標註(自動)模式

自動檢測所有目標並一次性建立建議。最適合引導大型資料集:

yaml
ai_support:
  enabled: true
  features:
    pre_annotate: true

分類模式

對選定區域或整個影像進行分類,返回帶有置信度分數的建議標籤:

yaml
ai_support:
  enabled: true
  features:
    classification: true

提示模式

提供指導文本而不直接給出答案。適合培訓新標註者:

yaml
ai_support:
  enabled: true
  features:
    hint: true

接受/拒絕工作流

當標註者點選 AI 輔助按鈕時,建議以虛線疊加層形式出現:

  1. 接受建議 — 雙擊虛線疊加層將其轉換為真實標註
  2. 拒絕建議 — 右擊疊加層將其消除
  3. 全部接受 — 點選工具欄中的"全部接受"一次性接受所有建議
  4. 全部清除 — 點選"清除"消除所有建議

這使標註者保持控制權,同時減少了從頭繪製邊界框的手動工作。

影片標註中的視覺 AI

視覺 AI 也適用於影片標註任務。您可以啟用場景檢測、關鍵幀檢測和目標跟蹤:

yaml
annotation_schemes:
  - annotation_type: video_annotation
    name: scenes
    description: "Segment this video into scenes"
    mode: segment
    labels:
      - name: "intro"
        color: "#4ECDC4"
      - name: "main_content"
        color: "#FF6B6B"
      - name: "outro"
        color: "#45B7D1"
 
    ai_support:
      enabled: true
      features:
        scene_detection: true
        pre_annotate: true
        hint: true
 
ai_support:
  enabled: true
  endpoint_type: "ollama_vision"
  ai_config:

max_frames 參數控制 AI 從影片中取樣多少幀進行分析。幀數越多意味著準確性越高,但處理速度越慢。

結合視覺和文本 AI 端點

如果您的項目同時包含文本和影像標註,可以為每種類型配置不同的端點。使用文本最佳化的模型處理提示和關鍵詞,使用視覺模型處理檢測:

yaml
ai_support:
  enabled: true
 
  # Text AI for radio buttons, text schemes, etc.
  endpoint_type: "ollama"
  ai_config:
    model: "llama3.2"
    include:
      all: true
 
  # Visual AI for image/video schemes
  visual_endpoint_type: "yolo"
  visual_ai_config:
    model: "yolov8m.pt"
    confidence_threshold: 0.5

或者使用雲視覺模型搭配本地文本模型:

yaml
ai_support:
  enabled: true
  endpoint_type: "ollama"
  visual_endpoint_type: "openai_vision"
  ai_config:
    model: "llama3.2"
  visual_ai_config:
    api_key: "${OPENAI_API_KEY}"
    model: "gpt-4o"

完整示例:產品照片標註

以下是一個生產就緒的配置,用於使用 YOLO 檢測和文本 AI 提示標註產品照片:

yaml
annotation_task_name: "Product Photo Annotation"
 
data_files:
  - data/product_photos.json
 
item_properties:
  id_key: sku
  text_key: photo_url
 
instance_display:
  layout:
    direction: horizontal
    gap: 24px
  fields:
    - key: photo_url
      type: image
      label: "Product Photo"
      display_options:
        max_width: 600
        zoomable: true
    - key: product_description
      type: text
      label: "Product Details"
 
annotation_schemes:
  - annotation_type: image_annotation
    name: product_regions
    description: "Draw boxes around products and defects"
    source_field: "photo_url"
    tools:
      - bbox
    labels:
      - name: "product"
        color: "#4ECDC4"
      - name: "defect"
        color: "#FF6B6B"
      - name: "label"
        color: "#45B7D1"
      - name: "packaging"
        color: "#96CEB4"
 
    ai_support:
      enabled: true
      features:
        detection: true
        pre_annotate: true
 
  - annotation_type: radio
    name: photo_quality
    description: "Is this photo suitable for the product listing?"
    labels:
      - Approved
      - Needs editing
      - Reshoot required
 
  - annotation_type: multiselect
    name: quality_issues
    description: "Select any issues present"
    labels:
      - Blurry
      - Poor lighting
      - Wrong angle
      - Background clutter
      - Color inaccurate
 
ai_support:
  enabled: true
  endpoint_type: "ollama"
  visual_endpoint_type: "yolo"
 
  ai_config:
 
  visual_ai_config:
 
output_annotation_dir: "annotation_output/"
export_annotation_format: "json"
user_config:
  allow_all_users: true

示例資料(data/product_photos.json):

json
{"sku": "SKU-001", "photo_url": "images/products/laptop_front.jpg", "product_description": "15-inch laptop, silver finish"}
{"sku": "SKU-002", "photo_url": "images/products/headphones_side.jpg", "product_description": "Over-ear wireless headphones, black"}
{"sku": "SKU-003", "photo_url": "images/products/backpack_full.jpg", "product_description": "40L hiking backpack, navy blue"}

視覺 AI 標註技巧

  1. 對大型資料集使用預標註 — 使用自動按鈕為所有目標生成建議,然後讓標註者稽核和糾正,而不是從頭繪製
  2. 將端點與任務匹配 — YOLO 用於精確檢測,視覺語言模型用於分類和理解
  3. 調整置信度閾值 — 從 0.5 開始,根據您觀察到的誤檢/漏檢權衡進行調整
  4. 使用提示進行標註者培訓 — 提示模式引導標註者而不會使其偏向特定答案
  5. 組合端點 — 用 YOLO 視覺端點檢測加上 Ollama 文本端點提示,可以兩全其美
  6. 快取 AI 結果 — 啟用磁碟快取以避免對相同影像重複執行檢測

故障排除

"未配置視覺 AI 端點"

確保 ai_support.enabledtrue,並且您設定了支援視覺的 endpoint_typeyoloollama_visionopenai_visionanthropic_vision

YOLO 檢測不到您的目標

YOLO 的內建類別覆蓋 80 種常見目標。如果您的標籤與 YOLO 的類名不匹配,請嘗試使用 YOLO-World 進行開放詞彙檢測,或降低 confidence_threshold

Ollama 返回錯誤

驗證 Ollama 正在執行且您已拉取了視覺模型:

bash
curl http://localhost:11434/api/tags  # Check Ollama is running
ollama list                           # Check installed models

雲 API 響應緩慢

啟用快取,使同一影像不會被分析兩次:

yaml
ai_support:
  cache_config:
    disk_cache:
      enabled: true
      path: "ai_cache/visual_cache.json"

下一步


完整文件請見 視覺 AI 支援