@@ -49,10 +49,8 @@ NeuralNetwork::NeuralNetwork(const std::shared_ptr<Layer>& last_layer,
49
49
50
50
void NeuralNetwork::insert_cnn_layer (const std::shared_ptr<Layer>& layer) {
51
51
std::shared_ptr<Convolution> derived =
52
- std::dynamic_pointer_cast<Convolution> (layer);
53
- // std::shared_ptr<Convolution> d = dynamic_cast<Derived<int> *>(b);
54
- std::shared_ptr<Layer> im2col =
55
- std::make_shared<Im2ColLayer>(Im2ColLayer (derived));
52
+ std::dynamic_pointer_cast<Convolution>(layer);
53
+ std::shared_ptr<Layer> im2col = std::make_shared<Im2ColLayer>(derived);
56
54
layer->_previous = im2col;
57
55
layers.push_front (im2col);
58
56
layers.push_front (layer);
@@ -68,9 +66,13 @@ void NeuralNetwork::construct_layers(std::shared_ptr<Layer> curr) {
68
66
curr.swap (tmp);
69
67
}
70
68
if (curr->name () == " Input" )
71
- layers.push_front (curr);
69
+ layers.push_front (curr);
72
70
else {
73
- throw std::runtime_error (" Must finish with the input" );
71
+ std::stringstream ss;
72
+ ss << " Cannot recognize the layer name " << curr->name () << " in:\n "
73
+ << __PRETTY_FUNCTION__ << " \n called from " << __FILE__ << " at "
74
+ << __LINE__;
75
+ throw std::invalid_argument (ss.str ());
74
76
}
75
77
}
76
78
@@ -91,7 +93,6 @@ void NeuralNetwork::allocate_storage(int obs, std::vector<SharedStorage>& inp,
91
93
92
94
vector<SharedStorage> NeuralNetwork::allocate_forward (int obs) {
93
95
vector<SharedStorage> vals;
94
- // int out_dim(0);
95
96
for (shared_ptr<Layer> layer : layers) {
96
97
allocate_storage (obs, vals, layer);
97
98
}
@@ -100,12 +101,10 @@ vector<SharedStorage> NeuralNetwork::allocate_forward(int obs) {
100
101
101
102
vector<SharedStorage> NeuralNetwork::allocate_backward (int obs) {
102
103
vector<SharedStorage> vals;
103
- // int out_dim(0);
104
104
std::deque<shared_ptr<Layer>>::iterator layer = layers.begin ();
105
105
std::deque<shared_ptr<Layer>>::iterator end = layers.end ();
106
106
--end;
107
107
while (layer != end) {
108
- // for (size_t i = 0; i < layers.size() - 1; i++) {
109
108
allocate_storage (obs, vals, *layer);
110
109
++layer;
111
110
}
@@ -128,8 +127,6 @@ void NeuralNetwork::forward_gpu(vector<SharedStorage>& values,
128
127
std::deque<shared_ptr<Layer>>::iterator layer = layers.begin ();
129
128
++layer;
130
129
while (layer != layers.end ()) {
131
- // for (; it != layers.end(); ++it) {
132
- // for (size_t layer_idx = 1; layer_idx < layers.size(); ++layer_idx) {
133
130
(*layer)->forward_gpu (values[i], values[i + 1 ], type);
134
131
i++;
135
132
++layer;
@@ -142,8 +139,6 @@ void NeuralNetwork::forward_cpu(vector<SharedStorage>& values,
142
139
std::deque<shared_ptr<Layer>>::iterator layer = layers.begin ();
143
140
++layer;
144
141
while (layer != layers.end ()) {
145
- // for (; it != layers.end(); ++it) {
146
- // for (size_t layer_idx = 1; layer_idx < layers.size(); ++layer_idx) {
147
142
(*layer)->forward_gpu (values[i], values[i + 1 ], type);
148
143
i++;
149
144
++layer;
0 commit comments