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