5#ifndef HYPERANALYSISALGORITHMS_HYPERMODEL_H
6#define HYPERANALYSISALGORITHMS_HYPERMODEL_H
77 using namespace asg::msgUserCode;
79 ANA_MSG_ERROR(
"HyPERModel: ONNX inference tools have not been set");
80 return StatusCode::FAILURE;
85 for (std::size_t i = 0; i < inputNames.size(); ++i) {
104 return StatusCode::FAILURE;
107 return StatusCode::SUCCESS;
137 template <
typename T>
139 const std::vector<int64_t>& shape) {
140 using namespace asg::msgUserCode;
141 static_assert(std::is_same_v<T, float> || std::is_same_v<T, int64_t>,
142 "HyPER ONNX inputs must be float or int64_t");
149 bound.
data = &values;
159 using namespace asg::msgUserCode;
165 std::vector<Ort::Value> inputTensors;
170 ANA_MSG_ERROR(
"HyPERModel: input node " << i <<
" was never set");
171 return StatusCode::FAILURE;
173 if (std::holds_alternative<std::vector<float>*>(bound.
data)) {
175 *std::get<std::vector<float>*>(bound.
data), bound.
shape));
178 *std::get<std::vector<int64_t>*>(bound.
data), bound.
shape));
184 const int64_t nEdges =
186 const int64_t nHyperEdges =
191 std::vector<Ort::Value> outputTensors;
201 std::vector<int64_t> shape{leading};
202 if (
node.trailingOne) shape.push_back(1);
207 outputTensors.push_back(
211 outputTensors.push_back(
216 return tool->inference(inputTensors, outputTensors);
223 template <
typename T>
225 using namespace asg::msgUserCode;
226 static_assert(std::is_same_v<T, float> || std::is_same_v<T, int64_t>,
227 "HyPER ONNX outputs must be float or int64_t");
233 if constexpr (std::is_same_v<T, float>) {
250 using namespace asg::msgUserCode;
256 if (!printContent || !bound.
set)
continue;
257 if (std::holds_alternative<std::vector<float>*>(bound.
data)) {
259 *std::get<std::vector<float>*>(bound.
data)));
262 *std::get<std::vector<int64_t>*>(bound.
data)));
268 using namespace asg::msgUserCode;
271 if (!printContent)
continue;
289 using InputData = std::variant<std::vector<float>*, std::vector<int64_t>*>;
296 template <
typename T>
298 std::string row =
"[";
299 for (
const T& value : values) row += std::to_string(value) +
", ";
304 std::string row =
"(";
305 for (
const int64_t dim : shape) row += std::to_string(dim) +
", ";
size_t size() const
Number of registered mappings.
std::vector< std::vector< float > > m_outputsFloat
T * getOutputs(const std::string &node)
Pointer to the buffer of the named output.
const AthOnnx::IOnnxRuntimeInferenceTool * m_toolTrainedOnEven
std::vector< BoundInput > m_boundInputs
std::variant< std::vector< float > *, std::vector< int64_t > * > InputData
static constexpr const char * s_edgeIndexName
Input nodes whose shapes carry the graph's dynamic dimensions.
void printOutputInfo(bool printContent=false) const
virtual std::vector< std::string > getOutputNames() const =0
Model-specific output names consumed by the parser.
HyPERTopology getTopology() const
static constexpr const char * s_hyperEdgeIndexName
std::vector< std::vector< int64_t > > m_outputsInt64
std::map< std::string, std::size_t > m_outputIndex
static std::string contentToString(const std::vector< T > &values)
void printInputInfo(bool printContent=false) const
std::vector< HyPEROutputNode > m_outputNodes
virtual std::vector< HyPEROutputNode > getModelOutputs() const =0
Every output node of the ONNX graph, in declaration order.
StatusCode initialize()
Resolve the node name -> node index maps.
virtual std::vector< std::string > getInputNames() const =0
Input node names in the order the ONNX graph declares them.
HyPERModel(const AthOnnx::IOnnxRuntimeInferenceTool *trainedOnEven, const AthOnnx::IOnnxRuntimeInferenceTool *trainedOnOdd, HyPERTopology topology)
std::map< std::string, std::size_t > m_inputIndex
void setInputs(const std::string &node, std::vector< T > &values, const std::vector< int64_t > &shape)
Bind an input by node name.
StatusCode evaluate(unsigned sessionIndex)
Run the model of the requested fold over the bound inputs.
virtual ~HyPERModel()=default
static std::string shapeToString(const std::vector< int64_t > &shape)
const AthOnnx::IOnnxRuntimeInferenceTool * m_toolTrainedOnOdd
void setTopology(HyPERTopology topology)=delete
int64_t getTensorSize(const std::vector< int64_t > &dataShape)
Ort::Value createTensor(std::vector< T > &data, const std::vector< int64_t > &dataShape)
HyPEROutputDim
Which of the graph's dynamic dimensions an output tensor scales with.
Description of a single output node of the ONNX graph.
bool trailingOne
shape is {N, 1} rather than {N}
bool isFloat
false means int64
HyPEROutputDim dim
which dynamic dimension the tensor scales with