|
| | OrtNeuralNet (const std::string &modelPath, bool useCuda=false, int gpuId=0) |
| | Construct a new OrtNeuralNet object.
|
| |
| tl::expected< std::vector< Tensor >, NeuralError > | infer (const Tensor &input) override |
| | Perform inference on the given input Tensor using the ONNX model.
|
| |
| size_t | inputCount () const override |
| | Get the number of inputs of the neural network.
|
| |
| size_t | outputCount () const override |
| | Get the number of outputs of the neural network.
|
| |
| Shape | inputShape (size_t idx=0) const override |
| | Get the input shape of the neural network.
|
| |
| Shape | outputShape (size_t idx=0) const override |
| | Get the output shape of the neural network.
|
| |
| std::string | inputName (size_t idx=0) const override |
| | Get the name of the input tensor.
|
| |
| std::string | outputName (size_t idx=0) const override |
| | Get the name of the output tensor.
|
| |
| int | gpuId () const override |
| | Get the GPU ID used by the neural network if it is configured to use GPU.
|
| |
| tl::expected< std::vector< Tensor >, NeuralError > | operator() (const Tensor &input) |
| | Call the infer method with the given input tensor.
|
| |
A class that implements the NeuralNet interface using ONNX Runtime.
This class is responsible for loading an ONNX model, performing inference, and converting between Tensor and ONNX Runtime's Ort::Value. It supports both CPU and GPU execution, depending on the model and the environment setup.
- Note
- DO NOT use this class directly in your code. Instead, use the NeuralNetFactory and NeuralNet interface to interact with neural networks.
Usage:
if (!neuralNet) {
std::cerr << "Failed to create neural network: " << neuralNet.error() << std::endl;
return -1;
}
cv::Mat inputMat(224, 224, CV_32FC3, cv::Scalar(0.0f));
auto output = neuralNet->infer(inputTensor);
if (!output) {
std::cerr << "Inference failed: " << output.error() << std::endl;
return -1;
}
Tensor outputTensor = output.value();
static tl::expected< NeuralNetPtr, NeuralError > create(const std::string &modelPath, bool useGpu=false, int gpuId=0)
Create a NeuralNet instance from a model file.
Definition NeuralNetFactory.cpp:4
Shape inputShape(size_t idx=0) const override
Get the input shape of the neural network.
Definition OrtNeuralNet.cpp:143
A Tensor represents a N-dimensional array containing elements of the same type. Can be used as input ...
Definition Tensor.h:201
static tl::expected< Tensor, NeuralError > fromCvMat(const cv::Mat &mat)
Create a new Tensor object from a cv::Mat. This will convert from CVs HWC layout to ONNX standard lay...
Definition Tensor.cpp:6
std::vector< int64_t > Shape
Shape of a N-dimensional Tensor represented as the size in each dimension. Can be -1 in case of dynam...
Definition Tensor.h:75