ConvNet  1.0
A GPU-based C++ implementation of Convolutional Neural Nets
 All Classes Namespaces Functions Variables
Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
ConvNet Class Reference

A Convolutional Net Model. More...

#include <convnet.h>

Inheritance diagram for ConvNet:
GradChecker MultiGPUConvNet

Public Member Functions

 ConvNet (const string &model_file)
 Instantiate a model using the config in model_file.
 
void SetupDataset (const string &train_data_config_file)
 
virtual void SetupDataset (const string &train_data_config_file, const string &val_data_config_file)
 
virtual void Train ()
 Start training. More...
 
void Validate (DataHandler *dataset, vector< float > &error)
 Validate the model on the specfied dataset and return the error. More...
 
void Validate (vector< float > &error)
 Validate the model on the validation dataset and return the error. More...
 
void Save ()
 Write the model to disk. More...
 
void Save (const string &output_file)
 Write the model to disk in the file specified. More...
 
void Load ()
 Load the model. More...
 
void Load (const string &input_file)
 Load the model from the file specified. More...
 
void Display ()
 Display the state of the model. More...
 
void DumpOutputs (const string &output_file, DataHandler *dataset, const vector< string > &layer_names)
 Write the state of the layers to disk. More...
 
void DumpOutputs (const string &output_file, const vector< string > &layer_names)
 Write the state of the layers to disk. More...
 
void AllocateMemory (bool fprop_only)
 Allocate memory for the model. More...
 

Protected Member Functions

void BuildNet ()
 Creates layers and edges. More...
 
void DestroyNet ()
 Release all memory held by the model. More...
 
void AllocateLayerMemory ()
 Allocate layer memory for using mini-batches of batch_size_. More...
 
void AllocateEdgeMemory (bool fprop_only)
 Allocate memory for edges. More...
 
string GetCheckpointFilename ()
 
void TimestampModel ()
 
void Sort ()
 Topologically sort layers. More...
 
void Fprop (Layer &input, Layer &output, Edge &edge, bool overwrite)
 Forward propagate one layer. More...
 
virtual void Bprop (Layer &output, Layer &input, Edge &edge, bool overwrite, bool update_weights)
 Back propagate through one layer. More...
 
virtual void Fprop (bool train)
 Forward propagate through the network. More...
 
virtual void Bprop (bool update_weights)
 Backpropagate through the network and update weights. More...
 
virtual void ComputeDeriv ()
 Computes the derivative of the loss function. More...
 
virtual void GetLoss (vector< float > &error)
 Computes the loss function (to be displayed). More...
 
void DumpOutputs (const string &output_file, DataHandler *dataset, vector< Layer * > &layers)
 Write the state of the layers to disk. More...
 
virtual void TrainOneBatch (vector< float > &error)
 Takes one optimization step. More...
 
void DisplayLayers ()
 
void DisplayEdges ()
 
void InsertPolyak ()
 
void LoadPolyakWeights ()
 
void LoadCurrentWeights ()
 
void WriteLog (int current_iter, float time, float training_error)
 
void WriteLog (int current_iter, float time, const vector< float > &training_error)
 
void WriteValLog (int current_iter, const vector< float > &error)
 
LayerGetLayerByName (const string &name)
 
bool CheckReduceLearningRate (const vector< float > &val_error)
 Decides if learning rate should be reduced. More...
 
void ReduceLearningRate (const float factor)
 Multiply learning rate by factor. More...
 

Static Protected Member Functions

static void AddVectors (vector< float > &a, vector< float > &b)
 

Protected Attributes

config::Model model_
 
vector< Layer * > layers_
 The model protobuf config. More...
 
vector< Layer * > data_layers_
 The layers in the network. More...
 
vector< Layer * > input_layers_
 Layers which have data associated with them. More...
 
vector< Layer * > output_layers_
 Input layers. More...
 
vector< Edge * > edges_
 Output layers. More...
 
int max_iter_
 The edges in the network. More...
 
int batch_size_
 
int current_iter_
 
int lr_reduce_counter_
 
DataHandlertrain_dataset_
 
DataHandlerval_dataset_
 
string checkpoint_dir_
 
string output_file_
 
string model_name_
 
ImageDisplayer displayer_
 
string model_filename_
 
string timestamp_
 
string log_file_
 
string val_log_file_
 

Detailed Description

A Convolutional Net Model.

This class provides the interface for training and using conv nets.

Member Function Documentation

void ConvNet::AllocateEdgeMemory ( bool  fprop_only)
protected

Allocate memory for edges.

Parameters
fprop_onlyIf true, does not allocate memory needed for optimization.
void ConvNet::AllocateLayerMemory ( )
protected

Allocate layer memory for using mini-batches of batch_size_.

void ConvNet::AllocateMemory ( bool  fprop_only)

Allocate memory for the model.

Parameters
fprop_onlyIf true, does not allocate memory needed for optimization.
void ConvNet::Bprop ( Layer output,
Layer input,
Edge edge,
bool  overwrite,
bool  update_weights 
)
protectedvirtual

Back propagate through one layer.

Passes down the gradients from the output layer to the input layer. Also updates the weights on the edge (if update_weights is true).

Parameters
outputthe output layer (gradients w.r.t this have been computed).
inputthe input layer (gradients w.r.t this will be computed here).
edgethe edge connecting the input to the output.
overwriteIf true, overwrite the deriv present in input, else add to it.
update_weightsIf true, the weights will be updated.
void ConvNet::Bprop ( bool  update_weights)
protectedvirtual

Backpropagate through the network and update weights.

Reimplemented in MultiGPUConvNet.

void ConvNet::BuildNet ( )
protected

Creates layers and edges.

bool ConvNet::CheckReduceLearningRate ( const vector< float > &  val_error)
protected

Decides if learning rate should be reduced.

void ConvNet::ComputeDeriv ( )
protectedvirtual

Computes the derivative of the loss function.

void ConvNet::DestroyNet ( )
protected

Release all memory held by the model.

void ConvNet::Display ( )

Display the state of the model.

Shows the layers and edges for which display is enabled.

void ConvNet::DumpOutputs ( const string &  output_file,
DataHandler dataset,
const vector< string > &  layer_names 
)

Write the state of the layers to disk.

This method runs the model on the specified dataset and writes the layer states out to disk in a hdf5 file.

Parameters
output_fileThe name of the output hdf5 file.
datasetThe dataset to be run.
layer_namesThe names of the layers whose state needs to be written out.
void ConvNet::DumpOutputs ( const string &  output_file,
const vector< string > &  layer_names 
)

Write the state of the layers to disk.

This method runs the model on the train dataset and writes the layer states out to disk in a hdf5 file.

Parameters
output_fileThe name of the output hdf5 file.
layer_namesThe names of the layers whose state needs to be written out.
void ConvNet::DumpOutputs ( const string &  output_file,
DataHandler dataset,
vector< Layer * > &  layers 
)
protected

Write the state of the layers to disk.

This method runs the model on the specified dataset and writes the layer states out to disk in a hdf5 file.

Parameters
output_fileThe name of the output hdf5 file.
datasetThe dataset to be run.
layersThe layers whose state needs to be written out.
void ConvNet::Fprop ( Layer input,
Layer output,
Edge edge,
bool  overwrite 
)
protected

Forward propagate one layer.

Passes up input through the edge and updates the state of the output.

Parameters
inputthe input layer.
outputthe output layer.
edgethe edge connecting the input to the output.
overwriteIf true, overwrite the state present in output, else add to it.
void ConvNet::Fprop ( bool  train)
protectedvirtual

Forward propagate through the network.

Parameters
trainIf true, this forward prop is being done during training, otherwise during test/validation. Used for determining whether to use drop units stochastcially or use all of them.

Reimplemented in MultiGPUConvNet.

void ConvNet::GetLoss ( vector< float > &  error)
protectedvirtual

Computes the loss function (to be displayed).

Reimplemented in GradChecker.

void ConvNet::Load ( )

Load the model.

void ConvNet::Load ( const string &  input_file)

Load the model from the file specified.

void ConvNet::ReduceLearningRate ( const float  factor)
protected

Multiply learning rate by factor.

void ConvNet::Save ( )

Write the model to disk.

void ConvNet::Save ( const string &  output_file)

Write the model to disk in the file specified.

void ConvNet::Sort ( )
protected

Topologically sort layers.

void ConvNet::Train ( )
virtual

Start training.

void ConvNet::TrainOneBatch ( vector< float > &  error)
protectedvirtual

Takes one optimization step.

void ConvNet::Validate ( DataHandler dataset,
vector< float > &  error 
)

Validate the model on the specfied dataset and return the error.

Parameters
datasetThe dataset.
errorA vector of errors (one element for each output layer).
void ConvNet::Validate ( vector< float > &  error)

Validate the model on the validation dataset and return the error.

Parameters
errorA vector of errors (one element for each output layer).

Member Data Documentation

vector<Layer*> ConvNet::data_layers_
protected

The layers in the network.

vector<Edge*> ConvNet::edges_
protected

Output layers.

vector<Layer*> ConvNet::input_layers_
protected

Layers which have data associated with them.

vector<Layer*> ConvNet::layers_
protected

The model protobuf config.

int ConvNet::max_iter_
protected

The edges in the network.

vector<Layer*> ConvNet::output_layers_
protected

Input layers.


The documentation for this class was generated from the following files: