Build Your Own Dice Detection Model with Vertex AI

Introduction

This article walks you through the steps for creating your own dice detection model using Vertex AI. Vertex AI is an ML Platform hosted on Google Cloud Platform. To use it, you first must create a GCP account.

After creating an account, create a GCP project and configure Vertex API. See the Vertex AI Setup Guide for more details.

Create a new dataset

For a dice detection model, use Image object detection because the model needs to be able to recognize multiple dice and their locations (image segmentation also works but it is overkill).

Next you will need to import a dataset. A dataset is a large collection of images of dice, having equal representation of all the possible dice values (one through six). For Vertex AI to make a reasonably accurate model, there needs to be at least 100 examples for each dice value. For best results, use pictures of dice you commonly play with in a setting where you commonly play from a viewpoint where your Histogramo detector will be detecting the dice.

For this tutorial, a public dataset on Kaggle, Six-sided Dice Dataset, was used.

Vertex AI Create Dataset

Vertex AI Create Dataset

Create Labels and label images

Click on the dataset to view its images. From this view, you can add new labels by clicking on the ADD NEW LABEL button. This brings up a modal which allows you to add labels (dice values) that the model will produce as output. For a dice detection model to be compatible with Histogramo, it must use the following labels:

  • one
  • two
  • three
  • four
  • five
  • six
  • Note that the screenshots in this tutorial are mislabeled (e.g. the label should be one, not 1).
Vertex AI Dataset

Vertex AI Dataset

Using the Vertex AI label console, click through each image and label all dice in each image. For more information, seeLabel data using the Google Cloud console.

This can be a bit of a grind, so it’s best to break the work into chunks. It is important to keep the bounding boxes tight around the dice. Each face of the bounding box should be touching one or more pixels of the dice.

Train the dice detection model

Once all the dataset images are labeled, go to the ANALYZE tab to check if you’re ready to train. There needs to be enough examples of each label in order for the model to be reasonably accurate. If you are ready to train, click TRAIN NEW MODEL.

Ready to Train

Ready to Train Screen

The Train New Model wizard appears. The model training method should be AutoML Edge so that the model can be exported for TensorFlow Lite.

Train a New Model Wizard (Training Method)

Train a New Model Wizard (Training Method)

Give your model a name and description in model details. The default settings for data split and encryption can be left as is.

Train a New Model Wizard (Model Details)

Train a New Model Wizard (Model Details)

Decide between a faster or more accurate model in training options.

Train a New Model Wizard (Training Options)

Train a New Model Wizard (Training Options)

Set a limit for how long you want to train your model. For the Six-sided Dice Dataset which has 250 images and around 250 instances of each dice value, training took about four hours to complete and cost $75. It is important to enable early stopping so that you don’t needlessly spend money when training stops yielding improvements.

Train a New Model Wizard (Compute and Pricing)

Train a New Model Wizard (Compute and Pricing)

After completing the wizard, the dice detection model starts training. This process takes several hours.

Training In Process

Training In Process

When training is complete, the training results can be viewed and the model can be deployed via various means.

Training Complete

Training Complete

The model’s performance can be evaluated by looking at its precision-recall curve for a given accuracy threshold. Accuracy thresholds range from 0 to 1, with 0 representing no confidence and 1 representing maximum confidence. The accuracy threshold can be set in Histogramo, dice detections with less confidence than the given accuracy threshold are discarded.

Model Evaluation

Model Evaluation

In Deploy & Test, choose TF Lite. This will save the model as a .tflite file in a Google storage bucket. You can then download the model from the storage bucket.

Use Your Edge-Optimized Model

Use Your Edge-Optimized Model

Export Model

Export Model