28 OrtAllocatorType allocatorType,
29 OrtMemType memoryType,
30 int64_t batchSize) : mModelPath(modelPath), mSession(nullptr), mMemoryInfo(Ort::MemoryInfo::CreateCpu(allocatorType, memoryType)), mBatchSize(batchSize)
37 Ort::SessionOptions options;
38 options.SetIntraOpNumThreads(1);
50 for (
size_t i = 0;
i <
mSession->GetInputCount(); ++
i) {
53 for (
size_t i = 0;
i <
mSession->GetInputCount(); ++
i) {
56 for (
size_t i = 0;
i <
mSession->GetOutputCount(); ++
i) {
64 for (
auto& elem : shape) {
89 if (
mSession->GetInputCount() != input.size()) {
99 std::vector<const char*> tmpInputs;
100 std::vector<const char*> tmpOutputs;
107 mModelOutput =
mSession->Run(Ort::RunOptions{
nullptr},
133 std::scoped_lock guard(mMutex);
134 mBatch.emplace_back(input);
135 if (mBatch.size() == mBatchSize) {
136 auto value = std::optional(std::move(mBatch));
147 std::fstream
file(
path, std::fstream::in);
148 if (!
file.is_open()) {
158 if (scales.empty()) {
162 if (means.size() != scales.size()) {
165 return std::make_pair(std::move(means), std::move(scales));
Meyers Singleton thread safe singleton. Responsible for collecting particle data for batch processing...
std::optional< std::vector< std::vector< float > > > getBatch(const std::vector< float > &input)
static BatchHandler & getInstance(size_t batchSize)
BatchHandler(const BatchHandler &)=delete
bool setInput(std::vector< std::vector< float > > &input) override
Implements setInput.
ConditionalModelSimulation(const std::string &modelPath, int64_t batchSize)
const std::vector< Ort::Value > & getResult() override
Returns single model output as const&. Returned vector is of size 1.
void run() override
Implements run().
Abstract class providing interface for various specialized implementations.
std::vector< Ort::Value > mInputTensors
Container for input tensors.
std::vector< std::string > mOutputNames
std::string mModelPath
model path (where to find the ONNX model)
std::vector< std::vector< int64_t > > mInputShapes
std::vector< std::string > mInputNames
Input/Output names and input shape.
void setInputOutputData()
Sets models metadata (input/output layers names, inputs shape) in onnx session.
NeuralFastSimulation(const std::string &modelPath, OrtAllocatorType allocatorType, OrtMemType memoryType, int64_t batchSize)
Ort::MemoryInfo mMemoryInfo
void setTensors(std::vector< std::vector< float > > &input)
Converts flattend input data to Ort::Value. Tensor shapes are taken from loaded model metadata.
Ort::AllocatorWithDefaultOptions mAllocator
void initRunSession()
(late) init session and provide mechanism to customize ONNX session with external options
size_t getBatchSize() const
GLsizei const GLfloat * value
GLsizei const GLchar *const * path
std::vector< float > parse_block(std::istream &input, const std::string &option)
Parses .txt file containing scales for model. Function will search for given marker (option) and read...
std::optional< std::pair< std::vector< float >, std::vector< float > > > loadScales(const std::string &path)
loads and parse model scales from file at path