In dieser Anleitung wird gezeigt, wie Sie mit dem Python SDK Gesichter in Videos unkenntlich machen. Im Beispiel werden Videodateien aus einem Cloud Storage-Bucket unkenntlich gemacht und unkenntlich gemachte Videoausgaben generiert. Diese Ausgabevideos werden im selben Cloud Storage-Bucket wie die Quellvideos gespeichert.
Lernziele
In dieser Anleitung wird Folgendes beschrieben:
- Cloud Storage-Bucket erstellen
- Laden Sie eine lokale Videodatei in den Bucket hoch.
- Senden Sie eine Anfrage mit dem Python SDK.
- Verpixelte Ausgabevideos ansehen
Kosten
In diesem Dokument verwenden Sie die folgenden kostenpflichtigen Komponenten von Google Cloud:
- Vertex AI Vision (Models - Person / face blur)
- Cloud Storage
Mit dem Preisrechner können Sie eine Kostenschätzung für Ihre voraussichtliche Nutzung vornehmen.
Nach Abschluss der in diesem Dokument beschriebenen Aufgaben können Sie weitere Kosten vermeiden, indem Sie die erstellten Ressourcen löschen. Weitere Informationen finden Sie unter Bereinigen.
Hinweise
- 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.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
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.
-
-
Make sure 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
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
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.
-
-
Make sure 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
PROJECT_ID
with your project ID. -
Replace
USER_IDENTIFIER
with the identifier for your user account. For example,user:myemail@example.com
. - Replace
ROLE
with each individual role.
- Replace
- Quellcode des Vertex AI Vision SDK abrufen:
git clone https://github.com/google/visionai.git
Die Python-Beispiele befinden sich im Verzeichnis
visionai/python/example/
. - Python SDK herunterladen:
wget https://github.com/google/visionai/releases/download/v0.0.5/visionai-0.0.5-py3-none-any.whl
Eingabedateien in Cloud Storage hinzufügen
Bevor Sie eine Anfrage mit dem Python SDK senden können, müssen Sie einen Cloud Storage-Bucket erstellen und ein lokales Video als Eingabe hochladen.
Erstellen Sie einen Cloud Storage-Bucket:
gcloud storage buckets create gs://BUCKET_NAME
Laden Sie eine lokale Videodatei in den neuen Bucket hoch:
gcloud storage cp LOCAL_FILE gs://BUCKET_NAME
Abhängigkeiten installieren und Anfrage senden
Nachdem Sie Ihren Cloud Storage-Bucket für Ein- und Ausgabevideos erstellt und ein lokales Video hinzugefügt haben, installieren Sie die erforderlichen Abhängigkeiten und senden Sie Ihre Anfrage.
Optional. Virtuelle Umgebung einrichten:
Wenn
virtualenv
nicht installiert ist, installieren Sie es:sudo apt-get install python3-venv
Erstellen Sie eine neue virtuelle Umgebung:
python3 -m venv vaivenv
Aktivieren Sie Ihre virtuelle Umgebung:
source vaivenv/bin/activate
Installieren Sie die Abhängigkeiten:
pip3 install visionai-0.0.5-py3-none-any.whl pip3 install google-cloud-storage
Senden Sie Ihre Anfrage mit dem Python SDK.
Ersetzen Sie die folgenden Variablen:
- PROJECT_ID: Ihre Google Cloud -Projekt-ID
- LOCATION_ID: Ihre Standort-ID. Beispiel:
us-central1
. Weitere Informationen Unterstützte Regionen. - BUCKET_NAME: Der Cloud Storage-Bucket, den Sie erstellt haben.
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
Die Ausgabe sollte in etwa so aussehen:
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! ```
Ausgabe prüfen
Nachdem die Verarbeitung Ihres Videos abgeschlossen ist, können Sie sich die Ausgabe in Ihrem Cloud Storage-Bucket ansehen. Die generierten unkenntlich gemachten Videodateien befinden sich im selben Cloud Storage-Bucket wie das Quellvideo.
Listen Sie alle Objekte in Ihrem Bucket mit dem Befehl
gcloud storage ls
auf:gcloud storage ls gs://bucket
Die Quell- und Ausgabedateien sollten in etwa so aussehen:
test1.mp4 test2.mp4 test1_deid_output.mp4 test2_deid_output.mp4
Optional. Laden Sie die Ausgabedateien mit dem Befehl
gcloud storage cp
lokal herunter und sehen Sie sich die unkenntlich gemachten Videos an:gcloud storage cp gs://BUCKET_NAME/FILE_NAME .
Bereinigen
Damit Ihrem Google Cloud-Konto die in dieser Anleitung verwendeten Ressourcen nicht in Rechnung gestellt werden, löschen Sie entweder das Projekt, das die Ressourcen enthält, oder Sie behalten das Projekt und löschen die einzelnen Ressourcen.
Nächste Schritte
- Weitere Informationen zum Modell zum Unkenntlichmachen von Personen
- Referenzarchitekturen, Diagramme und Best Practices zu Google Cloud kennenlernen. Weitere Informationen zu Cloud Architecture Center