ConvNet  1.0
A GPU-based C++ implementation of Convolutional Neural Nets
 All Classes Namespaces Functions Variables
edge_with_weight.h
1 #ifndef EDGE_WITH_WEIGHT_H_
2 #define EDGE_WITH_WEIGHT_H_
3 #include "edge.h"
4 #include "optimizer.h"
5 
9 class EdgeWithWeight : public Edge {
10  public:
11  EdgeWithWeight(const config::Edge& edge_config);
12  ~EdgeWithWeight();
13 
14  virtual void Initialize();
15  virtual void SaveParameters(hid_t file);
16  virtual void LoadParameters(hid_t file);
17  virtual void LoadParameters(hid_t file, const string& edge_name);
18 
19  virtual float GetRMSWeight();
20  virtual void ReduceLearningRate(float factor);
21  virtual bool HasNoParameters() const;
22  virtual int GetNumModules() const;
23  virtual void DisplayWeights();
24  virtual void DisplayWeightStats();
25  virtual void SetTiedTo(Edge* e);
26 
27  virtual void UpdateWeights();
28  Matrix& GetWeight() { return weights_;}
29  Matrix& GetGradWeight() { return grad_weights_;}
30  Matrix& GetBias() { return bias_;}
31  Matrix& GetGradBias() { return grad_bias_;}
32 
33  float GetDecayedEpsilon(float base_epsilon) const;
34  float GetMomentum() const;
35 
36  virtual void InsertPolyak();
37  virtual void BackupCurrent();
38  virtual void LoadCurrentOnGPU();
39  virtual void LoadPolyakOnGPU();
40 
41  protected:
42  // Tied edge management.
43  void IncrementNumGradsReceived();
44  int GetNumGradsReceived();
45 
46  Matrix weights_, grad_weights_, bias_, grad_bias_;
47  Optimizer * const weight_optimizer_;
48  Optimizer * const bias_optimizer_;
49  EdgeWithWeight* tied_edge_;
50 
51  vector<Matrix> polyak_weights_, polyak_bias_;
52  Matrix weights_backup_, bias_backup_;
53  const config::Edge::Initialization initialization_;
54  const int polyak_queue_size_;
55  int polyak_index_;
56  bool polyak_queue_full_;
57 
58  // Hyperparams.
59  const float init_wt_, init_bias_;
60 
61  const bool has_no_bias_;
62  int num_grads_received_, num_shares_;
63  const float scale_gradients_;
64 
65  const string pretrained_model_, pretrained_edge_name_;
66 };
67 #endif
virtual void SaveParameters(hid_t file)
Write the weights and biases in an hdf5 file.
Definition: edge_with_weight.cc:30
virtual void Initialize()
Initialize the weights and biases.
Definition: edge_with_weight.cc:109
virtual void DisplayWeights()
Displays the weights.
Definition: edge_with_weight.cc:66
virtual void SetTiedTo(Edge *e)
Sets the edge to be tied to another edge.
Definition: edge_with_weight.cc:230
virtual float GetRMSWeight()
Returns the root mean square weight value.
Definition: edge_with_weight.cc:148
virtual bool HasNoParameters() const
Returns whether the edge has any parameters.
Definition: edge_with_weight.cc:161
This class is intended to be used as a base class for implementing edges.
Definition: edge.h:13
virtual void DisplayWeightStats()
Displays the statistics of the weights.
Definition: edge_with_weight.cc:74
Base class for all optimizers.
Definition: optimizer.h:8
virtual void ReduceLearningRate(float factor)
Reduce the learning rate by factor.
Definition: edge_with_weight.cc:92
virtual void UpdateWeights()
Update the weights.
Definition: edge_with_weight.cc:97
A GPU matrix class.
Definition: matrix.h:11
virtual int GetNumModules() const
Returns the number of modules.
Definition: edge_with_weight.cc:165
virtual void LoadParameters(hid_t file)
Load the weights and biases from an hdf5 file.
Definition: edge_with_weight.cc:60
Base class for all edges which have weights.
Definition: edge_with_weight.h:9