• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      https://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.automl.v1beta1;
18 
19 import com.google.api.core.BetaApi;
20 import com.google.api.gax.core.BackgroundResource;
21 import com.google.api.gax.httpjson.longrunning.OperationsClient;
22 import com.google.api.gax.longrunning.OperationFuture;
23 import com.google.api.gax.rpc.OperationCallable;
24 import com.google.api.gax.rpc.UnaryCallable;
25 import com.google.cloud.automl.v1beta1.stub.PredictionServiceStub;
26 import com.google.cloud.automl.v1beta1.stub.PredictionServiceStubSettings;
27 import com.google.longrunning.Operation;
28 import java.io.IOException;
29 import java.util.Map;
30 import java.util.concurrent.TimeUnit;
31 import javax.annotation.Generated;
32 
33 // AUTO-GENERATED DOCUMENTATION AND CLASS.
34 /**
35  * Service Description: AutoML Prediction API.
36  *
37  * <p>On any input that is documented to expect a string parameter in snake_case or kebab-case,
38  * either of those cases is accepted.
39  *
40  * <p>This class provides the ability to make remote calls to the backing service through method
41  * calls that map to API methods. Sample code to get started:
42  *
43  * <pre>{@code
44  * // This snippet has been automatically generated and should be regarded as a code template only.
45  * // It will require modifications to work:
46  * // - It may require correct/in-range values for request initialization.
47  * // - It may require specifying regional endpoints when creating the service client as shown in
48  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
49  * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
50  *   ModelName name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]");
51  *   ExamplePayload payload = ExamplePayload.newBuilder().build();
52  *   Map<String, String> params = new HashMap<>();
53  *   PredictResponse response = predictionServiceClient.predict(name, payload, params);
54  * }
55  * }</pre>
56  *
57  * <p>Note: close() needs to be called on the PredictionServiceClient object to clean up resources
58  * such as threads. In the example above, try-with-resources is used, which automatically calls
59  * close().
60  *
61  * <p>The surface of this class includes several types of Java methods for each of the API's
62  * methods:
63  *
64  * <ol>
65  *   <li>A "flattened" method. With this type of method, the fields of the request type have been
66  *       converted into function parameters. It may be the case that not all fields are available as
67  *       parameters, and not every API method will have a flattened method entry point.
68  *   <li>A "request object" method. This type of method only takes one parameter, a request object,
69  *       which must be constructed before the call. Not every API method will have a request object
70  *       method.
71  *   <li>A "callable" method. This type of method takes no parameters and returns an immutable API
72  *       callable object, which can be used to initiate calls to the service.
73  * </ol>
74  *
75  * <p>See the individual methods for example code.
76  *
77  * <p>Many parameters require resource names to be formatted in a particular way. To assist with
78  * these names, this class includes a format method for each type of name, and additionally a parse
79  * method to extract the individual identifiers contained within names that are returned.
80  *
81  * <p>This class can be customized by passing in a custom instance of PredictionServiceSettings to
82  * create(). For example:
83  *
84  * <p>To customize credentials:
85  *
86  * <pre>{@code
87  * // This snippet has been automatically generated and should be regarded as a code template only.
88  * // It will require modifications to work:
89  * // - It may require correct/in-range values for request initialization.
90  * // - It may require specifying regional endpoints when creating the service client as shown in
91  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
92  * PredictionServiceSettings predictionServiceSettings =
93  *     PredictionServiceSettings.newBuilder()
94  *         .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials))
95  *         .build();
96  * PredictionServiceClient predictionServiceClient =
97  *     PredictionServiceClient.create(predictionServiceSettings);
98  * }</pre>
99  *
100  * <p>To customize the endpoint:
101  *
102  * <pre>{@code
103  * // This snippet has been automatically generated and should be regarded as a code template only.
104  * // It will require modifications to work:
105  * // - It may require correct/in-range values for request initialization.
106  * // - It may require specifying regional endpoints when creating the service client as shown in
107  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
108  * PredictionServiceSettings predictionServiceSettings =
109  *     PredictionServiceSettings.newBuilder().setEndpoint(myEndpoint).build();
110  * PredictionServiceClient predictionServiceClient =
111  *     PredictionServiceClient.create(predictionServiceSettings);
112  * }</pre>
113  *
114  * <p>To use REST (HTTP1.1/JSON) transport (instead of gRPC) for sending and receiving requests over
115  * the wire:
116  *
117  * <pre>{@code
118  * // This snippet has been automatically generated and should be regarded as a code template only.
119  * // It will require modifications to work:
120  * // - It may require correct/in-range values for request initialization.
121  * // - It may require specifying regional endpoints when creating the service client as shown in
122  * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
123  * PredictionServiceSettings predictionServiceSettings =
124  *     PredictionServiceSettings.newHttpJsonBuilder().build();
125  * PredictionServiceClient predictionServiceClient =
126  *     PredictionServiceClient.create(predictionServiceSettings);
127  * }</pre>
128  *
129  * <p>Please refer to the GitHub repository's samples for more quickstart code snippets.
130  */
131 @BetaApi
132 @Generated("by gapic-generator-java")
133 public class PredictionServiceClient implements BackgroundResource {
134   private final PredictionServiceSettings settings;
135   private final PredictionServiceStub stub;
136   private final OperationsClient httpJsonOperationsClient;
137   private final com.google.longrunning.OperationsClient operationsClient;
138 
139   /** Constructs an instance of PredictionServiceClient with default settings. */
create()140   public static final PredictionServiceClient create() throws IOException {
141     return create(PredictionServiceSettings.newBuilder().build());
142   }
143 
144   /**
145    * Constructs an instance of PredictionServiceClient, using the given settings. The channels are
146    * created based on the settings passed in, or defaults for any settings that are not set.
147    */
create(PredictionServiceSettings settings)148   public static final PredictionServiceClient create(PredictionServiceSettings settings)
149       throws IOException {
150     return new PredictionServiceClient(settings);
151   }
152 
153   /**
154    * Constructs an instance of PredictionServiceClient, using the given stub for making calls. This
155    * is for advanced usage - prefer using create(PredictionServiceSettings).
156    */
create(PredictionServiceStub stub)157   public static final PredictionServiceClient create(PredictionServiceStub stub) {
158     return new PredictionServiceClient(stub);
159   }
160 
161   /**
162    * Constructs an instance of PredictionServiceClient, using the given settings. This is protected
163    * so that it is easy to make a subclass, but otherwise, the static factory methods should be
164    * preferred.
165    */
PredictionServiceClient(PredictionServiceSettings settings)166   protected PredictionServiceClient(PredictionServiceSettings settings) throws IOException {
167     this.settings = settings;
168     this.stub = ((PredictionServiceStubSettings) settings.getStubSettings()).createStub();
169     this.operationsClient =
170         com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
171     this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
172   }
173 
PredictionServiceClient(PredictionServiceStub stub)174   protected PredictionServiceClient(PredictionServiceStub stub) {
175     this.settings = null;
176     this.stub = stub;
177     this.operationsClient =
178         com.google.longrunning.OperationsClient.create(this.stub.getOperationsStub());
179     this.httpJsonOperationsClient = OperationsClient.create(this.stub.getHttpJsonOperationsStub());
180   }
181 
getSettings()182   public final PredictionServiceSettings getSettings() {
183     return settings;
184   }
185 
getStub()186   public PredictionServiceStub getStub() {
187     return stub;
188   }
189 
190   /**
191    * Returns the OperationsClient that can be used to query the status of a long-running operation
192    * returned by another API method call.
193    */
getOperationsClient()194   public final com.google.longrunning.OperationsClient getOperationsClient() {
195     return operationsClient;
196   }
197 
198   /**
199    * Returns the OperationsClient that can be used to query the status of a long-running operation
200    * returned by another API method call.
201    */
202   @BetaApi
getHttpJsonOperationsClient()203   public final OperationsClient getHttpJsonOperationsClient() {
204     return httpJsonOperationsClient;
205   }
206 
207   // AUTO-GENERATED DOCUMENTATION AND METHOD.
208   /**
209    * Perform an online prediction. The prediction result will be directly returned in the response.
210    * Available for following ML problems, and their expected request payloads:
211    *
212    * <ul>
213    *   <li>Image Classification - Image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
214    *   <li>Image Object Detection - Image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
215    *   <li>Text Classification - TextSnippet, content up to 60,000 characters, UTF-8 encoded.
216    *   <li>Text Extraction - TextSnippet, content up to 30,000 characters, UTF-8 NFC encoded.
217    *   <li>Translation - TextSnippet, content up to 25,000 characters, UTF-8 encoded.
218    *   <li>Tables - Row, with column values matching the columns of the model, up to 5MB. Not
219    *       available for FORECASTING
220    * </ul>
221    *
222    * <p>[prediction_type][google.cloud.automl.v1beta1.TablesModelMetadata.prediction_type].
223    *
224    * <ul>
225    *   <li>Text Sentiment - TextSnippet, content up 500 characters, UTF-8 encoded.
226    * </ul>
227    *
228    * <p>Sample code:
229    *
230    * <pre>{@code
231    * // This snippet has been automatically generated and should be regarded as a code template only.
232    * // It will require modifications to work:
233    * // - It may require correct/in-range values for request initialization.
234    * // - It may require specifying regional endpoints when creating the service client as shown in
235    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
236    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
237    *   ModelName name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]");
238    *   ExamplePayload payload = ExamplePayload.newBuilder().build();
239    *   Map<String, String> params = new HashMap<>();
240    *   PredictResponse response = predictionServiceClient.predict(name, payload, params);
241    * }
242    * }</pre>
243    *
244    * @param name Required. Name of the model requested to serve the prediction.
245    * @param payload Required. Payload to perform a prediction on. The payload must match the problem
246    *     type that the model was trained to solve.
247    * @param params Additional domain-specific parameters, any string must be up to 25000 characters
248    *     long.
249    *     <ul>
250    *       <li>For Image Classification:
251    *     </ul>
252    *     <p>`score_threshold` - (float) A value from 0.0 to 1.0. When the model makes predictions
253    *     for an image, it will only produce results that have at least this confidence score. The
254    *     default is 0.5.
255    *     <p>&#42; For Image Object Detection: `score_threshold` - (float) When Model detects objects
256    *     on the image, it will only produce bounding boxes which have at least this confidence
257    *     score. Value in 0 to 1 range, default is 0.5. `max_bounding_box_count` - (int64) No more
258    *     than this number of bounding boxes will be returned in the response. Default is 100, the
259    *     requested value may be limited by server.
260    *     <ul>
261    *       <li>For Tables: feature_imp&lt;span&gt;ortan&lt;/span&gt;ce - (boolean) Whether feature
262    *           importance should be populated in the returned TablesAnnotation. The default is
263    *           false.
264    *     </ul>
265    *
266    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
267    */
predict( ModelName name, ExamplePayload payload, Map<String, String> params)268   public final PredictResponse predict(
269       ModelName name, ExamplePayload payload, Map<String, String> params) {
270     PredictRequest request =
271         PredictRequest.newBuilder()
272             .setName(name == null ? null : name.toString())
273             .setPayload(payload)
274             .putAllParams(params)
275             .build();
276     return predict(request);
277   }
278 
279   // AUTO-GENERATED DOCUMENTATION AND METHOD.
280   /**
281    * Perform an online prediction. The prediction result will be directly returned in the response.
282    * Available for following ML problems, and their expected request payloads:
283    *
284    * <ul>
285    *   <li>Image Classification - Image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
286    *   <li>Image Object Detection - Image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
287    *   <li>Text Classification - TextSnippet, content up to 60,000 characters, UTF-8 encoded.
288    *   <li>Text Extraction - TextSnippet, content up to 30,000 characters, UTF-8 NFC encoded.
289    *   <li>Translation - TextSnippet, content up to 25,000 characters, UTF-8 encoded.
290    *   <li>Tables - Row, with column values matching the columns of the model, up to 5MB. Not
291    *       available for FORECASTING
292    * </ul>
293    *
294    * <p>[prediction_type][google.cloud.automl.v1beta1.TablesModelMetadata.prediction_type].
295    *
296    * <ul>
297    *   <li>Text Sentiment - TextSnippet, content up 500 characters, UTF-8 encoded.
298    * </ul>
299    *
300    * <p>Sample code:
301    *
302    * <pre>{@code
303    * // This snippet has been automatically generated and should be regarded as a code template only.
304    * // It will require modifications to work:
305    * // - It may require correct/in-range values for request initialization.
306    * // - It may require specifying regional endpoints when creating the service client as shown in
307    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
308    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
309    *   String name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString();
310    *   ExamplePayload payload = ExamplePayload.newBuilder().build();
311    *   Map<String, String> params = new HashMap<>();
312    *   PredictResponse response = predictionServiceClient.predict(name, payload, params);
313    * }
314    * }</pre>
315    *
316    * @param name Required. Name of the model requested to serve the prediction.
317    * @param payload Required. Payload to perform a prediction on. The payload must match the problem
318    *     type that the model was trained to solve.
319    * @param params Additional domain-specific parameters, any string must be up to 25000 characters
320    *     long.
321    *     <ul>
322    *       <li>For Image Classification:
323    *     </ul>
324    *     <p>`score_threshold` - (float) A value from 0.0 to 1.0. When the model makes predictions
325    *     for an image, it will only produce results that have at least this confidence score. The
326    *     default is 0.5.
327    *     <p>&#42; For Image Object Detection: `score_threshold` - (float) When Model detects objects
328    *     on the image, it will only produce bounding boxes which have at least this confidence
329    *     score. Value in 0 to 1 range, default is 0.5. `max_bounding_box_count` - (int64) No more
330    *     than this number of bounding boxes will be returned in the response. Default is 100, the
331    *     requested value may be limited by server.
332    *     <ul>
333    *       <li>For Tables: feature_imp&lt;span&gt;ortan&lt;/span&gt;ce - (boolean) Whether feature
334    *           importance should be populated in the returned TablesAnnotation. The default is
335    *           false.
336    *     </ul>
337    *
338    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
339    */
predict( String name, ExamplePayload payload, Map<String, String> params)340   public final PredictResponse predict(
341       String name, ExamplePayload payload, Map<String, String> params) {
342     PredictRequest request =
343         PredictRequest.newBuilder().setName(name).setPayload(payload).putAllParams(params).build();
344     return predict(request);
345   }
346 
347   // AUTO-GENERATED DOCUMENTATION AND METHOD.
348   /**
349    * Perform an online prediction. The prediction result will be directly returned in the response.
350    * Available for following ML problems, and their expected request payloads:
351    *
352    * <ul>
353    *   <li>Image Classification - Image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
354    *   <li>Image Object Detection - Image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
355    *   <li>Text Classification - TextSnippet, content up to 60,000 characters, UTF-8 encoded.
356    *   <li>Text Extraction - TextSnippet, content up to 30,000 characters, UTF-8 NFC encoded.
357    *   <li>Translation - TextSnippet, content up to 25,000 characters, UTF-8 encoded.
358    *   <li>Tables - Row, with column values matching the columns of the model, up to 5MB. Not
359    *       available for FORECASTING
360    * </ul>
361    *
362    * <p>[prediction_type][google.cloud.automl.v1beta1.TablesModelMetadata.prediction_type].
363    *
364    * <ul>
365    *   <li>Text Sentiment - TextSnippet, content up 500 characters, UTF-8 encoded.
366    * </ul>
367    *
368    * <p>Sample code:
369    *
370    * <pre>{@code
371    * // This snippet has been automatically generated and should be regarded as a code template only.
372    * // It will require modifications to work:
373    * // - It may require correct/in-range values for request initialization.
374    * // - It may require specifying regional endpoints when creating the service client as shown in
375    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
376    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
377    *   PredictRequest request =
378    *       PredictRequest.newBuilder()
379    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
380    *           .setPayload(ExamplePayload.newBuilder().build())
381    *           .putAllParams(new HashMap<String, String>())
382    *           .build();
383    *   PredictResponse response = predictionServiceClient.predict(request);
384    * }
385    * }</pre>
386    *
387    * @param request The request object containing all of the parameters for the API call.
388    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
389    */
predict(PredictRequest request)390   public final PredictResponse predict(PredictRequest request) {
391     return predictCallable().call(request);
392   }
393 
394   // AUTO-GENERATED DOCUMENTATION AND METHOD.
395   /**
396    * Perform an online prediction. The prediction result will be directly returned in the response.
397    * Available for following ML problems, and their expected request payloads:
398    *
399    * <ul>
400    *   <li>Image Classification - Image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
401    *   <li>Image Object Detection - Image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.
402    *   <li>Text Classification - TextSnippet, content up to 60,000 characters, UTF-8 encoded.
403    *   <li>Text Extraction - TextSnippet, content up to 30,000 characters, UTF-8 NFC encoded.
404    *   <li>Translation - TextSnippet, content up to 25,000 characters, UTF-8 encoded.
405    *   <li>Tables - Row, with column values matching the columns of the model, up to 5MB. Not
406    *       available for FORECASTING
407    * </ul>
408    *
409    * <p>[prediction_type][google.cloud.automl.v1beta1.TablesModelMetadata.prediction_type].
410    *
411    * <ul>
412    *   <li>Text Sentiment - TextSnippet, content up 500 characters, UTF-8 encoded.
413    * </ul>
414    *
415    * <p>Sample code:
416    *
417    * <pre>{@code
418    * // This snippet has been automatically generated and should be regarded as a code template only.
419    * // It will require modifications to work:
420    * // - It may require correct/in-range values for request initialization.
421    * // - It may require specifying regional endpoints when creating the service client as shown in
422    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
423    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
424    *   PredictRequest request =
425    *       PredictRequest.newBuilder()
426    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
427    *           .setPayload(ExamplePayload.newBuilder().build())
428    *           .putAllParams(new HashMap<String, String>())
429    *           .build();
430    *   ApiFuture<PredictResponse> future =
431    *       predictionServiceClient.predictCallable().futureCall(request);
432    *   // Do something.
433    *   PredictResponse response = future.get();
434    * }
435    * }</pre>
436    */
predictCallable()437   public final UnaryCallable<PredictRequest, PredictResponse> predictCallable() {
438     return stub.predictCallable();
439   }
440 
441   // AUTO-GENERATED DOCUMENTATION AND METHOD.
442   /**
443    * Perform a batch prediction. Unlike the online
444    * [Predict][google.cloud.automl.v1beta1.PredictionService.Predict], batch prediction result won't
445    * be immediately available in the response. Instead, a long running operation object is returned.
446    * User can poll the operation result via
447    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
448    * [BatchPredictResult][google.cloud.automl.v1beta1.BatchPredictResult] is returned in the
449    * [response][google.longrunning.Operation.response] field. Available for following ML problems:
450    *
451    * <ul>
452    *   <li>Image Classification
453    *   <li>Image Object Detection
454    *   <li>Video Classification
455    *   <li>Video Object Tracking &#42; Text Extraction
456    *   <li>Tables
457    * </ul>
458    *
459    * <p>Sample code:
460    *
461    * <pre>{@code
462    * // This snippet has been automatically generated and should be regarded as a code template only.
463    * // It will require modifications to work:
464    * // - It may require correct/in-range values for request initialization.
465    * // - It may require specifying regional endpoints when creating the service client as shown in
466    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
467    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
468    *   ModelName name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]");
469    *   BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().build();
470    *   BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().build();
471    *   Map<String, String> params = new HashMap<>();
472    *   BatchPredictResult response =
473    *       predictionServiceClient.batchPredictAsync(name, inputConfig, outputConfig, params).get();
474    * }
475    * }</pre>
476    *
477    * @param name Required. Name of the model requested to serve the batch prediction.
478    * @param inputConfig Required. The input configuration for batch prediction.
479    * @param outputConfig Required. The Configuration specifying where output predictions should be
480    *     written.
481    * @param params Required. Additional domain-specific parameters for the predictions, any string
482    *     must be up to 25000 characters long.
483    *     <ul>
484    *       <li>For Text Classification:
485    *     </ul>
486    *     <p>`score_threshold` - (float) A value from 0.0 to 1.0. When the model makes predictions
487    *     for a text snippet, it will only produce results that have at least this confidence score.
488    *     The default is 0.5.
489    *     <ul>
490    *       <li>For Image Classification:
491    *     </ul>
492    *     <p>`score_threshold` - (float) A value from 0.0 to 1.0. When the model makes predictions
493    *     for an image, it will only produce results that have at least this confidence score. The
494    *     default is 0.5.
495    *     <ul>
496    *       <li>For Image Object Detection:
497    *     </ul>
498    *     <p>`score_threshold` - (float) When Model detects objects on the image, it will only
499    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
500    *     default is 0.5. `max_bounding_box_count` - (int64) No more than this number of bounding
501    *     boxes will be produced per image. Default is 100, the requested value may be limited by
502    *     server.
503    *     <ul>
504    *       <li>For Video Classification :
505    *     </ul>
506    *     <p>`score_threshold` - (float) A value from 0.0 to 1.0. When the model makes predictions
507    *     for a video, it will only produce results that have at least this confidence score. The
508    *     default is 0.5. `segment_classification` - (boolean) Set to true to request segment-level
509    *     classification. AutoML Video Intelligence returns labels and their confidence scores for
510    *     the entire segment of the video that user specified in the request configuration. The
511    *     default is "true". `shot_classification` - (boolean) Set to true to request shot-level
512    *     classification. AutoML Video Intelligence determines the boundaries for each camera shot in
513    *     the entire segment of the video that user specified in the request configuration. AutoML
514    *     Video Intelligence then returns labels and their confidence scores for each detected shot,
515    *     along with the start and end time of the shot. WARNING: Model evaluation is not done for
516    *     this classification type, the quality of it depends on training data, but there are no
517    *     metrics provided to describe that quality. The default is "false".
518    *     `1s_interval_classification` - (boolean) Set to true to request classification for a video
519    *     at one-second intervals. AutoML Video Intelligence returns labels and their confidence
520    *     scores for each second of the entire segment of the video that user specified in the
521    *     request configuration. WARNING: Model evaluation is not done for this classification type,
522    *     the quality of it depends on training data, but there are no metrics provided to describe
523    *     that quality. The default is "false".
524    *     <ul>
525    *       <li>For Tables:
526    *     </ul>
527    *     <p>feature_imp&lt;span&gt;ortan&lt;/span&gt;ce - (boolean) Whether feature importance
528    *     should be populated in the returned TablesAnnotations. The default is false.
529    *     <ul>
530    *       <li>For Video Object Tracking:
531    *     </ul>
532    *     <p>`score_threshold` - (float) When Model detects objects on video frames, it will only
533    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
534    *     default is 0.5. `max_bounding_box_count` - (int64) No more than this number of bounding
535    *     boxes will be returned per frame. Default is 100, the requested value may be limited by
536    *     server. `min_bounding_box_size` - (float) Only bounding boxes with shortest edge at least
537    *     that long as a relative value of video frame size will be returned. Value in 0 to 1 range.
538    *     Default is 0.
539    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
540    */
batchPredictAsync( ModelName name, BatchPredictInputConfig inputConfig, BatchPredictOutputConfig outputConfig, Map<String, String> params)541   public final OperationFuture<BatchPredictResult, OperationMetadata> batchPredictAsync(
542       ModelName name,
543       BatchPredictInputConfig inputConfig,
544       BatchPredictOutputConfig outputConfig,
545       Map<String, String> params) {
546     BatchPredictRequest request =
547         BatchPredictRequest.newBuilder()
548             .setName(name == null ? null : name.toString())
549             .setInputConfig(inputConfig)
550             .setOutputConfig(outputConfig)
551             .putAllParams(params)
552             .build();
553     return batchPredictAsync(request);
554   }
555 
556   // AUTO-GENERATED DOCUMENTATION AND METHOD.
557   /**
558    * Perform a batch prediction. Unlike the online
559    * [Predict][google.cloud.automl.v1beta1.PredictionService.Predict], batch prediction result won't
560    * be immediately available in the response. Instead, a long running operation object is returned.
561    * User can poll the operation result via
562    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
563    * [BatchPredictResult][google.cloud.automl.v1beta1.BatchPredictResult] is returned in the
564    * [response][google.longrunning.Operation.response] field. Available for following ML problems:
565    *
566    * <ul>
567    *   <li>Image Classification
568    *   <li>Image Object Detection
569    *   <li>Video Classification
570    *   <li>Video Object Tracking &#42; Text Extraction
571    *   <li>Tables
572    * </ul>
573    *
574    * <p>Sample code:
575    *
576    * <pre>{@code
577    * // This snippet has been automatically generated and should be regarded as a code template only.
578    * // It will require modifications to work:
579    * // - It may require correct/in-range values for request initialization.
580    * // - It may require specifying regional endpoints when creating the service client as shown in
581    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
582    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
583    *   String name = ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString();
584    *   BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().build();
585    *   BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().build();
586    *   Map<String, String> params = new HashMap<>();
587    *   BatchPredictResult response =
588    *       predictionServiceClient.batchPredictAsync(name, inputConfig, outputConfig, params).get();
589    * }
590    * }</pre>
591    *
592    * @param name Required. Name of the model requested to serve the batch prediction.
593    * @param inputConfig Required. The input configuration for batch prediction.
594    * @param outputConfig Required. The Configuration specifying where output predictions should be
595    *     written.
596    * @param params Required. Additional domain-specific parameters for the predictions, any string
597    *     must be up to 25000 characters long.
598    *     <ul>
599    *       <li>For Text Classification:
600    *     </ul>
601    *     <p>`score_threshold` - (float) A value from 0.0 to 1.0. When the model makes predictions
602    *     for a text snippet, it will only produce results that have at least this confidence score.
603    *     The default is 0.5.
604    *     <ul>
605    *       <li>For Image Classification:
606    *     </ul>
607    *     <p>`score_threshold` - (float) A value from 0.0 to 1.0. When the model makes predictions
608    *     for an image, it will only produce results that have at least this confidence score. The
609    *     default is 0.5.
610    *     <ul>
611    *       <li>For Image Object Detection:
612    *     </ul>
613    *     <p>`score_threshold` - (float) When Model detects objects on the image, it will only
614    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
615    *     default is 0.5. `max_bounding_box_count` - (int64) No more than this number of bounding
616    *     boxes will be produced per image. Default is 100, the requested value may be limited by
617    *     server.
618    *     <ul>
619    *       <li>For Video Classification :
620    *     </ul>
621    *     <p>`score_threshold` - (float) A value from 0.0 to 1.0. When the model makes predictions
622    *     for a video, it will only produce results that have at least this confidence score. The
623    *     default is 0.5. `segment_classification` - (boolean) Set to true to request segment-level
624    *     classification. AutoML Video Intelligence returns labels and their confidence scores for
625    *     the entire segment of the video that user specified in the request configuration. The
626    *     default is "true". `shot_classification` - (boolean) Set to true to request shot-level
627    *     classification. AutoML Video Intelligence determines the boundaries for each camera shot in
628    *     the entire segment of the video that user specified in the request configuration. AutoML
629    *     Video Intelligence then returns labels and their confidence scores for each detected shot,
630    *     along with the start and end time of the shot. WARNING: Model evaluation is not done for
631    *     this classification type, the quality of it depends on training data, but there are no
632    *     metrics provided to describe that quality. The default is "false".
633    *     `1s_interval_classification` - (boolean) Set to true to request classification for a video
634    *     at one-second intervals. AutoML Video Intelligence returns labels and their confidence
635    *     scores for each second of the entire segment of the video that user specified in the
636    *     request configuration. WARNING: Model evaluation is not done for this classification type,
637    *     the quality of it depends on training data, but there are no metrics provided to describe
638    *     that quality. The default is "false".
639    *     <ul>
640    *       <li>For Tables:
641    *     </ul>
642    *     <p>feature_imp&lt;span&gt;ortan&lt;/span&gt;ce - (boolean) Whether feature importance
643    *     should be populated in the returned TablesAnnotations. The default is false.
644    *     <ul>
645    *       <li>For Video Object Tracking:
646    *     </ul>
647    *     <p>`score_threshold` - (float) When Model detects objects on video frames, it will only
648    *     produce bounding boxes which have at least this confidence score. Value in 0 to 1 range,
649    *     default is 0.5. `max_bounding_box_count` - (int64) No more than this number of bounding
650    *     boxes will be returned per frame. Default is 100, the requested value may be limited by
651    *     server. `min_bounding_box_size` - (float) Only bounding boxes with shortest edge at least
652    *     that long as a relative value of video frame size will be returned. Value in 0 to 1 range.
653    *     Default is 0.
654    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
655    */
batchPredictAsync( String name, BatchPredictInputConfig inputConfig, BatchPredictOutputConfig outputConfig, Map<String, String> params)656   public final OperationFuture<BatchPredictResult, OperationMetadata> batchPredictAsync(
657       String name,
658       BatchPredictInputConfig inputConfig,
659       BatchPredictOutputConfig outputConfig,
660       Map<String, String> params) {
661     BatchPredictRequest request =
662         BatchPredictRequest.newBuilder()
663             .setName(name)
664             .setInputConfig(inputConfig)
665             .setOutputConfig(outputConfig)
666             .putAllParams(params)
667             .build();
668     return batchPredictAsync(request);
669   }
670 
671   // AUTO-GENERATED DOCUMENTATION AND METHOD.
672   /**
673    * Perform a batch prediction. Unlike the online
674    * [Predict][google.cloud.automl.v1beta1.PredictionService.Predict], batch prediction result won't
675    * be immediately available in the response. Instead, a long running operation object is returned.
676    * User can poll the operation result via
677    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
678    * [BatchPredictResult][google.cloud.automl.v1beta1.BatchPredictResult] is returned in the
679    * [response][google.longrunning.Operation.response] field. Available for following ML problems:
680    *
681    * <ul>
682    *   <li>Image Classification
683    *   <li>Image Object Detection
684    *   <li>Video Classification
685    *   <li>Video Object Tracking &#42; Text Extraction
686    *   <li>Tables
687    * </ul>
688    *
689    * <p>Sample code:
690    *
691    * <pre>{@code
692    * // This snippet has been automatically generated and should be regarded as a code template only.
693    * // It will require modifications to work:
694    * // - It may require correct/in-range values for request initialization.
695    * // - It may require specifying regional endpoints when creating the service client as shown in
696    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
697    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
698    *   BatchPredictRequest request =
699    *       BatchPredictRequest.newBuilder()
700    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
701    *           .setInputConfig(BatchPredictInputConfig.newBuilder().build())
702    *           .setOutputConfig(BatchPredictOutputConfig.newBuilder().build())
703    *           .putAllParams(new HashMap<String, String>())
704    *           .build();
705    *   BatchPredictResult response = predictionServiceClient.batchPredictAsync(request).get();
706    * }
707    * }</pre>
708    *
709    * @param request The request object containing all of the parameters for the API call.
710    * @throws com.google.api.gax.rpc.ApiException if the remote call fails
711    */
batchPredictAsync( BatchPredictRequest request)712   public final OperationFuture<BatchPredictResult, OperationMetadata> batchPredictAsync(
713       BatchPredictRequest request) {
714     return batchPredictOperationCallable().futureCall(request);
715   }
716 
717   // AUTO-GENERATED DOCUMENTATION AND METHOD.
718   /**
719    * Perform a batch prediction. Unlike the online
720    * [Predict][google.cloud.automl.v1beta1.PredictionService.Predict], batch prediction result won't
721    * be immediately available in the response. Instead, a long running operation object is returned.
722    * User can poll the operation result via
723    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
724    * [BatchPredictResult][google.cloud.automl.v1beta1.BatchPredictResult] is returned in the
725    * [response][google.longrunning.Operation.response] field. Available for following ML problems:
726    *
727    * <ul>
728    *   <li>Image Classification
729    *   <li>Image Object Detection
730    *   <li>Video Classification
731    *   <li>Video Object Tracking &#42; Text Extraction
732    *   <li>Tables
733    * </ul>
734    *
735    * <p>Sample code:
736    *
737    * <pre>{@code
738    * // This snippet has been automatically generated and should be regarded as a code template only.
739    * // It will require modifications to work:
740    * // - It may require correct/in-range values for request initialization.
741    * // - It may require specifying regional endpoints when creating the service client as shown in
742    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
743    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
744    *   BatchPredictRequest request =
745    *       BatchPredictRequest.newBuilder()
746    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
747    *           .setInputConfig(BatchPredictInputConfig.newBuilder().build())
748    *           .setOutputConfig(BatchPredictOutputConfig.newBuilder().build())
749    *           .putAllParams(new HashMap<String, String>())
750    *           .build();
751    *   OperationFuture<BatchPredictResult, OperationMetadata> future =
752    *       predictionServiceClient.batchPredictOperationCallable().futureCall(request);
753    *   // Do something.
754    *   BatchPredictResult response = future.get();
755    * }
756    * }</pre>
757    */
758   public final OperationCallable<BatchPredictRequest, BatchPredictResult, OperationMetadata>
batchPredictOperationCallable()759       batchPredictOperationCallable() {
760     return stub.batchPredictOperationCallable();
761   }
762 
763   // AUTO-GENERATED DOCUMENTATION AND METHOD.
764   /**
765    * Perform a batch prediction. Unlike the online
766    * [Predict][google.cloud.automl.v1beta1.PredictionService.Predict], batch prediction result won't
767    * be immediately available in the response. Instead, a long running operation object is returned.
768    * User can poll the operation result via
769    * [GetOperation][google.longrunning.Operations.GetOperation] method. Once the operation is done,
770    * [BatchPredictResult][google.cloud.automl.v1beta1.BatchPredictResult] is returned in the
771    * [response][google.longrunning.Operation.response] field. Available for following ML problems:
772    *
773    * <ul>
774    *   <li>Image Classification
775    *   <li>Image Object Detection
776    *   <li>Video Classification
777    *   <li>Video Object Tracking &#42; Text Extraction
778    *   <li>Tables
779    * </ul>
780    *
781    * <p>Sample code:
782    *
783    * <pre>{@code
784    * // This snippet has been automatically generated and should be regarded as a code template only.
785    * // It will require modifications to work:
786    * // - It may require correct/in-range values for request initialization.
787    * // - It may require specifying regional endpoints when creating the service client as shown in
788    * // https://cloud.google.com/java/docs/setup#configure_endpoints_for_the_client_library
789    * try (PredictionServiceClient predictionServiceClient = PredictionServiceClient.create()) {
790    *   BatchPredictRequest request =
791    *       BatchPredictRequest.newBuilder()
792    *           .setName(ModelName.of("[PROJECT]", "[LOCATION]", "[MODEL]").toString())
793    *           .setInputConfig(BatchPredictInputConfig.newBuilder().build())
794    *           .setOutputConfig(BatchPredictOutputConfig.newBuilder().build())
795    *           .putAllParams(new HashMap<String, String>())
796    *           .build();
797    *   ApiFuture<Operation> future =
798    *       predictionServiceClient.batchPredictCallable().futureCall(request);
799    *   // Do something.
800    *   Operation response = future.get();
801    * }
802    * }</pre>
803    */
batchPredictCallable()804   public final UnaryCallable<BatchPredictRequest, Operation> batchPredictCallable() {
805     return stub.batchPredictCallable();
806   }
807 
808   @Override
close()809   public final void close() {
810     stub.close();
811   }
812 
813   @Override
shutdown()814   public void shutdown() {
815     stub.shutdown();
816   }
817 
818   @Override
isShutdown()819   public boolean isShutdown() {
820     return stub.isShutdown();
821   }
822 
823   @Override
isTerminated()824   public boolean isTerminated() {
825     return stub.isTerminated();
826   }
827 
828   @Override
shutdownNow()829   public void shutdownNow() {
830     stub.shutdownNow();
831   }
832 
833   @Override
awaitTermination(long duration, TimeUnit unit)834   public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException {
835     return stub.awaitTermination(duration, unit);
836   }
837 }
838