Deploy a model to a machine
Configure your machine to load a trained model from the registry and apply it to live camera frames. You need an ML model service to load the model and a vision service to run it against camera input.
Tip
For the full guide to configuring vision services and cloud inference, see Configure computer vision.
1. Add the ML model service
The ML model service loads the model. Pick the module that matches your trained model’s framework:
| Framework | ML model service |
|---|---|
| TFLite | tflite_cpu |
| TensorFlow | tensorflow-cpu |
For hardware-specific alternatives (for example, triton for Nvidia GPU),
see Supported frameworks and hardware.
- Navigate to your machine’s CONFIGURE tab.
- Click + and select Configuration block.
- Search for the ML model service matching your framework (for example,
tflite_cpu) and select the matching result. - Click the block, then click Add component.
- Enter a name for the service (for example,
my-ml-model) and click Add component. The supporting module is installed automatically. - In the service configuration card, under Deployment, leave Deploy model on machine selected.
- Click Select model. In the dialog, browse My models or Registry to find your trained model.
- Select the model, choose a version (or leave it on Latest), and click Choose. The model path and label path are set automatically.
- Click Save in the top right.
2. Add the vision service
- Click + and select Configuration block.
- Search for
mlmodeland find the mlmodel block (type: VISION, built-in). - Click the block, then click Add component.
- Enter a name for the service (for example,
my-detector) and click Add component. - In the ML Model dropdown, select the ML model service you added in
step 1 (for example,
my-ml-model). - Optionally, select a Default Camera and adjust the Minimum confidence threshold (default: 0.5).
- Click Save.
3. Verify
- In the vision service’s configuration card, click Test.
- Select a camera to run the model against.
- You should see live classifications or detections overlaid on the camera feed.
Use the model in code
from viam.services.vision import VisionClient
# Get the vision service (assumes you have a robot connection)
vision = VisionClient.from_robot(robot, "my-detector")
# For classification
classifications = await vision.get_classifications(
image=my_image,
count=5,
)
for c in classifications:
print(f" {c.class_name}: {c.confidence:.2f}")
# For object detection
detections = await vision.get_detections(image=my_image)
for d in detections:
print(f" {d.class_name}: {d.confidence:.2f} "
f"at ({d.x_min}, {d.y_min}) to ({d.x_max}, {d.y_max})")
import "go.viam.com/rdk/services/vision"
// Get the vision service (assumes you have a robot connection)
visionSvc, err := vision.FromProvider(robot, "my-detector")
if err != nil {
logger.Fatal(err)
}
// For classification
classifications, err := visionSvc.Classifications(ctx, myImage, 5, nil)
if err != nil {
logger.Fatal(err)
}
for _, c := range classifications {
fmt.Printf(" %s: %.2f\n", c.Label(), c.Score())
}
// For object detection
detections, err := visionSvc.Detections(ctx, myImage, nil)
if err != nil {
logger.Fatal(err)
}
for _, d := range detections {
box := d.BoundingBox()
fmt.Printf(" %s: %.2f at (%d, %d) to (%d, %d)\n",
d.Label(), d.Score(),
box.Min.X, box.Min.Y, box.Max.X, box.Max.Y)
}
Troubleshooting
What’s next
- Add computer vision – the full guide to configuring vision services and cloud inference.
- Detect objects (2D) – use your object detection model to find and locate objects in camera images.
- Classify images – use your classification model to categorize images from your machine’s camera.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!