Skip to main content

Model.h File

Model — the simplified entry point for loading and running a compiled model archive on Modalix. More...

Included Headers

#include "model/PreprocessPlan.h" #include "nodes/io/Input.h" #include "pipeline/BoxDecodeType.h" #include "pipeline/Run.h" #include "pipeline/TensorSpec.h" #include <cstddef> #include <array> #include <cstdint> #include <memory> #include <optional> #include <string> #include <unordered_map> #include <vector>

Namespaces Index

namespacesimaai
namespaceneat
namespaceinternal

Classes Index

classModel

Loaded form of a compiled model archive; the simplified entry point to run inference on Modalix. More...

structModelInfo

Diagnostic snapshot of how the route planner resolved the model. More...

structRouteNeeds

What the model fundamentally needs in its pre/post chain (derived from manifest dtypes). More...

structRouteCapabilities

What pre/post adapters the MPK contract provides (read from manifest stages). More...

structRouteSelection

What the planner actually included in the materialized route. More...

structOutputTopology

Output topology: how many tensors the model emits, and whether they're physically packed. More...

structInferenceTerminalPolicy

Where the inference pipeline should terminate. More...

structPreprocessRequirements

Concrete preprocess parameters resolved by the planner from the MPK contract. More...

structOptions

User-provided options at Model construction time. More...

structRouteOptions

Options for Model::graph() — controls how the model assembles into a Graph. More...

classRunner

Long-lived execution handle returned by Model::build(...). More...

Description

Model — the simplified entry point for loading and running a compiled model archive on Modalix.

Model is the user-facing wrapper around a compiled model archive (.tar.gz). It loads the file, extracts and validates the manifest, runs the route planner, and exposes ready-to-use Graph fragments (preprocess, inference, postprocess) plus convenience run() and build() methods that drive a one-shot inference. Internally a Model is a Graph wrapper: the same composition, validation, and runtime machinery the Graph API exposes powers Model underneath. New users start with Model::run(input); advanced users compose their own Graph from model.graph() plus extra Nodes.

See Also

"Models" in the design deep dive (§0.7 — The main concepts)

See Also

"Graphs: the assembly contract" (§0.12) for what Model wraps

See Also

"MPK contract" (§0.16) for the inference contract embedded in Model archives

File Listing

The file content with the documentation metadata removed is:

1
19#pragma once
20
22#include "nodes/io/Input.h"
24#include "pipeline/Run.h"
26
27#include <cstddef>
28#include <array>
29#include <cstdint>
30#include <memory>
31#include <optional>
32#include <string>
33#include <unordered_map>
34#include <vector>
35
36#if defined(SIMA_WITH_OPENCV)
37#include <opencv2/core/mat.hpp>
38#endif
39
40namespace simaai::neat {
41
42namespace internal {
43struct ModelAccess;
44} // namespace internal
45class Graph;
46
49
79class Model {
80public:
88 struct ModelInfo {
90 struct RouteNeeds {
92 false;
94 false;
95 bool pre_cast = false;
97 false;
99 false;
100 bool post_cast = false;
101 };
102
106 false;
108 false;
110 false;
112 false;
114 false;
115 bool has_post_cast = false;
117 false;
118 };
119
124 bool infer_only = false;
125 std::string preprocess_graph;
127 std::string selected_post_kind;
129 };
130
133 std::size_t physical_outputs = 0U;
134 std::size_t logical_outputs =
135 0U;
136 bool packed_outputs = false;
137 };
138
139 std::string mpk_json_path;
141 std::string model_name;
142
147
148 std::vector<std::string> pre_kernels;
149 std::vector<std::string> post_kernels;
150 std::vector<std::string>
152 };
153
162 bool mla_only = false;
163 std::optional<std::size_t>
165 std::optional<std::string>
167 std::optional<std::string> last_plugin_id;
168 std::optional<std::string>
170 };
171
180 bool has_preproc_stage = false;
181 bool quant_needed = false;
182 bool tess_needed = false;
183 std::string input_media_type;
185 std::string input_format;
186 std::string output_format;
187 std::string output_dtype;
189 std::vector<int> axis_perm;
190 std::vector<int> output_shape;
191 std::vector<int> slice_shape;
192 std::optional<double> q_scale;
194 std::optional<std::int64_t> q_zp;
195 };
196
210 struct Options {
213
214 // ── Postprocessing / detection ─────────────────────────────────────────────────────────
223 float score_threshold = 0.0f;
225 0.0f;
226 int top_k = 0;
235
236 // ── Naming / wiring ────────────────────────────────────────────────────────────────────
239 std::string upstream_name = "decoder";
242 std::string name_suffix;
243
244 // ── Extraction lifecycle ───────────────────────────────────────────────────────────────
252
255
258
263
266
269
273 };
274
282 struct RouteOptions {
283 bool include_input = false;
284 bool include_output = false;
297 bool expose_all_outputs = false;
298 std::string upstream_name;
300 std::string name_suffix;
301 std::string
310 std::string processcvu_requested_run_target = "AUTO";
311
316
320
324
328 };
329
335 enum class Stage {
337 Inference,
339 Full
340 };
341
352 explicit Model(const std::string& model_path);
361 explicit Model(const std::string& model_path, const Options& opt);
362
363 Model(Model&&) noexcept;
364 Model& operator=(Model&&) noexcept;
365 ~Model();
367
368 // ── Stage composition ────────────────────────────────────────────────────────────────────
370 simaai::neat::Graph preprocess() const;
372 simaai::neat::Graph inference() const;
374 simaai::neat::Graph postprocess() const;
376 simaai::neat::Graph graph() const;
379 simaai::neat::Graph graph(RouteOptions opt) const;
380
381 // ── Introspection ────────────────────────────────────────────────────────────────────────
385 std::vector<TensorSpec> input_specs() const;
389 std::vector<TensorSpec> output_specs() const;
404 ModelInfo info() const;
406 std::unordered_map<std::string, std::string> metadata() const;
407
408 // ── Advanced / graph composition ─────────────────────────────────────────────────────────
410 Graph fragment(Stage stage) const;
413 std::string backend_fragment(Stage stage) const;
414
416 simaai::neat::InputOptions input_appsrc_options(bool tensor_mode) const;
418 std::vector<simaai::neat::InputOptions> input_appsrc_options_list(bool tensor_mode) const;
420 std::string find_config_path_by_plugin(const std::string& plugin_id) const;
423 std::string find_config_path_by_processor(const std::string& processor) const;
426 std::string infer_output_name() const;
427
447 class Runner {
448 public:
450 Runner() = default;
458 std::vector<std::string> ingress_names);
460 Runner(simaai::neat::Run run, std::vector<std::string> ingress_names);
461
463 explicit operator bool() const noexcept;
464#if defined(SIMA_WITH_OPENCV)
469 bool push(const std::vector<cv::Mat>& inputs);
470#endif
472 bool push(const simaai::neat::TensorList& inputs);
474 bool push(const simaai::neat::Sample& inputs);
481 simaai::neat::Sample pull(int timeout_ms = -1);
482#if defined(SIMA_WITH_OPENCV)
484 simaai::neat::TensorList run(const std::vector<cv::Mat>& inputs, int timeout_ms = -1);
485#endif
487 simaai::neat::TensorList run(const simaai::neat::TensorList& inputs, int timeout_ms = -1);
489 simaai::neat::Sample run(const simaai::neat::Sample& inputs, int timeout_ms = -1);
490
499 int warmup(const simaai::neat::TensorList& inputs, int warm = -1, int timeout_ms = -1);
501 void close();
509 std::string metrics_report(
517 std::string report(const simaai::neat::RunReportOptions& opt = {}) const;
520
521 private:
522 simaai::neat::Run run_{};
523 std::optional<simaai::neat::InputOptions> tensor_input_opt_for_cv_{};
524 std::vector<std::string> ingress_names_;
525 };
526
527private:
528 static const RouteOptions& default_route_options();
529 static const simaai::neat::RunOptions& default_run_options();
530
531public:
562 const RouteOptions& opt = default_route_options(),
563 const simaai::neat::RunOptions& run_opt = default_run_options());
566 const RouteOptions& opt = default_route_options(),
567 const simaai::neat::RunOptions& run_opt = default_run_options());
568#if defined(SIMA_WITH_OPENCV)
570 Runner build(const std::vector<cv::Mat>& inputs,
571 const RouteOptions& opt = default_route_options(),
572 const simaai::neat::RunOptions& run_opt = default_run_options());
573#endif
574
575 // ── One-shot execution (synchronous) ─────────────────────────────────────────────────────
587 simaai::neat::TensorList run(const simaai::neat::TensorList& inputs, int timeout_ms = -1);
589 simaai::neat::Sample run(const simaai::neat::Sample& inputs, int timeout_ms = -1);
590#if defined(SIMA_WITH_OPENCV)
592 simaai::neat::TensorList run(const std::vector<cv::Mat>& inputs, int timeout_ms = -1);
593#endif
594
595private:
596 friend struct internal::ModelAccess;
597 struct Impl;
598 std::unique_ptr<Impl> impl_;
599};
600
601} // namespace simaai::neat

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.