用於字幕和圖片問題回答的 Imagen (imagetext
) 是支援圖片問與答的模型名稱。即使模型未曾見過特定圖片,Bilden 為字幕和視覺問題回答工具也能回答與該圖片相關的問題。
如要在控制台中探索這個模型,請前往 Model Garden 查看「為字幕和視覺語音對話提供支援的 Imagen」模型資訊卡。
用途
圖像問答的常見用途包括:
- 讓使用者透過問與答功能與影像內容互動。
- 讓消費者能與零售應用程式和網站上顯示的產品圖片互動。
- 為視障人士提供無障礙選項。
HTTP 要求
POST https://us-central1-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/us-central1/publishers/google/models/imagetext:predict
要求主體
{
"instances": [
{
"prompt": string,
"image": {
// Union field can be only one of the following:
"bytesBase64Encoded": string,
"gcsUri": string,
// End of list of possible types for union field.
"mimeType": string
}
}
],
"parameters": {
"sampleCount": integer,
"seed": integer
}
}
請為視覺問答產生模型 imagetext
使用下列參數。詳情請參閱「使用視覺問答功能」。
參數 | 說明 | 可接受的值 |
---|---|---|
instances |
陣列,其中包含含有提示和圖片詳細資料的物件,可用於取得相關資訊。 | 陣列 (允許 1 個圖片物件) |
prompt |
您想針對圖片獲得的解答。 | 字串 (最多 80 個符記) |
bytesBase64Encoded |
要取得資訊的圖片。 | Base64 編碼的圖片字串 (PNG 或 JPEG,大小上限 20 MB) |
gcsUri |
要取得資訊的圖片 Cloud Storage URI。 | Cloud Storage 中圖片檔案的字串 URI (PNG 或 JPEG,大小上限 20 MB) |
mimeType |
(非必要) 您指定圖片的 MIME 類型。 | 字串 (image/jpeg 或 image/png ) |
sampleCount |
產生的文字字串數量。 | Int 值:1-3 |
seed |
(非必要) 隨機號碼產生器 (RNG) 的種子。如果 RNG 種子與輸入內容的請求相同,預測結果也會相同。 | 整數 |
要求範例
使用任何要求資料之前,請先替換以下項目:
- PROJECT_ID:您的 Google Cloud 專案 ID。
- LOCATION:專案所在的區域。例如
us-central1
、europe-west2
或asia-northeast3
。如需可用區域的清單,請參閱「Vertex AI 生成式 AI 位置」。 - VQA_PROMPT:您想瞭解圖片的相關問題。
- 這雙鞋的顏色是什麼?
- 上衣的袖子類型為何?
- B64_IMAGE:要取得字幕的圖片。圖片必須以 base64 編碼的位元組字串形式指定。大小限制:10 MB。
- RESPONSE_COUNT:您要產生的答案數量。可接受的整數值:1 到 3。
HTTP 方法和網址:
POST https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagetext:predict
JSON 要求主體:
{ "instances": [ { "prompt": "VQA_PROMPT", "image": { "bytesBase64Encoded": "B64_IMAGE" } } ], "parameters": { "sampleCount": RESPONSE_COUNT } }
如要傳送要求,請選擇以下其中一個選項:
curl
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagetext:predict"
PowerShell
將要求主體儲存在名為 request.json
的檔案中,然後執行下列指令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/publishers/google/models/imagetext:predict" | Select-Object -Expand Content
"sampleCount": 2
和 "prompt": "What is this?"
的要求。回應會傳回兩個預測字串答案。{ "predictions": [ "cappuccino", "coffee" ] }
回應主體
{
"predictions": [
string
]
}
回應元素 | 說明 |
---|---|
predictions |
代表 VQA 答案的文字字串清單,依信心程度排序。 |
回應範例
以下回應範例適用於含有 "sampleCount": 2
和 "prompt": "What is this?"
的要求。回應會傳回兩個預測字串答案。
{
"predictions": [
"cappuccino",
"coffee"
],
"deployedModelId": "DEPLOYED_MODEL_ID",
"model": "projects/PROJECT_ID/locations/us-central1/models/MODEL_ID",
"modelDisplayName": "MODEL_DISPLAYNAME",
"modelVersionId": "1"
}