Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jul 20, 2023. It is now read-only.

Commit bed2515

Browse files
yoshi-automationcallmehiphop
authored andcommitted
feat: image annotation batching (#375)
1 parent a64bf32 commit bed2515

26 files changed

Lines changed: 1523 additions & 951 deletions

.kokoro/lint.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@ cd $(dirname $0)/..
2323
npm install
2424

2525
# Install and link samples
26-
cd samples/
27-
npm link ../
28-
npm install
29-
cd ..
26+
if [ -f samples/package.json ]; then
27+
cd samples/
28+
npm link ../
29+
npm install
30+
cd ..
31+
fi
3032

3133
npm run lint

.kokoro/samples-test.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ if [ -f .kokoro/pre-samples-test.sh ]; then
3131
set -x
3232
fi
3333

34-
npm install
34+
if [ -f samples/package.json ]; then
35+
npm install
3536

36-
# Install and link samples
37-
cd samples/
38-
npm link ../
39-
npm install
40-
cd ..
37+
# Install and link samples
38+
cd samples/
39+
npm link ../
40+
npm install
41+
cd ..
4142

42-
npm run samples-test
43+
npm run samples-test
44+
fi

.kokoro/test.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ cd $(dirname $0)/..
2222

2323
npm install
2424
npm test
25-
./node_modules/nyc/bin/nyc.js report
2625

27-
bash $KOKORO_GFILE_DIR/codecov.sh
26+
COVERAGE_NODE=10
27+
if npx [email protected] --silent --node $COVERAGE_NODE; then
28+
NYC_BIN=./node_modules/nyc/bin/nyc.js
29+
if [ -f "$NYC_BIN" ]; then
30+
$NYC_BIN report
31+
fi
32+
bash $KOKORO_GFILE_DIR/codecov.sh
33+
else
34+
echo "coverage is only reported for Node $COVERAGE_NODE"
35+
fi

protos/google/cloud/vision/v1/geometry.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC.
1+
// Copyright 2019 Google LLC.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.

protos/google/cloud/vision/v1/image_annotator.proto

Lines changed: 140 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC.
1+
// Copyright 2019 Google LLC.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -49,6 +49,38 @@ service ImageAnnotator {
4949
};
5050
}
5151

52+
// Service that performs image detection and annotation for a batch of files.
53+
// Now only "application/pdf", "image/tiff" and "image/gif" are supported.
54+
//
55+
// This service will extract at most 5 (customers can specify which 5 in
56+
// AnnotateFileRequest.pages) frames (gif) or pages (pdf or tiff) from each
57+
// file provided and perform detection and annotation for each image
58+
// extracted.
59+
rpc BatchAnnotateFiles(BatchAnnotateFilesRequest)
60+
returns (BatchAnnotateFilesResponse) {
61+
option (google.api.http) = {
62+
post: "/v1/files:annotate"
63+
body: "*"
64+
};
65+
}
66+
67+
// Run asynchronous image detection and annotation for a list of images.
68+
//
69+
// Progress and results can be retrieved through the
70+
// `google.longrunning.Operations` interface.
71+
// `Operation.metadata` contains `OperationMetadata` (metadata).
72+
// `Operation.response` contains `AsyncBatchAnnotateImagesResponse` (results).
73+
//
74+
// This service will write image annotation outputs to json files in customer
75+
// GCS bucket, each json file containing BatchAnnotateImagesResponse proto.
76+
rpc AsyncBatchAnnotateImages(AsyncBatchAnnotateImagesRequest)
77+
returns (google.longrunning.Operation) {
78+
option (google.api.http) = {
79+
post: "/v1/images:asyncBatchAnnotate"
80+
body: "*"
81+
};
82+
}
83+
5284
// Run asynchronous image detection and annotation for a list of generic
5385
// files, such as PDF files, which may contain multiple pages and multiple
5486
// images per page. Progress and results can be retrieved through the
@@ -128,6 +160,28 @@ message Feature {
128160
string model = 3;
129161
}
130162

163+
// A bucketized representation of likelihood, which is intended to give clients
164+
// highly stable results across model upgrades.
165+
enum Likelihood {
166+
// Unknown likelihood.
167+
UNKNOWN = 0;
168+
169+
// It is very unlikely that the image belongs to the specified vertical.
170+
VERY_UNLIKELY = 1;
171+
172+
// It is unlikely that the image belongs to the specified vertical.
173+
UNLIKELY = 2;
174+
175+
// It is possible that the image belongs to the specified vertical.
176+
POSSIBLE = 3;
177+
178+
// It is likely that the image belongs to the specified vertical.
179+
LIKELY = 4;
180+
181+
// It is very likely that the image belongs to the specified vertical.
182+
VERY_LIKELY = 5;
183+
}
184+
131185
// External image source (Google Cloud Storage or web URL image location).
132186
message ImageSource {
133187
// **Use `image_uri` instead.**
@@ -294,7 +348,7 @@ message FaceAnnotation {
294348
}
295349

296350
// The bounding polygon around the face. The coordinates of the bounding box
297-
// are in the original image's scale, as returned in `ImageParams`.
351+
// are in the original image's scale.
298352
// The bounding box is computed to "frame" the face in accordance with human
299353
// expectations. It is based on the landmarker results.
300354
// Note that one or more x and/or y coordinates may not be generated in the
@@ -505,7 +559,7 @@ message ImageProperties {
505559
// Single crop hint that is used to generate a new crop when serving an image.
506560
message CropHint {
507561
// The bounding polygon for the crop region. The coordinates of the bounding
508-
// box are in the original image's scale, as returned in `ImageParams`.
562+
// box are in the original image's scale.
509563
BoundingPoly bounding_poly = 1;
510564

511565
// Confidence of this being a salient region. Range [0, 1].
@@ -565,7 +619,7 @@ message ImageContext {
565619
}
566620

567621
// Request for performing Google Cloud Vision API tasks over a user-provided
568-
// image, with user-requested features.
622+
// image, with user-requested features, and with context information.
569623
message AnnotateImageRequest {
570624
// The image to be processed.
571625
Image image = 1;
@@ -648,6 +702,9 @@ message AnnotateFileResponse {
648702

649703
// Individual responses to images found within the file.
650704
repeated AnnotateImageResponse responses = 2;
705+
706+
// This field gives the total number of pages in the file.
707+
int32 total_pages = 3;
651708
}
652709

653710
// Multiple image annotation requests are batched into a single service call.
@@ -662,6 +719,48 @@ message BatchAnnotateImagesResponse {
662719
repeated AnnotateImageResponse responses = 1;
663720
}
664721

722+
// A request to annotate one single file, e.g. a PDF, TIFF or GIF file.
723+
message AnnotateFileRequest {
724+
// Required. Information about the input file.
725+
InputConfig input_config = 1;
726+
727+
// Required. Requested features.
728+
repeated Feature features = 2;
729+
730+
// Additional context that may accompany the image(s) in the file.
731+
ImageContext image_context = 3;
732+
733+
// Pages of the file to perform image annotation.
734+
//
735+
// Pages starts from 1, we assume the first page of the file is page 1.
736+
// At most 5 pages are supported per request. Pages can be negative.
737+
//
738+
// Page 1 means the first page.
739+
// Page 2 means the second page.
740+
// Page -1 means the last page.
741+
// Page -2 means the second to the last page.
742+
//
743+
// If the file is GIF instead of PDF or TIFF, page refers to GIF frames.
744+
//
745+
// If this field is empty, by default the service performs image annotation
746+
// for the first 5 pages of the file.
747+
repeated int32 pages = 4;
748+
}
749+
750+
// A list of requests to annotate files using the BatchAnnotateFiles API.
751+
message BatchAnnotateFilesRequest {
752+
// The list of file annotation requests. Right now we support only one
753+
// AnnotateFileRequest in BatchAnnotateFilesRequest.
754+
repeated AnnotateFileRequest requests = 1;
755+
}
756+
757+
// A list of file annotation responses.
758+
message BatchAnnotateFilesResponse {
759+
// The list of file annotation responses, each response corresponding to each
760+
// AnnotateFileRequest in BatchAnnotateFilesRequest.
761+
repeated AnnotateFileResponse responses = 1;
762+
}
763+
665764
// An offline file annotation request.
666765
message AsyncAnnotateFileRequest {
667766
// Required. Information about the input file.
@@ -683,6 +782,21 @@ message AsyncAnnotateFileResponse {
683782
OutputConfig output_config = 1;
684783
}
685784

785+
// Request for async image annotation for a list of images.
786+
message AsyncBatchAnnotateImagesRequest {
787+
// Individual image annotation requests for this batch.
788+
repeated AnnotateImageRequest requests = 1;
789+
790+
// Required. The desired output location and metadata (e.g. format).
791+
OutputConfig output_config = 2;
792+
}
793+
794+
// Response to an async batch image annotation request.
795+
message AsyncBatchAnnotateImagesResponse {
796+
// The output location and metadata from AsyncBatchAnnotateImagesRequest.
797+
OutputConfig output_config = 1;
798+
}
799+
686800
// Multiple async file annotation requests are batched into a single service
687801
// call.
688802
message AsyncBatchAnnotateFilesRequest {
@@ -702,6 +816,14 @@ message InputConfig {
702816
// The Google Cloud Storage location to read the input from.
703817
GcsSource gcs_source = 1;
704818

819+
// File content, represented as a stream of bytes.
820+
// Note: As with all `bytes` fields, protobuffers use a pure binary
821+
// representation, whereas JSON representations use base64.
822+
//
823+
// Currently, this field only works for BatchAnnotateFiles requests. It does
824+
// not work for AsyncBatchAnnotateFiles requests.
825+
bytes content = 3;
826+
705827
// The type of the file. Currently only "application/pdf" and "image/tiff"
706828
// are supported. Wildcards are not supported.
707829
string mime_type = 2;
@@ -735,16 +857,23 @@ message GcsSource {
735857

736858
// The Google Cloud Storage location where the output will be written to.
737859
message GcsDestination {
738-
// Google Cloud Storage URI where the results will be stored. Results will
739-
// be in JSON format and preceded by its corresponding input URI. This field
740-
// can either represent a single file, or a prefix for multiple outputs.
741-
// Prefixes must end in a `/`.
860+
// Google Cloud Storage URI prefix where the results will be stored. Results
861+
// will be in JSON format and preceded by its corresponding input URI prefix.
862+
// This field can either represent a gcs file prefix or gcs directory. In
863+
// either case, the uri should be unique because in order to get all of the
864+
// output files, you will need to do a wildcard gcs search on the uri prefix
865+
// you provide.
742866
//
743867
// Examples:
744868
//
745-
// * File: gs://bucket-name/filename.json
746-
// * Prefix: gs://bucket-name/prefix/here/
747-
// * File: gs://bucket-name/prefix/here
869+
// * File Prefix: gs://bucket-name/here/filenameprefix The output files
870+
// will be created in gs://bucket-name/here/ and the names of the
871+
// output files will begin with "filenameprefix".
872+
//
873+
// * Directory Prefix: gs://bucket-name/some/location/ The output files
874+
// will be created in gs://bucket-name/some/location/ and the names of the
875+
// output files could be anything because there was no filename prefix
876+
// specified.
748877
//
749878
// If multiple outputs, each response is still AnnotateFileResponse, each of
750879
// which contains some subset of the full list of AnnotateImageResponse.
@@ -782,25 +911,3 @@ message OperationMetadata {
782911
// The time when the operation result was last updated.
783912
google.protobuf.Timestamp update_time = 6;
784913
}
785-
786-
// A bucketized representation of likelihood, which is intended to give clients
787-
// highly stable results across model upgrades.
788-
enum Likelihood {
789-
// Unknown likelihood.
790-
UNKNOWN = 0;
791-
792-
// It is very unlikely that the image belongs to the specified vertical.
793-
VERY_UNLIKELY = 1;
794-
795-
// It is unlikely that the image belongs to the specified vertical.
796-
UNLIKELY = 2;
797-
798-
// It is possible that the image belongs to the specified vertical.
799-
POSSIBLE = 3;
800-
801-
// It is likely that the image belongs to the specified vertical.
802-
LIKELY = 4;
803-
804-
// It is very likely that the image belongs to the specified vertical.
805-
VERY_LIKELY = 5;
806-
}

protos/google/cloud/vision/v1/product_search.proto

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2018 Google LLC.
1+
// Copyright 2019 Google LLC.
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -49,10 +49,12 @@ message ProductSearchParams {
4949

5050
// The filtering expression. This can be used to restrict search results based
5151
// on Product labels. We currently support an AND of OR of key-value
52-
// expressions, where each expression within an OR must have the same key.
52+
// expressions, where each expression within an OR must have the same key. An
53+
// '=' should be used to connect the key and value.
5354
//
5455
// For example, "(color = red OR color = blue) AND brand = Google" is
55-
// acceptable, but not "(color = red OR brand = Google)" or "color: red".
56+
// acceptable, but "(color = red OR brand = Google)" is not acceptable.
57+
// "color: red" is not acceptable because it uses a ':' instead of an '='.
5658
string filter = 8;
5759
}
5860

@@ -82,8 +84,9 @@ message ProductSearchResults {
8284
repeated Result results = 2;
8385
}
8486

85-
// Timestamp of the index which provided these results. Changes made after
86-
// this time are not reflected in the current results.
87+
// Timestamp of the index which provided these results. Products added to the
88+
// product set and products removed from the product set after this time are
89+
// not reflected in the current results.
8790
google.protobuf.Timestamp index_time = 2;
8891

8992
// List of results, one for each product match.

0 commit comments

Comments
 (0)