How to use @google-cloud/automl - 10 common examples

To help you get started, we’ve selected a few @google-cloud/automl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-automl / samples / vision / object-detection / list-models.v1beta1.js View on Github external
) {
  // [START automl_vision_object_detection_list_models]
  /**
   * Demonstrates using the AutoML client to list all models.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const filter_ = '[FILTER_EXPRESSIONS]'
  // e.g., "imageObjectDetectionModelMetadata:*";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function listModels() {
    // A resource that represents Google Cloud Platform location.
    const projectLocation = automlClient.locationPath(projectId, computeRegion);

    // List all the models available in the region by applying filter.
    const [response] = await automlClient.listModels({
      parent: projectLocation,
      filter: filter,
    });
    console.log(`List of models:`);
    for (const model of response) {
      console.log(`\nModel name: ${model.name}`);
      console.log(`Model Id: ${model.name.split(`/`).pop(-1)}`);
      console.log(`Model display name: ${model.displayName}`);
      console.log(`Dataset Id: ${model.datasetId}`);
github googleapis / nodejs-automl / samples / vision / object-detection / list-datasets.v1beta1.js View on Github external
) {
  // [START automl_vision_object_detection_list_datasets]
  /**
   * Demonstrates using the AutoML client to list all Datasets.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const filter_ = '[FILTER_EXPRESSIONS]'
  // e.g., "imageObjectDetectionDatasetMetadata:*";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  const util = require(`util`);

  async function listDatasets() {
    const projectLocation = automlClient.locationPath(projectId, computeRegion);

    // List all the datasets available in the region by applying filter.
    const [response] = await automlClient.listDatasets({
      parent: projectLocation,
      filter: filter,
    });
    console.log('List of datasets:');
    for (const dataset of response) {
      console.log(`\nDataset name: ${dataset.name}`);
      console.log(`Dataset Id: ${dataset.name.split(`/`).pop(-1)}`);
      console.log(`Dataset display name: ${dataset.displayName}`);
      console.log(`Dataset example count: ${dataset.exampleCount}`);
github googleapis / nodejs-automl / samples / vision / object-detection / get-dataset.v1beta1.js View on Github external
datasetId = 'YOUR_DATASET_ID'
) {
  // [START automl_vision_object_detection_get_dataset]
  /**
   * Demonstrates using the AutoML client to get a dataset by ID.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  const util = require(`util`);
  async function getDataset() {
    // Get the full path of the dataset.
    const datasetFullId = automlClient.datasetPath(
      projectId,
      computeRegion,
      datasetId
    );

    // Get a dataset.
    const [response] = await automlClient.getDataset({name: datasetFullId});
    console.log(`Got dataset: ${response.name}`);
    console.log(`Dataset Id: ${response.name.split(`/`).pop(-1)}`);
    console.log(`Dataset display name: ${response.displayName}`);
    console.log(`Dataset example count: ${response.exampleCount}`);
    console.log(
github googleapis / nodejs-automl / samples / vision / object-detection / deploy-model.v1beta1.js View on Github external
projectId = 'YOUR_PROJECT_ID',
  computeRegion = 'YOUR_REGION_NAME',
  modelId = 'MODEL_ID'
) {
  // [START automl_vision_object_detection_deploy_model]

  /**
   * Demonstrates using the AutoML client to deploy model.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function deployModel() {
    // Get the full path of the model.
    const modelFullId = automlClient.modelPath(
      projectId,
      computeRegion,
      modelId
    );

    // Deploy a model with the deploy model request.
    const [operation] = await automlClient.deployModel({name: modelFullId});

    const [response] = await operation.promise();
    console.log(`Deployment Details:`);
github googleapis / nodejs-automl / samples / vision / object-detection / get-operation-status.v1beta1.js View on Github external
function main(operationFullId = 'OPERATION_FULL_ID') {
  // [START automl_vision_object_detection_get_operation_status]
  /**
   * Demonstrates using the AutoML client to get operation status.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const operationFullId = '[OPERATION_FULL_ID]'
  // eg., "projects//locations/us-central1/operations/",
  // `Full name of an operation`;

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function getOperationStatus() {
    // Get the latest state of a long-running operation.
    const [response] = await automlClient.operationsClient.getOperation({
      name: operationFullId,
    });
    console.log(`Operation details:`);
    console.log(`\tName: ${response.name}`);
    console.log(`\tMetadata:`);
    console.log(`\t\tType Url: ${response.metadata.typeUrl}`);
    console.log(`\tDone: ${response.done}`);

    if (response.response) {
      console.log(`\tResponse:`);
github googleapis / nodejs-automl / samples / vision / object-detection / import-data.v1beta1.js View on Github external
computeRegion = 'YOUR_REGION_NAME',
  datasetId = 'YOUR_DATASET_ID',
  gcsPath = 'GCS_PATH'
) {
  // [START automl_vision_object_detection_import_data]
  /**
   * Demonstrates using the AutoML client to import labeled items.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120";
  // const gcsPath = '[GCS_PATH]' e.g., "gs:///",
  // `.csv paths in AutoML Vision Object Detection CSV format`;
  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function importData() {
    // Get the full path of the dataset.
    const datasetFullId = automlClient.datasetPath(
      projectId,
      computeRegion,
      datasetId
    );

    // Get the multiple Google Cloud Storage URIs.
    const inputUris = gcsPath.split(`,`);
    const inputConfig = {
      gcsSource: {
        inputUris: inputUris,
github googleapis / nodejs-automl / samples / vision / object-detection / display-evaluation.v1beta1.js View on Github external
/**
   * Demonstrates using the AutoML client to display model evaluation.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const modelId = '[MODEL_ID]' e.g., "IOD2122286140026257408";
  // const filter = '[FILTER_EXPRESSIONS]'
  // e.g., "imageObjectDetectionModelMetadata:*";

  const math = require(`mathjs`);
  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

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

  // Get the full path of the model.
  const modelFullId = automlClient.modelPath(projectId, computeRegion, modelId);

  // List all the model evaluations in the model by applying filter.
  automlClient
    .listModelEvaluations({parent: modelFullId, filter: filter})
    .then(respond => {
      const response = respond[0];
      // Iterate through the results.
      let modelEvaluationId = ``;
      for (const element of response) {
        // There is evaluation for each class in a model and for overall model.
        // Get only the evaluation of overall model.
        if (!element.annotationSpecId) {
          modelEvaluationId = element.name.split(`/`).pop(-1);
github googleapis / nodejs-automl / samples / vision / object-detection / import-data.v1beta1.js View on Github external
) {
  // [START automl_vision_object_detection_import_data]
  /**
   * Demonstrates using the AutoML client to import labeled items.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const datasetId = '[DATASET_ID]' e.g.,"IOD34216801856389120";
  // const gcsPath = '[GCS_PATH]' e.g., "gs:///",
  // `.csv paths in AutoML Vision Object Detection CSV format`;
  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function importData() {
    // Get the full path of the dataset.
    const datasetFullId = automlClient.datasetPath(
      projectId,
      computeRegion,
      datasetId
    );

    // Get the multiple Google Cloud Storage URIs.
    const inputUris = gcsPath.split(`,`);
    const inputConfig = {
      gcsSource: {
        inputUris: inputUris,
      },
    };
github googleapis / nodejs-automl / samples / vision / object-detection / delete-model.v1beta1.js View on Github external
modelId = 'YOUR_MODEL_ID'
) {
  // [START automl_vision_object_detection_delete_model]
  /**
   * Demonstrates using the AutoML client to delete a model.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const modelId = '[MODEL_ID]' e.g., "IOD1187015161160925184";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

  // Instantiates a client
  const automlClient = new AutoMlClient();
  async function deleteModel() {
    // Get the full path of the model.
    const modelFullId = automlClient.modelPath(
      projectId,
      computeRegion,
      modelId
    );

    // Delete a model.
    const [operation] = await automlClient.deleteModel({name: modelFullId});

    const [response] = await operation.promise();
    const operationDetails = response[2];

    // Get the Model delete details.
    console.log('Model delete details:');
github googleapis / nodejs-automl / samples / vision / object-detection / undeploy-model.v1beta1.js View on Github external
modelId = 'MODEL_ID'
) {
  // [START automl_vision_object_detection_undeploy_model]
  /**
   * Demonstrates using the AutoML client to undeploy model.
   * TODO(developer): Uncomment the following lines before running the sample.
   */
  // const projectId = '[PROJECT_ID]' e.g., "my-gcloud-project";
  // const computeRegion = '[REGION_NAME]' e.g., "us-central1";
  // const modelId = '[MODEL_ID]' e.g., "TEN5200971474357190656";

  //Imports the Google Cloud Automl library
  const {AutoMlClient} = require('@google-cloud/automl').v1beta1;

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

  async function undeployModel() {
    // Get the full path of the model.
    const modelFullId = automlClient.modelPath(
      projectId,
      computeRegion,
      modelId
    );

    // Deploy a model with the deploy model request.
    const [operation] = await automlClient.undeployModel({name: modelFullId});
    const [response] = await operation.promise();
    for (const element of response) {
      console.log(`Undeployment Details:`);
      console.log(`\tName: ${element.name}`);
      console.log(`\tMetadata:`);