fix onnx yolo race condition

This commit is contained in:
2026-05-04 23:45:05 +10:00
parent 03a63142ec
commit 91d81cbd88
3 changed files with 118 additions and 36 deletions
+17
View File
@@ -178,6 +178,23 @@ namespace ANSCENTER {
// Cached model input shape
cv::Size inputImageShape;
bool isDynamicInputShape{ false };
// Per-call preprocess that writes into caller-provided buffer + dims
// instead of the BasicOrtHandler members (input_values_handler /
// input_node_dims). detect() / detectBatch() use these so multiple
// threads sharing one ONNXYOLO instance can preprocess and infer
// concurrently — the Ort input tensor's backing storage is unique
// per call and lives on the caller's stack. Without this, thread B
// could overwrite the shared buffer between thread A's transform()
// and thread A's Run(), causing A's Run() to consume B's pixels and
// return detections that belong to B's frame. Observed on
// Intel/OpenVINO EP where nothing else serializes.
Ort::Value transformInto(const cv::Mat& mat,
std::vector<float>& outBuffer,
std::vector<int64_t>& outDims);
Ort::Value transformBatchInto(const std::vector<cv::Mat>& images,
std::vector<float>& outBuffer,
std::vector<int64_t>& outDims);
};
// ====================================================================