12 Layer(
const config::Layer& config);
63 void AccessStateBegin();
64 void AccessStateEnd();
65 void AccessDerivBegin();
66 void AccessDerivEnd();
81 void Display(
int image_id);
89 const string& GetName()
const {
return name_; }
90 int GetNumChannels()
const {
return num_channels_; }
91 int GetSize()
const {
return image_size_; }
92 bool IsInput()
const {
return is_input_; }
93 bool IsOutput()
const {
return is_output_; }
95 int GetGPUId()
const {
return gpu_id_; }
96 void AllocateMemoryOnOtherGPUs();
97 Matrix& GetOtherState(
int gpu_id);
98 Matrix& GetOtherDeriv(
int gpu_id);
99 void SyncIncomingState();
100 void SyncOutgoingState();
101 void SyncIncomingDeriv();
102 void SyncOutgoingDeriv();
104 static Layer* ChooseLayerClass(
const config::Layer& layer_config);
106 vector<Edge*> incoming_edge_, outgoing_edge_;
107 bool has_incoming_from_same_gpu_, has_outgoing_to_same_gpu_;
108 bool has_incoming_from_other_gpus_, has_outgoing_to_other_gpus_;
111 void ApplyDropoutAtTrainTime();
112 void ApplyDropoutAtTestTime();
115 const int num_channels_;
116 const bool is_input_, is_output_;
117 const float dropprob_;
118 const bool display_, dropout_scale_up_at_train_time_, gaussian_dropout_;
122 const float max_act_gaussian_dropout_;
124 int scale_targets_, image_size_;
135 set<int> other_incoming_gpu_ids_, other_outgoing_gpu_ids_;
156 const bool rectify_after_gaussian_dropout_;
Matrix & GetData()
Returns a reference to the data at this layer.
Definition: layer.h:78
virtual void ComputeDeriv()
Compute derivative of loss function.
Definition: layer.cc:407
Matrix & GetDeriv()
Returns a reference to the deriv at this layer.
Definition: layer.h:75
The base class for all layers.
Definition: layer.h:9
virtual void ComputeDeriv()
Compute derivative of loss function.
Definition: layer.cc:293
virtual void AllocateMemory(int imgsize, int batch_size)
Allocate memory for storing the state and derivative at this layer.
Definition: layer.cc:317
virtual void ComputeDeriv()=0
Compute derivative of loss function.
Matrix data_
Deriv of the loss function w.r.t.
Definition: layer.h:128
void ApplyDropout(bool train)
Apply dropout to this layer.
Definition: layer.cc:251
virtual float GetLoss()
Compute the value of the loss function that is displayed during training.
Definition: layer.cc:454
virtual float GetLoss2()
Compute the value of the actual loss function.
Definition: layer.cc:234
Implements a layer with a logistic activation function.
Definition: layer.h:190
virtual void ApplyActivation(bool train)=0
Apply the activation function.
virtual float GetLoss()=0
Compute the value of the loss function that is displayed during training.
Implements a layer with a linear activation function.
Definition: layer.h:139
This class is intended to be used as a base class for implementing edges.
Definition: edge.h:13
Implements a layer with a rectified linear activation function.
Definition: layer.h:150
virtual void ApplyActivation(bool train)
Apply the activation function.
Definition: layer.cc:354
map< int, Matrix > other_states_
Need to store random variates when doing gaussian dropout.
Definition: layer.h:130
void AddIncoming(Edge *e)
Add an incoming edge to this layer.
Definition: layer.cc:55
Matrix rand_gaussian_
Data (targets) associated with this layer.
Definition: layer.h:129
virtual void ApplyActivation(bool train)
Apply the activation function.
Definition: layer.cc:430
virtual void AllocateMemory(int imgsize, int batch_size)
Allocate memory for storing the state and derivative at this layer.
Definition: layer.cc:163
virtual void AllocateMemory(int image_size, int batch_size)
Allocate memory for storing the state and derivative at this layer.
Definition: layer.cc:424
Implements a layer with a softmax activation function.
Definition: layer.h:177
Layer(const config::Layer &config)
Instantiate a layer from config.
Definition: layer.cc:32
void AddOutgoing(Edge *e)
Add an outgoing edge from this layer.
Definition: layer.cc:66
A GPU matrix class.
Definition: matrix.h:11
virtual void AllocateMemory(int imgsize, int batch_size)
Allocate memory for storing the state and derivative at this layer.
Definition: layer.cc:400
virtual void AllocateMemory(int imgsize, int batch_size)
Allocate memory for storing the state and derivative at this layer.
Definition: layer.cc:348
virtual float GetLoss()
Compute the value of the loss function that is displayed during training.
Definition: layer.cc:413
virtual void ApplyDerivativeOfActivation()
Apply the derivative of the activation.
Definition: layer.cc:439
virtual void ApplyActivation(bool train)
Apply the activation function.
Definition: layer.cc:279
ImageDisplayer * img_display_
Copies of this layer's deriv on other gpus.
Definition: layer.h:133
virtual void ApplyDerivativeOfActivation()
Apply the derivative of the activation.
Definition: layer.cc:339
map< int, Matrix > other_derivs_
Copies of this layer's state on other gpus.
Definition: layer.h:131
virtual void ComputeDeriv()
Compute derivative of loss function.
Definition: layer.cc:369
Implements a layer with a softmax activation function.
Definition: layer.h:162
virtual void ApplyDerivativeOfActivation()=0
Apply the derivative of the activation.
virtual void ApplyDerivativeOfActivation()
Apply the derivative of the activation.
Definition: layer.cc:362
virtual void ComputeDeriv()
Compute derivative of loss function.
Definition: layer.cc:448
Matrix & GetState()
Returns a reference to the state of the layer.
Definition: layer.h:72
virtual void ApplyDerivativeOfActivation()
Apply the derivative of the activation.
Definition: layer.cc:287
virtual void ApplyActivation(bool train)
Apply the activation function.
Definition: layer.cc:328
Edge * GetIncomingEdge(int index)
Returns the incoming edge by index.
Definition: layer.h:69
virtual float GetLoss()
Compute the value of the loss function that is displayed during training.
Definition: layer.cc:303
Matrix deriv_
State (activation) of the layer.
Definition: layer.h:127
virtual float GetLoss2()
Compute the value of the actual loss function.
Definition: layer.cc:389
virtual float GetLoss()
Compute the value of the loss function that is displayed during training.
Definition: layer.cc:378
void ApplyDerivativeofDropout()
Apply derivative of dropout.
Definition: layer.cc:208