Files
kinect-bot 5879422ab9
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python root tests (pytest, no tracker deps) (push) Canceled after 0s
ci / Python tracker (pytest, tracker/.venv) (push) Canceled after 0s
feat(tracker-native): ONNX Runtime C++ inference foundation + setup
Scaffold the zero-Python native tracker. Convert the real MediaPipe BlazePose
landmark weights (from pose_landmarker_full.task) to ONNX and prove the ONNX
Runtime C++ API runs them bit-identically to Python (ort_smoke vs
ort_smoke_ref.py; landmarks match to 6dp, mask <=1.2% prob vs TFLite).
Reproducible setup scripts (setup_models.sh, fetch_ort.sh) and a Linux build.
No binaries committed (ORT + onnx/tflite are fetched/generated).
2026-11-25 18:29:48 -05:00

42 lines
1.7 KiB
C++

// Headless ORT C++ integration check; mirrored by scripts/ort_smoke_ref.py.
#include <onnxruntime_cxx_api.h>
#include <array>
#include <cmath>
#include <cstdio>
#include <vector>
int main(int argc, char** argv) {
const char* model = argc > 1 ? argv[1] : "models/pose_landmarks_detector.onnx";
Ort::Env env(ORT_LOGGING_LEVEL_WARNING, "smoke");
Ort::SessionOptions so;
so.SetIntraOpNumThreads(1);
so.SetGraphOptimizationLevel(ORT_ENABLE_ALL);
Ort::Session sess(env, model, so);
std::vector<float> in(static_cast<size_t>(1) * 256 * 256 * 3);
for (size_t i = 0; i < in.size(); ++i) {
in[i] = static_cast<float>(i % 1000) / 1000.0f;
}
std::array<int64_t, 4> shape{1, 256, 256, 3};
Ort::MemoryInfo mi = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);
Ort::Value input = Ort::Value::CreateTensor<float>(mi, in.data(), in.size(),
shape.data(), shape.size());
const char* in_names[] = {"input_1"};
const char* out_names[] = {"Identity", "Identity_1", "Identity_2",
"Identity_3", "Identity_4"};
auto outs = sess.Run(Ort::RunOptions{nullptr}, in_names, &input, 1, out_names, 5);
const float* lm = outs[0].GetTensorData<float>(); // [1,195]
const float* pres = outs[1].GetTensorData<float>(); // [1,1]
const float* mask = outs[2].GetTensorData<float>(); // [1,256,256,1] logits
double msum = 0.0;
for (int i = 0; i < 256 * 256; ++i) msum += 1.0 / (1.0 + std::exp(-mask[i]));
std::printf("lm0..4: %.6f %.6f %.6f %.6f %.6f\n", lm[0], lm[1], lm[2], lm[3], lm[4]);
std::printf("presence: %.6f\n", pres[0]);
std::printf("mask_prob_sum: %.3f\n", msum);
return 0;
}