ATLAS Offline Software
|
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration. More...
#include <VNetworkBase.h>
Public Types | |
typedef std::map< std::string, std::map< std::string, double > > | NetworkInputs |
Format for network inputs. More... | |
typedef std::map< std::string, double > | NetworkOutputs |
Format for network outputs. More... | |
Public Member Functions | |
VNetworkBase () | |
VNetworkBase default constructor. More... | |
VNetworkBase (const std::string &inputFile) | |
VNetworkBase constructor. More... | |
VNetworkBase (const VNetworkBase ©_from) | |
VNetworkBase copy constructor. More... | |
virtual | ~VNetworkBase () |
virtual NetworkOutputs | compute (NetworkInputs const &inputs) const =0 |
Function to pass values to the network. More... | |
virtual void | writeNetToTTree (TTree &tree)=0 |
Save the network to a TTree. More... | |
void | writeNetToTTree (TFile &root_file, std::string const &tree_name=m_defaultTreeName) |
Save the network to a TTree. More... | |
void | writeNetToTTree (std::string const &root_name, std::string const &tree_name=m_defaultTreeName) |
Save the network to a TTree. More... | |
virtual std::vector< std::string > | getOutputLayers () const =0 |
List the names of the outputs. More... | |
bool | isFile () const |
Check if the argument inputFile is the path of a file on disk. More... | |
virtual void | deleteAllButNet ()=0 |
Get rid of any memory objects that arn't needed to run the net. More... | |
bool | msgLvl (const MSG::Level lvl) const |
Check whether the logging system is active at the provided verbosity level. More... | |
MsgStream & | msg () const |
Return a stream for sending messages directly (no decoration) More... | |
MsgStream & | msg (const MSG::Level lvl) const |
Return a decorated starting stream for sending messages. More... | |
MSG::Level | level () const |
Retrieve output level. More... | |
virtual void | setLevel (MSG::Level lvl) |
Update outputlevel. More... | |
Static Public Member Functions | |
static std::string | representNetworkInputs (NetworkInputs const &inputs, int maxValues=3) |
String representation of network inputs. More... | |
static std::string | representNetworkOutputs (NetworkOutputs const &outputs, int maxValues=3) |
String representation of network outputs. More... | |
static bool | isFile (std::string const &inputFile) |
Check if a string is the path of a file on disk. More... | |
static std::string | startMsg (MSG::Level lvl, const std::string &file, int line) |
Make a message to decorate the start of logging. More... | |
Static Public Attributes | |
static const std::string | m_defaultTreeName = "onnxruntime_session" |
Default name for the TTree to save in. More... | |
Protected Member Functions | |
virtual void | setupPersistedVariables ()=0 |
Perform actions that prep data to create the net. More... | |
virtual void | setupNet ()=0 |
Perform actions that prepare network for use. More... | |
virtual void | print (std::ostream &strm) const |
Write a short description of this net to the string stream. More... | |
bool | isRootFile (std::string const &filename="") const |
Check if a string is possibly a root file path. More... | |
void | removePrefixes (NetworkOutputs &outputs) const |
Remove any common prefix from the outputs. More... | |
void | removePrefixes (std::vector< std::string > &output_names) const |
Remove any common prefix from the outputs. More... | |
Protected Attributes | |
std::string | m_inputFile |
Path to the file describing the network, including filename. More... | |
Private Member Functions | |
ClassDef (VNetworkBase, 1) | |
Private Attributes | |
std::string | m_nm |
Message source name. More... | |
Static Private Attributes | |
static boost::thread_specific_ptr< MsgStream > m_msg_tls | ATLAS_THREAD_SAFE |
Do not persistify! More... | |
Friends | |
std::ostream & | operator<< (std::ostream &strm, const VNetworkBase &vNetworkBase) |
Put-to operator to facilitate printing. More... | |
Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration.
Abstract base class for Neural networks. Intially aimed at replacing instances of an lwtnn network with a network that could be either lwtnn or ONNX, so it is an interface which mirrors that of lwtnn graphs. At least 3 derived classes are avaliable;
The TFCSNetworkFactory::Create function has this class as its return type so that it can make a run-time decision about which derived class to use, based on the file or data presented.
A template defining the interface to a neural network.
Has various subclasses to cover differing network libraries and save formats.
Definition at line 38 of file VNetworkBase.h.
typedef std::map<std::string, std::map<std::string, double> > VNetworkBase::NetworkInputs |
Format for network inputs.
The doubles are the values to be passed into the network. Strings in the outer map identify the input node, which must corrispond to the names of the nodes as read from the description of the network found by the constructor. Strings in the inner map identify the part of the input node, for some networks these must be simple integers, in string form, as parts of nodes do not always have the ability to carry real string labels.
Definition at line 90 of file VNetworkBase.h.
typedef std::map<std::string, double> VNetworkBase::NetworkOutputs |
Format for network outputs.
The doubles are the values generated by the network. Strings identify which node this value came from, and when nodes have multiple values, are suffixed with a number to indicate which part of the node they came from. So in multi-value nodes the format becomes "<node_name>_<part_n>"
Definition at line 100 of file VNetworkBase.h.
VNetworkBase::VNetworkBase | ( | ) |
VNetworkBase default constructor.
For use in streamers.
Definition at line 16 of file VNetworkBase.cxx.
|
explicit |
VNetworkBase constructor.
Only saves inputFile to m_inputFile; Inherting classes should call setupPersistedVariables and setupNet in constructor;
inputFile | file-path on disk (with file name) of a readable file containing a description of the network to be constructed or the content of the file. |
Definition at line 19 of file VNetworkBase.cxx.
VNetworkBase::VNetworkBase | ( | const VNetworkBase & | copy_from | ) |
VNetworkBase copy constructor.
Does not call setupPersistedVariables or setupNet but will pass on m_inputFile. Inherting classes should do whatever they need to move the variables created in the setup functions.
copy_from | existing network that we are copying |
Definition at line 25 of file VNetworkBase.cxx.
|
virtual |
Definition at line 34 of file VNetworkBase.cxx.
|
private |
|
pure virtual |
Function to pass values to the network.
This function hides variations in the formated needed by different network libraries, providing a uniform input and output type.
inputs | values to be evaluated by the network |
Implemented in TFCSONNXHandler, TFCSGANLWTNNHandler, and TFCSSimpleLWTNNHandler.
|
pure virtual |
Get rid of any memory objects that arn't needed to run the net.
Minimise memory usage by deleting any inputs that are no longer required to run the compute function. May prevent the net from being saved.
Implemented in TFCSONNXHandler, and VNetworkLWTNN.
|
pure virtual |
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.
Implemented in TFCSONNXHandler, TFCSGANLWTNNHandler, and TFCSSimpleLWTNNHandler.
bool VNetworkBase::isFile | ( | ) | const |
Check if the argument inputFile is the path of a file on disk.
Determines if the string that was passed to the constructor as inputFile corrisponds to tha path of a file that can be read on the disk.
Definition at line 117 of file VNetworkBase.cxx.
|
static |
Check if a string is the path of a file on disk.
Determines if a string corrisponds to tha path of a file that can be read on the disk.
inputFile | name of the pottential file |
Definition at line 119 of file VNetworkBase.cxx.
|
protected |
Check if a string is possibly a root file path.
Just checks if the string ends in .root as there are almost no reliable rules for file paths.
inputFile | name of the pottential file if blank, m_inputFile is used. |
Definition at line 101 of file VNetworkBase.cxx.
|
inlineinherited |
|
inlineinherited |
Return a stream for sending messages directly (no decoration)
Definition at line 231 of file MLogging.h.
|
inlineinherited |
Return a decorated starting stream for sending messages.
Definition at line 240 of file MLogging.h.
|
inlineinherited |
Check whether the logging system is active at the provided verbosity level.
Definition at line 222 of file MLogging.h.
|
protectedvirtual |
Write a short description of this net to the string stream.
Intended to facilitate the put-to operator, allowing subclasses to change how this object is displayed.
strm | output parameter, to which the description will be written. |
Reimplemented in TFCSONNXHandler, and VNetworkLWTNN.
Definition at line 73 of file VNetworkBase.cxx.
|
protected |
Remove any common prefix from the outputs.
outputs | The outputs, changed in place. |
Definition at line 151 of file VNetworkBase.cxx.
|
protected |
Remove any common prefix from the outputs.
outputs | The output names, changed in place. |
Definition at line 144 of file VNetworkBase.cxx.
|
static |
String representation of network inputs.
Create a string that summarises a set of network inputs. Gives basic dimensions plus a few values, up to the maxValues
inputs | values to be evaluated by the network |
maxValues | maximum number of values to include in the representaiton |
Definition at line 37 of file VNetworkBase.cxx.
|
static |
String representation of network outputs.
Create a string that summarises a set of network outputs. Gives basic dimensions plus a few values, up to the maxValues
outputs | output of the network |
maxValues | maximum number of values to include in the representaiton |
Definition at line 57 of file VNetworkBase.cxx.
|
virtualinherited |
|
protectedpure virtual |
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.
Implemented in TFCSONNXHandler, TFCSGANLWTNNHandler, and TFCSSimpleLWTNNHandler.
|
protectedpure virtual |
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.
Implemented in TFCSONNXHandler, and VNetworkLWTNN.
|
staticinherited |
Make a message to decorate the start of logging.
Print a message for the start of logging.
Definition at line 116 of file MLogging.cxx.
void VNetworkBase::writeNetToTTree | ( | std::string const & | root_name, |
std::string const & | tree_name = m_defaultTreeName |
||
) |
Save the network to a TTree.
All data required to recreate the network object is saved into a TTree. The format is not specified.
root_name | The path of the file to save inside. |
tree_name | The name of the TTree to save inside. |
Definition at line 93 of file VNetworkBase.cxx.
void VNetworkBase::writeNetToTTree | ( | TFile & | root_file, |
std::string const & | tree_name = m_defaultTreeName |
||
) |
Save the network to a TTree.
All data required to recreate the network object is saved into a TTree. The format is not specified.
root_file | The file to save inside. |
tree_name | The name of the TTree to save inside. |
Definition at line 83 of file VNetworkBase.cxx.
|
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.
tree | The tree to save inside. |
Implemented in TFCSONNXHandler, and VNetworkLWTNN.
|
friend |
Put-to operator to facilitate printing.
It is useful to be able to display a reasonable representation of a network for debugging. This can be altered by subclasses by changing the protected print function of this class.
Definition at line 154 of file VNetworkBase.h.
|
inlinestaticprivateinherited |
Do not persistify!
MsgStream instance (a std::cout like with print-out levels)
Definition at line 215 of file MLogging.h.
|
inlinestatic |
Default name for the TTree to save in.
Definition at line 173 of file VNetworkBase.h.
|
protected |
Path to the file describing the network, including filename.
Definition at line 245 of file VNetworkBase.h.
|
privateinherited |
Message source name.
Definition at line 211 of file MLogging.h.