제품 세트는 제품 그룹의 단순한 컨테이너입니다.
빈 제품 세트 만들기
모든 품목에 하나의 상품 세트만 사용하고 필요에 따라 테스트용 추가 제품 세트를 만드는 것이 좋습니다. 다음 코드 샘플에서는 빈 상품 세트를 만드는 방법을 보여줍니다.
REST 및 명령줄
아래의 요청 데이터를 사용하기 전에 다음을 바꿉니다.
- project-id: GCP 프로젝트 ID입니다.
- location-id: 유효한 위치 식별자입니다. 유효한 위치 식별자는
us-west1
,us-east1
,europe-west1
,asia-east1
입니다. - display-name: 선택한 문자열 표시 이름입니다.
HTTP 메서드 및 URL:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets
JSON 요청 본문:
{ "displayName": "display-name" }
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets
PowerShell
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets" | Select-Object -Expand Content
요청이 성공하면 서버가 200 OK
HTTP 상태 코드와 응답을 JSON 형식으로 반환합니다.
다음과 비슷한 출력이 표시됩니다. 제품 세트 ID(이 경우 b6d809615b6dd675
)를 사용하여 제품 세트의 다른 작업을 수행할 수 있습니다.
{ "name": "projects/project-id/locations/location-id/productSets/b6d809615b6dd675", "displayName": "new-product-set" }
C#
Go
자바
Node.js
PHP
Python
Ruby
일괄 가져오기를 사용하여 상품으로부터 상품 세트 만들기
또한 일괄 가져오기 기능을 사용하여 동시에 제품 세트를 만들고 여러 제품 및 참조 이미지를 만들 수 있습니다.
제품 세트, 제품, 참조 이미지에 대한 다양한 참조는 모두 사용자가 사용하는 일괄 가져오기 CSV에서 설정됩니다. 자세한 내용은 일괄 가져오기 CSV 형식 지정을 참조하세요.
다음 코드를 실행하여 일괄 가져오기를 수행합니다.
REST 및 명령줄
아래의 요청 데이터를 사용하기 전에 다음을 바꿉니다.
- project-id: GCP 프로젝트 ID입니다.
- location-id: 유효한 위치 식별자입니다. 유효한 위치 식별자는
us-west1
,us-east1
,europe-west1
,asia-east1
입니다. - storage-path: 입력 CSV 파일이 저장된 Cloud Storage 버킷/디렉터리입니다. 요청하는 사용자에게 적어도 버킷에 대한 읽기 권한이 있어야 합니다.
HTTP 메서드 및 URL:
POST https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets:import
JSON 요청 본문:
{ "inputConfig": { "gcsSource": { "csvFileUri": "storage-path" } } }
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets:import
PowerShell
요청 본문을 request.json
파일에 저장하고 다음 명령어를 실행합니다.
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://vision.googleapis.com/v1/projects/project-id/locations/location-id/productSets:import" | Select-Object -Expand Content
다음과 비슷한 출력이 표시됩니다. 작업 ID(이 경우 f10f34e32c40a710
)를 사용하여 작업 상태를 가져올 수 있습니다. 예를 들어 작업 상태 가져오기를 살펴보면 다음과 같습니다.
{ "name": "projects/project-id/locations/location-id/operations/f10f34e32c40a710" }
장기 실행 작업이 완료되면 가져오기 작업의 세부정보를 가져올 수 있습니다. 응답은 다음과 비슷하게 표시됩니다.
{ "name": "locations/location-id/operations/f10f34e32c40a710", "metadata": { "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata", "state": "SUCCESSFUL", "submitTime": "2019-12-06T21:16:04.476466873Z", "endTime": "2019-12-06T21:16:40.594258084Z" }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.vision.v1.ImportProductSetsResponse", "referenceImages": [ { "name": "projects/project-id/locations/location-id/products/product_id0/referenceImages/image0", "uri": "gs://my-storage-bucket/img_039.jpg" }, { "name": "projects/project-id/locations/location-id/products/product_id1/referenceImages/image1", "uri": "gs://my-storage-bucket/img_105.jpg" }, { "name": "projects/project-id/locations/location-id/products/product_id2/referenceImages/image2", "uri": "gs://my-storage-bucket/img_224.jpg" }, { "name": "projects/project-id/locations/location-id/products/product_id3/referenceImages/image3", "uri": "gs://my-storage-bucket/img_385.jpg" } ], "statuses": [ {}, {}, {}, {} ] } }
C#
Go
자바
Node.js
PHP
Python
Ruby
작업 상태 가져오기
요청한 여러 작업은 일괄 가져오기를 통한 제품 세트 생성, 제품 세트 삭제, 분리된 제품 삭제처럼 장기 실행되는 작업입니다. 이러한 유형의 요청은 작업 상태를 가져오는 데 사용할 수 있는 작업 ID와 함께 JSON을 반환합니다.
예를 들어 일괄 삭제( purge
) 요청은 다음 JSON을 반환합니다.
{ "name": "projects/project-id/locations/location-id/operations/bc4e1d412863e626" }
이 경우 작업 ID는 bc4e1d412863e626
입니다. 다음 샘플은 이 ID로 이 작업의 상태를 가져오는 방법을 보여줍니다.
REST 및 명령줄
아래의 요청 데이터를 사용하기 전에 다음을 바꿉니다.
- location-id: 유효한 위치 식별자입니다. 유효한 위치 식별자는
us-west1
,us-east1
,europe-west1
,asia-east1
입니다. - operation-id: 작업의 ID입니다. ID는 작업 이름의 마지막 요소입니다. 예를 들면 다음과 같습니다.
- 작업 이름:
projects/project-id/locations/location-id/operations/bc4e1d412863e626
- 작업 ID:
bc4e1d412863e626
- 작업 이름:
HTTP 메서드 및 URL:
GET https://vision.googleapis.com/v1/locations/location-id/operations/operation-id
요청을 보내려면 다음 옵션 중 하나를 선택합니다.
curl
다음 명령어를 실행합니다.
curl -X GET \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
https://vision.googleapis.com/v1/locations/location-id/operations/operation-id
PowerShell
다음 명령어를 실행합니다.
$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://vision.googleapis.com/v1/locations/location-id/operations/operation-id" | Select-Object -Expand Content
{ "name": "locations/location-id/operations/operation-id", "metadata": { "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata", "state": "SUCCESSFUL", "submitTime": "2019-09-04T15:58:39.131591882Z", "endTime": "2019-09-04T15:58:43.099020580Z" }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.vision.v1.PurgeProductsRequest", "parent": "projects/project-id/locations/location-id", "productSetPurgeConfig": { "productSetId": "project-set-id" }, "force": true } }
분리된 제품 삭제 작업이 완료되면 다음과 비슷한 출력이 표시됩니다.
{ "name": "locations/location-id/operations/operation-id", "metadata": { "@type": "type.googleapis.com/google.cloud.vision.v1.BatchOperationMetadata", "state": "SUCCESSFUL", "submitTime": "2019-09-04T16:08:38.278197397Z", "endTime": "2019-09-04T16:08:45.075778639Z" }, "done": true, "response": { "@type": "type.googleapis.com/google.cloud.vision.v1.PurgeProductsRequest", "parent": "projects/project-id/locations/location-id", "deleteOrphanProducts": true, "force": true } }