Phase 9: Deploy the winning model

At the end of this phase, the winning model runs on your machine and draws a labeled box on each die in the live camera feed.

What deploying does

Until now, your models have lived in the Viam cloud. Training and evaluation both ran there, on images already saved in your datasets. Deploying puts the model on your machine, so it runs on live camera images as they come in, without sending them to the cloud.

In practice, deploying adds two services to your machine’s configuration. When you save, viam-server downloads the model file and the module that runs it, and starts both services:

  • The ML model service, dice-model, loads the model file and runs it. It’s the tflite_cpu service from the registry for dice-tflite, or onnx-cpu for dice-yolo. It takes numbers in, the pixels of an image, and gives numbers back: box coordinates, label numbers and scores. It doesn’t know anything about cameras or dice.
  • The vision service, dice-detector, is the part that understands images. It’s the built-in mlmodel vision service, which ships with viam-server. It gets a frame from camera, prepares it for the model, sends it to dice-model, and turns the numbers that come back into detections: a box, a label and a confidence for each die. It also drops boxes below the confidence threshold you set.

The vision service is what your code talks to. In Phase 10, your Yahtzee module asks dice-detector for the detections in the latest camera frame and gets back a list of dice, without handling the model at all. Because the two services are separate, you could later swap in a retrained model, or the other one, without changing your code. For more, see How a vision service works.

Deploy the model

  1. On the DATA tab, click MODELS and click the winning model, dice-tflite or dice-yolo.
  2. Click Deploy.
  3. Select the latest version, your location, your machine and its part, then click Continue.
  4. Name the ML model service dice-model, then click Continue.
  5. Name the vision service dice-detector, and check that it uses camera.
  6. Click Deploy.

The deploy dialog picks the ML model service that matches the model’s framework and installs its module on your machine.

Checkpoint

On the CONFIGURE tab, the machine shows two new services, dice-model and dice-detector, and neither shows an error. If the services don’t appear, check that you clicked Deploy at the end of the dialog. If dice-model shows an error, wait a minute for its module to finish installing, then check the machine’s LOGS tab.

Set the confidence threshold

  1. On the CONFIGURE tab, open the dice-detector card.
  2. Set Minimum confidence threshold to the threshold you picked in Phase 8.
  3. Click Save.

The vision service drops any box below this threshold. A YOLO model from the registry script always returns its 100 best guesses, most of them near zero confidence, so without a threshold the feed fills with stray boxes.

Checkpoint

The dice-detector card shows your threshold, for example 0.5. If the setting doesn’t save, check the LOGS tab for a configuration error.

Check live detections

  1. Roll five dice onto the background.
  2. In the dice-detector card, click Test and select camera.

Checkpoint

The camera feed shows a box around each die, labeled with its value and a confidence score, and the values match the dice. If not, see Troubleshooting.

Troubleshooting

You see no boxes at all
Check that dice-model and dice-detector show no errors on the CONFIGURE tab. If either shows an error, check the machine’s LOGS tab for the cause. If neither does, check that the threshold in the dice-detector card is the one you picked in Phase 8, not a higher one.
Some dice have no box
The model isn’t confident enough about those dice to pass the threshold. Lower the threshold in the dice-detector card a little, and click Save.
Dice get the wrong value

The model reads dice best in the conditions it trained on. Check that the scene matches your dice-train images:

  • The camera is at the same height and angle.
  • The light is the same.
  • The dice roll on the same background.
  • You’re using the same dice.

If the scene matches and the model still misreads dice, it needs more training. See Refine your model.

In the next phase, you write an inline module that reads a roll from dice-detector and scores it.