# Deploy a model to a machine

Add an ML model service and vision service to run a trained model on your machine.
> Source: https://docs.viam.com/train/deploy-a-model/


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](/vision/configure/).
> 

## Deploy from the model details page

The fastest way to deploy a model is from the model's page in the Viam app:

1. Navigate to **Models** and click the model you want to deploy.
1. Click **Deploy** in the model header to open the deploy dialog, which walks you through a few steps.
1. Select a model version, location, machine, and machine part, then click **Continue**.
1. Name the ML model service, then click **Continue**.
1. Name the vision service. By default, it uses an existing camera on your machine.
1. Click **Deploy** to add the services to the machine's configuration.

After deploying, verify the model on the machine's **CONTROL** tab.

## Deploy from the machine's configure tab

To deploy a model by configuring services manually:

### 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](/train/overview/#supported-frameworks-and-hardware).

1. Navigate to your machine's **CONFIGURE** tab.
2. Click **+** and select **Blocks**.
3. Search for the ML model service matching your framework (for example,
   `tflite_cpu`) and select the matching result.
4. Click the block, then click **Add to machine**.
5. Enter a name for the service (for example, `my-ml-model`) and click
   **Add to machine**. The supporting module is installed automatically.
6. In the service configuration card, under **Deployment**, leave
   **Deploy model on machine** selected.
7. Click **Select model**. In the dialog, browse **My models** or
   **Registry** to find your trained model.
8. Select the model, choose a version (or leave it on **Latest**), and click
   **Choose**. The model path and label path are set automatically.
9. Click **Save** in the top right.

### 2. Add the vision service

1. Click **+** and select **Blocks**.
2. Search for `mlmodel` and find the **mlmodel** block (type: **VISION**,
   built-in).
3. Click the block, then click **Add to machine**.
4. Enter a name for the service (for example, `my-detector`) and click
   **Add to machine**.
5. In the **ML Model** dropdown, select the ML model service you added in
   step 1 (for example, `my-ml-model`).
6. Optionally, select a **Default Camera** and adjust the
   **Minimum confidence threshold** (default: 0.5).
7. Click **Save**.

### 3. Verify

1. In the vision service's configuration card, click **Test**.
2. Select a camera to run the model against.
3. You should see live classifications or detections overlaid on the camera
   feed.

## Use the model in code




### Python

```python
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})")
```

### Go

```go
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

**Model not appearing on the machine**



- **Check the ML model service configuration.** Open the service card in the
  **CONFIGURE** tab and verify a model is selected. If you see the
  **Select model** button, no model has been chosen yet.
- **Restart viam-server.** In some cases, the machine may need to restart to
  pick up a new model version.
- **Check machine connectivity.** The machine must be online and connected to
  the cloud to download model updates.




**Vision service returns no results**



- **Check the ML Model dropdown.** The vision service's **ML Model** dropdown
  must reference your ML model service by name. If it shows
  **No models available**, add an ML model service first.
- **Check the camera.** Verify that the camera is working in the **CONTROL** tab
  before testing the vision service.
- **Lower the confidence threshold.** The model may be producing results below
  your current threshold. Adjust the **Minimum confidence threshold** slider.




## What's next

- [Add computer vision](/vision/configure/) -- the full guide to configuring
  vision services and cloud inference.
- [Detect objects (2D)](/vision/object-detection/detect/) -- use your
  object detection model to find and locate objects in camera images.
- [Classify images](/vision/classify/) -- use your
  classification model to categorize images from your machine's camera.

