Managing models

You create a custom model by training it using a prepared dataset. AutoML Video Intelligence Classification uses the items from the dataset to train the model, test it, and evaluate its performance. You review the results, adjust the training dataset as needed, and train a new model using the improved dataset.

Training a model can take several hours to complete. The AutoML API enables you to check the status of training.

Since AutoML Video Intelligence Classification creates a new model each time you start training, your project may include numerous models. You can get a list of the models in your project and can delete models you no longer need.

The maximum lifespan for a custom model is two years. You must create and train a new model to continue classifying content after that amount of time.

Using curl

To make it more convenient to run the curl samples in this topic, set the following environment variable. Replace project-id with the name of your GCP project.

export PROJECT_ID="project-id"

Training models

When you have a dataset with a solid set of labeled training items, you are ready to create and train the custom model.

Web UI

  1. Open the AutoML Video Classification UI and navigate to the Datasets page.

    Datasets page in Google Cloud Console
  2. Select the dataset that you want to use to train the custom model.

    The display name of the selected dataset appears in the title bar, and the page lists the individual items in the dataset along with their labels.

    Videos tab with two videos shown
  3. When you are done reviewing the dataset, click the Train tab just below the title bar.

    The training page provides a basic analysis of your dataset and advises you about whether it is adequate for training. If AutoML Video Classification suggests changes, consider returning to the Videos page and adding items or labels.

  4. When the dataset is ready, click Start Training to create a new model or Train New Model if you want to create an additional model.

REST & CMD LINE

Before using any of the request data below, make the following replacements:

  • dataset-id: The ID is the last element of the name of your dataset. For example, if the name of your dataset is projects/434039606874/locations/us-central1/datasets/VCN3104518874390609379, then the ID of your dataset is VCN3104518874390609379.
  • Note:
    • project-id: name of your GCP project
    • location-id: for example, us-central1

HTTP method and URL:

POST https://automl.googleapis.com/v1beta1/projects/project-id/locations/location-id/models

Request JSON body:

{
  "displayName": "test_model",
  "dataset_id": "dataset-id",
  "videoClassificationModelMetadata": {}
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "name": "projects/project-id/locations/location-id/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "progressPercentage": 100,
    "createTime": "2019-11-27T01:56:28.395640Z",
    "updateTime": "2019-11-27T02:04:12.336070Z"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.Model",
    "name": "projects/project-id/locations/location-id/models/operation-id",
    "createTime": "2019-10-27T02:00:22.329970Z",
    "videoClassificationModelMetadata": {
      "trainBudget": "1",
      "trainCost": "1",
      "stopReason": "BUDGET_REACHED"
    },
    "displayName": "a_98487760535e48319dd204e6394670"
  }
}
  • operation-id: provided in the response when you started the operation, for example VCN123....

Java

/**
 * Demonstrates using the AutoML client to create a model.
 *
 * @param projectId the Id of the project.
 * @param computeRegion the Region name. (e.g., "us-central1")
 * @param datasetId the Id of the dataset to which model is created.
 * @param modelName the name of the model.
 * @throws IOException
 * @throws ExecutionException
 * @throws InterruptedException
 */
public static void createModel(
    String projectId, String computeRegion, String datasetId, String modelName)
    throws IOException, InterruptedException, ExecutionException {
  // Instantiates a client
  AutoMlClient client = AutoMlClient.create();

  // A resource that represents Google Cloud Platform location.
  LocationName projectLocation = LocationName.of(projectId, computeRegion);

  // Set model meta data
  VideoClassificationModelMetadata videoClassificationModelMetadata =
      VideoClassificationModelMetadata.newBuilder().build();

  // Set model name, dataset and metadata.
  Model myModel =
      Model.newBuilder()
          .setDisplayName(modelName)
          .setDatasetId(datasetId)
          .setVideoClassificationModelMetadata(videoClassificationModelMetadata)
          .build();

  // Create a model with the model metadata in the region.
  OperationFuture<Model, OperationMetadata> response =
      client.createModelAsync(projectLocation, myModel);

  System.out.println(
      String.format("Training operation name: %s", response.getInitialFuture().get().getName()));
  System.out.println("Training started...");
}

Node.js

const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to create 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 datasetId = '[DATASET_ID]' e.g., "VCN7209576908164431872";
// const modelName = '[MODEL_NAME]' e.g., "myModel";

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);

// Set datasetId, model name and model metadata for the dataset.
const myModel = {
  displayName: modelName,
  datasetId: datasetId,
  videoClassificationModelMetadata: {},
};

// Create a model with the model metadata in the region.
client
  .createModel({parent: projectLocation, model: myModel})
  .then(responses => {
    const initialApiResponse = responses[1];
    console.log(`Training operation name: ${initialApiResponse.name}`);
    console.log(`Training started...`);
  })
  .catch(err => {
    console.error(err);
  });

Python

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# dataset_id = 'DATASET_ID_HERE'
# model_name = 'MODEL_NAME_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.AutoMlClient()

# A resource that represents Google Cloud Platform location.
project_location = client.location_path(project_id, compute_region)

# Set model name and model metadata for the image dataset.
my_model = {
    "display_name": model_name,
    "dataset_id": dataset_id,
    "video_classification_model_metadata": {}
}

# Create a model with the model metadata in the region.
response = client.create_model(project_location, my_model)

print("Training operation name: {}".format(response.operation.name))
print("Training started...")

Getting information about a model

When training is complete, you can get information about the newly created model.

The examples in this section return the basic metadata about a model. To get details about a model's accuracy and readiness, see Evaluating models.

Web UI

  1. Navigate to the Models page in the AutoML Video Classification UI.

    Models page with one model shown
  2. Click the name of the model that you want to view.

REST & CMD LINE

Before using any of the request data below, make the following replacements:

  • model-name: The full name of your model provided by the response when you created the model. The full name has the format: projects/project-id/locations/location-id/models/model-id

HTTP method and URL:

GET https://automl.googleapis.com/v1beta1/projects/project-id/locations/location-id/models

Request JSON body:

{
  "displayName": "test_model",
  "dataset_id": "dataset-id",
  "videoClassificationModelMetadata": {}
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "name": "projects/915378992997/locations/us-central1/models/VCN2004101834179870720",
  "displayName": "my_model_01",
  "datasetId": "VCN3940649673949184000",
  "createTime": "2019-11-19T17:18:45.320701Z",
  "updateTime": "2019-11-19T17:18:45.320701Z",
  "videoClassificationModelMetadata": {}
}

Java

/**
 * Demonstrates using the AutoML client to get model details.
 *
 * @param projectId the Id of the project.
 * @param computeRegion the Region name. (e.g., "us-central1")
 * @param modelId the Id of the model.
 * @throws IOException
 */
public static void getModel(String projectId, String computeRegion, String modelId)
    throws IOException {
  // Instantiates a client
  AutoMlClient client = AutoMlClient.create();

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

  // Get complete detail of the model.
  Model model = client.getModel(modelFullId);

  // Display the model information.
  System.out.println(String.format("Model name: %s", model.getName()));
  System.out.println(
      String.format(
          "Model Id: %s", model.getName().split("/")[model.getName().split("/").length - 1]));
  System.out.println(String.format("Model display name: %s", model.getDisplayName()));
  System.out.println(String.format("Dataset Id: %s", model.getDatasetId()));
  System.out.println(
      String.format(
          "VideoClassificationModelMetadata: %s", model.getVideoClassificationModelMetadata()));
  DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
  String createTime =
      dateFormat.format(new java.util.Date(model.getCreateTime().getSeconds() * 1000));
  System.out.println(String.format("Model create time: %s", createTime));
  String updateTime =
  		dateFormat.format(new java.util.Date(model.getUpdateTime().getSeconds() * 1000));
  System.out.println(String.format("Model update time: %s", updateTime));
  System.out.println(String.format("Model deployment state: %s", model.getDeploymentState()));
}

Node.js

const automl = require(`@google-cloud/automl`);
const util = require(`util`);
const client = new automl.v1beta1.AutoMlClient();

/**
 * Demonstrates using the AutoML client to get model details.
 * 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., "VCN7209576908164431872";

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

// Get complete detail of the model.
client
  .getModel({name: modelFullId})
  .then(responses => {
    const model = responses[0];

    // Display the model information.
    console.log(`Model 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}`);

    if (model.modelMetadata === `videoClassificationModelMetadata`) {
      console.log(
        `Video Classification Model Metadata: ${util.inspect(
          model.videoClassificationModelMetadata,
          false,
          null
        )}`
      );
    }
    console.log(`Model deployment state: ${model.deploymentState}`);
  })
  .catch(err => {
    console.error(err);
  });

Python

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_id = 'MODEL_ID_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.AutoMlClient()

# Get the full path of the model.
model_full_id = client.model_path(project_id, compute_region, model_id)

# Get complete detail of the model.
model = client.get_model(model_full_id)

# Display the model information.
print("Model name: {}".format(model.name))
print("Model id: {}".format(model.name.split("/")[-1]))
print("Model display name: {}".format(model.display_name))
print("Model create time:")
print("\tseconds: {}".format(model.create_time.seconds))
print("\tnanos: {}".format(model.create_time.nanos))

Listing models

A project can include numerous models. This section describes how to retrieve a list of the available models for a project.

Web UI

Navigate to the Models page in the AutoML Video Classification UI to see the models in your project.

Models page with one model in list

To see the models for a different project, select the project from the drop-down list in the upper right of the title bar.

REST & CMD LINE

Before using any of the request data below, make the following replacements:

  • model-name: The full name of your model provided by the response when you created the model. The full name has the format: projects/project-id/locations/location-id/models

HTTP method and URL:

GET https://automl.googleapis.com/v1beta1/projects/project-id/locations/location-id/models

Request JSON body:


To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "model": [{
    "name": "projects/915378992997/locations/us-central1/models/VCN2004101834179870720",
    "displayName": "my_model_01",
    "datasetId": "VCN3940649673949184000",
    "createTime": "2019-11-19T17:18:45.320701Z",
    "updateTime": "2019-11-19T17:18:45.320701Z",
    "videoClassificationModelMetadata": {}
  }]
}

Java

/**
 * Demonstrates using the AutoML client to list all models.
 *
 * @param projectId the Id of the project.
 * @param computeRegion the Region name. (e.g., "us-central1")
 * @param filter the filter expression.
 * @throws IOException
 */
public static void listModels(String projectId, String computeRegion, String filter)
    throws IOException {
  // Instantiates a client
  AutoMlClient client = AutoMlClient.create();

  // A resource that represents Google Cloud Platform location.
  LocationName projectLocation = LocationName.of(projectId, computeRegion);

  // Create list models request.
  ListModelsRequest listModelsRequest =
      ListModelsRequest.newBuilder()
          .setParent(projectLocation.toString())
          .setFilter(filter)
          .build();

  // List all the models available in the region by applying filter.
  System.out.println("List of models:");
  for (Model model : client.listModels(listModelsRequest).iterateAll()) {
    // Display the model information.
    System.out.println(String.format("\nModel name: %s", model.getName()));
    System.out.println(
        String.format(
            "Model Id: %s", model.getName().split("/")[model.getName().split("/").length - 1]));
    System.out.println(String.format("Model display name: %s", model.getDisplayName()));
    System.out.println(String.format("Dataset Id: %s", model.getDatasetId()));
    System.out.println(
        String.format(
            "VideoClassificationModelMetadata: %s", model.getVideoClassificationModelMetadata()));
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
    String createTime =
        dateFormat.format(new java.util.Date(model.getCreateTime().getSeconds() * 1000));
    System.out.println(String.format("Model create time: %s", createTime));
    String updateTime =
  		  dateFormat.format(new java.util.Date(model.getUpdateTime().getSeconds() * 1000));
    System.out.println(String.format("Model update time: %s", updateTime));
    System.out.println(String.format("Model deployment state: %s", model.getDeploymentState()));
  }
}

Node.js

const automl = require(`@google-cloud/automl`);
const util = require(`util`);
const client = new automl.v1beta1.AutoMlClient();

/**
 * 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., "videoClassificationModelMetadata:*";

// A resource that represents Google Cloud Platform location.
const projectLocation = client.locationPath(projectId, computeRegion);

// List all the models available in the region by applying filter.
client
  .listModels({parent: projectLocation, filter: filter})
  .then(responses => {
    const model = responses[0];

    // Display the model information.
    console.log(`List of models:`);
    for (let i = 0; i < model.length; i++) {
      console.log(`\nModel name: ${model[i].name}`);
      console.log(`Model Id: ${model[i].name.split(`/`).pop(-1)}`);
      console.log(`Model display name: ${model[i].displayName}`);
      console.log(`Dataset Id: ${model[i].datasetId}`);

      if (model[i].modelMetadata === `videoClassificationModelMetadata`) {
        console.log(
          `Video Classification model metadata: ${util.inspect(
            model[i].videoClassificationModelMetadata,
            false,
            null
          )}`
        );
      }
      console.log(`Model deployment state: ${model[i].deploymentState}`);
    }
  })
  .catch(err => {
    console.error(err);
  });

Python

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# filter_ = 'DATASET_ID_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.AutoMlClient()

# A resource that represents Google Cloud Platform location.
project_location = client.location_path(project_id, compute_region)

# List all the models available in the region by applying filter.
response = client.list_models(project_location, filter_)

print("List of models:")
for model in response:
    # Display the model information.
    print("Model name: {}".format(model.name))
    print("Model id: {}".format(model.name.split("/")[-1]))
    print("Model display name: {}".format(model.display_name))
    print("Model create time:")
    print("\tseconds: {}".format(model.create_time.seconds))
    print("\tnanos: {}".format(model.create_time.nanos))

Deleting a model

The following example deletes a model.

Web UI

  1. Navigate to the Models page in the AutoML Video Classification UI.

    Models page with one model shown
  2. Click the three-dot menu at the far right of the row you want to delete and select Delete.
  3. Click Confirm in the confirmation dialog box.

REST & CMD LINE

Before using any of the request data below, make the following replacements:

  • model-name: The full name of your model provided by the response when you created the model. The full name has the format: projects/project-id/locations/location-id/models/model-id

HTTP method and URL:

DELETE https://automl.googleapis.com/v1beta1/projects/project-id/locations/test/models/model-id

Request JSON body:


To send your request, expand one of these options:

You should receive a JSON response similar to the following:

{
  "name": "projects/674030654376/locations/us-central1/operations/VCN2519201041560371200",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "createTime": "2018-10-25T01:50:41.551853Z",
    "updateTime": "2018-10-25T01:50:41.551853Z",
    "deleteDetails": {}
  }
}

Java

/**
 * Demonstrates using the AutoML client to delete a model.
 *
 * @param projectId the Id of the project.
 * @param computeRegion the Region name. (e.g., "us-central1")
 * @param modelId the Id of the model.
 * @throws IOException
 * @throws ExecutionException
 * @throws InterruptedException
 */
public static void deleteModel(String projectId, String computeRegion, String modelId)
    throws InterruptedException, ExecutionException, IOException {
  // Instantiates a client
  AutoMlClient client = AutoMlClient.create();

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

  // Delete a model.
  Empty response = client.deleteModelAsync(modelFullId).get();

  System.out.println("Model deletion started...");
  System.out.println(String.format("Model deleted. %s", response));
}

Node.js

const automl = require(`@google-cloud/automl`);
const client = new automl.v1beta1.AutoMlClient();

/**
 * 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., "VCN7209576908164431872";

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

// Delete a model.
client
  .deleteModel({name: modelFullId})
  .then(responses => {
    const operation = responses[0];
    return operation.promise();
  })
  .then(responses => {
    // The final result of the operation.
    const operationDetails = responses[2];

    // Get the Model delete details.
    console.log('Model delete details:');
    console.log(`\tOperation details:`);
    console.log(`\t\tName: ${operationDetails.name}`);
    console.log(`\tDone: ${operationDetails.done}`);
  })
  .catch(err => {
    console.error(err);
  });

Python

# TODO(developer): Uncomment and set the following variables
# project_id = 'PROJECT_ID_HERE'
# compute_region = 'COMPUTE_REGION_HERE'
# model_id = 'MODEL_ID_HERE'

from google.cloud import automl_v1beta1 as automl

client = automl.AutoMlClient()

# Get the full path of the model.
model_full_id = client.model_path(project_id, compute_region, model_id)

# Delete a model.
response = client.delete_model(model_full_id)

# synchronous check of operation status.
print("Model deleted. {}".format(response.result()))
Was this page helpful? Let us know how we did:

Send feedback about...

AutoML Video Intelligence