Edge device model quickstart

This quickstart walks you through the process of:

  • Copying a set of images into Google Cloud Storage.
  • Creating a CSV listing the images and their labels.
  • Using AutoML Vision to create your dataset, train a custom AutoML Vision Edge model, and make a prediction.
  • Exporting and deploying your AutoML Vision Edge model.

Before you begin

Configura tu proyecto

  1. Accede a tu Cuenta de Google.

    Si todavía no tienes una cuenta, regístrate para obtener una nueva.

  2. En GCP Console, ve a la página Administrar recursos y selecciona o crea un proyecto.

    Ir a la página Administrar recursos

  3. Comprueba que la facturación esté habilitada en tu proyecto.

    Descubre cómo puedes habilitar la facturación

  4. Habilita las Cloud AutoML and Storage API necesarias.

    Habilita las API

  5. Instala la herramienta de línea de comandos de gcloud.
  6. Sigue las instrucciones para crear una cuenta de servicio y descargar un archivo de claves correspondiente a esa cuenta.
  7. Establece la variable de entorno GOOGLE_APPLICATION_CREDENTIALS en la ruta de acceso al archivo de claves de la cuenta de servicio que descargaste durante la creación de la cuenta de servicio.
    export GOOGLE_APPLICATION_CREDENTIALS=key-file
  8. Establece la variable de entorno PROJECT_ID para el ID de tu proyecto.
    export PROJECT_ID=your-project-id
    Las llamadas a la API de AutoML y los nombres de los recursos incluyen el ID de tu proyecto. La variable de entorno PROJECT_ID proporciona una manera conveniente de especificar el ID.
  9. Agrega tu cuenta de servicio y agrégate tú mismo a la función de IAM de editor de AutoML.
    1. Reemplaza your-userid@your-domain con tu cuenta de usuario.
    2. Reemplaza service-account-name con el nombre de tu cuenta de servicio nueva, por ejemplo, service-account1@myproject.iam.gserviceaccount.com.
    gcloud auth login
    gcloud projects add-iam-policy-binding $PROJECT_ID \
       --member="user:your-userid@your-domain" \
       --role="roles/automl.admin"
    gcloud projects add-iam-policy-binding $PROJECT_ID \
       --member="serviceAccount:service-account-name" \
       --role="roles/automl.editor"
    

Create a Cloud Storage bucket

Use Cloud Shell, a browser-based Linux command line connected to your Cloud Console project, to create your Cloud Storage bucket:

  1. Open Cloud Shell.

  2. Create a Google Cloud Storage bucket. The bucket name must be in the format: project-id-vcm. The following command creates a storage bucket in the us-central1 region named project-id-vcm. For a complete list of available regions, see the Bucket Locations page.

    gsutil mb -p project-id -c regional -l us-central1 gs://project-id-vcm/

    Recommended file structure for your Cloud Storage files:

    gs://project-id-vcm/dataset-name/documents/document-name.txt

Copy the sample images into your bucket

Next, copy the flower dataset used in this Tensorflow blog post. The images are stored in a public Cloud Storage bucket, so you can copy them directly from there to your own bucket.

  1. In your Cloud Shell session, enter:

    gsutil -m cp -R gs://cloud-ml-data/img/flower_photos/ gs://${BUCKET}/img/
    

    The file copying takes about 20 minutes to complete.

Create the CSV file

The sample dataset contains a CSV file with all of the image locations and the labels for each image. You'll use that to create your own CSV file:

  1. Update the CSV file to point to the files in your own bucket:

    gsutil cat gs://${BUCKET}/img/flower_photos/all_data.csv | sed "s:cloud-ml-data:${BUCKET}:" > all_data.csv
    
  2. Copy the CSV file into your bucket:

    gsutil cp all_data.csv gs://${BUCKET}/csv/
    

Create your dataset

Visit the AutoML Vision UI to begin the process of creating your dataset and training your model.

When prompted, make sure to select the project that you used for your Cloud Storage bucket.

  1. From the AutoML Vision page, click New Dataset:

    New dataset button in console

  2. Specify a name for this dataset. Click the + sign to continue.

    New dataset name field

  3. Specify the Cloud Storage URI of your CSV file. For this quickstart, the CSV file is at gs://your-project-123-vcm/csv/all_data.csv. Make sure to replace your-project-123 with your specific project ID.

  4. Click Create Dataset. The import process takes a few minutes. When it completes, you are taken to the next page which has details on all of the images identified for your dataset, both labeled and unlabeled images. You can filter images by label by selecting a label under Filter labels. If you are using the flower dataset, you will see a warning alert which will notify you of repeated images or images with multiple labels (if multi-label is not enabled).

    Filtering by label example

    • You can add additional images and update labels for new and existing images after you have imported a CSV file.

Train your model

  1. Once your dataset has been created and processed, select the Train tab to initiate model training.

    select train tab

  2. Select TRAIN NEW MODEL to continue.

    Train new model option

    This will open a pop-up window with training options.

  3. From the training pop-up window, select 1. "Edge" from the Model type. Then select model optimized for 2. "Best trade-off" and your 3. node hour budget.

    Train Edge model

  4. Select "Start training" to begin model training.

    Training is initiated for your model, and should take about an hour. The training might stop earlier than the node hour you selected. The service will email you once training has completed, or if any errors occur.

Once training is complete, you can refer to evaluation metrics, as well as test and use the model.

Select the Evaluate tab to get more details on F1, Precision, and Recall scores.

Select an individual label under Filter labels to get details on true positives, false negatives and false positives.

Make a Prediction

Select the Predict tab for instructions on sending an image to your model for a prediction. You can also refer to Annotating images for examples.

Export and Deploy the Edge model

The final step in using an AutoML Vision Edge model is to export (optimize and download) and deploy (use) your model.

There are multiple ways you can export and deploy your models to use for prediction on Edge devices.

In this quickstart you will use Tensorflow Lite (TF Lite) as an example. TF Lite models are both easy to use and have a wide set of use cases.

  1. Under Use your Edge model, select the TFLite tab.

    Export TF Lite model

  2. Select Export to export a TF Lite package into your Cloud Storage storage bucket. The export process typically takes several minutes.

  3. After the export is completed, select the Cloud Storage link, and it will direct you to the Google Cloud Storage destination folder in the Google Cloud Platform Console.

In the Google Cloud Storage destination location you will find a folder named with timestamp and model format, under which you can find the following files:

  • a tflite file (model.tflite),
  • a dictionary file (dict.txt)
  • a metadata file (tflite_metadata.json)

What's Next

With these files, you can follow tutorials to deploy on Android devices, iOS devices, Raspberry Pi 3, or the Web.

Other model use options

  • You can also export the model as TensorFlow SavedModel and use it with a Docker container in the Container tab. See the container tutorial on how to export to a container.
  • You can export the model for running on Edge TPU in the Edge devices tab. Then follow Coral's official documentation about how to run an inference on the Edge TPU.
  • You can check check_box Format model for Core ML (iOS / macOS) before training the model for training a CoreML supported model. After training, you can export the model in CoreML tab, and follow the CoreML official documentation.
¿Te ha resultado útil esta página? Enviar comentarios:

Enviar comentarios sobre...

Si necesitas ayuda, visita nuestra página de asistencia.