Skip to content

Commit 30a2790

Browse files
committed
DOCS-4341: Update run inference
1 parent 19c5fa8 commit 30a2790

15 files changed

+1124
-170
lines changed
81.8 KB
Loading

docs/data-ai/ai/run-inference.md

Lines changed: 76 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -15,120 +15,129 @@ aliases:
1515
- /ml/vision/segmentation/
1616
- /ml/vision/
1717
- /get-started/quickstarts/detect-people/
18-
description: "Run inference on a model with a vision service or an SDK."
18+
description: "Run machine learning inference locally on your robot or remotely in the cloud using vision services, ML model services, or SDKs."
19+
date: "2025-09-12"
1920
---
2021

2122
Inference is the process of generating output from a machine learning (ML) model.
22-
With Viam, you can run inference to generate the following kinds of output:
2323

24-
- object detection (using bounding boxes)
25-
- classification (using tags)
26-
27-
You can run inference locally on a Viam machine, or remotely in the Viam cloud.
24+
You can run inference [locally on a Viam machine](#machine-inference), or [remotely in the Viam cloud](#cloud-inference).
2825

2926
## Machine inference
3027

31-
You can use `viam-server` to deploy and run ML models directly on your machines.
32-
33-
You can run inference on your machine in the following ways:
34-
35-
- with a vision service
36-
- manually in application logic with an SDK
28+
When you have [deployed an ML model](/data-ai/ai/deploy/) on your machine, you can run inference on your machine [directly with the ML model service](#using-an-ml-model-service-directly) or [using a vision service](#using-a-vision-service) that interprets the inferences.
3729

3830
Entry-level devices such as the Raspberry Pi 4 can run small ML models, such as TensorFlow Lite (TFLite).
39-
More powerful hardware, including the Jetson Xavier or Raspberry Pi 5 with an AI HAT+, can process larger AI models, including TensorFlow and ONNX.
31+
More powerful hardware, including the Jetson Xavier or Raspberry Pi 5 with an AI HAT+, can process larger models, including TensorFlow and ONNX.
32+
If your hardware does not support the model you want to run, see [Cloud inference](#cloud-inference).
33+
34+
### Using an ML model service directly
4035

4136
{{< tabs >}}
42-
{{% tab name="Vision service" %}}
37+
{{% tab name="Web UI" %}}
4338

44-
Vision services apply an ML model to a stream of images from a camera to generate bounding boxes or classifications.
39+
1. Visit your machine's **CONFIGURE** or **CONTROL** page.
40+
1. Expand the **TEST** area of the ML model service panel to view the tensor output.
4541

46-
{{<resources_svc api="rdk:service:vision" type="vision">}}
42+
{{< imgproc src="/tutorials/data-management/tensor-output.png" alt="Example tensor output" resize="x1000" class="shadow imgzoom fill" >}}
43+
44+
{{% /tab %}}
45+
{{% tab name="Python" %}}
46+
47+
The following code passes an image to an ML model service, and uses the [`Infer`](/dev/reference/apis/services/ml/#infer) method to make inferences:
48+
49+
{{< read-code-snippet file="/static/include/examples-generated/run-inference.snippet.run-inference.py" lang="py" class="line-numbers linkable-line-numbers" data-line="82-85" >}}
50+
51+
{{% /tab %}}
52+
{{% tab name="Go" %}}
53+
54+
The following code passes an image to an ML model service, and uses the [`Infer`](/dev/reference/apis/services/ml/#infer) method to make inferences:
55+
56+
{{< read-code-snippet file="/static/include/examples-generated/run-inference.snippet.run-inference.go" lang="go" class="line-numbers linkable-line-numbers" data-line="166-171" >}}
57+
58+
{{% /tab %}}
59+
{{< /tabs >}}
60+
61+
### Using a vision service
62+
63+
Vision services apply an ML model to a stream of images from a camera to:
4764

48-
{{% alert title="Tip" color="tip" %}}
49-
Some vision services include their own ML models, and thus do not require a deployed ML model.
50-
If your vision service does not include an ML model, you must [deploy an ML model to your machine](/data-ai/ai/deploy/) to use that service.
51-
{{% /alert %}}
65+
- detect objects (using bounding boxes)
66+
- classify (using tags)
5267

5368
To use a vision service:
5469

55-
1. Visit your machine's **CONFIGURE** page.
70+
1. Navigate to your machine's **CONFIGURE** page.
5671
1. Click the **+** icon next to your main machine part and select **Component or service**.
57-
1. Type in the name of the service and select a vision service.
58-
1. If your vision service does not include an ML model, [deploy an ML model to your machine](/data-ai/ai/deploy/) to use that service.
59-
1. Configure the service based on your use case.
60-
1. To view the deployed vision service, use the live detection feed.
61-
The feed shows an overlay of detected objects or classifications on top of a live camera feed.
62-
On the **CONFIGURE** or **CONTROL** pages for your machine, expand the **Test** area of the service panel to view the feed.
72+
1. Select a vision service.
73+
1. Configure your vision service.
74+
If your vision service does not include an ML model, you need to [deploy an ML model to your machine](/data-ai/ai/deploy/) and select it when configuring your vision service.
6375

64-
{{< imgproc src="/tutorials/data-management/blue-star.png" alt="Detected blue star" resize="x200" class="shadow" >}}
65-
{{< imgproc src="/tutorials/filtered-camera-module/viam-figure-preview.png" alt="Detection of a viam figure with a confidence score of 0.97" resize="x200" class="shadow" >}}
76+
{{% expand "Click to search available vision services" %}}
6677

67-
For instance, you could use [`viam:vision:mlmodel`](/operate/reference/services/vision/mlmodel/) with the `EfficientDet-COCO` ML model to detect a variety of objects, including people, bicycles, and apples, in a camera feed.
68-
69-
Alternatively, you could use [`viam-soleng:vision:openalpr`](https://app.viam.com/module/viam-soleng/viamalpr) to detect license plates in images.
70-
Since this service includes its own ML model, there is no need to configure a separate ML model.
78+
{{<resources_svc api="rdk:service:vision" type="vision">}}
7179

72-
After adding a vision service, you can use a vision service API method with a classifier or a detector to get inferences programmatically.
73-
For more information, see the APIs for [ML Model](/dev/reference/apis/services/ml/) and [Vision](/dev/reference/apis/services/vision/).
80+
{{% /expand%}}
7481

75-
{{% /tab %}}
76-
{{% tab name="SDK" %}}
82+
{{% expand "Click to view example vision services" %}}
7783

78-
With the Viam SDK, you can pass image data to an ML model service, read the output annotations, and react to output in your own code.
79-
Use the [`Infer`](/dev/reference/apis/services/ml/#infer) method of the ML Model API to make inferences.
84+
<!-- prettier-ignore -->
85+
| Example | Description |
86+
| ------- | ----------- |
87+
| Detect a variety of objects | Use the [`viam:vision:mlmodel`](/operate/reference/services/vision/mlmodel/) vision service with the `EfficientDet-COCO` ML model to detect a variety of objects, including people, bicycles, and apples, in a camera feed. |
88+
| Detect license plates | Use the [`viam-soleng:vision:openalpr`](https://app.viam.com/module/viam-soleng/viamalpr) vision service to detect license plates in images. This service includes its own ML model. |
8089

81-
For example:
90+
{{% /expand%}}
8291

8392
{{< tabs >}}
84-
{{% tab name="Python" %}}
93+
{{% tab name="Web UI" %}}
8594

86-
```python {class="line-numbers linkable-line-numbers"}
87-
import numpy as np
95+
1. Visit your machine's **CONFIGURE** or **CONTROL** page.
96+
1. Expand the **TEST** area of the vision service panel.
8897

89-
my_mlmodel = MLModelClient.from_robot(robot=machine, name="my_mlmodel_service")
98+
The feed shows an overlay of detected objects or classifications on top of a live camera feed.
99+
100+
{{< imgproc src="/tutorials/data-management/blue-star.png" alt="Detected blue star" resize="x200" class="shadow" >}}
101+
{{< imgproc src="/tutorials/filtered-camera-module/viam-figure-preview.png" alt="Detection of a viam figure with a confidence score of 0.97" resize="x200" class="shadow" >}}
90102

91-
image_data = np.zeros((1, 384, 384, 3), dtype=np.uint8)
103+
{{% /tab %}}
104+
{{% tab name="Python" %}}
92105

93-
# Create the input tensors dictionary
94-
input_tensors = {
95-
"image": image_data
96-
}
106+
The following code passes an image from a camera to a vision service and uses the [`GetClassifications`](/dev/reference/apis/services/vision/#GetClassifications) method:
97107

98-
output_tensors = await my_mlmodel.infer(input_tensors)
99-
```
108+
{{< read-code-snippet file="/static/include/examples-generated/run-vision-service.snippet.run-vision-service.py" lang="py" class="line-numbers linkable-line-numbers" data-line="36-37" >}}
100109

101110
{{% /tab %}}
102111
{{% tab name="Go" %}}
103112

104-
```go {class="line-numbers linkable-line-numbers"}
105-
input_tensors := ml.Tensors{"0": tensor.New(tensor.WithShape(1, 2, 3), tensor.WithBacking([]int{1, 2, 3, 4, 5, 6}))}
113+
The following code passes an image from a camera to a vision service and uses the [`GetClassifications`](/dev/reference/apis/services/vision/#GetClassifications) method:
106114

107-
output_tensors, err := myMLModel.Infer(context.Background(), input_tensors)
108-
```
115+
{{< read-code-snippet file="/static/include/examples-generated/run-vision-service.snippet.run-vision-service.go" lang="go" class="line-numbers linkable-line-numbers" data-line="66-69" >}}
109116

110117
{{% /tab %}}
111-
{{< /tabs >}}
118+
{{% tab name="TypeScript" %}}
119+
120+
The following code passes an image from a camera to a vision service and uses the [`GetClassifications`](/dev/reference/apis/services/vision/#GetClassifications) method:
121+
122+
{{< read-code-snippet file="/static/include/examples-generated/run-vision-service.snippet.run-vision-service.ts" lang="ts" class="line-numbers linkable-line-numbers" data-line="32-38" >}}
112123

113124
{{% /tab %}}
114125
{{< /tabs >}}
115126

116127
## Cloud inference
117128

118129
Cloud inference enables you to run machine learning models in the Viam cloud, instead of on a local machine.
119-
Cloud inference often provides more computing power than edge devices, so you can benefit from:
130+
Cloud inference provides more computing power than edge devices, enabling you to run more computationally-intensive models or achieve faster inference times.
120131

121-
- larger, more accurate models
122-
- faster inference times
132+
You can run cloud inference using any TensorFlow and TensorFlow Lite model in the Viam registry, including unlisted models owned by or shared with you.
123133

124-
You can run cloud inference using any TensorFlow and TensorFlow Lite model in the Viam registry, including private models owned by or shared with your organization.
125-
126-
To run cloud inference, you must pass
134+
To run cloud inference, you must pass the following:
127135

128136
- the binary data ID and organization of the data you want to run inference on
129137
- the name, version, and organization of the model you want to use for inference
130138

131-
The [`viam infer`](/dev/tools/cli/#infer) CLI command runs inference in the cloud on a piece of data using the specified ML model:
139+
You can obtain the binary data ID from the [**DATA** tab](https://app.viam.com/data/view) and the organization ID by running the CLI command `viam org list`.
140+
You can find the model information on the [**MODELS** tab](https://app.viam.com/models).
132141

133142
```sh {class="command-line" data-prompt="$" data-output="2-18"}
134143
viam infer --binary-data-id <binary-data-id> --model-name <model-name> --model-org-id <org-id-that-owns-model> --model-version "2025-04-14T16-38-25" --org-id <org-id-that-executes-inference>
@@ -151,5 +160,7 @@ Bounding Box Format: [x_min, y_min, x_max, y_max]
151160
No annotations.
152161
```
153162

154-
`infer` returns a list of detected classes or bounding boxes depending on the output of the ML model you specified, as well as a list of confidence values for those classes or boxes.
155-
This method returns bounding box output using proportional coordinates between 0 and 1, with the origin `(0, 0)` in the top left of the image and `(1, 1)` in the bottom right.
163+
The command returns a list of detected classes or bounding boxes depending on the output of the ML model you specified, as well as a list of confidence values for those classes or boxes.
164+
The bounding box output uses proportional coordinates between 0 and 1, with the origin `(0, 0)` in the top left of the image and `(1, 1)` in the bottom right.
165+
166+
For more information, see [`viam infer`](/dev/tools/cli/#infer).

docs/data-ai/reference/triggers-configuration.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ Triggers support the following attributes:
3131
The following template demonstrates the form of a JSON configuration for a trigger that alerts when data syncs to the Viam cloud:
3232

3333
```json {class="line-numbers linkable-line-numbers"}
34-
"triggers": [
35-
{
36-
"name": "<trigger name>",
37-
"event": {
38-
"type": "part_data_ingested",
39-
"data_ingested": {
40-
"data_types": ["binary", "tabular", "file", "unspecified"]
41-
}
42-
},
43-
"notifications": [
44-
{
45-
"type": "<webhook|email>",
46-
"value": "<webhook URL or email address>",
47-
"seconds_between_notifications": <number of seconds>
48-
}
49-
]
50-
}
51-
]
34+
"triggers": [
35+
{
36+
"name": "<trigger name>",
37+
"event": {
38+
"type": "part_data_ingested",
39+
"data_ingested": {
40+
"data_types": ["binary", "tabular", "file", "unspecified"]
41+
}
42+
},
43+
"notifications": [
44+
{
45+
"type": "<webhook|email>",
46+
"value": "<webhook URL or email address>",
47+
"seconds_between_notifications": <number of seconds>
48+
}
49+
]
50+
}
51+
]
5252
```
5353

5454
## Conditional attributes

0 commit comments

Comments
 (0)