prediction_service.proto 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. // Copyright 2016 Google Inc.
  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. // http://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. syntax = "proto3";
  15. package google.cloud.ml.v1beta1;
  16. import "google/api/annotations.proto";
  17. option java_multiple_files = true;
  18. option java_outer_classname = "PredictionServiceProto";
  19. option java_package = "com.google.cloud.ml.api.v1beta1";
  20. // Copyright 2016 Google Inc. All Rights Reserved.
  21. //
  22. // Proto file for the Prediction service, both online and batch prediction.
  23. // The Prediction API, which serves predictions for models managed by
  24. // ModelService.
  25. service OnlinePredictionService {
  26. // Performs prediction on the data in the request.
  27. //
  28. // Responses are very similar to requests. There are two top-level fields,
  29. // each of which are JSON lists:
  30. //
  31. // * `predictions`: The list of predictions for each of the inputs
  32. // in the request.
  33. // * `error`: An error message if any instance produced an error.
  34. //
  35. // There is a one-to-one correspondence between the predictions and the
  36. // instances in the request. Each individual prediction takes the same form
  37. // as an instance in the request, namely JSON strings, numbers, booleans,
  38. // or lists thereof. If your model has more than one output tensor, each
  39. // prediction will be a JSON object with the keys being the output aliases
  40. // in the graph.
  41. //
  42. // If there is an error processing any single instance, no predictions
  43. // are returned and the `error` field is populated with the error message.
  44. //
  45. // Examples:
  46. //
  47. // <pre>
  48. // # Predictions for three input instances, predictions are an integer label,
  49. //
  50. // # e.g., a digit in digit recognition
  51. //
  52. // {"predictions": [5, 4, 3]}
  53. //
  54. // # Predictions for two input instances in a two-class classification
  55. //
  56. // # problem. The labels are strings and scores are the probability of
  57. //
  58. // # "car" and "beach".
  59. //
  60. // {"predictions": [{"label": "beach", "scores": [0.1, 0.9]},
  61. // {"label": "car", "scores": [0.75, 0.25]}]}
  62. //
  63. // # An error:
  64. //
  65. // {"error": "Divide by zero"}
  66. // </pre>
  67. rpc Predict(PredictRequest) returns (google.api.HttpBody) {
  68. option (google.api.http) = { post: "/v1beta1/{name=projects/**}:predict" body: "*" };
  69. }
  70. }
  71. // Request for predictions to be issued against a trained model.
  72. //
  73. // The body of the request consists of a single JSON object with a single
  74. // top-level field:
  75. //
  76. // * `instances`: a list of JSON values representing the instances to use for
  77. // prediction.
  78. //
  79. // The structure of each element of the instances list is the type of data
  80. // your model expects to work on. There are two types of instances: those
  81. // that include named inputs and those that do not.
  82. //
  83. // Most data does not include named inputs. In this case, each instance will
  84. // be a JSON boolean, number, string, or (possibly deeply nested) list of
  85. // any of the above. For instance, if your model accepts rows of CSV data,
  86. // then each element is a string; if each data instance is a vector of ints
  87. // or floats, use a JSON list of numbers, etc. More examples are as follows:
  88. //
  89. // <pre>
  90. // # CSV data
  91. //
  92. // {"instances": ["1.0,true,\\"x\\"", "-2.0,false,\\"y\\""]}
  93. //
  94. // # Text
  95. //
  96. // {"instances": ["the quick brown fox", "la bruja le dio"]}
  97. //
  98. // # Sentences, each a list of words (vectors of strings).
  99. //
  100. // {"instances": [["the","quick","brown"], ["la","bruja","le"]]}
  101. //
  102. // # Three instances, each a floating point scalar, e.g., to compute f(x).
  103. //
  104. // {"instances": [0.0, 1.1, 2.2]} # 3 instances (integer scalars)
  105. //
  106. // # Two instances, each a 3 element vecor of ints.
  107. //
  108. // {"instances": [[0,1,2], [3,4,5],...]}
  109. //
  110. // # A single instance, which is 2x3 matrix of ints.
  111. //
  112. // {"instances": [[[0,1,2], [3,4,5]], ...]}
  113. //
  114. // # A single image represented as a 3-dimensional list with dimesions:
  115. //
  116. // # height, width, and channels (3).
  117. //
  118. // {"instances": [[[[0,1,2], [3,4,5], …]]]]}
  119. // </pre>
  120. //
  121. // Importantly, if your data is not UTF-8 (the only currently supported
  122. // character set), you will need to base64 encode the data and mark it as
  123. // binary. The latter is accomplished by using a JSON object of the form:
  124. // <pre>{"b": "..."} </pre>
  125. // in place of any JSON string that is base64 encoded. For example:
  126. //
  127. // <pre>
  128. // # Two Serialized tf.Examples (fake data, for illustrative purposes only)
  129. //
  130. // {"instances": [{"b": "X5ad6u"}, {"b": "IA9j4nx"}]}
  131. //
  132. // # Two JPEG image byte strings (fake data, for illustrative purposes only)
  133. //
  134. // {"instances": [{"b": "ASa8asdf"}, {"b": "JLK7ljk3"}]}
  135. // </pre>
  136. //
  137. // In the case that your data includes named references, you will send a
  138. // JSON object with the named references as the keys. For instance, if
  139. // you used Cloud ML's preprocessing library and used the JSON key-value
  140. // pair data format, you would send instances as follows:
  141. //
  142. // <pre>
  143. // # JSON input data to be preprocessed.
  144. //
  145. // {"instances": [{"a": 1.0, "b": true, "c": "x"},
  146. // {"a": -2.0, "b": false, "c": "y"}]}
  147. // </pre>
  148. //
  149. // Another use case is if your underlying TensorFlow graph contains multiple
  150. // input tensors, then the keys would be the aliases to the input tensors, e.g.,
  151. //
  152. // <pre>
  153. // # Graph with input tensor aliases "tag" (string) and "image" (base64
  154. //
  155. // # encoded string).
  156. //
  157. // {"instances": [{"tag": "beach", "image": {"b": "ASa8asdf"}},
  158. // {"tag": "car", "image": {"b": "JLK7ljk3"}}]}
  159. //
  160. // # Graph with input tensor aliases "tag" (string) and "image"
  161. //
  162. // # (3-dimensional array of 8-bit ints).
  163. //
  164. // {"instances": [{"tag": "beach", "image": [[[263,1,10], [262,2,11], ...]]},
  165. // {"tag": "car", "image": [[[10,11,24], [23,10,15], ...]]}]}
  166. // </pre>
  167. //
  168. // There is a one-to-one correspondence between the predictions and the
  169. // instances in the request. Each individual prediction takes the same form
  170. // as an instance in the request, namely JSON strings, numbers, booleans, or
  171. // lists thereof. If your model has more than one output tensor, each
  172. // prediction will be a JSON object with the keys being the output aliases
  173. // in the graph.
  174. //
  175. // Examples:
  176. //
  177. // <pre>
  178. // # Predictions for three input instances, predictions are an integer label,
  179. //
  180. // # e.g., a digit in digit recognition
  181. //
  182. // {"predictions": [5, 4, 3]}
  183. //
  184. // # Predictions for two input instances in a two-class classification
  185. //
  186. // # problem. The labels are strings and scores are the probability of "car"
  187. //
  188. // # and "beach".
  189. //
  190. // {"predictions": [{"label": "beach", "scores": [0.1, 0.9]},
  191. // {"label": "car", "scores": [0.75, 0.25]}]}
  192. // </pre>
  193. message PredictRequest {
  194. // Required. The resource name of a model or a version.
  195. // Authorization: requires `Viewer` role on the parent project.
  196. string name = 1;
  197. //
  198. // Required. The prediction request body.
  199. google.api.HttpBody http_body = 2;
  200. }