Previous
Train a model
Configure your machine to load a trained model from the registry and apply it to live camera frames. You need an ML model service to load the model and a vision service to run it against camera input.
For the full guide to configuring vision services and cloud inference, see Configure computer vision.
tflite and find the tflite_cpu block (by viam,
badge: MLMODEL).my-ml-model) and click
Add component. The supporting viam:tflite_cpu module is installed
automatically.mlmodel and find the mlmodel block (type: VISION,
built-in).my-detector) and click
Add component.my-ml-model).
from viam.services.vision import VisionClient
# Get the vision service (assumes you have a robot connection)
vision = VisionClient.from_robot(robot, "my-detector")
# For classification
classifications = await vision.get_classifications(
image=my_image,
count=5,
)
for c in classifications:
print(f" {c.class_name}: {c.confidence:.2f}")
# For object detection
detections = await vision.get_detections(image=my_image)
for d in detections:
print(f" {d.class_name}: {d.confidence:.2f} "
f"at ({d.x_min}, {d.y_min}) to ({d.x_max}, {d.y_max})")
import "go.viam.com/rdk/services/vision"
// Get the vision service (assumes you have a robot connection)
visionSvc, err := vision.FromProvider(robot, "my-detector")
if err != nil {
logger.Fatal(err)
}
// For classification
classifications, err := visionSvc.Classifications(ctx, myImage, 5, nil)
if err != nil {
logger.Fatal(err)
}
for _, c := range classifications {
fmt.Printf(" %s: %.2f\n", c.Label(), c.Score())
}
// For object detection
detections, err := visionSvc.Detections(ctx, myImage, nil)
if err != nil {
logger.Fatal(err)
}
for _, d := range detections {
box := d.BoundingBox()
fmt.Printf(" %s: %.2f at (%d, %d) to (%d, %d)\n",
d.Label(), d.Score(),
box.Min.X, box.Min.Y, box.Max.X, box.Max.Y)
}
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!