Train a Model

You can add classification tags or bounding boxes to images collected by machines, add them to a dataset, and use the annotated data to train a Single Label Classification Model, Multi Label Classification Model or Object Detection Model within Viam.

When training machine learning models, it is important to supply a variety of different data about the subject. In the case of image classification, it is important to provide images of the object being identified in different situations, such as from different angles or in different lighting situations. The more varied the provided data set, the more accurate the resulting model becomes.

Train a model

After creating a dataset, navigate to the DATA tab and the DATASETS subtab. Then click on the dataset you want to train a model from and click on the Train model button on your dataset’s page.

On the Train a model menu:

  1. Leave New model and Built-in training selected. If you want to train on a custom training script, select that option. Click Next steps.
  2. Enter a name or use the suggested name for your new model.
  3. Select a Model Type and one or more labels to train on:
    • Single Label Classification: The resulting model predicts one of the selected labels or UNKNOWN per image. If you are only using one label, ensure that the dataset you are training on also contains unlabeled images.
    • Multi Label Classification: The resulting model predicts one or more of the selected labels per image.
    • Object Detection: The resulting model predicts either no detected objects or any number of object labels alongside their locations per image.
  4. Click Train model

The model now starts training and you can follow its process in the Training section of the Models page.

Once the model has finished training, it becomes visible in the Models section of the page.

The trained model

Train a new version of a model

From your dataset’s page, click the Train a model menu, select New version, then select the existing model, and click Train model. The model will train using the same script that was used when you trained the first version. For example, if you used the built-in TFLite training script to train the first version, it will be used to train all future versions of this model.

If you deploy a model to a machine, Viam automatically assumes that this is the latest version of the model and that you would always like to deploy the latest version of the model to the machine. If you train a new version of that model, Viam will automatically deploy the new version to the machine and replace the old version.

If you do not want Viam to automatically deploy the latest version of the model, you can change packages configuration in the JSON machine configuration.

You can get the version number from a specific model version by navigating to the models page finding the model’s row, clicking on the right-side menu marked with and selecting Copy package JSON. For example: 2024-02-28T13-36-51. The model package config looks like this:

  "package": "<model_id>/<model_name>",
  "version": "YYYY-MM-DDThh-mm-ss",
  "name": "<model_name>",
  "type": "ml_model"

Delete a model

You can delete a model from the models page in the Viam app:

  • To delete a trained model, click the icon to the right of the model name under the Models section of the page, and select Delete.

    Delete a trained model

  • To delete a model that has failed training, click the trash can icon to the right of the model name under the Training section of the page.

    Delete a failed model

Next steps

Have questions, or want to meet other people working on robots? Join our Community Discord.

If you notice any issues with the documentation, feel free to file an issue or edit this file.