Generic named inference, for tools with different I/O conventions.
325{
326 if (!graphData.
graph) {
328 return StatusCode::FAILURE;
329 }
330 if (graphData.
graph->dataTensor.empty()) {
332 return StatusCode::FAILURE;
333 }
334
335 if (msgLvl(MSG::DEBUG)) {
336
337
339 if (!graphData.
graph->dataTensor.empty()) {
340 const auto& featureTensor = graphData.
graph->dataTensor[0];
341 auto featShape = featureTensor.GetTensorTypeAndShapeInfo().GetShape();
343 << (featShape.size()>1 ? ("," + std::to_string(featShape[1])) : "")
344 << (featShape.size()>2 ? ("," + std::to_string(featShape[2])) : "") << "]");
345
346 float* featData = const_cast<Ort::Value&>(featureTensor).GetTensorMutableData<float>();
347 const size_t totalElements = featureTensor.GetTensorTypeAndShapeInfo().GetElementCount();
348 ATH_MSG_DEBUG(
"Features tensor total elements: " << totalElements);
349
350
351 const size_t nFeat = (featShape.size() > 1 && featShape[1] > 0) ? static_cast<size_t>(featShape[1]) : 1;
352 const size_t nNodes = totalElements / nFeat;
353 const size_t debugNodes = std::min(nNodes, static_cast<size_t>(10));
354
355
356
357 std::vector<std::string> featNames;
358 {
359 Ort::AllocatorWithDefaultOptions allocator;
360 Ort::ModelMetadata meta =
model().GetModelMetadata();
361 auto keys = meta.GetCustomMetadataMapKeysAllocated(allocator);
362 std::vector<std::string> keyNames;
363 keyNames.reserve(
keys.size());
364 for (
const auto& k : keys) keyNames.emplace_back(
k.get());
366 "x_feature_names", "node_feature_names", "feature_names", "input_feature_names"};
367 for (const std::string& key : candidates) {
368 if (std::find(keyNames.begin(), keyNames.end(), key) != keyNames.end()) {
369 std::string
val = meta.LookupCustomMetadataMapAllocated(
key.c_str(), allocator).get();
371 break;
372 }
373 }
374 if (featNames.empty()) {
375 ATH_MSG_DEBUG(
"No usable feature-name metadata key found in model; using generic fN labels.");
376 }
377 }
378 auto featLabel = [&](
size_t f) -> std::string {
379 if (f < featNames.size())
return featNames[
f];
380 return "f" + std::to_string(f);
381 };
382
383
384 {
385 std::ostringstream
legend;
386 legend <<
"Node feature legend (" << nFeat <<
" features):";
387 for (
size_t f = 0;
f < nFeat; ++
f) {
388 legend <<
" f" <<
f <<
"=" << featLabel(f);
389 if (f + 1 < nFeat)
legend <<
",";
390 }
392 }
393
394 for (
size_t n = 0;
n < debugNodes; ++
n) {
395 std::ostringstream
row;
396 row <<
"ONNXNode[" <<
n <<
"]:";
397 for (
size_t f = 0;
f < nFeat; ++
f) {
398 row <<
" f" <<
f <<
"=" << featData[
n * nFeat +
f];
399 if (f + 1 < nFeat)
row <<
",";
400 }
402 }
403 }
405 }
406
407 Ort::RunOptions run_options;
408 run_options.SetRunLogSeverityLevel(ORT_LOGGING_LEVEL_ERROR);
409
411
412 Ort::IoBinding binding(
model());
413 for (std::size_t i = 0;
i < inputNames.size(); ++
i) {
414 binding.BindInput(inputNames[i], graphData.
graph->dataTensor[i]);
415 }
416
417 Ort::MemoryInfo cpuOut = Ort::MemoryInfo::CreateCpu(OrtArenaAllocator, OrtMemTypeDefault);
418 for (const char* outName : outputNames) {
419 binding.BindOutput(outName, cpuOut);
420 }
421
422 model().Run(run_options, binding);
423 binding.SynchronizeOutputs();
424
425 std::vector<Ort::Value>
outputs = binding.GetOutputValues();
428 return StatusCode::FAILURE;
429 }
430
431 float* outData =
outputs[0].GetTensorMutableData<
float>();
432 const size_t outSize =
outputs[0].GetTensorTypeAndShapeInfo().GetElementCount();
433 ATH_MSG_DEBUG(
"ONNX (IoBinding) raw output elementCount = " << outSize);
434
436 std::span<float> preds(outData, outData + outSize);
437 for (
size_t i = 0;
i < outSize; ++
i) {
438 if (!std::isfinite(preds[i])) {
439 ATH_MSG_WARNING(
"Non-finite prediction detected at " << i <<
" -> set to -100.");
441 }
442 }
443 }
444
445 for (auto& v : outputs) {
446 graphData.
graph->dataTensor.emplace_back(std::move(v));
447 }
448 return StatusCode::SUCCESS;
449 }
450
451
452 std::vector<Ort::Value>
outputs =
453 model().Run(run_options,
454 inputNames.data(),
455 graphData.
graph->dataTensor.data(),
456 graphData.
graph->dataTensor.size(),
459
462 return StatusCode::FAILURE;
463 }
464
465 float* outData =
outputs[0].GetTensorMutableData<
float>();
466 const size_t outSize =
outputs[0].GetTensorTypeAndShapeInfo().GetElementCount();
468
470 std::span<float> preds(outData, outData + outSize);
471 for (
size_t i = 0;
i < outSize; ++
i) {
472 if (!std::isfinite(preds[i])) {
473 ATH_MSG_WARNING(
"Non-finite prediction detected at " << i <<
" -> set to -100.");
475 }
476 }
477 }
478
479 for (auto& v : outputs) {
480 graphData.
graph->dataTensor.emplace_back(std::move(v));
481 }
482 return StatusCode::SUCCESS;
483}
row
Appending html table to final .html summary file.