圖片微調

本頁面提供先決條件和詳細操作說明,協助您使用監督式學習,根據圖片資料微調 Gemini 模型。

用途

微調功能可讓您調整基礎 Gemini 模型,用於執行專業工作。 以下是幾個圖像用途:

  • 強化產品目錄:從圖片擷取主要屬性 (例如品牌、顏色、尺寸),自動建立及豐富產品目錄。
  • 圖片審核:微調模型,偵測並標記圖片中的不當或有害內容,確保上網體驗安全無虞。
  • 目視檢查:訓練模型,在圖片中找出特定物件或瑕疵,自動執行品管或檢查程序。
  • 圖片分類:提高特定領域的圖片分類準確率,例如醫學影像或衛星圖像分析。
  • 圖片推薦:分析圖片,提供個人化推薦內容,例如類似產品或互補商品。
  • 表格內容擷取:從圖片中的表格擷取資料,並轉換為試算表或資料庫等結構化格式。

限制

  • 每個範例的圖片數量上限:30 張
  • 圖片檔案大小上限:20 MB

如要進一步瞭解圖片樣本規定,請參閱「圖像解讀」頁面。

資料集格式

資料集的 fileUri 可以是 Cloud Storage 值區中檔案的 URI,也可以是公開的 HTTP 或 HTTPS 網址。

GenerationConfig 物件的 mediaResolution 欄位可用來控制媒體檔案品質與代表媒體的權杖數量之間的取捨。解析度越高,模型就能感知更多細節,進而產生更細緻的調整模型行為,但也會使用更多權杖。這不會影響傳送至模型的圖片尺寸。如未指定,預設解析度為 MEDIA_RESOLUTION_HIGH

mediaResolution 適用於 Gemini 3 以下版本

以下是 Gemini 3 以上版本支援的 mediaResolution 值,可用於微調圖片資料:

  • MEDIA_RESOLUTION_LOW:64 個權杖
  • MEDIA_RESOLUTION_MEDIUM:256 個權杖
  • MEDIA_RESOLUTION_HIGH:256 個權杖 + (256 個權杖 * 掃描和平移圖片數量)

如要查看一般格式範例,請參閱「Gemini 的資料集範例」。

以下是圖片資料集的範例:

{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "fileData": {
            "mimeType": "image/jpeg",
            "fileUri": "gs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/image/longcap100/100.jpeg"
            }
        },
        {
          "text": "Describe this image in detail that captures the essence of it."
        }
      ]
    },
    {
      "role": "model",
      "parts": [
        {
          "text": "A man stands on a road, wearing a blue denim jacket, tan pants, and white sneakers. He has his hands in his pockets and is wearing a white t-shirt under his jacket. The man's pants are cuffed, and his shoes are white. The road is dark grey, and the leaves are green. The man is standing in the shade, and the light is shining on the ground."
        }
      ]
    }
  ],
  "generationConfig": {
    "mediaResolution": "MEDIA_RESOLUTION_LOW"
  }
}

mediaResolution (適用於 Gemini 3 以上版本)

如果是 Gemini 3 以上的機型,您也可以為個別媒體設定媒體解析度Part。這樣一來,您就能在資料集中混合使用不同解析度 (例如,為一個項目設定 MEDIA_RESOLUTION_HIGH,為另一個項目設定 MEDIA_RESOLUTION_LOW)。如要進一步瞭解部分層級的解析度及其對應的權杖計數,請參閱「媒體解析度」。

Part 層級的媒體解析度設定優先於全域設定。

以下範例資料集會在 Part 和全域層級設定媒體解析度:

{
  "contents": [
    {
      "role": "user",
      "parts": [
        {
          "fileData": {
            "mimeType": "image/jpeg",
            "fileUri": "gs://image.jpeg"
          }
        },
        {
          "fileData": {
            "mimeType": "image/jpeg",
            "fileUri": "gs://ultra_high_res_image.jpeg"
          },
          "mediaResolution": {
            "level": "MEDIA_RESOLUTION_HIGH"
          }
        },
        {
          "text": "Describe these images in detail."
        }
      ]
    },
    {
      "role": "model",
      "parts": [
        {
          "text": "Image 1 is low resolution while image 2 is sharp and clear"
        }
      ]
    }
  ],
  "generationConfig": {
    "mediaResolution": "MEDIA_RESOLUTION_LOW"
  }
}

範例資料集

您可以使用下列範例資料集,瞭解如何調整 Gemini 模型。如要使用這些資料集,請在建立文字模型監督式微調工作時,於適用的參數中指定 URI。

如要使用範例調整用資料集,請指定其位置,如下所示:

"training_dataset_uri": "gs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/image/sft_train_data.jsonl",

如要使用範例驗證資料集,請依下列方式指定其位置:

"validation_dataset_uri": "gs://cloud-samples-data/ai-platform/generative_ai/gemini-2_0/image/sft_validation_data.jsonl",

後續步驟