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