1 #ifndef CAFFE_RECURRENT_LAYER_HPP_ 2 #define CAFFE_RECURRENT_LAYER_HPP_ 8 #include "caffe/blob.hpp" 9 #include "caffe/common.hpp" 10 #include "caffe/layer.hpp" 11 #include "caffe/net.hpp" 12 #include "caffe/proto/caffe.pb.h" 13 #include "caffe/util/format.hpp" 17 template <
typename Dtype>
class RecurrentLayer;
25 template <
typename Dtype>
26 class RecurrentLayer :
public Layer<Dtype> {
28 explicit RecurrentLayer(
const LayerParameter& param)
29 :
Layer<Dtype>(param) {}
30 virtual void LayerSetUp(
const vector<Blob<Dtype>*>& bottom,
31 const vector<Blob<Dtype>*>& top);
32 virtual void Reshape(
const vector<Blob<Dtype>*>& bottom,
33 const vector<Blob<Dtype>*>& top);
36 virtual inline const char*
type()
const {
return "Recurrent"; }
39 if (this->
layer_param_.recurrent_param().expose_hidden()) {
40 vector<string> inputs;
42 min_bottoms += inputs.size();
49 if (this->
layer_param_.recurrent_param().expose_hidden()) {
50 vector<string> outputs;
52 num_tops += outputs.size();
59 return bottom_index != 1;
148 const vector<bool>& propagate_down,
const vector<
Blob<Dtype>*>& bottom);
177 vector<Blob<Dtype>* > recur_input_blobs_;
178 vector<Blob<Dtype>* > recur_output_blobs_;
179 vector<Blob<Dtype>* > output_blobs_;
187 #endif // CAFFE_RECURRENT_LAYER_HPP_ virtual void LayerSetUp(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Does layer-specific setup: your layer should implement this function as well as Reshape.
Definition: recurrent_layer.cpp:14
bool static_input_
Whether the layer has a "static" input copied across all timesteps.
Definition: recurrent_layer.hpp:163
virtual int MinBottomBlobs() const
Returns the minimum number of bottom blobs required by the layer, or -1 if no minimum number is requi...
Definition: recurrent_layer.hpp:37
A layer factory that allows one to register layers. During runtime, registered layers can be called b...
Definition: blob.hpp:14
virtual bool AllowForceBackward(const int bottom_index) const
Return whether to allow force_backward for a given bottom blob index.
Definition: recurrent_layer.hpp:57
int last_layer_index_
The last layer to run in the network. (Any later layers are losses added to force the recurrent net t...
Definition: recurrent_layer.hpp:169
virtual void RecurrentInputBlobNames(vector< string > *names) const =0
Fills names with the names of the 0th timestep recurrent input Blob&s. Subclasses should define this ...
virtual void Forward_cpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Definition: recurrent_layer.cpp:245
virtual void Forward_gpu(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Using the GPU device, compute the layer output. Fall back to Forward_cpu() if unavailable.
int T_
The number of timesteps in the layer's input, and the number of timesteps over which to backpropagate...
Definition: recurrent_layer.hpp:160
virtual void RecurrentOutputBlobNames(vector< string > *names) const =0
Fills names with the names of the Tth timestep recurrent output Blob&s. Subclasses should define this...
virtual void RecurrentInputShapes(vector< BlobShape > *shapes) const =0
Fills shapes with the shapes of the recurrent input Blob&s. Subclasses should define this – see RNNL...
shared_ptr< Net< Dtype > > unrolled_net_
A Net to implement the Recurrent functionality.
Definition: recurrent_layer.hpp:151
virtual void Reshape(const vector< Blob< Dtype > *> &bottom, const vector< Blob< Dtype > *> &top)
Adjust the shapes of top blobs and internal buffers to accommodate the shapes of the bottom blobs...
Definition: recurrent_layer.cpp:183
virtual void Backward_cpu(const vector< Blob< Dtype > *> &top, const vector< bool > &propagate_down, const vector< Blob< Dtype > *> &bottom)
Using the CPU device, compute the gradients for any parameters and for the bottom blobs if propagate_...
Definition: recurrent_layer.cpp:277
virtual void OutputBlobNames(vector< string > *names) const =0
Fills names with the names of the output blobs, concatenated across all timesteps. Should return a name for each top Blob. Subclasses should define this – see RNNLayer and LSTMLayer for examples.
virtual const char * type() const
Returns the layer type.
Definition: recurrent_layer.hpp:36
Layer(const LayerParameter ¶m)
Definition: layer.hpp:40
virtual int ExactNumTopBlobs() const
Returns the exact number of top blobs required by the layer, or -1 if no exact number is required...
Definition: recurrent_layer.hpp:47
bool expose_hidden_
Whether the layer's hidden state at the first and last timesteps are layer inputs and outputs...
Definition: recurrent_layer.hpp:175
LayerParameter layer_param_
Definition: layer.hpp:297
virtual int MaxBottomBlobs() const
Returns the maximum number of bottom blobs required by the layer, or -1 if no maximum number is requi...
Definition: recurrent_layer.hpp:46
int N_
The number of independent streams to process simultaneously.
Definition: recurrent_layer.hpp:154
virtual void FillUnrolledNet(NetParameter *net_param) const =0
Fills net_param with the recurrent network architecture. Subclasses should define this – see RNNLaye...
A wrapper around SyncedMemory holders serving as the basic computational unit through which Layers...
Definition: blob.hpp:24