Classification
A classification pipeline returns a scalar result per class on each InferenceResult. See SimplifiedPipeline for the shared setup and Interpreting results for the result model.
- Python
- C#
- C / C++
import denkflow
pipeline = denkflow.Pipeline.from_denkflow("path/to/model.denkflow", pat="YOUR-PAT")
simplified = denkflow.SimplifiedPipeline(pipeline)
results = simplified.run("path/to/image.jpg")
for image_result in results:
for r in image_result.results:
if r.scalar:
print(f"{r.scalar.class_label.name}: {r.scalar.value:.2f}")
using DenkFlow;
using var license = HubLicenseSource.FromPat("YOUR-PAT");
using var pipeline = Pipeline.FromDenkflow("path/to/model.denkflow", license);
using var simplified = new SimplifiedPipeline(pipeline);
using ImageInferenceResults results =
simplified.Run("path/to/image.jpg");
foreach (ImageInferenceResult imageResult in results)
{
foreach (InferenceResult result in imageResult.Results)
{
if (result.Scalar is Scalar scalar)
{
Console.WriteLine(
$"{scalar.ClassLabel.Name}: {scalar.Value:F2}");
}
}
}
DenkflowPipeline* pipeline = NULL;
DenkflowSimplifiedPipeline* simplified = NULL;
DenkflowImageInferenceResults* results = NULL;
DenkflowHubLicenseSource* license = NULL;
handle_error(denkflow_hub_license_source_from_pat(&license, "YOUR-PAT", NULL, NULL),
"denkflow_hub_license_source_from_pat");
handle_error(denkflow_pipeline_from_denkflow(&pipeline, "path/to/model.denkflow", (void*)license),
"denkflow_pipeline_from_denkflow");
handle_error(denkflow_simplified_pipeline_new(&simplified, &pipeline),
"denkflow_simplified_pipeline_new");
handle_error(denkflow_simplified_pipeline_run_from_file(&results, simplified, "path/to/image.jpg", 0.0f),
"denkflow_simplified_pipeline_run_from_file");
for (size_t b = 0; b < results->image_results_length; ++b) {
DenkflowImageInferenceResult* image_result = &results->image_results[b];
for (size_t i = 0; i < image_result->results_length; ++i) {
DenkflowInferenceResult* r = &image_result->results[i];
if (r->scalar != NULL) {
printf("%s: %f\n", r->scalar->class_label.name, r->scalar->value);
}
}
}
denkflow_inference_results_free(&results);
denkflow_simplified_pipeline_free(&simplified);
denkflow_free_object((void**)&license);
Draw classification scores
When annotation labels are enabled, classification scores are sorted from highest
to lowest and drawn as separate class-colored chips in the top-left corner.
top_classifications / TopClassifications controls how many scores are shown;
0 omits them. Keep the source image tensor so it can render the inference
results, and set annotation_label_font_size / LabelFontSize to a positive
value. See Drawing results for Python,
C#, and C examples.