TFCSONNXHandler class
#include <TFCSONNXHandler.h>
A handler specific for an ONNX network.
Contents
Class for a neural network read in the ONNX format. Derived from the abstract base class VNetworkBase such that it can be used interchangeably with it's sibling classes, TFCSSimpleLWTNNHandler and TFCSGANLWTNNHandler.
The TFCSNetworkFactory::Create function has VNetworkBase as its return type so that it can make a run-time decision about which derived class to use, based on the data or file presented. As such it's best not to create this directly, instead allow TFCSNetworkFactory::Create to create the appropreat network object so that new network formats can be accommodated by writing new subclasses of VNetworkBase. Inherits from the generic interface VNetworkBase, such that it can be used interchangeably with other network formats and libraries.
Base classes
- class VNetworkBase
- A template defining the interface to a neural network.
Constructors, destructors, conversion operators
- TFCSONNXHandler(const std::string& inputFile) explicit
- TFCSONNXHandler constructor.
- TFCSONNXHandler(const std::vector<char>& bytes) explicit
- TFCSONNXHandler constructor.
- TFCSONNXHandler(const TFCSONNXHandler& copy_from)
- TFCSONNXHandler copy constructor.
- VNetworkBase()
- VNetworkBase default constructor.
- VNetworkBase() explicit
- VNetworkBase constructor.
- VNetworkBase()
- VNetworkBase copy constructor.
Public functions
- auto compute(NetworkInputs const& inputs) const -> NetworkOutputs override
- Function to pass values to the network.
- void writeNetToTTree(TTree& tree) override
- Save the network to a TTree.
- auto getOutputLayers() const -> std::vector<std::string> override
- List the names of the outputs.
- void deleteAllButNet() override
- Get rid of any memory objects that aren't needed to run the net.
- void writeNetToTTree() pure virtual
- Save the network to a TTree.
- void writeNetToTTree()
- Save the network to a TTree.
- void writeNetToTTree()
- Save the network to a TTree.
Protected functions
- void print(std::ostream& strm) const override
- Write a short description of this net to the string stream.
- void setupPersistedVariables() override
- Perform actions that prep data to create the net.
- void setupNet() override
- Perform actions that prepare network for use.
Function documentation
TFCSONNXHandler:: TFCSONNXHandler(const std::string& inputFile) explicit
TFCSONNXHandler constructor.
| Parameters | |
|---|---|
| inputFile | file-path on disk (with file name) of a readable onnx file containing a proto format description of the network to be constructed. |
Calls setupPersistedVariables and setupNet.
TFCSONNXHandler:: TFCSONNXHandler(const std::vector<char>& bytes) explicit
TFCSONNXHandler constructor.
| Parameters | |
|---|---|
| bytes | byte content of a .onnx file, (which are a subset if proto files). Allows TFCSONNXHandler objects to be created from data in memory, retrieved rom any source. The bytes are not copied internally, and must remain in memory while the net is in use. (TODO check that assertion) |
As this passes nothing to the super constructor the setupPersistedVariables will not be called.
TFCSONNXHandler:: TFCSONNXHandler(const TFCSONNXHandler& copy_from)
TFCSONNXHandler copy constructor.
| Parameters | |
|---|---|
| copy_from | existing network that we are copying |
Will copy the variables that would be generated by setupPersistedVariables and setupNet.
TFCSONNXHandler:: VNetworkBase() explicit
VNetworkBase constructor.
Only saves inputFile to m_inputFile; Inheriting classes should call setupPersistedVariables and setupNet in constructor;
TFCSONNXHandler:: VNetworkBase()
VNetworkBase copy constructor.
Does not call setupPersistedVariables or setupNet but will pass on m_inputFile. Inheriting classes should do whatever they need to move the variables created in the setup functions.
NetworkOutputs TFCSONNXHandler:: compute(NetworkInputs const& inputs) const override
Function to pass values to the network.
| Parameters | |
|---|---|
| inputs | values to be evaluated by the network |
| Returns | the output of the network |
This function is used to actually run data through the loaded network and obtain results.
void TFCSONNXHandler:: writeNetToTTree(TTree& tree) override
Save the network to a TTree.
| Parameters | |
|---|---|
| tree | The tree to save inside. |
All data required to recreate the network object is saved into a TTree. The format is not specified. Will still work even if deleteAllButNet has already been called.
std::vector<std::string> TFCSONNXHandler:: getOutputLayers() const override
List the names of the outputs.
Outputs are stored in an NetworkOutputs object which is indexed by strings. This function returns the list of all strings that will index the outputs.
void TFCSONNXHandler:: deleteAllButNet() override
Get rid of any memory objects that aren't needed to run the net.
Minimize memory usage by deleting nay inputs that are no longer required to run the compute function. Doesn't actually do anything for this network type.
void TFCSONNXHandler:: writeNetToTTree() pure virtual
Save the network to a TTree.
All data required to recreate the network object is saved into a TTree. The format is not specified.
void TFCSONNXHandler:: writeNetToTTree()
Save the network to a TTree.
All data required to recreate the network object is saved into a TTree. The format is not specified.
void TFCSONNXHandler:: writeNetToTTree()
Save the network to a TTree.
All data required to recreate the network object is saved into a TTree. The format is not specified.
void TFCSONNXHandler:: print(std::ostream& strm) const override protected
Write a short description of this net to the string stream.
| Parameters | |
|---|---|
| strm | output parameter, to which the description will be written. |
Specialized for ONNX to print the input and output nodes with their dimensions.
void TFCSONNXHandler:: setupPersistedVariables() override protected
Perform actions that prep data to create the net.
Will be called in the class constructor before calling setupNet, but not in the streamer. It sets any variables that the sreamer would persist when saving or loading to file.
void TFCSONNXHandler:: setupNet() override protected
Perform actions that prepare network for use.
Will be called in the streamer or class constructor after the inputs have been set (either automaically by the streamer or by setupPersistedVariables in the constructor). Does not delete any resources used.