Training Edge exportable models

You create a custom model by training it using a prepared dataset. AutoML API 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 Vision 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 can delete models you no longer need. Alternatively, you can use the Cloud AutoML Vision UI to list and delete models created via the AutoML API that you do not need anymore.

Note:

  • Unless otherwise specified in applicable terms of service or documentation, custom models created in Cloud AutoML products cannot be exported.
  • 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.
  • Edge models are optimized for inference on an Edge device. Consequently, Edge model accuracy will differ from Cloud model accuracy.

Models are based on state-of-the-art research at Google. Your model will be available as a TF Lite package. For more information about how to integrate a TensorFlow Lite model using the TensorFlow Lite SDK reference the following links for iOS and Android.

Training Edge models

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

TensorFlow serving and TF Lite models

When training Edge models you can specify three distinct values in the modelType field depending on your model needs:

  • mobile-low-latency-1 for low latency,
  • mobile-versatile-1 for general purpose usage, or
  • mobile-high-accuracy-1 for higher prediction quality.

The model type will also be shown in the API request response.

Web UI

  1. Open the AutoML Vision UI.

    The Datasets page shows the available datasets for the current project.

    Dataset list page

  2. Select the dataset 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.

    Image items page

  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 Vision suggests changes, consider returning to the Images page and adding items or labels.

  4. When the dataset is ready, choose "Edge" from the Model type options. After selecting to train an Edge model, choose from the three Edge options based on your model needs. You can use the Estimate latency for selector to get estimated latency, size and accuracy values for different devices. Latency values are estimated for an input image of size 224px by 224px.

    You can also specify your training budget in terms of compute hours in this window.

    Train Edge model

    After specifying all your settings, click Start Training.

Training a model can take several hours to complete.

Command-line

  • Replace dataset-id with the ID of your dataset. 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/3104518874390609379, then the ID of your dataset is 3104518874390609379.
curl \
  -X POST \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://automl.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models \
  -d '{
    "displayName": "test_model",
    "dataset_id": "dataset-id",
    "imageClassificationModelMetadata": {
      "trainBudget": "1",
      "modelType": "mobile-low-latency-1"
    },
  }'

You should see output similar to the following. You can use the operation ID to get the status of the task. For an example, see Getting the status of an operation.

{
  "name": "projects/434039606874/locations/us-central1/operations/1979469554520652445",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "createTime": "2018-04-27T01:28:41.338120Z",
    "updateTime": "2018-04-27T01:28:41.338120Z",
    "cancellable": true
  }
}

Core ML models

Web UI

  1. Open the AutoML Vision UI.

    The Datasets page shows the available datasets for the current project.

    Dataset list page

  2. Select the dataset 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.

    Image items page

  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 Vision suggests changes, consider returning to the Images page and adding items or labels.

  4. When the dataset is ready, choose "Edge" from the Model type options. After selecting to train an Edge model, a checkbox will appear with the option to check_box "Format model for Core ML". Select the box.

    Train ML Core model checkbox image

  5. After selecting the box to train a Core ML model, choose from the three Edge options based on your model needs. You can use the Estimate latency for selector to get estimated latency, size and accuracy values for different devices. Latency values are estimated for an input image of size 224px by 224px.

    You can also specify your training budget in terms of compute hours in this window.

    After specifying all your settings, click Start Training.

Training a model can take several hours to complete.

Command-line

When training mobile models you can specify three distinct values in the modelType field depending on your model needs:

  • mobile-core-ml-low-latency-1 for low latency,
  • mobile-core-ml-versatile-1 for general purpose usage, or
  • mobile-core-ml-high-accuracy-1 for higher prediction quality.

The model type will also be shown in the API request response.

  • Replace dataset-id with the ID of your dataset. 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/3104518874390609379, then the ID of your dataset is 3104518874390609379.
curl \
  -X POST \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://automl.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models \
  -d '{
    "displayName": "test_model",
    "dataset_id": "dataset-id",
    "imageClassificationModelMetadata": {
      "trainBudget": "1",
      "modelType": "mobile-core-ml-low-latency-1"
    },
  }'

You should see output similar to the following. You can use the operation ID to get the status of the task. For an example, see Getting the status of an operation.

{
  "name": "projects/434039606874/locations/us-central1/operations/1979469554520652445",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "createTime": "2018-04-27T01:28:41.338120Z",
    "updateTime": "2018-04-27T01:28:41.338120Z",
    "cancellable": true
  }
}

Getting the status of an operation

You can check the status of a long-running task (importing items into a dataset or training a model) using the operation ID from the response when you started the task.

You can only check the status of operations using the AutoML API.

Command-line

In the command below, replace operation-name with the full name of your operation. The full name has the format projects/{project-id}/locations/us-central1/operations/{operation-id}.

curl \
  -X GET \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://automl.googleapis.com/v1beta1/operation-id

You should see output similar to the following for an import operation:

{
  "name": "projects/434039606874/locations/us-central1/operations/2116326435840390257",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "progressPercentage": 100,
    "partialFailures": [
      {
        "code": 7,
        "message": "Duplicated files detected gs://my-project-lcm/training-data/astros.txt
        and gs://my-project-lcm/training-data/cubs.txt have the same content"
      },
    ],
    "createTime": "2018-04-27T01:39:59.821460Z",
    "updateTime": "2018-04-27T01:43:09.564770Z"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.protobuf.Empty"
  }
}

You should see output similar to the following for a create model operation:

{
  "name": "projects/434039606874/locations/us-central1/operations/2126599795587061786",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.OperationMetadata",
    "progressPercentage": 100,
    "createTime": "2018-04-27T01:56:28.395640Z",
    "updateTime": "2018-04-27T02:04:12.336070Z"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.automl.v1beta1.Model",
    "name": "projects/434039606874/locations/us-central1/models/3745331181667467569",
    "createTime": "2018-04-27T02:00:22.329970Z",
    "imageClassificationModelMetadata": {
      "trainBudget": "1",
      "trainCost": "1",
      "stopReason": "BUDGET_REACHED",
      "modelType": "mobile-versatile-1"
    },
    "displayName": "a_98487760535e48319dd204e6394670"
  }
}

Cancelling an 0peration

You can cancel an import or training task using the operation ID.

Command-line

In the command below, replace operation-name with the full name of your operation. The full name has the format projects/{project-id}/locations/us-central1/operations/{operation-id}.

curl \
  -X POST "Content-Type: application/json" \
  -H "Authorization: Bearer `gcloud auth application-default print-access-token`" \
  https://automl.googleapis.com/v1beta1/operation-name:cancel"

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.

Command-line

* Replace model-name with the full name of your model, from the response when you created the model. The full name has the format: projects/{project-id}/locations/us-central1/models/{model-id}
curl \
  -X GET \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)"
  -H "Content-Type: application/json" \
  https://automl.googleapis.com/v1beta1/model-name

You should see output similar to the following:

{
  "model": [
    {
      "name": "projects/434039606874/locations/us-central1/models/3745331181667467569",
      "createTime": "2018-04-27T02:00:22.329970Z",
      "imageClassificationModelMetadata": {
        "trainBudget": "1",
        "trainCost": "1",
        "stopReason": "BUDGET_REACHED",
        "modelType": "mobile-high-accuracy-1"
      },
      "displayName": "a_98487760535e48319dd204e6394670"
    },
}

Resumable training

You can now pause and resume your custom model training for large datasets (with more than one thousand images).

Web UI

  1. Open the AutoML Vision UI.

    The Datasets page shows the available datasets for the current project.

    Dataset list page

  2. Select the dataset 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.

    Image items page

  3. When you are done reviewing the dataset, click the Train tab just below the title bar.

    If you previously trained models they will appear in a list in this tab.

    List of trained models

  4. If resumable training is available for a model it will appear as an option in blue text next to See full evaluation.

    Select Resume training to resume training on an applicable model.

    Resume training option

Command-line

curl \
  -X POST \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://automl.googleapis.com/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models \
  -d '{
    "displayName": "test_model",
    "dataset_id": "dataset-id",
    "imageClassificationModelMetadata": {
      "trainBudget": "1",
      "modelType": "mobile-low-latency-1",
      "base_model_id": "model-id",
    },
  }'

The imageClassificationModelMetadata.modelType field is not required for resumable training. If modelType is not provided, the type of the base model will automatically be used. If modelType is provided AutoML Vision will check if it matches the base model type. In all cases, you can only resume training on a model of the same type.

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud AutoML Vision
Need help? Visit our support page.