Exporting Edge models

After you have created (trained) a model, you can export your custom model.

After exporting your model you can then deploy the model to a device.

You can export an image classification model in either generic Tensorflow Lite format, general TensorFlow format, or TensorFlow.js for Web format to a Google Cloud Storage location using the ExportModel API.

Export to devices

TensorFlow Lite models

Web UI

  1. Open the Cloud AutoML Vision Object Detection UI and click the lightbulb icon in the left navigation bar to display the available models.

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

  2. Select the row for the model you want to use to label your images.

  3. Select the Test & use tab.

  4. In the Use your model section select the TF Lite card. This opens a side "Use your on-device model" window.

    Export TF Lite model option image

  5. In the side window, specify the output Google Cloud Storage location. After choosing the storage location for your model output, select Export to begin the model export operation.

    Choose a storage location for exported model image

  6. After exporting you can select the "Open in Google Cloud Storage" option in the same window to go directly to the export directory in Google Cloud Storage.

REST & CMD LINE

In the "modelFormat" field specify "tflite" (default).

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

  • project-id: your GCP project ID.
  • model-id: the ID of your model, from the response when you created the model. The ID is the last element of the name of your model. For example:
    • model name: projects/project-id/locations/location-id/models/IOD4412217016962778756
    • model id: IOD4412217016962778756
  • output-storage-bucket: a Google Cloud Storage bucket/directory to save output files to, expressed in the following form: gs://bucket/directory/. The requesting user must have write permission to the bucket.

HTTP method and URL:

POST https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/model-id:export

Request JSON body:

{
  "outputConfig": {
    "modelFormat": "tflite",
    "gcsDestination": {
      "outputUriPrefix": "output-storage-bucket/"
    },
  }
}

To send your request, choose one of these options:

curl

Save the request body in a file called request.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/model-id:export

PowerShell

Save the request body in a file called request.json, and execute the following command:

$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/model-id:export" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "name": "projects/project-id/locations/us-central1/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "createTime": "2019-07-22T21:23:21.643041Z",
    "updateTime": "2019-07-22T21:23:21.643041Z",
    "exportModelDetails": {
      "outputInfo": {
        "gcsOutputDirectory": "output-storage-bucket/model-export/iod/tflite-dataset-name-YYYY-MM-DDThh:mm:ss.sssZ"
      }
    }
  }
}

As a result you will see a folder structure in the directory you provided (cloud-storage-bucket/[directory]). The created folder structure will have the following general format (timestamp in ISO-8601 format):

  • cloud-storage-bucket/model-export/iod/model-type-dataset-name-YYYY-MM-DDThh:mm:ss.sssZ

For example:

  • cloud-storage-bucket/model-export/iod/tf-saved-model-dataset-name-2019-07-22T21:25:35.135Z
  • cloud-storage-bucket/model-export/iod/tflite-dataset-name-2019-07-22T21:23:18.861Z

The folder contains a TensorFlow Lite model named model.tflite, a label file named dict.txt, and a tflite_metadata.json file.

Timestamp folder example

Using the exported model

After exporting your model to a Google Cloud Storage bucket you can deploy your AutoML Vision Edge model on Android devices, iOS devices, or Raspberry Pi 3.

Export to a container

Web UI

  1. Open the Cloud AutoML Vision Object Detection UI and click the lightbulb icon in the left navigation bar to display the available models.

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

  2. Click the row for the model you want to use to label your images.

  3. Select the Test & use tab.

  4. In the Use your model section select the TF Lite card. This opens a side "Use your on-device model" window.

    Export TF Lite model option image

  5. In the side window, specify the output Google Cloud Storage location. After choosing the storage location for your model output, select Export to begin the model export operation.

    Choose a storage location for exported model image

  6. After exporting you can select the "Open in Google Cloud Storage" option in the same window to go directly to the export directory in Google Cloud Storage.

REST & CMD LINE

In the "modelFormat" field specify "tf-saved-model".

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

  • project-id: your GCP project ID.
  • model-id: the ID of your model, from the response when you created the model. The ID is the last element of the name of your model. For example:
    • model name: projects/project-id/locations/location-id/models/IOD4412217016962778756
    • model id: IOD4412217016962778756
  • output-storage-bucket: a Google Cloud Storage bucket/directory to save output files to, expressed in the following form: gs://bucket/directory/. The requesting user must have write permission to the bucket.

HTTP method and URL:

POST https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/${model-id}:export

Request JSON body:

{
  "outputConfig": {
    "modelFormat": "tf-saved-model",
    "gcsDestination": {
      "outputUriPrefix": "output-storage-bucket/"
    },
  }
}

To send your request, choose one of these options:

curl

Save the request body in a file called request.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/${model-id}:export

PowerShell

Save the request body in a file called request.json, and execute the following command:

$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/${model-id}:export" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "name": "projects/project-id/locations/us-central1/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "createTime": "2019-07-22T21:23:21.643041Z",
    "updateTime": "2019-07-22T21:23:21.643041Z",
    "exportModelDetails": {
      "outputInfo": {
        "gcsOutputDirectory": "output-storage-bucket/model-export/iod/tf-saved-model-dataset-name-YYYY-MM-DDThh:mm:ss.sssZ"
      }
    }
  }
}

As a result you will see a folder structure in the directory you provided (cloud-storage-bucket/[directory]). The created folder structure will have the following general format (timestamp in ISO-8601 format):

  • cloud-storage-bucket/model-export/iod/model-type-dataset-name-YYYY-MM-DDThh:mm:ss.sssZ

For example:

  • cloud-storage-bucket/model-export/iod/tf-saved-model-dataset-name-2019-07-22T21:25:35.135Z
  • cloud-storage-bucket/model-export/iod/tflite-dataset-name-2019-07-22T21:23:18.861Z

The folder contains a TensorFlow model named saved_model.pb.

Timestamp folder example

Using the exported model

After exporting your model to a Google Cloud Storage bucket you can use your exported model to make predictions in a Docker image. See the Containers tutorial for instructions on deployment to a container.

Export for Web

Web UI

  1. Open the AutoML Vision UI and select the lightbulb icon in the side navigation bar to display the available models.

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

  2. Select the row for the model you want to use to label your images.

  3. Select the Test & Use tab just below the title bar.

  4. In the Use your model section select the Tensorflow.js option. After selecting the Tensorflow.js option, select Export to export your Web-ready TensorFlow.js model.

    Export TensorFlow.js screenshot

Integrated UI

  1. Open the Vision Dashboard and select the lightbulb icon in the side navigation bar to display the available models.

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

  2. Select the row for the model you want to use to label your images.

  3. Select the Test & Use tab just below the title bar.

  4. In the Use your model section select the Tensorflow.js option. After selecting the Tensorflow.js option, select Export to export your Web-ready TensorFlow.js model.

    updated export TensorFlow.js model screenshot

REST & CMD LINE

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

  • project-id: your GCP project ID.
  • model-id: the ID of your model, from the response when you created the model. The ID is the last element of the name of your model. For example:
    • model name: projects/project-id/locations/location-id/models/IOD4412217016962778756
    • model id: IOD4412217016962778756
  • output-storage-bucket: a Google Cloud Storage bucket/directory to save output files to, expressed in the following form: gs://bucket/directory/. The requesting user must have write permission to the bucket.

HTTP method and URL:

POST https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/model-id:export

Request JSON body:

{
  "outputConfig": {
    "modelFormat": "tf_js",
    "gcsDestination": {
      "outputUriPrefix": "output-storage-bucket/"
    },
  }
}

To send your request, choose one of these options:

curl

Save the request body in a file called request.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/model-id:export

PowerShell

Save the request body in a file called request.json, and execute the following command:

$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://automl.googleapis.com/v1/projects/project-id/locations/us-central1/models/model-id:export" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "name": "projects/project-id/locations/us-central1/operations/operation-id",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.automl.v1.OperationMetadata",
    "createTime": "2019-07-22T21:23:21.643041Z",
    "updateTime": "2019-07-22T21:23:21.643041Z",
    "exportModelDetails": {
      "outputInfo": {
        "gcsOutputDirectory": "output-storage-bucket/model-export/icn/tf_js-dataset-name-YYYY-MM-DDThh:mm:ss.sssZ"
      }
    }
  }
}

As a result you will see a folder in the directory you provided (${USER_GCS_PATH}). The created folder will be named according to timestamp in the format /model-export/icn/tf_js-dataset-name-YYYY-MM-DDThh:mm:ss.sssZ (for example, tf_js-edge_model-2019-10-03T17:24:46.999Z).

The folder contains binary files (.bin), a label file named dict.txt, and a model.json file.

Tensorflow.js folder example