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, Edge TPU compiled TensorFlow Lite format, or TensorFlow format to a Google Cloud Storage location using the ExportModel API.

Using curl

To make it more convenient to run the curl samples in this topic, set the following environment variable.

export ENDPOINT="automl.googleapis.com"

Export to devices

TensorFlow Lite models

Web UI

  1. Open the AutoML Vision 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. Click the Predict tab just below the title bar.

  4. In the Use your Edge model section click the TF Lite tab. After selecting the TF Lite tab, select Export to export your Edge TF Lite model.

    Export TF Lite model

Command-line

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

curl \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://${ENDPOINT}/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models/${MODEL_ID}:export \
  -d '{
        "output_config": {
          "model_format": "tflite",
          "gcs_destination": {
              "output_uri_prefix": "${USER_GCS_PATH}"
          },
        }
      }'

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 with the model type in the format YYYY-MM-DD_hh-mm-ss-sss_${model-type} (for example, 2018-10-26_18-16-30-458_tflite).

Timestamp folder example

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

Each line in the label file dict.txt represents a label of the predictions returned by the TensorFlow Lite model, in the same order they were requested. For example, the dict.txt for the flowers dataset is as follows:

daisy
dandelion
roses
sunflowers
tulips

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.

Core ML models

Web UI

  1. Open the AutoML Vision 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. Click the Predict tab just below the title bar.

  4. In the Use your Edge model section click the Core ML tab. After selecting the Core ML tab, click Export to export your on-device TF Lite model.

    Export Core ML model

Command-line

In the "model_format" field specify "core-ml".

curl \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://${ENDPOINT}/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models/${MODEL_ID}:export \
  -d '{
        "output_config": {
        "model_format": "core-ml",
          "gcs_destination": {
              "output_uri_prefix": "${USER_GCS_PATH}"
          },
        }
      }'

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 YYYY-MM-DD_hh-mm-ss-sss_${model-type} (for example, 2018-10-26_18-16-30-458_core-ml).

Timestamp folder example

The folder contains a Core ML model named model.mlmodel and a label file named dict.txt.

Each line in the label file dict.txt represents a label of the predictions returned by the TensorFlow Lite model, in the same order they were requested. For example, the dict.txt for the flowers dataset is as follows:

daisy
dandelion
roses
sunflowers
tulips

Using the exported model

After exporting your model to a Google Cloud Storage bucket you can deploy your AutoML Vision Edge model on iOS devices.

Export to a container

Web UI

  1. Open the AutoML Vision 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. Click the Predict tab just below the title bar.

  4. In the Use your Edge model section click the Container tab. After selecting the Container tab, click Export to export your on-device TF Lite model.

    Export TF Lite model

Command-line

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

curl \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://${ENDPOINT}/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models/${MODEL_ID}:export \
  -d '{
        "output_config": {
        "model_format": "tf-saved-model",
          "gcs_destination": {
              "output_uri_prefix": "${USER_GCS_PATH}"
          },
        }
      }'

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 YYYY-MM-DD_hh-mm-ss-sss_${model-type} (for example, 2018-10-26_18-16-30-458_tf-saved-model).

Timestamp folder example

The folder contains a TensorFlow model named saved_model.pb.

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 to Edge TPU

Web UI

  1. Open the AutoML Vision 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. Click the Predict tab just below the title bar.

  4. In the Use your Edge model section select the Edge devices tab.

    Export TF Lite model

  5. From the dropdown menu, select Edge TPU. After selecting the Edge TPU option, click Export to export your Edge TF Lite model.

    Export TF Lite model dropdown

Command-line

curl \
  -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
  -H "Content-Type: application/json" \
  https://${ENDPOINT}/v1beta1/projects/${PROJECT_ID}/locations/us-central1/models/${MODEL_ID}:export \
  -d '{
        "output_config": {
          "gcs_destination": {
              "output_uri_prefix": "${USER_GCS_PATH}"
          },
              "params": {
                "model-format": "edgetpu_tflite"
          }
        }
      }'

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 YYYY-MM-DD_hh-mm-ss-sss_${model-type} (for example, 2018-10-26_18-16-30-458_edgetpu-tflite).

Timestamp folder example

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

Each line in the label file dict.txt represents a label of the predictions returned by the TensorFlow Lite model, in the same order they were requested. For example, the dict.txt for the flowers dataset is as follows:

daisy
dandelion
roses
sunflowers
tulips

Using the exported model

For more information on how to deploy to Edge TPU, see Coral's official documentation.

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

Send feedback about...

Cloud AutoML Vision
Need help? Visit our support page.