Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[SIT] std::stod on full string breaks per-layer flag parsing for numeric-leading layer name (#37447)

Vigh Sebastianf18ce7c5f390
diff --git a/src/plugins/intel_npu/tools/single-image-test/argument_parse_helpers.cpp b/src/plugins/intel_npu/tools/single-image-test/argument_parse_helpers.cpp
index c5cd125d2b2..1f56a019403 100644
--- a/src/plugins/intel_npu/tools/single-image-test/argument_parse_helpers.cpp
+++ b/src/plugins/intel_npu/tools/single-image-test/argument_parse_helpers.cpp
@@ -220,6 +220,8 @@ void utils::parseCommandLine(int argc, char* argv[]) {
* @example parsePerLayerValues("logits:0.03;pred_boxes:0.05", 1.0)
* returns {"logits": 0.03, "pred_boxes": 0.05}
* @example parsePerLayerValues("0.01", 1.0) returns {"*": 0.01}
+ * @example parsePerLayerValues("3dconv:0.01;head:0.02", 1.0)
+ * returns {"3dconv": 0.01, "head": 0.02} (layer names may start with a digit)
*/
utils::PerLayerValueMap utils::parsePerLayerValues(const std::string& str, double defaultValue) {
PerLayerValueMap result;
@@ -232,13 +234,17 @@ utils::PerLayerValueMap utils::parsePerLayerValues(const std::string& str, doubl
return result;
}
- // Try to parse as a single number first
- try {
- double value = std::stod(str);
- result["*"] = value;
- return result;
- } catch (...) {
- // Not a single number, parse as key:value pairs
+ if (str.find_first_of(":;") == std::string::npos) {
+ try {
+ size_t pos = 0;
+ const double value = std::stod(str, &pos);
+ if (str.find_first_not_of(" \t", pos) == std::string::npos) {
+ result["*"] = value;
+ return result;
+ }
+ } catch (...) {
+ // Not a single number; fall through to per-layer parsing.
+ }
}
// Parse "layer1:value1;layer2:value2" format
diff --git a/src/plugins/intel_npu/tools/single-image-test/map_metric_helpers.cpp b/src/plugins/intel_npu/tools/single-image-test/map_metric_helpers.cpp
index 8d0b5f15a50..c477a812249 100644
--- a/src/plugins/intel_npu/tools/single-image-test/map_metric_helpers.cpp
+++ b/src/plugins/intel_npu/tools/single-image-test/map_metric_helpers.cpp
@@ -188,7 +188,8 @@ static std::vector<Detection> parseTwoTensorDetections(const ov::Tensor& pred_bo
exp_sum += std::exp(logit - max_logit);
}
- float confidence = 1.0f / exp_sum;
+ // exp_sum is 0 only when there are no classes; guard against div-by-zero.
+ float confidence = exp_sum > 0.0f ? 1.0f / exp_sum : 0.0f;
if (confidence > confidence_threshold && best_class >= 0) {
detections.emplace_back(x_min, y_min, x_max, y_max, confidence, best_class);