명령줄을 사용하여 동영상 객체 추적
빠른 시작에서는 다음과 같은 과정을 안내합니다.
- Cloud Storage에 동영상 집합 복사
- 동영상 및 해당 라벨을 나열하는 CSV 파일 만들기
- AutoML Video Object Tracking을 사용하여 데이터 세트를 만들고 모델을 학습시키고 사용합니다.
시작하기 전에
프로젝트 설정
- Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
- Install the Google Cloud CLI.
-
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.
-
-
AutoML and Cloud Storage API를 사용 설정합니다.
gcloud services enable storage-component.googleapis.com
automl.googleapis.com storage-api.googleapis.com - Install the Google Cloud CLI.
-
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.
-
-
AutoML and Cloud Storage API를 사용 설정합니다.
gcloud services enable storage-component.googleapis.com
automl.googleapis.com storage-api.googleapis.com PROJECT_ID
환경 변수를 프로젝트 ID로 설정합니다.export PROJECT_ID=PROJECT_ID
AutoML API 호출 및 리소스 이름에는 프로젝트 ID가 포함됩니다.PROJECT_ID
환경 변수는 ID를 지정하는 편리한 방법을 제공합니다.
데이터세트를 만들고 학습 데이터 가져오기
데이터 세트 생성
데이터 세트 이름을 결정하고 다음 curl
또는 PowerShell 명령어를 사용하여 이 이름의 새 데이터 세트를 만듭니다.
REST
다음은 POST 요청을 보내는 방법을 보여줍니다. 이 예시에서는 Google Cloud CLI를 사용하여 액세스 토큰을 만듭니다. gcloud CLI 설치에 대한 안내는 AutoML Video Intelligence 객체 추적 빠른 시작을 참조하세요.요청 데이터를 사용하기 전에 다음을 바꿉니다.
- dataset-name: 대상 데이터 세트의 이름입니다.
예를 들면my_dataset_01
입니다. - 참고:
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 하는 Cloud 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다.
HTTP 메서드 및 URL:
POST https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets
JSON 요청 본문:
{ "displayName": "dataset-name", "videoObjectTrackingDatasetMetadata": { } }
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets"
PowerShell
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets" | Select-Object -Expand Content
VOT12345....
학습 데이터 가져오기
REST
학습 데이터를 가져오려면importData
메서드를 사용합니다. 이 메서드를 사용하려면 다음 두 매개변수를 제공해야 합니다.
- 학습 경로가 포함된 CSV의 경로입니다.
- 테스트 데이터 CSV 파일입니다. 참고: 이러한 파일은 Cloud Storage의 'automl-video-demo-data'버킷에서 사용할 수 있습니다.
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- dataset-id: 데이터 세트의 ID입니다. ID는 데이터 세트 이름의 마지막 요소입니다. 예를 들면 다음과 같습니다.
- 데이터 세트 이름:
projects/project-number/locations/location-id/datasets/3104518874390609379
- 데이터 세트 ID:
3104518874390609379
- 데이터 세트 이름:
- bucket-name: 모델 학습 파일 목록 CSV 파일을 저장한 Cloud Storage 버킷의 이름으로 바꿉니다.
- csv-file-name: 모델 학습 파일 목록 CSV 파일의 이름으로 바꿉니다.
- 참고:
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 하는 Cloud 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다.
HTTP 메서드 및 URL:
POST https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets/dataset-id:importData
JSON 요청 본문:
{ "inputConfig": { "gcsSource": { "inputUris": ["gs://bucket-name/csv-file-name.csv"] } } }
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets/dataset-id:importData"
PowerShell
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets/dataset-id:importData" | Select-Object -Expand Content
VOT7506374678919774208
가 포함 된 응답을 보여줍니다.
가져오기 작업의 상태 가져오기
다음 curl
또는 PowerShell 명령어를 사용하여 데이터 가져오기 작업의 상태를 쿼리할 수 있습니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- operation-id: 작업을 시작할 때 요청으로 생성되고 응답으로 제공된 장기 실행 작업의 ID로 예를 들면
VOT12345....
입니다. - 참고:
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 하는 Cloud 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다.
HTTP 메서드 및 URL:
GET https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/operations/operation-id
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
다음 명령어를 실행합니다.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
"https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/operations/operation-id"
PowerShell
다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/operations/operation-id" | Select-Object -Expand Content
done: true
로 표시됩니다.
- operation-name: AutoML Video Intelligence 객체 추적 API에서 반환하는 작업의 이름입니다. 작업 이름은
projects/project-number/locations/location-id/operations/operation-id
형식입니다.
모든 데이터 세트 나열
다음 curl
또는 PowerShell 명령어를 사용하여 데이터 세트 목록과 데이터 세트로 가져온 샘플 동영상 수를 가져옵니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 할 클라우드 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다.
HTTP 메서드 및 URL:
GET https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
다음 명령어를 실행합니다.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
"https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets "
PowerShell
다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets " | Select-Object -Expand Content
VOT3940649673949184000
는 작업을 시작할 때 요청으로 생성되고 응답에서 제공되는 장기 실행 작업의 작업 ID입니다.
모델 학습
모델 학습 작업 시작
데이터 세트를 만들고 학습 데이터를 데이터 세트로 가져온 후 커스텀 모델을 학습시킬 수 있습니다. 다음 curl
또는 PowerShell 명령어를 사용하여 모델을 학습시킵니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- dataset-id: 대상 데이터 세트의 이름입니다.
예를 들어
my_dataset_01
표시 이름입니다. - model-name: 모델에 선택한 이름으로 바꿉니다.
- 참고:
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 하는 Cloud 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다.
HTTP 메서드 및 URL:
POST https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models
JSON 요청 본문:
{ "datasetId": "dataset-id", "displayName": "model-name", "videoObjectTrackingModelMetadata": {}, }
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models"
PowerShell
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models" | Select-Object -Expand Content
VOT1741767155885539328
가 포함된 응답을 보여줍니다.
모델 학습 작업의 상태 가져오기
다음 curl
또는 PowerShell 명령어를 사용하여 모델 학습 작업의 상태를 쿼리할 수 있습니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- operation-name: AutoML Video Intelligence Object Tracking API에서 반환하는 작업의 이름입니다. 작업 이름은
projects/project-number/locations/location-id/operations/operation-id
형식입니다. - 참고:
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 하는 Cloud 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다.
HTTP 메서드 및 URL:
GET https://automl.googleapis.com/v1beta1/operation-name
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
다음 명령어를 실행합니다.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
"https://automl.googleapis.com/v1beta1/operation-name"
PowerShell
다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1beta1/operation-name" | Select-Object -Expand Content
done: true
가 표시됩니다.
모델이 사용 가능한지 확인
모델 학습 작업이 성공적으로 완료되면 프로젝트 모델을 나열하는 다음 명령어를 사용하여 모델을 사용할 수 있는지 확인할 수 있습니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 할 클라우드 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다.
HTTP 메서드 및 URL:
GET https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models
요청을 보내려면 다음 옵션 중 하나를 펼칩니다.
다음과 비슷한 JSON 응답이 표시됩니다.
예측하기
batchPredict 메서드를 사용하여 동영상의 주석(예측)을 요청할 수 있습니다. batchPredict
메서드에서는 다음 두 가지 입력을 사용합니다.
- 주석을 추가할 동영상의 경로가 포함된 Cloud Storage 버킷에 저장된 CSV 파일
- 주석을 추가할 동영상의 세그먼트를 식별하는 시작 및 종료 시간입니다.
이 빠른 시작에서는 traffic_video_batch_predict.csv
라는 CSV 파일을 사용합니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- model-id: 모델의 식별자로 바꿉니다.
- input-uri: 파일 이름을 포함하여 주석을 추가하고자 하는 파일을 포함한 Cloud Storage 버킷입니다.
gs://
로 시작해야 합니다.
예시:"inputUris": ["gs://automl-video-demo-data/traffic_videos/traffic_video_batch_predict.csv"],
- output-bucket: 예측 결과가 포함될 Cloud Storage 버킷으로 바꿉니다.
- object-id: Cloud Storage 버킷에서 예측 요청 출력을 저장할 위치를 식별하는 객체 이름으로 바꿉니다. 참고: Cloud Storage 버킷에 대한 쓰기 권한이 있어야 합니다.
- 참고:
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 하는 Cloud 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다.
HTTP 메서드 및 URL:
POST https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models/model-id:batchPredict
JSON 요청 본문:
{ "inputConfig": { "gcsSource": { "inputUris": ["input-uri"] } }, "outputConfig": { "gcsDestination": { "outputUriPrefix": "gs://output-bucket/object-id" } } "params": { "score_threshold": "0.0" } }
요청을 보내려면 다음 옵션 중 하나를 펼칩니다.
다음과 비슷한 JSON 응답이 표시됩니다.
예측 작업의 상태 가져오기
다음 curl
또는 PowerShell 명령어를 사용하여 일괄 예측 작업의 상태를 쿼리할 수 있습니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 할 클라우드 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다. - operation-id: 작업을 시작할 때 요청으로 생성되고 응답으로 제공된 장기 실행 작업의 ID로 예를 들면
VOT12345....
입니다.
HTTP 메서드 및 URL:
GET https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/operations/operation-id
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
다음 명령어를 실행합니다.
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "x-goog-user-project: project-number" \
"https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/operations/operation-id"
PowerShell
다음 명령어를 실행합니다.
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred"; "x-goog-user-project" = "project-number" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/operations/operation-id" | Select-Object -Expand Content
projects/project-number/locations/location-id/operations/operation-id
형식입니다.
일괄 예측 작업이 완료되면 명령어에 지정된 Cloud Storage 버킷에 예측 출력이 저장됩니다. 각 동영상 세그먼트에 대한 JSON 파일이 있습니다. JSON 파일의 형식은 my-video-01.avi.json과 같으며 파일 확장자 .json은 원래 파일 이름에 추가됩니다.
{ "inputUris": ["automl-video-demo-data/sample_video.avi"], "object_annotations": [ { "annotation_spec": { "display_name": "Cat", "description": "Cat" }, "confidence": 0.43253016 "frames": [ { "frame": { "time_offset": { "seconds": 4, "nanos": 960000000 }, "normalized_bounding_box": { "x_min": 0.1, "y_min": 0.1, "x_max": 0.8, "y_max": 0.8 } } }, { "frame": { "time_offset": { "seconds": 5, "nanos": 960000000 }, "normalized_bounding_box": { "x_min": 0.2, "y_min": 0.2, "x_max": 0.9, "y_max": 0.9 } } } ], "segment": { "start_time_offset": { "seconds": 4, "nanos": 960000000 }, "end_time_offset": { "seconds": 5, "nanos": 960000000 } } } ], "error": { "details": [ ] } }
삭제
커스텀 모델과 관련 데이터 세트가 더 이상 필요하지 않으면 삭제할 수 있습니다.
모델 삭제
다음 curl
또는 PowerShell 명령어를 사용하여 모델을 삭제할 수 있습니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 할 클라우드 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다. - model-id: 모델의 식별자로 바꿉니다.
HTTP 메서드 및 URL:
DELETE https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/models/model-id
요청을 보내려면 다음 옵션 중 하나를 펼칩니다.
성공 상태 코드(2xx)와 빈 응답을 받게 됩니다.
데이터 세트 삭제
다음 curl
또는 PowerShell 명령어를 사용하여 데이터 세트를 삭제할 수 있습니다.
REST
요청 데이터를 사용하기 전에 다음을 바꿉니다.
- project-number: 프로젝트 수입니다.
- location-id: 주석이 있어야 할 클라우드 리전입니다. 지원되는 클라우드 리전은
us-east1
,us-west1
,europe-west1
,asia-east1
입니다. 리전을 지정하지 않으면 동영상 파일 위치를 기준으로 리전이 결정됩니다. - datase-id: 데이터 세트 ID의 식별자로 바꿉니다.
HTTP 메서드 및 URL:
DELETE https://automl.googleapis.com/v1beta1/projects/project-number/locations/location-id/datasets/dataset-id
요청을 보내려면 다음 옵션 중 하나를 펼칩니다.
성공 상태 코드(2xx)와 빈 응답을 받게 됩니다.