OpenMS
Loading...
Searching...
No Matches
ONNXPredictorBase.h
Go to the documentation of this file.
1// Copyright (c) 2002-present, OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: Satyam Yadav $
7// --------------------------------------------------------------------------
8
9#pragma once
10
11#include <OpenMS/config.h>
12#include <cstddef>
13#include <cstdint>
14#include <functional>
15#include <string>
16#include <memory>
17#include <vector>
18
19// Forward declaration to avoid exposing ONNX headers globally
20namespace Ort {
21 struct Session;
22 struct SessionOptions;
23 struct MemoryInfo;
24}
25
26namespace OpenMS
27{
43 class OPENMS_DLLAPI ONNXPredictorBase
44 {
45 public:
49 explicit ONNXPredictorBase(const std::string& model_path, int threads = 4);
50
52
55
57 ONNXPredictorBase& operator=(ONNXPredictorBase&&) noexcept;
58
60 Ort::Session& session();
61 const Ort::Session& session() const;
62
64 Ort::MemoryInfo& memoryInfo();
65 const Ort::MemoryInfo& memoryInfo() const;
66
68 std::vector<std::string> getInputNames() const;
69
71 std::vector<std::string> getOutputNames() const;
72
74 std::vector<int64_t> getInputShape(size_t input_index) const;
75
77 size_t getInputCount() const;
78
80 size_t getOutputCount() const;
81
90 void forEachBatch(const std::vector<std::vector<size_t>>& groups, size_t batch_size,
91 const std::function<void(const size_t* indices, size_t n)>& run) const;
92
93 private:
94 int threads_ = 1;
95 std::unique_ptr<Ort::SessionOptions> session_options_;
96 std::unique_ptr<Ort::Session> session_;
97 std::unique_ptr<Ort::MemoryInfo> memory_info_;
98 };
99} // namespace OpenMS
Owns the ONNX Runtime session of one model file, for the predictors built on it.
Definition ONNXPredictorBase.h:44
ONNXPredictorBase & operator=(const ONNXPredictorBase &)=delete
ONNXPredictorBase(const ONNXPredictorBase &)=delete
ONNXPredictorBase(ONNXPredictorBase &&) noexcept
ONNXPredictorBase(const std::string &model_path, int threads=4)
Constructor initializes the generic ONNX session safely across platforms.
Main OpenMS namespace.
Definition openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
Definition ONNXPredictorBase.h:20
STL namespace.