이 튜토리얼에서는 Python SDK를 사용하여 동영상에서 얼굴을 흐리게 처리하는 방법을 보여줍니다. 이 예에서는 Cloud Storage 버킷의 동영상 파일을 흐리게 처리하고 흐리게 처리된 동영상 출력을 생성합니다. 이러한 출력 동영상은 소스 동영상과 동일한 Cloud Storage 버킷에 저장됩니다.
목표
이 튜토리얼에서는 다음 작업을 처리하는 방법을 보여줍니다.
- Cloud Storage 버킷을 만듭니다.
- 로컬 동영상 파일을 버킷에 업로드합니다.
- Python SDK를 사용하여 요청을 전송합니다.
- 흐리게 처리된 출력 동영상을 확인합니다.
비용
이 문서에서는 비용이 청구될 수 있는 Google Cloud구성요소( )를 사용합니다.
- Vertex AI Vision (Models - Person / face blur)
- Cloud Storage
프로젝트 사용량을 기준으로 예상 비용을 산출하려면 가격 계산기를 사용합니다.
이 문서에 설명된 태스크를 완료했으면 만든 리소스를 삭제하여 청구가 계속되는 것을 방지할 수 있습니다. 자세한 내용은 삭제를 참조하세요.
시작하기 전에
- 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
- Vertex AI Vision SDK 소스 코드를 가져옵니다.
git clone https://github.com/google/visionai.git
Python 예시는
visionai/python/example/
디렉터리에 있습니다. - Python SDK를 가져옵니다.
wget https://github.com/google/visionai/releases/download/v0.0.5/visionai-0.0.5-py3-none-any.whl
Cloud Storage에 입력 파일 추가
Python SDK를 사용하여 요청을 보내기 전에 Cloud Storage 버킷을 만들고 입력으로 사용할 로컬 동영상을 업로드합니다.
Cloud Storage 버킷을 만듭니다.
gcloud storage buckets create gs://BUCKET_NAME
로컬 동영상 파일을 새 버킷에 업로드합니다.
gcloud storage cp LOCAL_FILE gs://BUCKET_NAME
종속 항목 설치 및 요청 전송
입력 및 출력 동영상을 위한 Cloud Storage 버킷을 만들고 로컬 동영상을 추가한 후 필요한 종속 항목을 설치하고 요청을 보냅니다.
(선택사항) 가상 환경을 설정합니다.
설치되어 있지 않다면
virtualenv
를 설치합니다.sudo apt-get install python3-venv
새 가상 환경을 만듭니다.
python3 -m venv vaivenv
가상 환경을 활성화합니다.
source vaivenv/bin/activate
종속 항목을 설치합니다.
pip3 install visionai-0.0.5-py3-none-any.whl pip3 install google-cloud-storage
Python SDK로 요청을 보냅니다.
다음 변수를 바꿉니다.
- PROJECT_ID: Google Cloud 프로젝트 ID입니다.
- LOCATION_ID: 위치 ID입니다. 예를 들면
us-central1
입니다. 자세히 알아보기 지원되는 지역 - BUCKET_NAME: 만든 Cloud Storage 버킷입니다.
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
다음과 비슷한 출력이 표시됩니다.
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! ```
출력 검사
동영상 처리가 완료되면 Cloud Storage 버킷에서 출력을 검사할 수 있습니다. 생성된 흐리게 처리된 동영상 파일은 소스 동영상과 동일한 Cloud Storage 버킷에 있습니다.
gcloud storage ls
명령어를 사용하여 버킷의 모든 객체를 나열합니다.gcloud storage ls gs://bucket
다음과 비슷한 소스 파일과 출력 파일이 표시됩니다.
test1.mp4 test2.mp4 test1_deid_output.mp4 test2_deid_output.mp4
(선택사항)
gcloud storage cp
명령어를 사용하여 출력 파일을 로컬로 다운로드하고 흐리게 처리된 동영상을 확인합니다.gcloud storage cp gs://BUCKET_NAME/FILE_NAME .
삭제
이 튜토리얼에서 사용된 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 리소스가 포함된 프로젝트를 삭제하거나 프로젝트를 유지하고 개별 리소스를 삭제하세요.
다음 단계
- 인물 흐리게 처리 모델에 대해 자세히 알아보세요.
- Google Cloud에 대한 참조 아키텍처, 다이어그램, 권장사항 살펴보기 Cloud 아키텍처 센터 살펴보기