Questo tutorial mostra come utilizzare l'SDK Python per sfocare i volti nei video. L'esempio sfoca i file video di un bucket Cloud Storage e genera output video sfocati. Questi video di output vengono archiviati nello stesso bucket Cloud Storage dei video di origine.
Obiettivi
Questo tutorial mostra come:
- Creare un bucket Cloud Storage.
- Carica un file video locale nel bucket.
- Invia una richiesta utilizzando l'SDK Python.
- Visualizzare i video di output sfocati.
Costi
In questo documento vengono utilizzati i seguenti componenti fatturabili di Google Cloud:
- Vertex AI Vision (Models - Person / face blur)
- Cloud Storage
Per generare una stima dei costi in base all'utilizzo previsto,
utilizza il calcolatore prezzi.
Al termine delle attività descritte in questo documento, puoi evitare l'addebito di ulteriori costi eliminando le risorse che hai creato. Per ulteriori informazioni, vedi Pulizia.
Prima di iniziare
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
Install the Google Cloud CLI.
-
Se utilizzi un provider di identità (IdP) esterno, devi prima accedere alla gcloud CLI con la tua identità federata.
-
Per inizializzare gcloud CLI, esegui questo comando:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI Vision, Cloud Storage APIs:
gcloud services enable visionai.googleapis.com
storage.googleapis.com -
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/visionai.editor, roles/storage.objectAdmin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID
: your project ID.USER_IDENTIFIER
: the identifier for your user account—for example,myemail@example.com
.ROLE
: the IAM role that you grant to your user account.
-
Install the Google Cloud CLI.
-
Se utilizzi un provider di identità (IdP) esterno, devi prima accedere alla gcloud CLI con la tua identità federata.
-
Per inizializzare gcloud CLI, esegui questo comando:
gcloud init
-
Create or select a Google Cloud project.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_ID
with a name for the Google Cloud project you are creating. -
Select the Google Cloud project that you created:
gcloud config set project PROJECT_ID
Replace
PROJECT_ID
with your Google Cloud project name.
-
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI Vision, Cloud Storage APIs:
gcloud services enable visionai.googleapis.com
storage.googleapis.com -
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Grant roles to your user account. Run the following command once for each of the following IAM roles:
roles/visionai.editor, roles/storage.objectAdmin
gcloud projects add-iam-policy-binding PROJECT_ID --member="user:USER_IDENTIFIER" --role=ROLE
Replace the following:
PROJECT_ID
: your project ID.USER_IDENTIFIER
: the identifier for your user account—for example,myemail@example.com
.ROLE
: the IAM role that you grant to your user account.
- Recupera il codice sorgente dell'SDK Vertex AI Vision:
git clone https://github.com/google/visionai.git
Gli esempi Python si trovano nella directory
visionai/python/example/
. - Ottieni l'SDK Python:
wget https://github.com/google/visionai/releases/download/v0.0.5/visionai-0.0.5-py3-none-any.whl
Crea un bucket Cloud Storage:
gcloud storage buckets create gs://BUCKET_NAME
Carica un file video locale nel nuovo bucket:
gcloud storage cp LOCAL_FILE gs://BUCKET_NAME
Facoltativo. Configura l'ambiente virtuale:
Se non è installato, installa
virtualenv
:sudo apt-get install python3-venv
Crea un nuovo ambiente virtuale:
python3 -m venv vaivenv
Attiva l'ambiente virtuale:
source vaivenv/bin/activate
Installa le dipendenze:
pip3 install visionai-0.0.5-py3-none-any.whl pip3 install google-cloud-storage
Invia la richiesta con l'SDK Python.
Effettua le seguenti sostituzioni di variabili:
- PROJECT_ID: il tuo ID progetto Google Cloud .
- LOCATION_ID: il tuo ID sede. Ad esempio,
us-central1
. Scopri di più. Regioni supportate. - BUCKET_NAME: il bucket Cloud Storage che hai creato.
python3 visionai/python/example/blur_gcs_video.py \ --project_id=PROJECT_ID –cluster_id=application-cluster-0 \ –location_id=LOCATION_ID –bucket_name=BUCKET_NAME
Dovresti vedere un output simile al seguente:
Listing mp4 files... test1.mp4 test2.mp4 Creating deid processes... process vnluvxgl is created process rvrdoucx is created Waiting for processes to finish... process vnluvxgl state is COMPLETED process rvrdoucx state is COMPLETED All processes have finished, please check the GCS bucket! ```
Elenca tutti gli oggetti nel bucket con il comando
gcloud storage ls
:gcloud storage ls gs://bucket
Dovresti vedere i file di origine e i file di output simili ai seguenti:
test1.mp4 test2.mp4 test1_deid_output.mp4 test2_deid_output.mp4
Facoltativo. Scarica i file di output localmente con il comando
gcloud storage cp
e visualizza i video sfocati:gcloud storage cp gs://BUCKET_NAME/FILE_NAME .
- Scopri di più sul modello di sfocatura delle persone.
- Esplora architetture, diagrammi e best practice di riferimento su Google Cloud. Consulta il nostro Cloud Architecture Center.
Aggiungi file di input a Cloud Storage
Prima di poter inviare una richiesta utilizzando l'SDK Python, crea un bucket Cloud Storage e carica un video locale da utilizzare come input.
Installa le dipendenze e invia la richiesta
Dopo aver creato il bucket Cloud Storage per i video di input e output e aver aggiunto un video locale, installa le dipendenze necessarie e invia la richiesta.
Esamina l'output
Una volta completata l'elaborazione del video, puoi esaminare l'output nel tuo bucket Cloud Storage. I file video sfocati generati si troveranno nello stesso bucket Cloud Storage del video sorgente.
Esegui la pulizia
Per evitare che al tuo account Google Cloud vengano addebitati costi relativi alle risorse utilizzate in questo tutorial, elimina il progetto che contiene le risorse oppure mantieni il progetto ed elimina le singole risorse.