From 7519562a5455bfd5d55c12a2c299da1adf03448c Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Wed, 13 Nov 2024 11:18:20 -0500 Subject: [PATCH 1/5] Edit mlmodel service from QA --- .../services/apis/generated/mlmodel.md | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/static/include/services/apis/generated/mlmodel.md b/static/include/services/apis/generated/mlmodel.md index 77413f6505..3300c746dd 100644 --- a/static/include/services/apis/generated/mlmodel.md +++ b/static/include/services/apis/generated/mlmodel.md @@ -22,8 +22,14 @@ import numpy as np my_mlmodel = MLModelClient.from_robot(robot=machine, name="my_mlmodel_service") -nd_array = np.array([1, 2, 3], dtype=np.float64) -input_tensors = {"0": nd_array} +output_tensors = await my_mlmodel.infer(input_tensors) + +image_data = np.zeros((1, 384, 384, 3), dtype=np.uint8) + +# Create the input tensors dictionary +input_tensors = { + "image": image_data +} output_tensors = await my_mlmodel.infer(input_tensors) ``` @@ -46,7 +52,20 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ **Example:** ```go {class="line-numbers linkable-line-numbers"} -input_tensors := ml.Tensors{"0": tensor.New(tensor.WithShape(1, 2, 3), tensor.WithBacking([]int{1, 2, 3, 4, 5, 6}))} +import ( + "go.viam.com/rdk/ml" + "gorgonia.org/tensor" +) + +myMLModel, err := mlmodel.FromRobot(machine, "mlmodel-1") + +input_tensors := ml.Tensors{ + "image": tensor.New( + tensor.Of(tensor.Uint8), + tensor.WithShape(1, 384, 384, 3), + tensor.WithBacking(make([]uint8, 1*384*384*3)), + ), +} output_tensors, err := myMLModel.Infer(context.Background(), input_tensors) ``` @@ -97,6 +116,7 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ **Example:** ```go {class="line-numbers linkable-line-numbers"} +myMLModel, err := mlmodel.FromRobot(machine, "mlmodel-1") metadata, err := myMLModel.Metadata(context.Background()) ``` @@ -206,7 +226,7 @@ Get the `ResourceName` for this instance of the ML model service with the given **Example:** ```python {class="line-numbers linkable-line-numbers"} -my_mlmodel_svc_name = MLModelClient.get_resource_name("my_mlmodel_svc") +my_mlmodel_svc_name = my_mlmodel.get_resource_name("my_mlmodel_svc") ``` For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/services/mlmodel/client/index.html#viam.services.mlmodel.client.MLModelClient.get_resource_name). From 5b3d4e40731f4dc6a8720be5c29942d19ce041ba Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Mon, 18 Nov 2024 10:48:03 -0500 Subject: [PATCH 2/5] Apply suggestions from code review --- static/include/services/apis/generated/mlmodel.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/include/services/apis/generated/mlmodel.md b/static/include/services/apis/generated/mlmodel.md index 3300c746dd..46aa248140 100644 --- a/static/include/services/apis/generated/mlmodel.md +++ b/static/include/services/apis/generated/mlmodel.md @@ -226,7 +226,7 @@ Get the `ResourceName` for this instance of the ML model service with the given **Example:** ```python {class="line-numbers linkable-line-numbers"} -my_mlmodel_svc_name = my_mlmodel.get_resource_name("my_mlmodel_svc") +my_mlmodel_svc_name = MLModelClient.get_resource_name("my_mlmodel_svc") ``` For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/services/mlmodel/client/index.html#viam.services.mlmodel.client.MLModelClient.get_resource_name). From 05a6badee2e10a7b8ac2ce9ae2195db1e68a54f9 Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Mon, 18 Nov 2024 10:49:28 -0500 Subject: [PATCH 3/5] Update mlmodel.md fix indentation --- static/include/services/apis/generated/mlmodel.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/static/include/services/apis/generated/mlmodel.md b/static/include/services/apis/generated/mlmodel.md index 46aa248140..2f10de04b3 100644 --- a/static/include/services/apis/generated/mlmodel.md +++ b/static/include/services/apis/generated/mlmodel.md @@ -53,17 +53,17 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ ```go {class="line-numbers linkable-line-numbers"} import ( - "go.viam.com/rdk/ml" - "gorgonia.org/tensor" + "go.viam.com/rdk/ml" + "gorgonia.org/tensor" ) myMLModel, err := mlmodel.FromRobot(machine, "mlmodel-1") input_tensors := ml.Tensors{ - "image": tensor.New( - tensor.Of(tensor.Uint8), - tensor.WithShape(1, 384, 384, 3), - tensor.WithBacking(make([]uint8, 1*384*384*3)), + "image": tensor.New( + tensor.Of(tensor.Uint8), + tensor.WithShape(1, 384, 384, 3), + tensor.WithBacking(make([]uint8, 1*384*384*3)), ), } From 38ad63a4ee0553d0c010dde3ed61a39fac515dd2 Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Mon, 18 Nov 2024 10:50:59 -0500 Subject: [PATCH 4/5] Update mlmodel.md --- static/include/services/apis/generated/mlmodel.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/static/include/services/apis/generated/mlmodel.md b/static/include/services/apis/generated/mlmodel.md index 2f10de04b3..836a4b8b9a 100644 --- a/static/include/services/apis/generated/mlmodel.md +++ b/static/include/services/apis/generated/mlmodel.md @@ -53,18 +53,18 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ ```go {class="line-numbers linkable-line-numbers"} import ( - "go.viam.com/rdk/ml" - "gorgonia.org/tensor" + "go.viam.com/rdk/ml" + "gorgonia.org/tensor" ) myMLModel, err := mlmodel.FromRobot(machine, "mlmodel-1") input_tensors := ml.Tensors{ - "image": tensor.New( - tensor.Of(tensor.Uint8), - tensor.WithShape(1, 384, 384, 3), - tensor.WithBacking(make([]uint8, 1*384*384*3)), - ), + "image": tensor.New( + tensor.Of(tensor.Uint8), + tensor.WithShape(1, 384, 384, 3), + tensor.WithBacking(make([]uint8, 1*384*384*3)), + ), } output_tensors, err := myMLModel.Infer(context.Background(), input_tensors) From 60a8840682dd2436eef7749895288676288e19ab Mon Sep 17 00:00:00 2001 From: Sierra Guequierre Date: Fri, 22 Nov 2024 10:18:30 -0500 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: Naomi Pentrel <5212232+npentrel@users.noreply.github.com> --- static/include/services/apis/generated/mlmodel.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/static/include/services/apis/generated/mlmodel.md b/static/include/services/apis/generated/mlmodel.md index 836a4b8b9a..9c9131b851 100644 --- a/static/include/services/apis/generated/mlmodel.md +++ b/static/include/services/apis/generated/mlmodel.md @@ -57,7 +57,7 @@ import ( "gorgonia.org/tensor" ) -myMLModel, err := mlmodel.FromRobot(machine, "mlmodel-1") +myMLModel, err := mlmodel.FromRobot(machine, "my_mlmodel_service") input_tensors := ml.Tensors{ "image": tensor.New( @@ -116,7 +116,7 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ **Example:** ```go {class="line-numbers linkable-line-numbers"} -myMLModel, err := mlmodel.FromRobot(machine, "mlmodel-1") +myMLModel, err := mlmodel.FromRobot(machine, "my_mlmodel_service") metadata, err := myMLModel.Metadata(context.Background()) ```