Skip to main content
Version: 0.6.x

Basic Classification

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

import denkflow

pat = "YOUR-PAT"

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

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

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 classification results is the scalar tensor
results_receiver = pipeline.subscribe_scalar_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()

print("Classification Results:")
for image_results in results_per_image:
for class_label_result in image_results:
print(f"{class_label_result.class_label}: {class_label_result.value:.2f}")