Commit 8a11e440 authored by Federico Rossi's avatar Federico Rossi

Fixed residual shortcut

parent 4147e4d8
......@@ -8,7 +8,7 @@
namespace tiny_dnn {
enum ShortcutSide { BEGIN, END };
thread_local std::vector<vec_t> shortcuts_;
thread_local std::vector<std::queue<vec_t>*> shortcuts_;
class shortcut_layer : public activation_layer {
private:
unsigned int mapping_;
......@@ -21,17 +21,19 @@ class shortcut_layer : public activation_layer {
mapping_ = shortcut_counter_ = shortcuts_.size();
side_ = side;
if(side == END)
shortcuts_.push_back(vec_t());
shortcuts_.push_back(new std::queue<vec_t>());
}
std::string layer_type() const override { return "shortcut-"+std::to_string(mapping_); }
void forward_activation(const vec_t &x, vec_t &y) override {
if(side_ == BEGIN)
shortcuts_.at(mapping_) = vec_t(x.begin(),x.end());
shortcuts_.at(mapping_)->push(vec_t(x.begin(),x.end()));
for (size_t j = 0; j < x.size(); j++) {
y[j] = x[j];
if(side_ == END)
y[j] += shortcuts_.at(mapping_).at(j);
if(side_ == END) {
y[j] += shortcuts_.at(mapping_)->front().at(j);
shortcuts_.at(mapping_)->pop();
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment