From cc0f8362c785435cc42d1ae5e8800ce8c2176614 Mon Sep 17 00:00:00 2001 From: sky leilani <45158875+skyleilani@users.noreply.github.com> Date: Wed, 8 May 2024 14:37:04 -0400 Subject: [PATCH] DOCS-2234: Review ML, CV, and Data Go snippets (#2862) --- docs/data/_index.md | 2 - docs/ml/deploy/_index.md | 16 ++------ docs/ml/vision/_index.md | 84 ++++------------------------------------ 3 files changed, 12 insertions(+), 90 deletions(-) diff --git a/docs/data/_index.md b/docs/data/_index.md index 7d49622ac1..98af040c7b 100644 --- a/docs/data/_index.md +++ b/docs/data/_index.md @@ -160,8 +160,6 @@ Sync data stored on the machine to the cloud. For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/datamanager). ```go {class="line-numbers linkable-line-numbers"} -data, err := datamanager.FromRobot(robot, "my_data_service") - // Sync data stored on the machine to the cloud. err := data.Sync(context.Background(), nil) ``` diff --git a/docs/ml/deploy/_index.md b/docs/ml/deploy/_index.md index 17b17dc9f4..a6e85e689a 100644 --- a/docs/ml/deploy/_index.md +++ b/docs/ml/deploy/_index.md @@ -155,11 +155,9 @@ output_tensors = await my_mlmodel.infer(input_tensors) For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/mlmodel#Service). ```go {class="line-numbers linkable-line-numbers"} -myMLModel, err := mlmodel.FromRobot(robot, "my_mlmodel_service") - input_tensors := ml.Tensors{"0": tensor.New(tensor.WithShape(1, 2, 3), tensor.WithBacking(6))} -output_tensors, err := myMLModel.Infer(ctx.Background(), input_tensors) +output_tensors, err := myMLModel.Infer(context.Background(), input_tensors) ``` {{% /tab %}} @@ -203,9 +201,7 @@ metadata = await my_mlmodel.metadata() For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/mlmodel#Service). ```go {class="line-numbers linkable-line-numbers"} -myMLModel, err := mlmodel.FromRobot(robot, "my_mlmodel_service") - -metadata, err := myMLModel.Metadata(ctx.Background()) +metadata, err := myMLModel.Metadata(context.Background()) ``` {{% /tab %}} @@ -260,9 +256,7 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ - [(error)](https://pkg.go.dev/builtin#error): An error, if one occurred. ```go {class="line-numbers linkable-line-numbers"} -myMLModel, err := mlmodel.FromRobot(robot, "my_mlmodel_service") - -resp, err := myMLModel.DoCommand(ctx, map[string]interface{}{"command": "dosomething", "someparameter": 52}) +resp, err := myMLModel.DoCommand(context.Background(), map[string]interface{}{"command": "dosomething", "someparameter": 52}) ``` For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource). @@ -305,9 +299,7 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ - [(error)](https://pkg.go.dev/builtin#error) : An error, if one occurred. ```go {class="line-numbers linkable-line-numbers"} -myMLModel, err := mlmodel.FromRobot(robot, "my_mlmodel_service") - -err := myMLModel.Close(ctx) +err := myMLModel.Close(context.Background()) ``` For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource). diff --git a/docs/ml/vision/_index.md b/docs/ml/vision/_index.md index 71fd5281c2..f615c2a810 100644 --- a/docs/ml/vision/_index.md +++ b/docs/ml/vision/_index.md @@ -178,19 +178,6 @@ detections = await my_detector.get_detections(img) For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/vision). ```go {class="line-numbers linkable-line-numbers" data-line="22"} -// Grab the camera from the machine -cameraName := "cam1" -myCam, err := camera.FromRobot(robot, cameraName) -if err != nil { - logger.Fatalf("cannot get camera: %v", err) -} - -// Grab the detector you configured on your machine -visService, err := vision.from_robot(robot=robot, name='my_detector') -if err != nil { - logger.Fatalf("Cannot get vision service: %v", err) -} - // Get the stream from a camera camStream, err := myCam.Stream(context.Background()) @@ -256,19 +243,6 @@ detections = await my_detector.get_detections_from_camera(camera_name) For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/vision). ```go {class="line-numbers linkable-line-numbers" data-line="15"} -// Grab the camera from the machine -cameraName := "cam1" -myCam, err := camera.FromRobot(robot, cameraName) -if err != nil { - logger.Fatalf("cannot get camera: %v", err) -} - -// Grab the detector you configured on your machine -visService, err := vision.from_robot(robot=robot, name='my_detector') -if err != nil { - logger.Fatalf("Cannot get vision service: %v", err) -} - // Get detections from the camera output detections, err := visService.DetectionsFromCamera(context.Background(), myCam, nil) if err != nil { @@ -335,21 +309,12 @@ classifications = await my_classifier.get_classifications(img, 2) For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/vision). ```go {class="line-numbers linkable-line-numbers" data-line="22"} -// Grab the camera from the machine -cameraName := "cam1" -myCam, err := camera.FromRobot(robot, cameraName) -if err != nil { - logger.Fatalf("cannot get camera: %v", err) -} - -// Grab the classifier you configured on your machine -visService, err := vision.from_robot(robot=robot, name='my_classifier') -if err != nil { - logger.Fatalf("Cannot get vision service: %v", err) -} - // Get the stream from a camera camStream, err := myCam.Stream(context.Background()) +if err!=nil { + logger.Error(err) + return + } // Get an image from the camera stream img, release, err := camStream.Next(context.Background()) @@ -392,7 +357,7 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ camera_name = "cam1" # Grab the classifier you configured on your machine -my_classifier = VisionClient.from_robot(robot, "my_classifier") +my_classifier = VisionClient.from_robot(machine, "my_classifier") # Get the 2 classifications with the highest confidence scores from the next # image from the camera @@ -419,19 +384,6 @@ classifications = await my_classifier.get_classifications_from_camera( For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/vision). ```go {class="line-numbers linkable-line-numbers" data-line="15"} -// Grab the camera from the machine -cameraName := "cam1" -myCam, err := camera.FromRobot(robot, cameraName) -if err != nil { - logger.Fatalf("cannot get camera: %v", err) -} - -// Grab the classifier you configured on your machine -visService, err := vision.from_robot(robot=robot, name='my_classifier') -if err != nil { - logger.Fatalf("Cannot get vision service: %v", err) -} - // Get the 2 classifications with the highest confidence scores from the camera output classifications, err := visService.ClassificationsFromCamera(context.Background(), myCam, 2, nil) if err != nil { @@ -491,21 +443,8 @@ objects = await my_segmenter.get_object_point_clouds(cam1) For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/services/vision). ```go {class="line-numbers linkable-line-numbers" data-line="15"} -// Grab the camera from the machine -cameraName := "cam1" -myCam, err := camera.FromRobot(robot, cameraName) -if err != nil { - logger.Fatalf("cannot get camera: %v", err) -} - -// Grab the segmenter you configured on your machine -visService, err := vision.from_robot(robot=robot, name='my_segmenter') -if err != nil { - logger.Fatalf("Cannot get vision service: %v", err) -} - // Get the objects from the camera output -objects, err := visService.ObjectPointClouds(context.Background(), myCam, nil) +objects, err := visService.GetObjectPointClouds(context.Background(), "cam1", nil) if err != nil { logger.Fatalf("Could not get point clouds: %v", err) } @@ -564,12 +503,7 @@ await vision_svc.do_command(my_command) ```go {class="line-numbers linkable-line-numbers"} // Access your vision service -visService, err := vision.from_robot(robot=robot, name="my_vision_svc") -if err != nil { - logger.Fatal(err) -} - -resp, err := visService.DoCommand(ctx, map[string]interface{}{"command": "dosomething", "someparameter": 52}) +resp, err := visService.DoCommand(context.Background(), map[string]interface{}{"command": "dosomething", "someparameter": 52}) ``` For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource). @@ -612,9 +546,7 @@ For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/ - [(error)](https://pkg.go.dev/builtin#error) : An error, if one occurred. ```go {class="line-numbers linkable-line-numbers"} -visService, err := vision.FromRobot(robot, "my_vision_svc") - -err := visService.Close(ctx) +err := visService.Close(context.Background()) ``` For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).