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 saperne di più, consulta Esegui la 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 a gcloud CLI con la tua identità federata.
-
Per inizializzare gcloud CLI, esegui questo comando:
gcloud init -
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith 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_IDwith your Google Cloud project name.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI Vision, Cloud Storage APIs:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.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.objectAdmingcloud 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 a gcloud CLI con la tua identità federata.
-
Per inizializzare gcloud CLI, esegui questo comando:
gcloud init -
Create or select a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator role
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith 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_IDwith your Google Cloud project name.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI Vision, Cloud Storage APIs:
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.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.objectAdmingcloud 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/. - Scarica 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_NAMECarica un file video locale nel nuovo bucket:
gcloud storage cp LOCAL_FILE gs://BUCKET_NAMEFacoltativo. Configura l'ambiente virtuale:
Se non è installato, installa
virtualenv:sudo apt-get install python3-venvCrea un nuovo ambiente virtuale:
python3 -m venv vaivenvAttiva l'ambiente virtuale:
source vaivenv/bin/activate
Installa le dipendenze:
pip3 install visionai-0.0.5-py3-none-any.whl pip3 install google-cloud-storageInvia la richiesta con l'SDK Python.
Effettua le seguenti sostituzioni delle variabili:
- PROJECT_ID: l'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_NAMEDovresti 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://bucketDovresti vedere i file di origine e i file di output simili ai seguenti:
test1.mp4 test2.mp4 test1_deid_output.mp4 test2_deid_output.mp4Facoltativo. Scarica i file di output localmente con il comando
gcloud storage cpe 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 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 di origine.
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.