| 40 | |
| 41 | template <typename Dtype> |
| 42 | void RNNLayer<Dtype>::FillUnrolledNet(NetParameter* net_param) const { |
| 43 | const int num_output = this->layer_param_.recurrent_param().num_output(); |
| 44 | CHECK_GT(num_output, 0) << "num_output must be positive"; |
| 45 | const FillerParameter& weight_filler = |
| 46 | this->layer_param_.recurrent_param().weight_filler(); |
| 47 | const FillerParameter& bias_filler = |
| 48 | this->layer_param_.recurrent_param().bias_filler(); |
| 49 | |
| 50 | // Add generic LayerParameter's (without bottoms/tops) of layer types we'll |
| 51 | // use to save redundant code. |
| 52 | LayerParameter hidden_param; |
| 53 | hidden_param.set_type("InnerProduct"); |
| 54 | hidden_param.mutable_inner_product_param()->set_num_output(num_output); |
| 55 | hidden_param.mutable_inner_product_param()->set_bias_term(false); |
| 56 | hidden_param.mutable_inner_product_param()->set_axis(2); |
| 57 | hidden_param.mutable_inner_product_param()-> |
| 58 | mutable_weight_filler()->CopyFrom(weight_filler); |
| 59 | |
| 60 | LayerParameter biased_hidden_param(hidden_param); |
| 61 | biased_hidden_param.mutable_inner_product_param()->set_bias_term(true); |
| 62 | biased_hidden_param.mutable_inner_product_param()-> |
| 63 | mutable_bias_filler()->CopyFrom(bias_filler); |
| 64 | |
| 65 | LayerParameter sum_param; |
| 66 | sum_param.set_type("Eltwise"); |
| 67 | sum_param.mutable_eltwise_param()->set_operation( |
| 68 | EltwiseParameter_EltwiseOp_SUM); |
| 69 | |
| 70 | LayerParameter tanh_param; |
| 71 | tanh_param.set_type("TanH"); |
| 72 | |
| 73 | LayerParameter scale_param; |
| 74 | scale_param.set_type("Scale"); |
| 75 | scale_param.mutable_scale_param()->set_axis(0); |
| 76 | |
| 77 | LayerParameter slice_param; |
| 78 | slice_param.set_type("Slice"); |
| 79 | slice_param.mutable_slice_param()->set_axis(0); |
| 80 | |
| 81 | vector<BlobShape> input_shapes; |
| 82 | RecurrentInputShapes(&input_shapes); |
| 83 | CHECK_EQ(1, input_shapes.size()); |
| 84 | |
| 85 | LayerParameter* input_layer_param = net_param->add_layer(); |
| 86 | input_layer_param->set_type("Input"); |
| 87 | InputParameter* input_param = input_layer_param->mutable_input_param(); |
| 88 | input_layer_param->add_top("h_0"); |
| 89 | input_param->add_shape()->CopyFrom(input_shapes[0]); |
| 90 | |
| 91 | LayerParameter* cont_slice_param = net_param->add_layer(); |
| 92 | cont_slice_param->CopyFrom(slice_param); |
| 93 | cont_slice_param->set_name("cont_slice"); |
| 94 | cont_slice_param->add_bottom("cont"); |
| 95 | cont_slice_param->mutable_slice_param()->set_axis(0); |
| 96 | |
| 97 | // Add layer to transform all timesteps of x to the hidden state dimension. |
| 98 | // W_xh_x = W_xh * x + b_h |
| 99 | { |
no test coverage detected