Illustrated C/C++ source sheets, symbol index, API relationship graph, compiler console and debug trace

LIVE AI / FLEXIBLE SENSING / FLIGHT CONTEXT

Sensoraia API

Live AI and sensing, connected to the flight.
See, listen, inspect and return supported results while airborne.

Loading...
Searching...
No Matches
inference_model.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 OpenUAS
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18/** @file inference_model.h
19 * @brief Integrity-checked model contracts and independently owned tensor workspaces. */
20#ifndef SENSORAIA_INFERENCE_MODEL_H
21#define SENSORAIA_INFERENCE_MODEL_H
22
23#include "inference_image.h"
24#include "inference_settings.h"
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/** @brief Parsed descriptor with self-referencing tensor-name pointers; do not copy after parsing. */
41
42/** @brief Independent, noncopyable model owner; mapped tensor buffers and session are reused between jobs. */
47 void *storage; /**< Private mapped arena; ORT's own allocations are additional. */
48 size_t storage_bytes; /**< Mapped tensor bytes, not the whole model/process footprint. */
49 unsigned timeout_ms; /**< Per-run cooperative budget. */
51 bool capture_identity; /**< Sequence/time came from this retained capture rather than an offline request. */
52 bool private_image; /**< Producer owns exclusive pre-publication mutation rights. */
53};
54
55/** @brief Load a bounded descriptor and verify its exact graph digest; hashes are not authentication.
56 * @param model Destination contract; discard it on failure.
57 * @param descriptor SENSORAIA_MODEL_V1 flat INI path.
58 * @param graph Graph whose bytes must match the descriptor hash.
59 * @param error Writable failure diagnostic.
60 * @param capacity Available bytes in error.
61 * @return True for a complete descriptor and matching graph identity. */
62bool inference_model_read(struct inference_model *model, const char *descriptor,
63 const char *graph, char *error, size_t capacity);
64/** @brief Parse a descriptor, not graph bytes; graph integrity remains a separate read-time check.
65 * @param model Destination with name storage backing its own tensor views.
66 * @param contents Destructively parsed input with at least length+1 writable bytes.
67 * @param length Input bytes excluding the writable terminator.
68 * @param error Writable failure diagnostic.
69 * @param capacity Available bytes in error.
70 * @return True for supported schema, bounded concrete tensors and complete preprocessing. */
71bool inference_model_parse(struct inference_model *model, char *contents, size_t length,
72 char *error, size_t capacity);
73/** @brief Hash a stable nonempty regular file using bounded streaming scratch.
74 * @param filename Immutable input path during hashing.
75 * @param digest Destination for 64 lowercase hex characters and a NUL.
76 * @return True for a complete stable read; digest is undefined on failure. */
77bool inference_file_sha256(const char *filename, char digest[65]);
78/** @brief Resolve one model-owned label without retaining a pointer into a mutable list.
79 * @param model Parsed descriptor with comma-separated labels.
80 * @param category Zero-based class index.
81 * @param label Writable nontruncated class name.
82 * @param capacity Available bytes in label.
83 * @return True when the requested label exists and fits. */
84bool inference_model_label(const struct inference_model *model, unsigned category,
85 char *label, size_t capacity);
86/** @brief Verify a bundle, map bounded tensors and bind one warm session.
87 * @param context Zero-initialized noncopyable owner.
88 * @param settings Resolved ONNX configuration; values are consumed during open.
89 * @param adapter Required application ABI, or NULL when the caller validates it separately.
90 * @param error Writable failure diagnostic.
91 * @param capacity Available bytes in error.
92 * @return True after the graph can use this context's tensor buffers.
93 * @note Mapping tensor storage does not make ORT allocations heap-free or bound whole-board RAM. */
94bool inference_context_open(struct inference_context *context,
95 const struct inference_settings *settings, const char *adapter,
96 char *error, size_t capacity);
97/** @brief Run the currently prepared tensors using the context's timeout policy.
98 * @param context Exclusive open model owner.
99 * @param error Writable failure diagnostic.
100 * @param capacity Available bytes in error.
101 * @return True for valid completed output; ignore output on failure. */
102bool inference_context_run(struct inference_context *context, char *error, size_t capacity);
103/** @brief Prepare a single image input without running the model, so camera leases can be released first.
104 * @param context Open owner with one declared image tensor.
105 * @param image Borrowed immutable pixels valid for this call only.
106 * @param error Writable failure diagnostic.
107 * @param capacity Available bytes in error.
108 * @return True after filling input storage and its source-coordinate transform. */
110 const struct inference_image *image,
111 char *error, size_t capacity);
112/** @brief Release the session before unmapping its borrowed tensor storage.
113 * @param context Exclusive owner; NULL and repeated closes are harmless. */
114void inference_context_close(struct inference_context *context);
115
116#ifdef __cplusplus
117}
118#endif
119#endif
static unsigned capacity[COVERAGE_CAMERAS]
int descriptor
Definition chdk_pipe.c:142
Source-independent, bounded model preprocessing with reversible coordinate bookkeeping.
bool inference_context_run(struct inference_context *context, char *error, size_t capacity)
Run the currently prepared tensors using the context's timeout policy.
bool inference_context_open(struct inference_context *context, const struct inference_settings *settings, const char *adapter, char *error, size_t capacity)
Verify a bundle, map bounded tensors and bind one warm session.
bool inference_context_prepare_image(struct inference_context *context, const struct inference_image *image, char *error, size_t capacity)
Prepare a single image input without running the model, so camera leases can be released first.
bool inference_file_sha256(const char *filename, char digest[65])
Hash a stable nonempty regular file using bounded streaming scratch.
bool inference_model_read(struct inference_model *model, const char *descriptor, const char *graph, char *error, size_t capacity)
Load a bounded descriptor and verify its exact graph digest; hashes are not authentication.
bool inference_model_label(const struct inference_model *model, unsigned category, char *label, size_t capacity)
Resolve one model-owned label without retaining a pointer into a mutable list.
void inference_context_close(struct inference_context *context)
Release the session before unmapping its borrowed tensor storage.
bool inference_model_parse(struct inference_model *model, char *contents, size_t length, char *error, size_t capacity)
Parse a descriptor, not graph bytes; graph integrity remains a separate read-time check.
Shared application_settings.ini discovery with module-owned extra keys.
struct jpeg_error_mgr error
Definition lwir_image.c:60
#define ONNX_NAME_CAPACITY
#define ONNX_TENSOR_LIMIT
Independent, noncopyable model owner; mapped tensor buffers and session are reused between jobs.
uint64_t sensor_timestamp_ns
struct inference_image_transform transform
struct inference_model model
struct onnx_session session
Model-owned preprocessing; normalized samples are (sample - mean) * scale.
Exact resized content rectangle, including rounded letterbox offsets.
Borrowed immutable planes; lengths/strides prove all addressed rows are available.
Parsed descriptor with self-referencing tensor-name pointers; do not copy after parsing.
struct inference_image_spec image
char descriptor_sha256[65]
char input_names[ONNX_TENSOR_LIMIT][ONNX_NAME_CAPACITY]
char output_names[ONNX_TENSOR_LIMIT][ONNX_NAME_CAPACITY]
struct onnx_tensor inputs[ONNX_TENSOR_LIMIT]
struct onnx_tensor outputs[ONNX_TENSOR_LIMIT]
Per-application configuration; all resolved paths belong to this caller-owned value.
Noncopyable caller-owned session; zero-initialize and serialize open/run/close ownership.
Named concrete tensor view; its aligned backing storage must outlive the session.
struct captured_image image
Definition usher.c:371