ConvNet  1.0
A GPU-based C++ implementation of Convolutional Neural Nets
 All Classes Namespaces Functions Variables
convnet.h
1 #ifndef CONVNET_H_
2 #define CONVNET_H_
3 #include "layer.h"
4 #include "hdf5.h"
5 #include "datahandler.h"
6 #include <vector>
7 #include <string>
8 using namespace std;
9 
14 class ConvNet {
15  public:
19  ConvNet(const string& model_file);
20  ~ConvNet();
21  void SetupDataset(const string& train_data_config_file);
22  virtual void SetupDataset(const string& train_data_config_file, const string& val_data_config_file);
23 
25  virtual void Train();
26 
31  void Validate(DataHandler* dataset, vector<float>& error);
32 
36  void Validate(vector<float>& error);
37 
39  void Save();
40 
42  void Save(const string& output_file);
43 
45  void Load();
46 
48  void Load(const string& input_file);
49 
53  void Display();
54 
63  void DumpOutputs(const string& output_file, DataHandler* dataset, const vector<string>& layer_names);
64 
72  void DumpOutputs(const string& output_file, const vector<string>& layer_names);
73 
77  void AllocateMemory(bool fprop_only);
78 
79  protected:
81  void BuildNet();
82 
84  void DestroyNet();
85 
87  void AllocateLayerMemory();
88 
92  void AllocateEdgeMemory(bool fprop_only);
93 
94  string GetCheckpointFilename();
95  void TimestampModel();
96 
98  void Sort();
99 
107  void Fprop(Layer& input, Layer& output, Edge& edge, bool overwrite);
108 
119  virtual void Bprop(Layer& output, Layer& input, Edge& edge, bool overwrite, bool update_weights);
120 
126  virtual void Fprop(bool train);
127 
129  virtual void Bprop(bool update_weights);
130 
132  virtual void ComputeDeriv();
133 
135  virtual void GetLoss(vector<float>& error);
136 
144  void DumpOutputs(const string& output_file, DataHandler* dataset, vector<Layer*>& layers) ;
145 
146 
148  virtual void TrainOneBatch(vector<float>& error);
149  void DisplayLayers();
150  void DisplayEdges();
151  void InsertPolyak();
152  void LoadPolyakWeights();
153  void LoadCurrentWeights();
154  void WriteLog(int current_iter, float time, float training_error);
155  void WriteLog(int current_iter, float time, const vector<float>& training_error);
156  void WriteValLog(int current_iter, const vector<float>& error);
157  Layer* GetLayerByName(const string& name);
158 
160  bool CheckReduceLearningRate(const vector<float>& val_error);
161 
163  void ReduceLearningRate(const float factor);
164 
165  config::Model model_;
166  vector<Layer*> layers_;
167  vector<Layer*> data_layers_;
168  vector<Layer*> input_layers_;
169  vector<Layer*> output_layers_;
170  vector<Edge*> edges_;
171  int max_iter_, batch_size_, current_iter_, lr_reduce_counter_;
172  DataHandler *train_dataset_, *val_dataset_;
173  string checkpoint_dir_, output_file_, model_name_;
174  ImageDisplayer displayer_;
175  string model_filename_, timestamp_, log_file_, val_log_file_;
176 
177  // a+=b;
178  static void AddVectors(vector<float>& a, vector<float>& b);
179 };
180 
181 #endif
The base class for all layers.
Definition: layer.h:9
Definition: util.h:59
vector< Layer * > output_layers_
Input layers.
Definition: convnet.h:169
STL namespace.
vector< Layer * > data_layers_
The layers in the network.
Definition: convnet.h:167
This class is intended to be used as a base class for implementing edges.
Definition: edge.h:13
A Convolutional Net Model.
Definition: convnet.h:14
vector< Layer * > input_layers_
Layers which have data associated with them.
Definition: convnet.h:168
vector< Edge * > edges_
Output layers.
Definition: convnet.h:170
int max_iter_
The edges in the network.
Definition: convnet.h:171
Makes data accessible to the model.
Definition: datahandler.h:14
vector< Layer * > layers_
The model protobuf config.
Definition: convnet.h:166