google-cloud-automl 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +11 -0
- data/AUTHENTICATION.md +199 -0
- data/LICENSE +201 -0
- data/README.md +69 -0
- data/lib/google/cloud/automl/v1beta1/annotation_payload_pb.rb +34 -0
- data/lib/google/cloud/automl/v1beta1/annotation_spec_pb.rb +18 -0
- data/lib/google/cloud/automl/v1beta1/automl_client.rb +1914 -0
- data/lib/google/cloud/automl/v1beta1/automl_client_config.json +146 -0
- data/lib/google/cloud/automl/v1beta1/classification_pb.rb +65 -0
- data/lib/google/cloud/automl/v1beta1/column_spec_pb.rb +28 -0
- data/lib/google/cloud/automl/v1beta1/credentials.rb +41 -0
- data/lib/google/cloud/automl/v1beta1/data_items_pb.rb +48 -0
- data/lib/google/cloud/automl/v1beta1/data_stats_pb.rb +77 -0
- data/lib/google/cloud/automl/v1beta1/data_types_pb.rb +36 -0
- data/lib/google/cloud/automl/v1beta1/dataset_pb.rb +38 -0
- data/lib/google/cloud/automl/v1beta1/detection_pb.rb +52 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/annotation_payload.rb +63 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/annotation_spec.rb +41 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/classification.rb +203 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/column_spec.rb +72 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/data_items.rb +94 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/data_stats.rb +160 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/data_types.rb +107 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/dataset.rb +77 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/detection.rb +134 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/geometry.rb +43 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/image.rb +141 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/io.rb +975 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/model.rb +92 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/model_evaluation.rb +100 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/prediction_service.rb +136 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/ranges.rb +31 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/regression.rb +41 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/service.rb +368 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/table_spec.rb +64 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/tables.rb +261 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/temporal.rb +33 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/text.rb +53 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/text_extraction.rb +60 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/text_segment.rb +37 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/text_sentiment.rb +76 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/translation.rb +63 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/cloud/automl/v1beta1/video.rb +35 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/longrunning/operations.rb +51 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/protobuf/duration.rb +91 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/protobuf/field_mask.rb +222 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/protobuf/struct.rb +74 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/protobuf/timestamp.rb +111 -0
- data/lib/google/cloud/automl/v1beta1/doc/google/rpc/status.rb +87 -0
- data/lib/google/cloud/automl/v1beta1/geometry_pb.rb +21 -0
- data/lib/google/cloud/automl/v1beta1/image_pb.rb +43 -0
- data/lib/google/cloud/automl/v1beta1/io_pb.rb +80 -0
- data/lib/google/cloud/automl/v1beta1/model_evaluation_pb.rb +37 -0
- data/lib/google/cloud/automl/v1beta1/model_pb.rb +44 -0
- data/lib/google/cloud/automl/v1beta1/operations_pb.rb +90 -0
- data/lib/google/cloud/automl/v1beta1/prediction_service_client.rb +442 -0
- data/lib/google/cloud/automl/v1beta1/prediction_service_client_config.json +36 -0
- data/lib/google/cloud/automl/v1beta1/prediction_service_pb.rb +39 -0
- data/lib/google/cloud/automl/v1beta1/prediction_service_services_pb.rb +72 -0
- data/lib/google/cloud/automl/v1beta1/ranges_pb.rb +17 -0
- data/lib/google/cloud/automl/v1beta1/regression_pb.rb +20 -0
- data/lib/google/cloud/automl/v1beta1/service_pb.rb +177 -0
- data/lib/google/cloud/automl/v1beta1/service_services_pb.rb +159 -0
- data/lib/google/cloud/automl/v1beta1/table_spec_pb.rb +22 -0
- data/lib/google/cloud/automl/v1beta1/tables_pb.rb +56 -0
- data/lib/google/cloud/automl/v1beta1/temporal_pb.rb +18 -0
- data/lib/google/cloud/automl/v1beta1/text_extraction_pb.rb +32 -0
- data/lib/google/cloud/automl/v1beta1/text_pb.rb +33 -0
- data/lib/google/cloud/automl/v1beta1/text_segment_pb.rb +18 -0
- data/lib/google/cloud/automl/v1beta1/text_sentiment_pb.rb +29 -0
- data/lib/google/cloud/automl/v1beta1/translation_pb.rb +33 -0
- data/lib/google/cloud/automl/v1beta1/video_pb.rb +25 -0
- data/lib/google/cloud/automl/v1beta1.rb +231 -0
- data/lib/google/cloud/automl/version.rb +22 -0
- data/lib/google/cloud/automl.rb +219 -0
- data/lib/google-cloud-automl.rb +15 -0
- metadata +203 -0
@@ -0,0 +1,442 @@
|
|
1
|
+
# Copyright 2019 Google LLC
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
#
|
15
|
+
# EDITING INSTRUCTIONS
|
16
|
+
# This file was generated from the file
|
17
|
+
# https://github.com/googleapis/googleapis/blob/master/google/cloud/automl/v1beta1/prediction_service.proto,
|
18
|
+
# and updates to that file get reflected here through a refresh process.
|
19
|
+
# For the short term, the refresh process will only be runnable by Google
|
20
|
+
# engineers.
|
21
|
+
|
22
|
+
|
23
|
+
require "json"
|
24
|
+
require "pathname"
|
25
|
+
|
26
|
+
require "google/gax"
|
27
|
+
require "google/gax/operation"
|
28
|
+
require "google/longrunning/operations_client"
|
29
|
+
|
30
|
+
require "google/cloud/automl/v1beta1/prediction_service_pb"
|
31
|
+
require "google/cloud/automl/v1beta1/credentials"
|
32
|
+
require "google/cloud/automl/version"
|
33
|
+
|
34
|
+
module Google
|
35
|
+
module Cloud
|
36
|
+
module AutoML
|
37
|
+
module V1beta1
|
38
|
+
# AutoML Prediction API.
|
39
|
+
#
|
40
|
+
# On any input that is documented to expect a string parameter in
|
41
|
+
# snake_case or kebab-case, either of those cases is accepted.
|
42
|
+
#
|
43
|
+
# @!attribute [r] prediction_service_stub
|
44
|
+
# @return [Google::Cloud::AutoML::V1beta1::PredictionService::Stub]
|
45
|
+
class PredictionServiceClient
|
46
|
+
# @private
|
47
|
+
attr_reader :prediction_service_stub
|
48
|
+
|
49
|
+
# The default address of the service.
|
50
|
+
SERVICE_ADDRESS = "automl.googleapis.com".freeze
|
51
|
+
|
52
|
+
# The default port of the service.
|
53
|
+
DEFAULT_SERVICE_PORT = 443
|
54
|
+
|
55
|
+
# The default set of gRPC interceptors.
|
56
|
+
GRPC_INTERCEPTORS = []
|
57
|
+
|
58
|
+
DEFAULT_TIMEOUT = 30
|
59
|
+
|
60
|
+
# The scopes needed to make gRPC calls to all of the methods defined in
|
61
|
+
# this service.
|
62
|
+
ALL_SCOPES = [
|
63
|
+
"https://www.googleapis.com/auth/cloud-platform"
|
64
|
+
].freeze
|
65
|
+
|
66
|
+
class OperationsClient < Google::Longrunning::OperationsClient
|
67
|
+
self::SERVICE_ADDRESS = PredictionServiceClient::SERVICE_ADDRESS
|
68
|
+
self::GRPC_INTERCEPTORS = PredictionServiceClient::GRPC_INTERCEPTORS
|
69
|
+
end
|
70
|
+
|
71
|
+
MODEL_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
|
72
|
+
"projects/{project}/locations/{location}/models/{model}"
|
73
|
+
)
|
74
|
+
|
75
|
+
private_constant :MODEL_PATH_TEMPLATE
|
76
|
+
|
77
|
+
# Returns a fully-qualified model resource name string.
|
78
|
+
# @param project [String]
|
79
|
+
# @param location [String]
|
80
|
+
# @param model [String]
|
81
|
+
# @return [String]
|
82
|
+
def self.model_path project, location, model
|
83
|
+
MODEL_PATH_TEMPLATE.render(
|
84
|
+
:"project" => project,
|
85
|
+
:"location" => location,
|
86
|
+
:"model" => model
|
87
|
+
)
|
88
|
+
end
|
89
|
+
|
90
|
+
# @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
|
91
|
+
# Provides the means for authenticating requests made by the client. This parameter can
|
92
|
+
# be many types.
|
93
|
+
# A `Google::Auth::Credentials` uses a the properties of its represented keyfile for
|
94
|
+
# authenticating requests made by this client.
|
95
|
+
# A `String` will be treated as the path to the keyfile to be used for the construction of
|
96
|
+
# credentials for this client.
|
97
|
+
# A `Hash` will be treated as the contents of a keyfile to be used for the construction of
|
98
|
+
# credentials for this client.
|
99
|
+
# A `GRPC::Core::Channel` will be used to make calls through.
|
100
|
+
# A `GRPC::Core::ChannelCredentials` for the setting up the RPC client. The channel credentials
|
101
|
+
# should already be composed with a `GRPC::Core::CallCredentials` object.
|
102
|
+
# A `Proc` will be used as an updater_proc for the Grpc channel. The proc transforms the
|
103
|
+
# metadata for requests, generally, to give OAuth credentials.
|
104
|
+
# @param scopes [Array<String>]
|
105
|
+
# The OAuth scopes for this service. This parameter is ignored if
|
106
|
+
# an updater_proc is supplied.
|
107
|
+
# @param client_config [Hash]
|
108
|
+
# A Hash for call options for each method. See
|
109
|
+
# Google::Gax#construct_settings for the structure of
|
110
|
+
# this data. Falls back to the default config if not specified
|
111
|
+
# or the specified config is missing data points.
|
112
|
+
# @param timeout [Numeric]
|
113
|
+
# The default timeout, in seconds, for calls made through this client.
|
114
|
+
# @param metadata [Hash]
|
115
|
+
# Default metadata to be sent with each request. This can be overridden on a per call basis.
|
116
|
+
# @param service_address [String]
|
117
|
+
# Override for the service hostname, or `nil` to leave as the default.
|
118
|
+
# @param service_port [Integer]
|
119
|
+
# Override for the service port, or `nil` to leave as the default.
|
120
|
+
# @param exception_transformer [Proc]
|
121
|
+
# An optional proc that intercepts any exceptions raised during an API call to inject
|
122
|
+
# custom error handling.
|
123
|
+
def initialize \
|
124
|
+
credentials: nil,
|
125
|
+
scopes: ALL_SCOPES,
|
126
|
+
client_config: {},
|
127
|
+
timeout: DEFAULT_TIMEOUT,
|
128
|
+
metadata: nil,
|
129
|
+
service_address: nil,
|
130
|
+
service_port: nil,
|
131
|
+
exception_transformer: nil,
|
132
|
+
lib_name: nil,
|
133
|
+
lib_version: ""
|
134
|
+
# These require statements are intentionally placed here to initialize
|
135
|
+
# the gRPC module only when it's required.
|
136
|
+
# See https://github.com/googleapis/toolkit/issues/446
|
137
|
+
require "google/gax/grpc"
|
138
|
+
require "google/cloud/automl/v1beta1/prediction_service_services_pb"
|
139
|
+
|
140
|
+
credentials ||= Google::Cloud::AutoML::V1beta1::Credentials.default
|
141
|
+
|
142
|
+
@operations_client = OperationsClient.new(
|
143
|
+
credentials: credentials,
|
144
|
+
scopes: scopes,
|
145
|
+
client_config: client_config,
|
146
|
+
timeout: timeout,
|
147
|
+
lib_name: lib_name,
|
148
|
+
service_address: service_address,
|
149
|
+
service_port: service_port,
|
150
|
+
lib_version: lib_version,
|
151
|
+
metadata: metadata,
|
152
|
+
)
|
153
|
+
|
154
|
+
if credentials.is_a?(String) || credentials.is_a?(Hash)
|
155
|
+
updater_proc = Google::Cloud::AutoML::V1beta1::Credentials.new(credentials).updater_proc
|
156
|
+
end
|
157
|
+
if credentials.is_a?(GRPC::Core::Channel)
|
158
|
+
channel = credentials
|
159
|
+
end
|
160
|
+
if credentials.is_a?(GRPC::Core::ChannelCredentials)
|
161
|
+
chan_creds = credentials
|
162
|
+
end
|
163
|
+
if credentials.is_a?(Proc)
|
164
|
+
updater_proc = credentials
|
165
|
+
end
|
166
|
+
if credentials.is_a?(Google::Auth::Credentials)
|
167
|
+
updater_proc = credentials.updater_proc
|
168
|
+
end
|
169
|
+
|
170
|
+
package_version = Google::Cloud::AutoML::VERSION
|
171
|
+
|
172
|
+
google_api_client = "gl-ruby/#{RUBY_VERSION}"
|
173
|
+
google_api_client << " #{lib_name}/#{lib_version}" if lib_name
|
174
|
+
google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}"
|
175
|
+
google_api_client << " grpc/#{GRPC::VERSION}"
|
176
|
+
google_api_client.freeze
|
177
|
+
|
178
|
+
headers = { :"x-goog-api-client" => google_api_client }
|
179
|
+
headers.merge!(metadata) unless metadata.nil?
|
180
|
+
client_config_file = Pathname.new(__dir__).join(
|
181
|
+
"prediction_service_client_config.json"
|
182
|
+
)
|
183
|
+
defaults = client_config_file.open do |f|
|
184
|
+
Google::Gax.construct_settings(
|
185
|
+
"google.cloud.automl.v1beta1.PredictionService",
|
186
|
+
JSON.parse(f.read),
|
187
|
+
client_config,
|
188
|
+
Google::Gax::Grpc::STATUS_CODE_NAMES,
|
189
|
+
timeout,
|
190
|
+
errors: Google::Gax::Grpc::API_ERRORS,
|
191
|
+
metadata: headers
|
192
|
+
)
|
193
|
+
end
|
194
|
+
|
195
|
+
# Allow overriding the service path/port in subclasses.
|
196
|
+
service_path = service_address || self.class::SERVICE_ADDRESS
|
197
|
+
port = service_port || self.class::DEFAULT_SERVICE_PORT
|
198
|
+
interceptors = self.class::GRPC_INTERCEPTORS
|
199
|
+
@prediction_service_stub = Google::Gax::Grpc.create_stub(
|
200
|
+
service_path,
|
201
|
+
port,
|
202
|
+
chan_creds: chan_creds,
|
203
|
+
channel: channel,
|
204
|
+
updater_proc: updater_proc,
|
205
|
+
scopes: scopes,
|
206
|
+
interceptors: interceptors,
|
207
|
+
&Google::Cloud::AutoML::V1beta1::PredictionService::Stub.method(:new)
|
208
|
+
)
|
209
|
+
|
210
|
+
@predict = Google::Gax.create_api_call(
|
211
|
+
@prediction_service_stub.method(:predict),
|
212
|
+
defaults["predict"],
|
213
|
+
exception_transformer: exception_transformer,
|
214
|
+
params_extractor: proc do |request|
|
215
|
+
{'name' => request.name}
|
216
|
+
end
|
217
|
+
)
|
218
|
+
@batch_predict = Google::Gax.create_api_call(
|
219
|
+
@prediction_service_stub.method(:batch_predict),
|
220
|
+
defaults["batch_predict"],
|
221
|
+
exception_transformer: exception_transformer,
|
222
|
+
params_extractor: proc do |request|
|
223
|
+
{'name' => request.name}
|
224
|
+
end
|
225
|
+
)
|
226
|
+
end
|
227
|
+
|
228
|
+
# Service calls
|
229
|
+
|
230
|
+
# Perform an online prediction. The prediction result will be directly
|
231
|
+
# returned in the response.
|
232
|
+
# Available for following ML problems, and their expected request payloads:
|
233
|
+
# * Image Classification - Image in .JPEG, .GIF or .PNG format, image_bytes
|
234
|
+
# up to 30MB.
|
235
|
+
# * Image Object Detection - Image in .JPEG, .GIF or .PNG format, image_bytes
|
236
|
+
# up to 30MB.
|
237
|
+
# * Text Classification - TextSnippet, content up to 60,000 characters,
|
238
|
+
# UTF-8 encoded.
|
239
|
+
# * Text Extraction - TextSnippet, content up to 30,000 characters,
|
240
|
+
# UTF-8 NFC encoded.
|
241
|
+
# * Translation - TextSnippet, content up to 25,000 characters, UTF-8
|
242
|
+
# encoded.
|
243
|
+
# * Tables - Row, with column values matching the columns of the model,
|
244
|
+
# up to 5MB. Not available for FORECASTING
|
245
|
+
#
|
246
|
+
# {Google::Cloud::AutoML::V1beta1::TablesModelMetadata#prediction_type prediction_type}.
|
247
|
+
#
|
248
|
+
# @param name [String]
|
249
|
+
# Name of the model requested to serve the prediction.
|
250
|
+
# @param payload [Google::Cloud::AutoML::V1beta1::ExamplePayload | Hash]
|
251
|
+
# Required.
|
252
|
+
# Payload to perform a prediction on. The payload must match the
|
253
|
+
# problem type that the model was trained to solve.
|
254
|
+
# A hash of the same form as `Google::Cloud::AutoML::V1beta1::ExamplePayload`
|
255
|
+
# can also be provided.
|
256
|
+
# @param params [Hash{String => String}]
|
257
|
+
# Additional domain-specific parameters, any string must be up to 25000
|
258
|
+
# characters long.
|
259
|
+
#
|
260
|
+
# * For Image Classification:
|
261
|
+
#
|
262
|
+
# `score_threshold` - (float) A value from 0.0 to 1.0. When the model
|
263
|
+
# makes predictions for an image, it will only produce results that have
|
264
|
+
# at least this confidence score. The default is 0.5.
|
265
|
+
# * For Tables:
|
266
|
+
# `feature_importance` - (boolean) Whether
|
267
|
+
#
|
268
|
+
# [feature_importance][[google.cloud.automl.v1beta1.TablesModelColumnInfo.feature_importance]
|
269
|
+
# should be populated in the returned
|
270
|
+
#
|
271
|
+
# [TablesAnnotation(-s)][[google.cloud.automl.v1beta1.TablesAnnotation].
|
272
|
+
# The default is false.
|
273
|
+
# @param options [Google::Gax::CallOptions]
|
274
|
+
# Overrides the default settings for this call, e.g, timeout,
|
275
|
+
# retries, etc.
|
276
|
+
# @yield [result, operation] Access the result along with the RPC operation
|
277
|
+
# @yieldparam result [Google::Cloud::AutoML::V1beta1::PredictResponse]
|
278
|
+
# @yieldparam operation [GRPC::ActiveCall::Operation]
|
279
|
+
# @return [Google::Cloud::AutoML::V1beta1::PredictResponse]
|
280
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
281
|
+
# @example
|
282
|
+
# require "google/cloud/automl"
|
283
|
+
#
|
284
|
+
# prediction_client = Google::Cloud::AutoML::Prediction.new(version: :v1beta1)
|
285
|
+
# formatted_name = Google::Cloud::AutoML::V1beta1::PredictionServiceClient.model_path("[PROJECT]", "[LOCATION]", "[MODEL]")
|
286
|
+
#
|
287
|
+
# # TODO: Initialize `payload`:
|
288
|
+
# payload = {}
|
289
|
+
# response = prediction_client.predict(formatted_name, payload)
|
290
|
+
|
291
|
+
def predict \
|
292
|
+
name,
|
293
|
+
payload,
|
294
|
+
params: nil,
|
295
|
+
options: nil,
|
296
|
+
&block
|
297
|
+
req = {
|
298
|
+
name: name,
|
299
|
+
payload: payload,
|
300
|
+
params: params
|
301
|
+
}.delete_if { |_, v| v.nil? }
|
302
|
+
req = Google::Gax::to_proto(req, Google::Cloud::AutoML::V1beta1::PredictRequest)
|
303
|
+
@predict.call(req, options, &block)
|
304
|
+
end
|
305
|
+
|
306
|
+
# Perform a batch prediction. Unlike the online {Google::Cloud::AutoML::V1beta1::PredictionService::Predict Predict}, batch
|
307
|
+
# prediction result won't be immediately available in the response. Instead,
|
308
|
+
# a long running operation object is returned. User can poll the operation
|
309
|
+
# result via {Google::Longrunning::Operations::GetOperation GetOperation}
|
310
|
+
# method. Once the operation is done, {Google::Cloud::AutoML::V1beta1::BatchPredictResult BatchPredictResult} is returned in
|
311
|
+
# the {Google::Longrunning::Operation#response response} field.
|
312
|
+
# Available for following ML problems:
|
313
|
+
# * Video Classification
|
314
|
+
# * Video Object Tracking
|
315
|
+
# * Text Extraction
|
316
|
+
# * Tables
|
317
|
+
#
|
318
|
+
# @param name [String]
|
319
|
+
# Name of the model requested to serve the batch prediction.
|
320
|
+
# @param input_config [Google::Cloud::AutoML::V1beta1::BatchPredictInputConfig | Hash]
|
321
|
+
# Required. The input configuration for batch prediction.
|
322
|
+
# A hash of the same form as `Google::Cloud::AutoML::V1beta1::BatchPredictInputConfig`
|
323
|
+
# can also be provided.
|
324
|
+
# @param output_config [Google::Cloud::AutoML::V1beta1::BatchPredictOutputConfig | Hash]
|
325
|
+
# Required. The Configuration specifying where output predictions should
|
326
|
+
# be written.
|
327
|
+
# A hash of the same form as `Google::Cloud::AutoML::V1beta1::BatchPredictOutputConfig`
|
328
|
+
# can also be provided.
|
329
|
+
# @param params [Hash{String => String}]
|
330
|
+
# Additional domain-specific parameters for the predictions, any string must
|
331
|
+
# be up to 25000 characters long.
|
332
|
+
#
|
333
|
+
# * For Video Classification :
|
334
|
+
# `score_threshold` - (float) A value from 0.0 to 1.0. When the model
|
335
|
+
# makes predictions for a video, it will only produce results that
|
336
|
+
# have at least this confidence score. The default is 0.5.
|
337
|
+
# `segment_classification` - (boolean) Set to true to request
|
338
|
+
# segment-level classification. AutoML Video Intelligence returns
|
339
|
+
# labels and their confidence scores for the entire segment of the
|
340
|
+
# video that user specified in the request configuration.
|
341
|
+
# The default is "true".
|
342
|
+
# `shot_classification` - (boolean) Set to true to request shot-level
|
343
|
+
# classification. AutoML Video Intelligence determines the boundaries
|
344
|
+
# for each camera shot in the entire segment of the video that user
|
345
|
+
# specified in the request configuration. AutoML Video Intelligence
|
346
|
+
# then returns labels and their confidence scores for each detected
|
347
|
+
# shot, along with the start and end time of the shot.
|
348
|
+
# WARNING: Model evaluation is not done for this classification type,
|
349
|
+
# the quality of it depends on training data, but there are no metrics
|
350
|
+
# provided to describe that quality. The default is "false".
|
351
|
+
# `1s_interval_classification` - (boolean) Set to true to request
|
352
|
+
# classification for a video at one-second intervals. AutoML Video
|
353
|
+
# Intelligence returns labels and their confidence scores for each
|
354
|
+
# second of the entire segment of the video that user specified in the
|
355
|
+
# request configuration.
|
356
|
+
# WARNING: Model evaluation is not done for this classification
|
357
|
+
# type, the quality of it depends on training data, but there are no
|
358
|
+
# metrics provided to describe that quality. The default is
|
359
|
+
# "false".
|
360
|
+
#
|
361
|
+
# * For Video Object Tracking:
|
362
|
+
# `score_threshold` - (float) When Model detects objects on video frames,
|
363
|
+
# it will only produce bounding boxes which have at least this
|
364
|
+
# confidence score. Value in 0 to 1 range, default is 0.5.
|
365
|
+
# `max_bounding_box_count` - (int64) No more than this number of bounding
|
366
|
+
# boxes will be returned per frame. Default is 100, the requested
|
367
|
+
# value may be limited by server.
|
368
|
+
# `min_bounding_box_size` - (float) Only bounding boxes with shortest edge
|
369
|
+
# at least that long as a relative value of video frame size will be
|
370
|
+
# returned. Value in 0 to 1 range. Default is 0.
|
371
|
+
# @param options [Google::Gax::CallOptions]
|
372
|
+
# Overrides the default settings for this call, e.g, timeout,
|
373
|
+
# retries, etc.
|
374
|
+
# @return [Google::Gax::Operation]
|
375
|
+
# @raise [Google::Gax::GaxError] if the RPC is aborted.
|
376
|
+
# @example
|
377
|
+
# require "google/cloud/automl"
|
378
|
+
#
|
379
|
+
# prediction_client = Google::Cloud::AutoML::Prediction.new(version: :v1beta1)
|
380
|
+
# formatted_name = Google::Cloud::AutoML::V1beta1::PredictionServiceClient.model_path("[PROJECT]", "[LOCATION]", "[MODEL]")
|
381
|
+
#
|
382
|
+
# # TODO: Initialize `input_config`:
|
383
|
+
# input_config = {}
|
384
|
+
#
|
385
|
+
# # TODO: Initialize `output_config`:
|
386
|
+
# output_config = {}
|
387
|
+
#
|
388
|
+
# # Register a callback during the method call.
|
389
|
+
# operation = prediction_client.batch_predict(formatted_name, input_config, output_config) do |op|
|
390
|
+
# raise op.results.message if op.error?
|
391
|
+
# op_results = op.results
|
392
|
+
# # Process the results.
|
393
|
+
#
|
394
|
+
# metadata = op.metadata
|
395
|
+
# # Process the metadata.
|
396
|
+
# end
|
397
|
+
#
|
398
|
+
# # Or use the return value to register a callback.
|
399
|
+
# operation.on_done do |op|
|
400
|
+
# raise op.results.message if op.error?
|
401
|
+
# op_results = op.results
|
402
|
+
# # Process the results.
|
403
|
+
#
|
404
|
+
# metadata = op.metadata
|
405
|
+
# # Process the metadata.
|
406
|
+
# end
|
407
|
+
#
|
408
|
+
# # Manually reload the operation.
|
409
|
+
# operation.reload!
|
410
|
+
#
|
411
|
+
# # Or block until the operation completes, triggering callbacks on
|
412
|
+
# # completion.
|
413
|
+
# operation.wait_until_done!
|
414
|
+
|
415
|
+
def batch_predict \
|
416
|
+
name,
|
417
|
+
input_config,
|
418
|
+
output_config,
|
419
|
+
params: nil,
|
420
|
+
options: nil
|
421
|
+
req = {
|
422
|
+
name: name,
|
423
|
+
input_config: input_config,
|
424
|
+
output_config: output_config,
|
425
|
+
params: params
|
426
|
+
}.delete_if { |_, v| v.nil? }
|
427
|
+
req = Google::Gax::to_proto(req, Google::Cloud::AutoML::V1beta1::BatchPredictRequest)
|
428
|
+
operation = Google::Gax::Operation.new(
|
429
|
+
@batch_predict.call(req, options),
|
430
|
+
@operations_client,
|
431
|
+
Google::Cloud::AutoML::V1beta1::BatchPredictResult,
|
432
|
+
Google::Cloud::AutoML::V1beta1::OperationMetadata,
|
433
|
+
call_options: options
|
434
|
+
)
|
435
|
+
operation.on_done { |operation| yield(operation) } if block_given?
|
436
|
+
operation
|
437
|
+
end
|
438
|
+
end
|
439
|
+
end
|
440
|
+
end
|
441
|
+
end
|
442
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
{
|
2
|
+
"interfaces": {
|
3
|
+
"google.cloud.automl.v1beta1.PredictionService": {
|
4
|
+
"retry_codes": {
|
5
|
+
"idempotent": [
|
6
|
+
"DEADLINE_EXCEEDED",
|
7
|
+
"UNAVAILABLE"
|
8
|
+
],
|
9
|
+
"non_idempotent": []
|
10
|
+
},
|
11
|
+
"retry_params": {
|
12
|
+
"default": {
|
13
|
+
"initial_retry_delay_millis": 100,
|
14
|
+
"retry_delay_multiplier": 1.3,
|
15
|
+
"max_retry_delay_millis": 60000,
|
16
|
+
"initial_rpc_timeout_millis": 60000,
|
17
|
+
"rpc_timeout_multiplier": 1.0,
|
18
|
+
"max_rpc_timeout_millis": 60000,
|
19
|
+
"total_timeout_millis": 600000
|
20
|
+
}
|
21
|
+
},
|
22
|
+
"methods": {
|
23
|
+
"Predict": {
|
24
|
+
"timeout_millis": 60000,
|
25
|
+
"retry_codes_name": "non_idempotent",
|
26
|
+
"retry_params_name": "default"
|
27
|
+
},
|
28
|
+
"BatchPredict": {
|
29
|
+
"timeout_millis": 20000,
|
30
|
+
"retry_codes_name": "non_idempotent",
|
31
|
+
"retry_params_name": "default"
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: google/cloud/automl/v1beta1/prediction_service.proto
|
3
|
+
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
require 'google/api/annotations_pb'
|
8
|
+
require 'google/cloud/automl/v1beta1/annotation_payload_pb'
|
9
|
+
require 'google/cloud/automl/v1beta1/data_items_pb'
|
10
|
+
require 'google/cloud/automl/v1beta1/io_pb'
|
11
|
+
require 'google/cloud/automl/v1beta1/operations_pb'
|
12
|
+
require 'google/longrunning/operations_pb'
|
13
|
+
require 'google/api/client_pb'
|
14
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
15
|
+
add_message "google.cloud.automl.v1beta1.PredictRequest" do
|
16
|
+
optional :name, :string, 1
|
17
|
+
optional :payload, :message, 2, "google.cloud.automl.v1beta1.ExamplePayload"
|
18
|
+
map :params, :string, :string, 3
|
19
|
+
end
|
20
|
+
add_message "google.cloud.automl.v1beta1.PredictResponse" do
|
21
|
+
repeated :payload, :message, 1, "google.cloud.automl.v1beta1.AnnotationPayload"
|
22
|
+
map :metadata, :string, :string, 2
|
23
|
+
end
|
24
|
+
add_message "google.cloud.automl.v1beta1.BatchPredictRequest" do
|
25
|
+
optional :name, :string, 1
|
26
|
+
optional :input_config, :message, 3, "google.cloud.automl.v1beta1.BatchPredictInputConfig"
|
27
|
+
optional :output_config, :message, 4, "google.cloud.automl.v1beta1.BatchPredictOutputConfig"
|
28
|
+
map :params, :string, :string, 5
|
29
|
+
end
|
30
|
+
add_message "google.cloud.automl.v1beta1.BatchPredictResult" do
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
module Google::Cloud::AutoML::V1beta1
|
35
|
+
PredictRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.automl.v1beta1.PredictRequest").msgclass
|
36
|
+
PredictResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.automl.v1beta1.PredictResponse").msgclass
|
37
|
+
BatchPredictRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.automl.v1beta1.BatchPredictRequest").msgclass
|
38
|
+
BatchPredictResult = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.automl.v1beta1.BatchPredictResult").msgclass
|
39
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# Source: google/cloud/automl/v1beta1/prediction_service.proto for package 'Google::Cloud::AutoML::V1beta1'
|
3
|
+
# Original file comments:
|
4
|
+
# Copyright 2019 Google LLC.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
#
|
19
|
+
|
20
|
+
|
21
|
+
require 'grpc'
|
22
|
+
require 'google/cloud/automl/v1beta1/prediction_service_pb'
|
23
|
+
|
24
|
+
module Google::Cloud::AutoML::V1beta1
|
25
|
+
module PredictionService
|
26
|
+
# AutoML Prediction API.
|
27
|
+
#
|
28
|
+
# On any input that is documented to expect a string parameter in
|
29
|
+
# snake_case or kebab-case, either of those cases is accepted.
|
30
|
+
class Service
|
31
|
+
|
32
|
+
include GRPC::GenericService
|
33
|
+
|
34
|
+
self.marshal_class_method = :encode
|
35
|
+
self.unmarshal_class_method = :decode
|
36
|
+
self.service_name = 'google.cloud.automl.v1beta1.PredictionService'
|
37
|
+
|
38
|
+
# Perform an online prediction. The prediction result will be directly
|
39
|
+
# returned in the response.
|
40
|
+
# Available for following ML problems, and their expected request payloads:
|
41
|
+
# * Image Classification - Image in .JPEG, .GIF or .PNG format, image_bytes
|
42
|
+
# up to 30MB.
|
43
|
+
# * Image Object Detection - Image in .JPEG, .GIF or .PNG format, image_bytes
|
44
|
+
# up to 30MB.
|
45
|
+
# * Text Classification - TextSnippet, content up to 60,000 characters,
|
46
|
+
# UTF-8 encoded.
|
47
|
+
# * Text Extraction - TextSnippet, content up to 30,000 characters,
|
48
|
+
# UTF-8 NFC encoded.
|
49
|
+
# * Translation - TextSnippet, content up to 25,000 characters, UTF-8
|
50
|
+
# encoded.
|
51
|
+
# * Tables - Row, with column values matching the columns of the model,
|
52
|
+
# up to 5MB. Not available for FORECASTING
|
53
|
+
#
|
54
|
+
# [prediction_type][google.cloud.automl.v1beta1.TablesModelMetadata.prediction_type].
|
55
|
+
rpc :Predict, PredictRequest, PredictResponse
|
56
|
+
# Perform a batch prediction. Unlike the online [Predict][google.cloud.automl.v1beta1.PredictionService.Predict], batch
|
57
|
+
# prediction result won't be immediately available in the response. Instead,
|
58
|
+
# a long running operation object is returned. User can poll the operation
|
59
|
+
# result via [GetOperation][google.longrunning.Operations.GetOperation]
|
60
|
+
# method. Once the operation is done, [BatchPredictResult][google.cloud.automl.v1beta1.BatchPredictResult] is returned in
|
61
|
+
# the [response][google.longrunning.Operation.response] field.
|
62
|
+
# Available for following ML problems:
|
63
|
+
# * Video Classification
|
64
|
+
# * Video Object Tracking
|
65
|
+
# * Text Extraction
|
66
|
+
# * Tables
|
67
|
+
rpc :BatchPredict, BatchPredictRequest, Google::Longrunning::Operation
|
68
|
+
end
|
69
|
+
|
70
|
+
Stub = Service.rpc_stub_class
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: google/cloud/automl/v1beta1/ranges.proto
|
3
|
+
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
require 'google/api/annotations_pb'
|
8
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
|
+
add_message "google.cloud.automl.v1beta1.DoubleRange" do
|
10
|
+
optional :start, :double, 1
|
11
|
+
optional :end, :double, 2
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Google::Cloud::AutoML::V1beta1
|
16
|
+
DoubleRange = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.automl.v1beta1.DoubleRange").msgclass
|
17
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Generated by the protocol buffer compiler. DO NOT EDIT!
|
2
|
+
# source: google/cloud/automl/v1beta1/regression.proto
|
3
|
+
|
4
|
+
|
5
|
+
require 'google/protobuf'
|
6
|
+
|
7
|
+
require 'google/api/annotations_pb'
|
8
|
+
Google::Protobuf::DescriptorPool.generated_pool.build do
|
9
|
+
add_message "google.cloud.automl.v1beta1.RegressionEvaluationMetrics" do
|
10
|
+
optional :root_mean_squared_error, :float, 1
|
11
|
+
optional :mean_absolute_error, :float, 2
|
12
|
+
optional :mean_absolute_percentage_error, :float, 3
|
13
|
+
optional :r_squared, :float, 4
|
14
|
+
optional :root_mean_squared_log_error, :float, 5
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
module Google::Cloud::AutoML::V1beta1
|
19
|
+
RegressionEvaluationMetrics = Google::Protobuf::DescriptorPool.generated_pool.lookup("google.cloud.automl.v1beta1.RegressionEvaluationMetrics").msgclass
|
20
|
+
end
|