This class implements a neural network. A neural network is a directed graph consisting of layers that perform calculations on data blobs. The graph starts with source layers and ends with sink layers.
CDnn::CDnn( IMathEngine& mathEngine, CRandom& random )
Specify the math engine and the random numbers generator in the constructor. Note that the network and all its layers have to use the same math engine.
void AddLayer( CBaseLayer& layer );
Adds a layer to the neural network. An error will occur if the layer is already in a network, or the network already has a layer with the same name.
virtual bool HasLayer( const char* name ) const;
Checks if a layer with the specified name is present in the network.
virtual CPtr<CBaseLayer> GetLayer( const char* name );
virtual CPtr<const CBaseLayer> GetLayer( const char* name ) const;
Retrieves a pointer to the layer with the specified name. If no such layer exists, an error will occur.
void DeleteLayer( const char* name );
void DeleteLayer( CBaseLayer& layer );
Removes the specified layer from the network. If it is not connected to the network, an error will occur.
virtual void GetLayerList( CArray<const char*>& layerList ) const;
Retrieves the list of names of all layers in the network.
void CDnn::DeleteAllLayers();
Removes all layers from the network.
CPtr<CDnnInitializer> GetInitializer();
void SetInitializer( const CPtr<CDnnInitializer>& initializer );
The class that should be used to initialize the layer weights before starting training. Xavier initialization is used by default.
CDnnSolver* GetSolver();
const CDnnSolver* GetSolver() const;
void SetSolver( CDnnSolver* solver );
The class that implements optimization of the layers' trainable parameters.
void RunAndLearnOnce();
Runs one iteration with training. After this method call you may extract the data from the sink layers.
void RunOnce();
Runs the network without training. After this method call you may extract the data from the sink layers.
void Serialize( CArchive& archive );
Serializes the network. If the archive is open for writing, the network will be written into the archive. If it is open for reading, the network layers will be deleted and the new network will be read from the archive.
void SerializeCheckpoint( CArchive& archive );
Serializes the network and additional data, required to resume training from this point (gradient history etc.).
When loading it creates a new optimizer, which can be retrieved by CDnn::GetSolver
method.
CTextStream* GetLog();
void SetLog( CTextStream* newLog );
Retrieves and sets the text stream used to log the network operation.
int GetLogFrequency() const;
void SetLogFrequency( int logFrequency );
Retrieves and sets the logging frequency. By default, every 100th iteration of RunOnce
or RunAndLearnOnce
will be logged.