The Vision Warehouse API allows you to manage Vision Warehouse resources using the command line.
A connected warehouse (corpus
) in a data-ingesting deployed app has one or
more media objects (for example, video resources). These media objects
(asset
resources) contain metadata and resource annotations (annotations
).
Depending on the models used on the media objects these annotations can
consist of varying types of information such as labels, bounding boxes, and
timestamps.
Use the following commands to manage these annotations.
There are two types of annotations:
- Asset-level annotation: An annotation that applied to the whole asset.
For example:
camera-location
. - Partition-level annotation: An annotation that only applied to part of the asset. You must specify a temporal partition (start time and end time) for streaming video asset or a relative temporal partition (start offset or end offset) for batch video asset to get partition-level annotation information.
Before creating an annotation, you must create a corresponding data schema with the same key to indicate the data type of the value of the annotation. If you need to change the value type of a specific key, you must delete all annotations using this key. After you delete these annotations you can update the corresponding data schema.
Create a warehouse asset annotation
You must complete the following steps before you can create an annotation for an asset:
- Create an
asset
resource in a warehouse. - Create a
dataSchema
resource with the same key to indicate the data type of theannotation
value.
An annotation
resource can optionally have a temporal partition associated with it.
For example, if an annotation applies to the whole asset, you can omit
any temporal partition associated with it. Similarly, if an
annotation applies to only a specific part of a video asset, you can supply
the time range of the asset when creating the annotation
resource.
Create an annotation with no temporal partition
If an annotation applies to the entirety of a video asset, you don't have to
provide a temporal partition for it. Use the following sample to create an annotation
resource for a whole asset (no video time period specified).
REST
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- ANNOTATION_ID: (Optional) A user-provided value for the annotation ID. In this
request, the value is added to the request URL in the form:
- https://ENDPOINT/v1/[...]/corpora/CORPUS_ID/assets/ASSET_ID/annotations?annotation_id=ANNOTATION_ID
HTTP method and URL:
POST https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations
Request JSON body:
{ "user_specified_annotation":{ "key": "camera-location", "value": { "str_value": "Sunnyvale" } } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations"
PowerShell
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID", "userSpecifiedAnnotation": { "key": "camera-location", "value": { "strValue": "Sunnyvale" } } }
Create an annotation with a temporal partition
If an annotation applies to only part of a streaming video asset, you can
provide a time range for the target video portion. Use the following sample to
create an annotation
resource for a specific time period of a video
asset using a temporal partition.
REST
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- ANNOTATION_ID: (Optional) A user-provided value for the annotation ID. In this
request, the value is added to the request URL in the form:
- https://ENDPOINT/v1/[...]/corpora/CORPUS_ID/assets/ASSET_ID/annotations?annotation_id=ANNOTATION_ID
HTTP method and URL:
POST https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations
Request JSON body:
{ "user_specified_annotation": { "key": "object-detected", "value": { "str_value": "cat" }, "partition": { "temporal_partition": { "start_time": { "seconds": "1630464728" }, "end_time": { "seconds": "1630464729" } } } } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations"
PowerShell
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID", "userSpecifiedAnnotation": { "key": "object-detected", "value": { "strValue": "cat" }, "partition": { "temporalPartition": { "startTime": "2022-09-14T20:33:09Z", "endTime": "2022-09-14T20:33:39Z" } } } }
Create an annotation with a relative temporal partition
If an annotation applies to only part of a batch video asset, you can
provide a time range for the target video portion. Use the following sample to
create an annotation
resource for a specific time period of a video
asset using a relative temporal partition.
REST
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- ANNOTATION_ID: (Optional) A user-provided value for the annotation ID. In this
request, the value is added to the request URL in the form:
- https://ENDPOINT/v1/[...]/corpora/CORPUS_ID/assets/ASSET_ID/annotations?annotation_id=ANNOTATION_ID
HTTP method and URL:
POST https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations
Request JSON body:
{ "user_specified_annotation": { "key": "object-detected", "value": { "str_value": "cat" }, "partition": { "relative_temporal_partition": { "start_offset": { "seconds": "60" }, "end_offset": { "seconds": "300" } } } } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
,
and execute the following command:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations"
PowerShell
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID", "userSpecifiedAnnotation": { "key": "object-detected", "value": { "strValue": "cat" }, "partition": { "relative_temporal_partition": { "start_offset": "60s", "end_offset": "300s" } } } }
Update an annotation (no temporal partition)
REST
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- ANNOTATION_ID: The ID of your target annotation.
HTTP method and URL:
PATCH https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID
Request JSON body:
{ "user_specified_annotation":{ "key": "camera-location", "value": { "str_value": "UPDATED_FIELD_VALUE" } } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
,
and execute the following command:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID"
PowerShell
Save the request body in a file named request.json
,
and execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID", "userSpecifiedAnnotation": { "key": "camera-location", "value": { "strValue": "UPDATED_FIELD_VALUE" } } }
List asset annotations
List all Annotations under a specific asset.
REST
To list asset annotations, send a GET request by using the projects.locations.corpora.assets.annotations.list method.
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- PAGE_SIZE: (Optional) The number of results to return.
HTTP method and URL:
GET https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations?page_size=PAGE_SIZE
To send your request, choose one of these options:
curl
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations?page_size=PAGE_SIZE"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations?page_size=PAGE_SIZE" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "annotations": [ { "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID1", "userSpecifiedAnnotation": { "key": "object-detected", "value": { "strValue": "cat" }, "partition": { "temporalPartition": { "startTime": "2022-09-14T20:33:09Z", "endTime": "2022-09-14T20:33:39Z" } } } }, { "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID2", "userSpecifiedAnnotation": { "key": "object-detected", "value": { "strValue": "dog" }, "partition": { "temporalPartition": { "startTime": "2022-09-14T20:33:09Z", "endTime": "2022-09-14T20:33:39Z" } } } } ], "nextPageToken": "ChQxMzkzNTQyNzE0MDk3NzU3NDg5MBAC" }
Get next page information:
If your list request returns a nextPageToken
you can use that token
to list more annotation
resources.
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- PAGE_SIZE: (Optional) The number of results to return.
HTTP method and URL:
GET https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations?page_size=PAGE_SIZE&page_token=NEXT_PAGE_TOKEN
To send your request, choose one of these options:
curl
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations?page_size=PAGE_SIZE&page_token=NEXT_PAGE_TOKEN"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations?page_size=PAGE_SIZE&page_token=NEXT_PAGE_TOKEN" | Select-Object -Expand Content
nextPageToken
depending on the number of annotations available.
{ "annotations": [ { "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID1", "userSpecifiedAnnotation": { [...] } }, { "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID2", "userSpecifiedAnnotation": { [...] } } ], "nextPageToken": "IhXxMzkzJLIyNzPQNEk3NzU3NDg5CBIP" }
Get an asset annotation
REST
To get details about an asset's annotation, send a GET request by using the projects.locations.corpora.assets.annotations.get method.
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- ANNOTATION_ID: The ID of your target annotation.
HTTP method and URL:
GET https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID
To send your request, choose one of these options:
curl
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPORA_ID/assets/ASSET_ID/annotations/ANNOTATIONS_ID", "userSpecifiedAnnotation": { "key": "object-detected", "value": { "strValue": "dog" }, "partition": { "temporalPartition": { "startTime": "2022-09-14T20:33:09Z", "endTime": "2022-09-14T20:33:39Z" } } } }
List asset annotations with a filter
You can use filters to narrow results returned from an annotations list request.
Supported filters:
partition.temporal_partition.start_time
†partition.temporal_partition.end_time
†key
† Timestamps are specified in the
RFC-3339 format
(for example, 2012-04-21T11:30:00-04:00
). These filters also
offer comparison and logical operators. For example:
-
GET https://warehouse-visionai.googleapis.com/v1/projects/123456789/locations/us-central1/corpora/82403458240/assets/48575742017/annotations'?page_size=5&filter=partition.temporal_partition.start_time>"2022-02-01T17:55:38-00:00"%20AND%20partition.temporal_partition.end_time<"2022-02-01T17:55:48-00:00"'
REST
To list and filter asset annotations, send a GET request by using the projects.locations.corpora.assets.annotations.list method.
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- FILTER_NAME, FILTER_VALUE: The criteria you want to filter the returned
list. For example:
'?filter=key="KEY_VALUE"'
'?filter=partition.temporal_partition.start_time="2022-02-01T17:55:38-00:00"'
'?filter=partition.temporal_partition.end_time="2022-02-01T17:55:48-00:00"'
HTTP method and URL:
GET https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations'?filter=FILTER_NAME="FILTER_VALUE"'
To send your request, choose one of these options:
curl
Execute the following command:
curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations'?filter=FILTER_NAME="FILTER_VALUE"'"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations'?filter=FILTER_NAME="FILTER_VALUE"'" | Select-Object -Expand Content
The response depends on the filters applied and can
also contain a nextPageToken
depending on the number of annotations available.
You can also apply multiple filters and page fields (pageSize
,
pageToken
) in a single request:
- https://ENDPOINT/v1/[...]/annotations '?filter=partition.temporal_partition.start_time="START_TIME"%20AND%20 key="KEY_VALUE"&page_token=PAGE_TOKEN'
Delete an asset annotation
REST
To delete an asset's annotation, send a DELETE request by using the projects.locations.corpora.assets.annotations.delete method.
Before using any of the request data, make the following replacements:
- REGIONALIZED_ENDPOINT: Endpoint might include a prefix matching the
LOCATION_ID
such aseurope-west4-
. See more about regionalized endpoints. - PROJECT_NUMBER: Your Google Cloud project number.
- LOCATION_ID: The region where you are using
Vertex AI Vision. For example:
us-central1
,europe-west4
. See available regions. - CORPUS_ID: The ID of your target corpus.
- ASSET_ID: The ID of your target asset.
- ANNOTATION_ID: The ID of your target annotation.
HTTP method and URL:
DELETE https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID
To send your request, choose one of these options:
curl
Execute the following command:
curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID"
PowerShell
Execute the following command:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://warehouse-visionai.googleapis.com/v1/projects/PROJECT_NUMBER/locations/LOCATION_ID/corpora/CORPUS_ID/assets/ASSET_ID/annotations/ANNOTATION_ID" | Select-Object -Expand Content
You should receive a JSON response similar to the following:
{}