diff --git a/docs/data-ai/ai/create-dataset.md b/docs/data-ai/ai/create-dataset.md index b08766a59f..0e0408861a 100644 --- a/docs/data-ai/ai/create-dataset.md +++ b/docs/data-ai/ai/create-dataset.md @@ -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 >}} diff --git a/docs/dev/reference/changelog.md b/docs/dev/reference/changelog.md index 699fc9e402..8ebfd5ce3d 100644 --- a/docs/dev/reference/changelog.md +++ b/docs/dev/reference/changelog.md @@ -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. diff --git a/static/include/services/apis/generated/data_manager-table.md b/static/include/services/apis/generated/data_manager-table.md index 2ad9682c4a..9def9e598f 100644 --- a/static/include/services/apis/generated/data_manager-table.md +++ b/static/include/services/apis/generated/data_manager-table.md @@ -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. | | diff --git a/static/include/services/apis/generated/data_manager.md b/static/include/services/apis/generated/data_manager.md index a484f02d42..74a1a92988 100644 --- a/static/include/services/apis/generated/data_manager.md +++ b/static/include/services/apis/generated/data_manager.md @@ -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) + +**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.