Skip to main content
Version: 0.6.x

Basic Segmentation

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

import denkflow

pat = "YOUR-PAT"

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

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

segmentation_threshold = 0.5

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

pipeline.initialize()

image_tensor = denkflow.ImageTensor.from_file(image_path)

pipeline.publish_image_tensor(input_topic, image_tensor)

# The tensor type for segmentation results is the segmentation mask tensor
results_receiver = pipeline.subscribe_segmentation_mask_tensor(output_topic)

# Run the pipeline. This operation will block until the pipeline has finished running.
pipeline.run()

tensor = results_receiver.receive()

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}")