Skip to content

DOCS-4082: Document new UploadImageToDataset method in data manager service API #4424

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/data-ai/ai/create-dataset.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,37 @@ We recommend you tag the images first and then use the CLI to [add the tagged im
Once you have enough images, consider disabling data capture to [avoid incurring fees](https://www.viam.com/product/pricing) for capturing large amounts of training data.

{{< /alert >}}
{{% /tab %}}
{{% tab name="Programmatic upload" %}}

You can also upload images directly to datasets programmatically using the data manager service's `UploadImageToDataset` method. This is useful for automated workflows where you want to capture and upload images to datasets without manual intervention.

```python {class="line-numbers linkable-line-numbers"}
from viam.services.data_manager import DataManagerClient

# Get the data manager service
data_manager = DataManagerClient.from_robot(robot, "builtin")

# Read image file
with open("path/to/image.jpg", "rb") as f:
image_data = f.read()

# Upload to datasets with tags
await data_manager.upload_image_to_dataset(
image=image_data,
dataset_ids=["dataset_1", "dataset_2"],
tags=["training", "outdoor", "robot_vision"]
)
```

This method allows you to:
- Upload images directly from your robot's code
- Target multiple datasets simultaneously
- Apply tags for organization and filtering
- Integrate with automated data collection workflows

For more details, see the [data manager service API documentation](/dev/reference/apis/services/data/#uploadimagetodataset).

{{% /tab %}}
{{< /tabs >}}

Expand Down
6 changes: 6 additions & 0 deletions docs/dev/reference/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ date: "2024-09-18"
# updated: "" # When the content was last entirely checked
---

{{% changelog color="added" title="UploadImageToDataset method in data manager service" date="2025-06-26" %}}

Added new `UploadImageToDataset` method to the data manager service API that allows programmatic upload of images directly to datasets. This method accepts image data as bytes along with dataset IDs and tags, enabling automated dataset population for machine learning workflows.

{{% /changelog %}}

{{% changelog color="added" title="Move machines between locations" date="2025-06-10" %}}

Organization owners and location owners can now move machines between locations within their organization using the web UI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
| Method Name | Description | `viam-micro-server` Support |
| ----------- | ----------- | --------------------------- |
| [`Sync`](/dev/reference/apis/services/data/#sync) | Sync data stored on the machine to the cloud. | |
| [`UploadImageToDataset`](/dev/reference/apis/services/data/#uploadimagetodataset) | Upload an image directly to specified datasets. | |
| [`Reconfigure`](/dev/reference/apis/services/data/#reconfigure) | Reconfigure this resource. | |
| [`DoCommand`](/dev/reference/apis/services/data/#docommand) | Execute model-specific commands that are not otherwise defined by the service API. | |
| [`Close`](/dev/reference/apis/services/data/#close) | Safely shut down the resource and prevent further use. | |
119 changes: 119 additions & 0 deletions static/include/services/apis/generated/data_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,125 @@ For more information, see the [TypeScript SDK Docs](https://ts.viam.dev/classes/
{{% /tab %}}
{{< /tabs >}}

### UploadImageToDataset

Upload an image directly to specified datasets for machine learning workflows.

{{< tabs >}}
{{% tab name="Python" %}}

**Parameters:**

- `image` (bytes): The image data as bytes.
- `dataset_ids` (List[str]): List of dataset IDs to upload the image to.
- `tags` (List[str]): List of tags to apply to the uploaded image.
- `extra` (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.
- `timeout` (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.

**Returns:**

- None

**Example:**

```python {class="line-numbers linkable-line-numbers"}
from viam.services.data_manager import DataManagerClient

# Get the data manager service
data_manager = DataManagerClient.from_robot(robot, "builtin")

# Read image file
with open("path/to/image.jpg", "rb") as f:
image_data = f.read()

# Upload to datasets with tags
await data_manager.upload_image_to_dataset(
image=image_data,
dataset_ids=["dataset_1", "dataset_2"],
tags=["training", "outdoor", "robot_vision"]
)
```

{{% /tab %}}
{{% tab name="Go" %}}

**Parameters:**

- `ctx` [(Context)](https://pkg.go.dev/context#Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
- `image` ([]byte): The image data as bytes.
- `datasetIDs` ([]string): List of dataset IDs to upload the image to.
- `tags` ([]string): List of tags to apply to the uploaded image.
- `extra` [(map[string]interface{})](https://go.dev/blog/maps): Extra options to pass to the underlying RPC call.

**Returns:**

- [(error)](https://pkg.go.dev/builtin#error): An error, if one occurred.

**Example:**

```go {class="line-numbers linkable-line-numbers"}
// Get the data manager service
dataManager, err := datamanager.FromRobot(machine, "builtin")

// Read image file
imageData, err := os.ReadFile("path/to/image.jpg")
if err != nil {
return err
}

// Upload to datasets with tags
err = dataManager.UploadImageToDataset(
context.Background(),
imageData,
[]string{"dataset_1", "dataset_2"},
[]string{"training", "outdoor", "robot_vision"},
nil,
)
```

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/datamanager#Service).

{{% /tab %}}
{{% tab name="TypeScript" %}}

**Parameters:**

- `image` (Uint8Array): The image data as bytes.
- `datasetIds` (string[]): List of dataset IDs to upload the image to.
- `tags` (string[]): List of tags to apply to the uploaded image.
- `extra` (Struct) (optional): Extra options to pass to the underlying RPC call.
- `callOptions` (CallOptions) (optional): Call options for the request.

**Returns:**

- (Promise<void>)

**Example:**

```ts {class="line-numbers linkable-line-numbers"}
const dataManager = new VIAM.DataManagerClient(
machine,
'builtin'
);

// Read image file (example using File API in browser)
const fileInput = document.getElementById('imageFile') as HTMLInputElement;
const file = fileInput.files[0];
const imageData = new Uint8Array(await file.arrayBuffer());

// Upload to datasets with tags
await dataManager.uploadImageToDataset(
imageData,
['dataset_1', 'dataset_2'],
['training', 'outdoor', 'robot_vision']
);
```

For more information, see the [TypeScript SDK Docs](https://ts.viam.dev/classes/DataManagerClient.html).

{{% /tab %}}
{{< /tabs >}}

### Reconfigure

Reconfigure this resource.
Expand Down
Loading