Evaluating a sequence of images
A batched image tensor is evaluated in a single run, producing one ImageInferenceResult per image in input order. This extends the classification example to a sequence. See Running inference for the batching model.
- Python
- C / C++
import denkflow
image_paths = ["path/to/image_1.jpg", "path/to/image_2.jpg", "path/to/image_3.jpg"]
pipeline = denkflow.Pipeline.from_denkflow("path/to/model.denkflow", pat="YOUR-PAT")
simplified = denkflow.SimplifiedPipeline(pipeline)
batch = denkflow.ImageTensor.from_files(image_paths)
results = simplified.run(batch)
for path, image_result in zip(image_paths, results):
print(f"Results for {path}:")
for r in image_result.results:
if r.scalar:
print(f" {r.scalar.class_label.name}: {r.scalar.value:.2f}")
DenkflowPipeline* pipeline = NULL;
DenkflowSimplifiedPipeline* simplified = NULL;
DenkflowImageTensor* batch = NULL;
DenkflowImageInferenceResults* results = NULL;
DenkflowHubLicenseSource* license = NULL;
const char* image_paths[3] = {
"path/to/image_1.jpg", "path/to/image_2.jpg", "path/to/image_3.jpg"
};
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");
// Load the images into a single batched tensor.
handle_error(denkflow_image_tensor_from_files(&batch, image_paths, 3),
"denkflow_image_tensor_from_files");
handle_error(denkflow_simplified_pipeline_run_from_tensor(&results, simplified, (void**)&batch, 0.0f),
"denkflow_simplified_pipeline_run_from_tensor");
for (size_t b = 0; b < results->image_results_length; ++b) {
printf("Image %zu\n", 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);