Class v1.PredictionServiceClient (4.0.1)

AutoML Prediction API.

On any input that is documented to expect a string parameter in snake_case or dash-case, either of those cases is accepted. v1

Package

@google-cloud/automl

Constructors

(constructor)(opts, gaxInstance)

constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);

Construct an instance of PredictionServiceClient.

Parameters
NameDescription
opts ClientOptions
gaxInstance typeof gax | typeof fallback

: loaded instance of google-gax. Useful if you need to avoid loading the default gRPC version and want to use the fallback HTTP implementation. Load only fallback version and pass it to the constructor: ``` const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC const client = new PredictionServiceClient({fallback: true}, gax); ```

Properties

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath(), exists for compatibility reasons.

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

operationsClient

operationsClient: gax.OperationsClient;

pathTemplates

pathTemplates: {
        [name: string]: gax.PathTemplate;
    };

port

static get port(): number;

The port for this API service.

predictionServiceStub

predictionServiceStub?: Promise<{
        [name: string]: Function;
    }>;

scopes

static get scopes(): string[];

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static get servicePath(): string;

The DNS address for this API service.

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

annotationSpecPath(project, location, dataset, annotationSpec)

annotationSpecPath(project: string, location: string, dataset: string, annotationSpec: string): string;

Return a fully-qualified annotationSpec resource name string.

Parameters
NameDescription
project string
location string
dataset string
annotationSpec string
Returns
TypeDescription
string

{string} Resource name string.

batchPredict(request, options)

batchPredict(request?: protos.google.cloud.automl.v1.IBatchPredictRequest, options?: CallOptions): Promise<[
        LROperation<protos.google.cloud.automl.v1.IBatchPredictResult, protos.google.cloud.automl.v1.IOperationMetadata>,
        protos.google.longrunning.IOperation | undefined,
        {} | undefined
    ]>;

Perform a batch prediction. Unlike the online , 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 method. Once the operation is done, BatchPredictResult is returned in the response field. Available for following ML scenarios:

* AutoML Vision Classification * AutoML Vision Object Detection * AutoML Video Intelligence Classification * AutoML Video Intelligence Object Tracking * AutoML Natural Language Classification * AutoML Natural Language Entity Extraction * AutoML Natural Language Sentiment Analysis * AutoML Tables

Parameters
NameDescription
request IBatchPredictRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ LROperation<protos.google.cloud.automl.v1.IBatchPredictResult, protos.google.cloud.automl.v1.IOperationMetadata>, protos.google.longrunning.IOperation | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing a long running operation. Its promise() method returns a promise you can await for. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Name of the model requested to serve the batch prediction.
   */
  // const name = 'abc123'
  /**
   *  Required. The input configuration for batch prediction.
   */
  // const inputConfig = {}
  /**
   *  Required. The Configuration specifying where output predictions should
   *  be written.
   */
  // const outputConfig = {}
  /**
   *  Additional domain-specific parameters for the predictions, any string must
   *  be up to 25000 characters long.
   *  AutoML Natural Language Classification
   *  `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.
   *  AutoML Vision Classification
   *  `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.
   *  AutoML Vision 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) The maximum number of bounding
   *    boxes returned per image. The default is 100, the
   *    number of bounding boxes returned might be limited by the server.
   *  AutoML Video Intelligence Classification
   *  `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.
   *    The default is false.
   *    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.
   *  `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. The default is false.
   *    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.
   *  AutoML Video Intelligence Object Tracking
   *  `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) The maximum number of bounding
   *    boxes returned per image. The default is 100, the
   *    number of bounding boxes returned might be limited by the server.
   *  `min_bounding_box_size`
   *  : (float) Only bounding boxes with shortest edge
   *    at least that long as a relative value of video frame size are
   *    returned. Value in 0 to 1 range. Default is 0.
   */
  // const params = [1,2,3,4]

  // Imports the Automl library
  const {PredictionServiceClient} = require('@google-cloud/automl').v1;

  // Instantiates a client
  const automlClient = new PredictionServiceClient();

  async function callBatchPredict() {
    // Construct request
    const request = {
      name,
      inputConfig,
      outputConfig,
    };

    // Run request
    const [operation] = await automlClient.batchPredict(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callBatchPredict();

batchPredict(request, options, callback)

batchPredict(request: protos.google.cloud.automl.v1.IBatchPredictRequest, options: CallOptions, callback: Callback<LROperation<protos.google.cloud.automl.v1.IBatchPredictResult, protos.google.cloud.automl.v1.IOperationMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IBatchPredictRequest
options CallOptions
callback Callback<LROperation<protos.google.cloud.automl.v1.IBatchPredictResult, protos.google.cloud.automl.v1.IOperationMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

batchPredict(request, callback)

batchPredict(request: protos.google.cloud.automl.v1.IBatchPredictRequest, callback: Callback<LROperation<protos.google.cloud.automl.v1.IBatchPredictResult, protos.google.cloud.automl.v1.IOperationMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IBatchPredictRequest
callback Callback<LROperation<protos.google.cloud.automl.v1.IBatchPredictResult, protos.google.cloud.automl.v1.IOperationMetadata>, protos.google.longrunning.IOperation | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

checkBatchPredictProgress(name)

checkBatchPredictProgress(name: string): Promise<LROperation<protos.google.cloud.automl.v1.BatchPredictResult, protos.google.cloud.automl.v1.OperationMetadata>>;

Check the status of the long running operation returned by batchPredict().

Parameter
NameDescription
name string

The operation name that will be passed.

Returns
TypeDescription
Promise<LROperation<protos.google.cloud.automl.v1.BatchPredictResult, protos.google.cloud.automl.v1.OperationMetadata>>

{Promise} - The promise which resolves to an object. The decoded operation object has result and metadata field to get information from. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Name of the model requested to serve the batch prediction.
   */
  // const name = 'abc123'
  /**
   *  Required. The input configuration for batch prediction.
   */
  // const inputConfig = {}
  /**
   *  Required. The Configuration specifying where output predictions should
   *  be written.
   */
  // const outputConfig = {}
  /**
   *  Additional domain-specific parameters for the predictions, any string must
   *  be up to 25000 characters long.
   *  AutoML Natural Language Classification
   *  `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.
   *  AutoML Vision Classification
   *  `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.
   *  AutoML Vision 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) The maximum number of bounding
   *    boxes returned per image. The default is 100, the
   *    number of bounding boxes returned might be limited by the server.
   *  AutoML Video Intelligence Classification
   *  `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.
   *    The default is false.
   *    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.
   *  `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. The default is false.
   *    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.
   *  AutoML Video Intelligence Object Tracking
   *  `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) The maximum number of bounding
   *    boxes returned per image. The default is 100, the
   *    number of bounding boxes returned might be limited by the server.
   *  `min_bounding_box_size`
   *  : (float) Only bounding boxes with shortest edge
   *    at least that long as a relative value of video frame size are
   *    returned. Value in 0 to 1 range. Default is 0.
   */
  // const params = [1,2,3,4]

  // Imports the Automl library
  const {PredictionServiceClient} = require('@google-cloud/automl').v1;

  // Instantiates a client
  const automlClient = new PredictionServiceClient();

  async function callBatchPredict() {
    // Construct request
    const request = {
      name,
      inputConfig,
      outputConfig,
    };

    // Run request
    const [operation] = await automlClient.batchPredict(request);
    const [response] = await operation.promise();
    console.log(response);
  }

  callBatchPredict();

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns
TypeDescription
Promise<void>

{Promise} A promise that resolves when the client is closed.

datasetPath(project, location, dataset)

datasetPath(project: string, location: string, dataset: string): string;

Return a fully-qualified dataset resource name string.

Parameters
NameDescription
project string
location string
dataset string
Returns
TypeDescription
string

{string} Resource name string.

getProjectId()

getProjectId(): Promise<string>;
Returns
TypeDescription
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
NameDescription
callback Callback<string, undefined, undefined>
Returns
TypeDescription
void

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns
TypeDescription
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

matchAnnotationSpecFromAnnotationSpecName(annotationSpecName)

matchAnnotationSpecFromAnnotationSpecName(annotationSpecName: string): string | number;

Parse the annotation_spec from AnnotationSpec resource.

Parameter
NameDescription
annotationSpecName string

A fully-qualified path representing AnnotationSpec resource.

Returns
TypeDescription
string | number

{string} A string representing the annotation_spec.

matchDatasetFromAnnotationSpecName(annotationSpecName)

matchDatasetFromAnnotationSpecName(annotationSpecName: string): string | number;

Parse the dataset from AnnotationSpec resource.

Parameter
NameDescription
annotationSpecName string

A fully-qualified path representing AnnotationSpec resource.

Returns
TypeDescription
string | number

{string} A string representing the dataset.

matchDatasetFromDatasetName(datasetName)

matchDatasetFromDatasetName(datasetName: string): string | number;

Parse the dataset from Dataset resource.

Parameter
NameDescription
datasetName string

A fully-qualified path representing Dataset resource.

Returns
TypeDescription
string | number

{string} A string representing the dataset.

matchLocationFromAnnotationSpecName(annotationSpecName)

matchLocationFromAnnotationSpecName(annotationSpecName: string): string | number;

Parse the location from AnnotationSpec resource.

Parameter
NameDescription
annotationSpecName string

A fully-qualified path representing AnnotationSpec resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchLocationFromDatasetName(datasetName)

matchLocationFromDatasetName(datasetName: string): string | number;

Parse the location from Dataset resource.

Parameter
NameDescription
datasetName string

A fully-qualified path representing Dataset resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchLocationFromModelEvaluationName(modelEvaluationName)

matchLocationFromModelEvaluationName(modelEvaluationName: string): string | number;

Parse the location from ModelEvaluation resource.

Parameter
NameDescription
modelEvaluationName string

A fully-qualified path representing ModelEvaluation resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchLocationFromModelName(modelName)

matchLocationFromModelName(modelName: string): string | number;

Parse the location from Model resource.

Parameter
NameDescription
modelName string

A fully-qualified path representing Model resource.

Returns
TypeDescription
string | number

{string} A string representing the location.

matchModelEvaluationFromModelEvaluationName(modelEvaluationName)

matchModelEvaluationFromModelEvaluationName(modelEvaluationName: string): string | number;

Parse the model_evaluation from ModelEvaluation resource.

Parameter
NameDescription
modelEvaluationName string

A fully-qualified path representing ModelEvaluation resource.

Returns
TypeDescription
string | number

{string} A string representing the model_evaluation.

matchModelFromModelEvaluationName(modelEvaluationName)

matchModelFromModelEvaluationName(modelEvaluationName: string): string | number;

Parse the model from ModelEvaluation resource.

Parameter
NameDescription
modelEvaluationName string

A fully-qualified path representing ModelEvaluation resource.

Returns
TypeDescription
string | number

{string} A string representing the model.

matchModelFromModelName(modelName)

matchModelFromModelName(modelName: string): string | number;

Parse the model from Model resource.

Parameter
NameDescription
modelName string

A fully-qualified path representing Model resource.

Returns
TypeDescription
string | number

{string} A string representing the model.

matchProjectFromAnnotationSpecName(annotationSpecName)

matchProjectFromAnnotationSpecName(annotationSpecName: string): string | number;

Parse the project from AnnotationSpec resource.

Parameter
NameDescription
annotationSpecName string

A fully-qualified path representing AnnotationSpec resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromDatasetName(datasetName)

matchProjectFromDatasetName(datasetName: string): string | number;

Parse the project from Dataset resource.

Parameter
NameDescription
datasetName string

A fully-qualified path representing Dataset resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromModelEvaluationName(modelEvaluationName)

matchProjectFromModelEvaluationName(modelEvaluationName: string): string | number;

Parse the project from ModelEvaluation resource.

Parameter
NameDescription
modelEvaluationName string

A fully-qualified path representing ModelEvaluation resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

matchProjectFromModelName(modelName)

matchProjectFromModelName(modelName: string): string | number;

Parse the project from Model resource.

Parameter
NameDescription
modelName string

A fully-qualified path representing Model resource.

Returns
TypeDescription
string | number

{string} A string representing the project.

modelEvaluationPath(project, location, model, modelEvaluation)

modelEvaluationPath(project: string, location: string, model: string, modelEvaluation: string): string;

Return a fully-qualified modelEvaluation resource name string.

Parameters
NameDescription
project string
location string
model string
modelEvaluation string
Returns
TypeDescription
string

{string} Resource name string.

modelPath(project, location, model)

modelPath(project: string, location: string, model: string): string;

Return a fully-qualified model resource name string.

Parameters
NameDescription
project string
location string
model string
Returns
TypeDescription
string

{string} Resource name string.

predict(request, options)

predict(request?: protos.google.cloud.automl.v1.IPredictRequest, options?: CallOptions): Promise<[
        protos.google.cloud.automl.v1.IPredictResponse,
        protos.google.cloud.automl.v1.IPredictRequest | undefined,
        {} | undefined
    ]>;

Perform an online prediction. The prediction result is directly returned in the response. Available for following ML scenarios, and their expected request payloads:

AutoML Vision Classification

* An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.

AutoML Vision Object Detection

* An image in .JPEG, .GIF or .PNG format, image_bytes up to 30MB.

AutoML Natural Language Classification

* A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF format with size upto 2MB.

AutoML Natural Language Entity Extraction

* A TextSnippet up to 10,000 characters, UTF-8 NFC encoded or a document in .PDF, .TIF or .TIFF format with size upto 20MB.

AutoML Natural Language Sentiment Analysis

* A TextSnippet up to 60,000 characters, UTF-8 encoded or a document in .PDF, .TIF or .TIFF format with size upto 2MB.

AutoML Translation

* A TextSnippet up to 25,000 characters, UTF-8 encoded.

AutoML Tables

* A row with column values matching the columns of the model, up to 5MB. Not available for FORECASTING prediction_type.

Parameters
NameDescription
request IPredictRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
TypeDescription
Promise<[ protos.google.cloud.automl.v1.IPredictResponse, protos.google.cloud.automl.v1.IPredictRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing PredictResponse. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Name of the model requested to serve the prediction.
   */
  // const name = 'abc123'
  /**
   *  Required. Payload to perform a prediction on. The payload must match the
   *  problem type that the model was trained to solve.
   */
  // const payload = {}
  /**
   *  Additional domain-specific parameters, any string must be up to 25000
   *  characters long.
   *  AutoML Vision Classification
   *  `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.
   *  AutoML Vision 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) The maximum number of bounding
   *    boxes returned. The default is 100. The
   *    number of returned bounding boxes might be limited by the server.
   *  AutoML Tables
   *  `feature_importance`
   *  : (boolean) Whether
   *  feature_importance google.cloud.automl.v1.TablesModelColumnInfo.feature_importance 
   *    is populated in the returned list of
   *    TablesAnnotation google.cloud.automl.v1.TablesAnnotation 
   *    objects. The default is false.
   */
  // const params = [1,2,3,4]

  // Imports the Automl library
  const {PredictionServiceClient} = require('@google-cloud/automl').v1;

  // Instantiates a client
  const automlClient = new PredictionServiceClient();

  async function callPredict() {
    // Construct request
    const request = {
      name,
      payload,
    };

    // Run request
    const response = await automlClient.predict(request);
    console.log(response);
  }

  callPredict();

predict(request, options, callback)

predict(request: protos.google.cloud.automl.v1.IPredictRequest, options: CallOptions, callback: Callback<protos.google.cloud.automl.v1.IPredictResponse, protos.google.cloud.automl.v1.IPredictRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IPredictRequest
options CallOptions
callback Callback<protos.google.cloud.automl.v1.IPredictResponse, protos.google.cloud.automl.v1.IPredictRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void

predict(request, callback)

predict(request: protos.google.cloud.automl.v1.IPredictRequest, callback: Callback<protos.google.cloud.automl.v1.IPredictResponse, protos.google.cloud.automl.v1.IPredictRequest | null | undefined, {} | null | undefined>): void;
Parameters
NameDescription
request IPredictRequest
callback Callback<protos.google.cloud.automl.v1.IPredictResponse, protos.google.cloud.automl.v1.IPredictRequest | null | undefined, {} | null | undefined>
Returns
TypeDescription
void