iVS3D v2.0.9
Loading...
Searching...
No Matches
NeuralNet.h
Go to the documentation of this file.
1#pragma once
2
10#include "Tensor.h"
11#include "NeuralError.h"
12
13#include <tl/expected.hpp>
14#include <string>
15#include <vector>
16#include <memory>
17
18namespace NN
19{
31 class NeuralNet {
32 public:
33 virtual ~NeuralNet() = default;
34
46 virtual tl::expected<std::vector<Tensor>, NeuralError> infer(const Tensor& input) = 0;
47
56 tl::expected<std::vector<Tensor>, NeuralError> operator()(const Tensor& input) {
57 return infer(input);
58 }
59
65 virtual size_t inputCount() const = 0;
71 virtual size_t outputCount() const = 0;
77 virtual Shape inputShape(size_t idx = 0) const = 0;
78
84 virtual Shape outputShape(size_t idx = 0) const = 0;
85
91 virtual std::string inputName(size_t idx = 0) const = 0;
92
98 virtual std::string outputName(size_t idx = 0) const = 0;
99
109 virtual int gpuId() const = 0;
110 };
111
121 using NeuralNetPtr = std::shared_ptr<NeuralNet>;
122}
Defines error handling classes for the neural network module.
Contains the Tensor class for representing N-dimensional arrays with various data types.
Represents an error that occurred in the neural network module and contains the error type and messag...
Definition NeuralError.h:48
Abstract base class for neural networks.
Definition NeuralNet.h:31
virtual size_t inputCount() const =0
Get the number of inputs of the neural network.
virtual tl::expected< std::vector< Tensor >, NeuralError > infer(const Tensor &input)=0
Perform inference on the given input tensor.
virtual Shape outputShape(size_t idx=0) const =0
Get the output shape of the neural network. This might contain dynamic dimensions (e....
virtual std::string outputName(size_t idx=0) const =0
Get the name of the output tensor.
virtual int gpuId() const =0
Get the GPU ID used by the neural network if it is configured to use GPU.
virtual std::string inputName(size_t idx=0) const =0
Get the name of the input tensor.
virtual Shape inputShape(size_t idx=0) const =0
Get the input shape of the neural network. This might contain dynamic dimensions (e....
virtual size_t outputCount() const =0
Get the number of outputs of the neural network.
tl::expected< std::vector< Tensor >, NeuralError > operator()(const Tensor &input)
Call the infer method with the given input tensor.
Definition NeuralNet.h:56
A Tensor represents a N-dimensional array containing elements of the same type. Can be used as input ...
Definition Tensor.h:201
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
std::shared_ptr< NeuralNet > NeuralNetPtr
Smart pointer type for managing NeuralNet instances.
Definition NeuralNet.h:121
NN Neural Network Library containing Tensor and NeuralNet classes for inference.
Definition NeuralError.h:13