Skip to content

Commit 80351a4

Browse files
DOCS-2675: Document cloud inference (#4322)
1 parent 6e22728 commit 80351a4

File tree

2 files changed

+118
-39
lines changed

2 files changed

+118
-39
lines changed

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

Lines changed: 82 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
linkTitle: "Run inference"
3-
title: "Run inference on a model"
3+
title: "Run inference"
44
weight: 50
55
layout: "docs"
66
type: "docs"
@@ -18,57 +18,64 @@ aliases:
1818
description: "Run inference on a model with a vision service or an SDK."
1919
---
2020

21-
After deploying an ml model, you need to configure an additional service to use the inferences the deployed model makes.
22-
You can run inference on an ML model with a vision service or use an SDK to further process inferences.
21+
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-
## Use a vision service
24+
- object detection (using bounding boxes)
25+
- classification (using tags)
2526

26-
Vision services work to provide computer vision.
27-
They use an ML model and apply it to the stream of images from your camera.
27+
You can run inference locally on a Viam machine, or remotely in the Viam cloud.
2828

29-
{{<resources_svc api="rdk:service:vision" type="vision">}}
30-
31-
{{< readfile "/static/include/create-your-own-mr.md" >}}
32-
33-
Note that many of these services have built in ML models, and thus do not need to be run alongside an ML model service.
29+
## Machine inference
3430

35-
One vision service you can use to run inference on a camera stream if you have an ML model service configured is the `mlmodel` service.
31+
You can use `viam-server` to deploy and run ML models directly on your machines.
3632

37-
### Configure an mlmodel vision service
33+
You can run inference on your machine in the following ways:
3834

39-
Add the `vision / ML model` service to your machine.
40-
Then, from the **Select model** dropdown, select the name of the ML model service you configured when [deploying](/data-ai/ai/deploy/) your model (for example, `mlmodel-1`).
35+
- with a vision service
36+
- manually in application logic with an SDK
4137

42-
**Save** your changes.
38+
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.
4340

44-
### Test your changes
41+
{{< tabs >}}
42+
{{% tab name="Vision service" %}}
4543

46-
You can test a deployed vision service by clicking on the **Test** area of its configuration panel or from the [**CONTROL** page](/manage/troubleshoot/teleoperate/default-interface/#viam-app).
44+
Vision services apply an ML model to a stream of images from a camera to generate bounding boxes or classifications.
4745

48-
The camera stream shows when the vision service identifies something.
49-
Try pointing the camera at a scene similar to your training data.
46+
{{<resources_svc api="rdk:service:vision" type="vision">}}
5047

51-
{{< imgproc src="/tutorials/data-management/blue-star.png" alt="Detected blue star" resize="x200" class="shadow" >}}
52-
{{< 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" >}}
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 %}}
5352

54-
{{% expand "Want to limit the number of shown classifications or detections? Click here." %}}
53+
To use a vision service:
5554

56-
If you are seeing a lot of classifications or detections, you can set a minimum confidence threshold.
55+
1. Visit the **CONFIGURE** page of the Viam app.
56+
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 in the Viam app.
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.
5763

58-
Start by setting the value to 0.8.
59-
This reduces your output by filtering out anything below a threshold of 80% confidence.
60-
You can adjust this attribute as necessary.
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" >}}
6166

62-
Click the **Save** button in the top right corner of the page to save your configuration, then close and reopen the **TEST** panel of the vision service configuration panel.
63-
Now if you reopen the panel, you will only see classifications or detections with a confidence value higher than the `default_minimum_confidence` attribute.
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.
6468

65-
{{< /expand>}}
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.
6671

67-
For more detailed information, including optional attribute configuration, see the [`mlmodel` docs](/operate/reference/services/vision/mlmodel/).
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/).
6874

69-
## Use an SDK
75+
{{% /tab %}}
76+
{{% tab name="SDK" %}}
7077

71-
You can also run inference using a Viam SDK.
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.
7279
Use the [`Infer`](/dev/reference/apis/services/ml/#infer) method of the ML Model API to make inferences.
7380

7481
For example:
@@ -103,10 +110,46 @@ output_tensors, err := myMLModel.Infer(context.Background(), input_tensors)
103110
{{% /tab %}}
104111
{{< /tabs >}}
105112

106-
After adding a vision service, you can use a vision service API method with a classifier or a detector to get inferences programmatically.
107-
For more information, see the ML Model and Vision APIs:
113+
{{% /tab %}}
114+
{{< /tabs >}}
115+
116+
## Cloud inference
117+
118+
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:
120+
121+
- larger, more accurate models
122+
- faster inference times
123+
124+
You can run cloud inference using any Tensorflow model in the Viam registry, including private models owned by or shared with your organization.
125+
126+
To run cloud inference, you must pass
127+
128+
- the binary data ID and organization of the data you want to run inference on
129+
- the name, version, and organization of the model you want to use for inference
130+
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:
132+
133+
```sh {class="command-line" data-prompt="$" data-output="2-18"}
134+
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>
135+
Inference Response:
136+
Output Tensors:
137+
Tensor Name: num_detections
138+
Shape: [1]
139+
Values: [1.0000]
140+
Tensor Name: classes
141+
Shape: [32 1]
142+
Values: [...]
143+
Tensor Name: boxes
144+
Shape: [32 1 4]
145+
Values: [...]
146+
Tensor Name: confidence
147+
Shape: [32 1]
148+
Values: [...]
149+
Annotations:
150+
Bounding Box Format: [x_min, y_min, x_max, y_max]
151+
No annotations.
152+
```
108153

109-
{{< cards >}}
110-
{{< card link="/dev/reference/apis/services/ml/" customTitle="ML Model API" noimage="True" >}}
111-
{{% card link="/dev/reference/apis/services/vision/" customTitle="Vision service API" noimage="True" %}}
112-
{{< /cards >}}
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.

docs/dev/tools/cli.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,42 @@ done
544544
| `--resource-name` | Resource name. Sometimes called "component name". | `export tabular` | **Required** |
545545
| `--resource-subtype` | Resource {{< glossary_tooltip term_id="api-namespace-triplet" text="API namespace triplet" >}}. | `export tabular` | **Required** |
546546

547+
### `infer`
548+
549+
The `infer` command enables you to run [cloud inference](/data-ai/ai/run-inference/#cloud-inference) on data. Cloud inference runs in the cloud, instead of on a local machine.
550+
551+
```sh {class="command-line" data-prompt="$" data-output="2-18"}
552+
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>
553+
Inference Response:
554+
Output Tensors:
555+
Tensor Name: num_detections
556+
Shape: [1]
557+
Values: [1.0000]
558+
Tensor Name: classes
559+
Shape: [32 1]
560+
Values: [...]
561+
Tensor Name: boxes
562+
Shape: [32 1 4]
563+
Values: [...]
564+
Tensor Name: confidence
565+
Shape: [32 1]
566+
Values: [...]
567+
Annotations:
568+
Bounding Box Format: [x_min, y_min, x_max, y_max]
569+
No annotations.
570+
```
571+
572+
#### Named arguments
573+
574+
<!-- prettier-ignore -->
575+
| Argument | Description | Required? |
576+
| -------- | ----------- | --------- |
577+
| `--binary-data-id` | The binary data ID of the image you want to run inference on. | **Required** |
578+
| `--model-name` | The name of the model that you want to run in the cloud. | **Required** |
579+
| `--model-version` | The version of the model that you want to run in the cloud. To find the latest version string for a model, visit the [registry page](https://app.viam.com/registry?type=ML+Model) for that model. You can find the latest version string in the **Version history** section, for instance "2024-02-16T12-55-32". Pass this value as a string, using double quotes. | **Required** |
580+
| `--org-id` | The organization ID of the organization that will run the inference. | **Required** |
581+
| `--model-org-id` | The organization ID of the organization that owns the model. | **Required** |
582+
547583
### `locations`
548584

549585
The `locations` command allows you to manage the [locations](/manage/reference/organize/) that you have access to.

0 commit comments

Comments
 (0)