Skip to content

Commit

Permalink
DOCS-2234: Review ML, CV, and Data Go snippets (#2862)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyleilani authored May 8, 2024
1 parent 4def597 commit cc0f836
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 90 deletions.
2 changes: 0 additions & 2 deletions docs/data/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down
16 changes: 4 additions & 12 deletions docs/ml/deploy/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}}
Expand Down Expand Up @@ -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 %}}
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand Down
84 changes: 8 additions & 76 deletions docs/ml/vision/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit cc0f836

Please sign in to comment.