Skip to main content
Version: 0.7.x [Latest Alpha]

Basic Segmentation

This example loads a complete segmentation pipeline file (.denkflow) exported from the Hub.

import denkflow

pat = "YOUR-PAT"

denkflow_path = "path/to/model/file.denkflow"
image_path = "path/to/an/image.jpg"

input_topic = "camera/image"
output_topic = "segmentation_node/output"

segmentation_threshold = 0.5

pipeline = denkflow.Pipeline.from_denkflow(
denkflow_path,
pat=pat
)

pipeline.initialize()

receiver = pipeline.subscribe(output_topic)

image_tensor = denkflow.ImageTensor.from_file(image_path)

pipeline.publish_image_tensor(input_topic, image_tensor)

pipeline.run()

tensor = receiver.receive_segmentation_mask_tensor()

results_per_image = tensor.to_objects(segmentation_threshold)

print("Segmentation Results:")
for results_per_class_label in results_per_image:
for result_for_class_label in results_per_class_label:
print(f"{result_for_class_label.class_label.name}:")
for object in result_for_class_label.objects:
print(f" {object.confidence}")