Questa pagina mostra come ottenere previsioni collettive dai modelli di classificazione dei video utilizzando la console Google Cloud o l'API Vertex AI. Le previsioni batch sono richieste asincrone. Le previsioni batch vengono richieste direttamente dal modello senza dover eseguire il deployment del modello su un endpoint.
I modelli video AutoML non supportano le previsioni online.
Generazione di previsioni batch
Per effettuare una richiesta di previsione batch, specifica un'origine di input e un formato di output in cui Vertex AI memorizza i risultati delle previsioni.
Requisiti dei dati di input
L'input per le richieste batch specifica gli elementi da inviare al modello per
la previsione. Le previsioni batch per il tipo di modello video AutoML utilizzano un
file JSON Lines per specificare un elenco di video per i quali fare previsioni, quindi
lo archiviano in un bucket Cloud Storage. Puoi specificare
Infinity
per il campo timeSegmentEnd
per specificare la fine del video. La
l'esempio seguente mostra una singola riga in un file JSON Lines di input.
{'content': 'gs://sourcebucket/datasets/videos/source_video.mp4', 'mimeType': 'video/mp4', 'timeSegmentStart': '0.0s', 'timeSegmentEnd': '2.366667s'}
Richiedi una previsione batch
Per le richieste di previsione batch, puoi utilizzare la console Google Cloud l'API Vertex AI. In base al numero di input che hai inviato, viene visualizzata una l'attività di previsione batch può richiedere del tempo.
Console Google Cloud
Utilizza la console Google Cloud per richiedere una previsione batch.
Nella console Google Cloud, nella sezione Vertex AI, vai a alla pagina Previsioni batch.
Fai clic su Crea per aprire la finestra Nuova previsione batch e completare segui questi passaggi:
- Inserisci un nome per la previsione batch.
- In Nome modello, seleziona il nome del modello da utilizzare per questa previsione batch.
- In Percorso di origine, specifica la posizione di Cloud Storage in cui in cui si trova il file di input di linee JSON.
- Per Percorso di destinazione, specifica una posizione di Cloud Storage in cui sono archiviati i risultati della previsione batch. Il formato Output è determinato dall'obiettivo del modello. Modelli AutoML per le immagini di output JSON Lines.
API
Utilizzare l'API Vertex AI per inviare richieste di previsione batch.
REST
Prima di utilizzare i dati della richiesta, effettua le seguenti sostituzioni:
- LOCATION_ID: regione in cui è archiviato il modello e viene eseguito il job di previsione batch. Per
ad esempio
us-central1
. - PROJECT_ID: il tuo ID progetto
- BATCH_JOB_NAME: nome visualizzato del job batch
- MODEL_ID: l'ID del modello da utilizzare per fare previsioni
- THRESHOLD_VALUE (facoltativo): il modello restituisce solo le previsioni con punteggi di confidenza almeno pari a questo valore
- SEGMENT_CLASSIFICATION (facoltativo): un valore booleano che
determina se richiedere la classificazione a livello di segmento. Vertex AI
restituisce le etichette e i relativi punteggi di affidabilità per l'intero segmento di tempo di
il video specificato nell'istanza di input. L'impostazione predefinita è
true
. - SHOT_CLASSIFICATION (facoltativo): un valore booleano che determina
se richiedere la classificazione a livello di inquadratura. Vertex AI determina i confini di ogni inquadratura della videocamera nell'intero segmento di tempo del video specificato nell'istanza di input. Vertex AI restituisce quindi
etichette e i relativi punteggi di affidabilità per ogni scatto rilevato, insieme al
l'ora di inizio e di fine della scena. Il valore predefinito è
false
. - ONE_SEC_INTERVAL_CLASSIFICATION (facoltativo): un valore booleano che determina se richiedere la classificazione di un video a intervalli di un secondo. Vertex AI restituisce le etichette e i relativi punteggi di affidabilità per
ogni secondo dell'intero segmento temporale del video
specificato nell'istanza di input. Il valore predefinito è
false
. - URI: URI Cloud Storage in cui si trova il file JSON Lines di input individuarlo.
- BUCKET: il tuo bucket Cloud Storage
- PROJECT_NUMBER: il numero di progetto generato automaticamente per il tuo progetto
Metodo HTTP e URL:
POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/batchPredictionJobs
Corpo JSON della richiesta:
{ "displayName": "BATCH_JOB_NAME", "model": "projects/PROJECT_ID/locations/LOCATION_ID/models/MODEL_ID", "modelParameters": { "confidenceThreshold": THRESHOLD_VALUE, "segmentClassification": SEGMENT_CLASSIFICATION, "shotClassification": SHOT_CLASSIFICATION, "oneSecIntervalClassification": ONE_SEC_INTERVAL_CLASSIFICATION }, "inputConfig": { "instancesFormat": "jsonl", "gcsSource": { "uris": ["URI"], }, }, "outputConfig": { "predictionsFormat": "jsonl", "gcsDestination": { "outputUriPrefix": "OUTPUT_BUCKET", }, }, }
Per inviare la richiesta, scegli una delle seguenti opzioni:
curl
Salva il corpo della richiesta in un file denominato request.json
.
ed esegui questo comando:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/batchPredictionJobs"
PowerShell
Salva il corpo della richiesta in un file denominato request.json
.
ed esegui questo comando:
$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_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/batchPredictionJobs" | Select-Object -Expand Content
Dovresti ricevere una risposta JSON simile alla seguente:
{ "name": "projects/PROJECT_NUMBER/locations/us-central1/batchPredictionJobs/BATCH_JOB_ID", "displayName": "BATCH_JOB_NAME", "model": "projects/PROJECT_NUMBER/locations/us-central1/models/MODEL_ID", "inputConfig": { "instancesFormat": "jsonl", "gcsSource": { "uris": [ "CONTENT" ] } }, "outputConfig": { "predictionsFormat": "jsonl", "gcsDestination": { "outputUriPrefix": "BUCKET" } }, "state": "JOB_STATE_PENDING", "createTime": "2020-05-30T02:58:44.341643Z", "updateTime": "2020-05-30T02:58:44.341643Z", "modelDisplayName": "MODEL_NAME", "modelObjective": "MODEL_OBJECTIVE" }
Puoi eseguire il polling dello stato del job batch utilizzando
BATCH_JOB_ID finché il job state
non è
JOB_STATE_SUCCEEDED
.
Java
Prima di provare questo esempio, segui le istruzioni per la configurazione di Java nel Guida rapida di Vertex AI con librerie client. Per ulteriori informazioni, consulta API Java Vertex AI documentazione di riferimento.
Per eseguire l'autenticazione su Vertex AI, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, consulta Configurare l'autenticazione per un ambiente di sviluppo locale.
Node.js
Prima di provare questo esempio, segui le istruzioni per la configurazione di Node.js nel Guida rapida di Vertex AI con librerie client. Per ulteriori informazioni, consulta la documentazione di riferimento dell'API Node.js di Vertex AI.
Per eseguire l'autenticazione su Vertex AI, configura Credenziali predefinite dell'applicazione. Per ulteriori informazioni, vedi Configura l'autenticazione per un ambiente di sviluppo locale.
Python
Per scoprire come installare o aggiornare l'SDK Vertex AI per Python, vedi Installare l'SDK Vertex AI per Python. Per ulteriori informazioni, consulta documentazione di riferimento dell'API Python.
Recuperare i risultati della previsione batch
Vertex AI invia l'output della previsione batch alla destinazione specificata.
Quando un'attività di previsione batch è completata, l'output della previsione è archiviato nel bucket Cloud Storage specificato nella richiesta.
Esempi di risultati della previsione batch
Di seguito è riportato un esempio di previsione batch da una classificazione di video un modello di machine learning.
{ "instance": { "content": "gs://bucket/video.mp4", "mimeType": "video/mp4", "timeSegmentStart": "1s", "timeSegmentEnd": "5s" } "prediction": [{ "id": "1", "displayName": "cat", "type": "segment-classification", "timeSegmentStart": "1s", "timeSegmentEnd": "5s", "confidence": 0.7 }, { "id": "1", "displayName": "cat", "type": "shot-classification", "timeSegmentStart": "1s", "timeSegmentEnd": "4s", "confidence": 0.9 }, { "id": "2", "displayName": "dog", "type": "shot-classification", "timeSegmentStart": "4s", "timeSegmentEnd": "5s", "confidence": 0.6 }, { "id": "1", "displayName": "cat", "type": "one-sec-interval-classification", "timeSegmentStart": "1s", "timeSegmentEnd": "1s", "confidence": 0.95 }, { "id": "1", "displayName": "cat", "type": "one-sec-interval-classification", "timeSegmentStart": "2s", "timeSegmentEnd": "2s", "confidence": 0.9 }, { "id": "1", "displayName": "cat", "type": "one-sec-interval-classification", "timeSegmentStart": "3s", "timeSegmentEnd": "3s", "confidence": 0.85 }, { "id": "2", "displayName": "dog", "type": "one-sec-interval-classification", "timeSegmentStart": "4s", "timeSegmentEnd": "4s", "confidence": 0.6 }] }