Skip to content

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

[Protopipe] Add seed option to random generator (#31276)

Septimiu Neagă057963c81cbe
diff --git a/src/plugins/intel_npu/tools/protopipe/README.md b/src/plugins/intel_npu/tools/protopipe/README.md
index 5e9ad94c573..23100b51e2c 100644
--- a/src/plugins/intel_npu/tools/protopipe/README.md
+++ b/src/plugins/intel_npu/tools/protopipe/README.md
@@ -403,11 +403,11 @@ As the prerequisite for accuracy validation it's useful to have a mechanism that
Use additional parameters to configure `reference` mode:
- `input_data` - **Required**. Path that contain input data for the model, if entity under the path is empty, input data will be generated randomly and dumped into the path specified.
- `output_data` - **Required**. Path where to dump reference output data.
-- `random` - **Optional**. Initializer to generate input data randomly. (Default: ` { dist: uniform, low: 0.0, high: 255 }`)
+- `random` - **Optional**. Initializer to generate input data randomly. (Default: ` { dist: uniform, low: 0.0, high: 255, seed: -1 }`)
Examples:
```
-random: { dist: uniform, low: -1.0, high: 1.0 } # specified globally for all models
+random: { dist: uniform, low: -1.0, high: 1.0, seed: 4 } # specified globally for all models
multi_inference:
- input_stream_list:
- network:
diff --git a/src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp b/src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp
index 5e627e19916..588bece695c 100644
--- a/src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp
+++ b/src/plugins/intel_npu/tools/protopipe/src/parser/config.cpp
@@ -197,7 +197,8 @@ struct convert<UniformGenerator::Ptr> {
if (!node["high"]) {
THROW_ERROR("Uniform distribution must have \"high\" attribute");
}
- generator = std::make_shared<UniformGenerator>(node["low"].as<double>(), node["high"].as<double>());
+ int seed = node["seed"] ? node["seed"].as<int>() : 0xffffffff;
+ generator = std::make_shared<UniformGenerator>(node["low"].as<double>(), node["high"].as<double>(), seed);
return true;
}
};
diff --git a/src/plugins/intel_npu/tools/protopipe/src/utils/data_providers.cpp b/src/plugins/intel_npu/tools/protopipe/src/utils/data_providers.cpp
index f3eaf7756e1..1d6eff978c7 100644
--- a/src/plugins/intel_npu/tools/protopipe/src/utils/data_providers.cpp
+++ b/src/plugins/intel_npu/tools/protopipe/src/utils/data_providers.cpp
@@ -11,11 +11,12 @@
#include "utils.hpp"
#include "utils/error.hpp"
-UniformGenerator::UniformGenerator(double low, double high): m_low(low), m_high(high) {
+UniformGenerator::UniformGenerator(double low, double high, int seed): m_low(low), m_high(high), m_seed(seed) {
ASSERT(low <= high);
}
void UniformGenerator::generate(cv::Mat& mat) {
+ cv::setRNGSeed(m_seed);
cv::randu(mat, m_low, m_high);
}
diff --git a/src/plugins/intel_npu/tools/protopipe/src/utils/data_providers.hpp b/src/plugins/intel_npu/tools/protopipe/src/utils/data_providers.hpp
index 2bd45b7f19c..22696d1236e 100644
--- a/src/plugins/intel_npu/tools/protopipe/src/utils/data_providers.hpp
+++ b/src/plugins/intel_npu/tools/protopipe/src/utils/data_providers.hpp
@@ -29,12 +29,13 @@ public:
class UniformGenerator : public IRandomGenerator {
public:
using Ptr = std::shared_ptr<UniformGenerator>;
- UniformGenerator(double low, double high);
+ UniformGenerator(double low, double high, int seed = 0xffffffff);
void generate(cv::Mat& mat) override;
virtual std::string str() const override;
private:
double m_low, m_high;
+ int m_seed;
};
class RandomProvider : public IDataProvider {