diff --git a/include/layers/DropOutLayer.hpp b/include/layers/DropOutLayer.hpp index c5b891ed..019b2c4d 100644 --- a/include/layers/DropOutLayer.hpp +++ b/include/layers/DropOutLayer.hpp @@ -8,10 +8,13 @@ namespace it_lab_ai { class DropOutLayer : public Layer { private: double drop_rate_; + bool training_mode_; public: - DropOutLayer(double drop_rate = 0.0) : Layer(kDropout) { + DropOutLayer(double drop_rate = 0.0, bool training_mode = false) + : Layer(kDropout) { drop_rate_ = drop_rate; + training_mode_ = training_mode; } void run(const std::vector& input, std::vector& output) override; diff --git a/src/layers/DropOutLayer.cpp b/src/layers/DropOutLayer.cpp index f7741d87..bff08057 100644 --- a/src/layers/DropOutLayer.cpp +++ b/src/layers/DropOutLayer.cpp @@ -11,6 +11,12 @@ void DropOutLayer::run(const std::vector& input, if (input.size() != 1) { throw std::runtime_error("DropOutLayer: Input tensors not 1"); } + + // If not in training mode, just pass through the input + if (!training_mode_) { + output[0] = input[0]; + return; + } const double lower_bound = 0; const double upper_bound = 100; std::uniform_real_distribution unif(lower_bound, upper_bound); diff --git a/test/single_layer/test_dropoutlayer.cpp b/test/single_layer/test_dropoutlayer.cpp index f8ce1cce..a5c4cb43 100644 --- a/test/single_layer/test_dropoutlayer.cpp +++ b/test/single_layer/test_dropoutlayer.cpp @@ -17,7 +17,7 @@ TEST(DropOutLayer, IncompatibleInput) { } TEST(DropOutLayer, dropoutlayer_int) { - DropOutLayer layer(1); + DropOutLayer layer(1, true); Shape sh({2, 2}); Tensor input = make_tensor({1, -1, 2, -2}, sh); Tensor output; @@ -47,7 +47,7 @@ TEST(DropOutLayer, dropoutlayer_float) { } TEST(DropOutLayer, dropoutlayer_float_50proc) { - DropOutLayer layer(0.5); + DropOutLayer layer(0.5, true); Shape sh({10, 10}); std::vector a(100, static_cast(0.01)); Tensor input = make_tensor(a, sh); @@ -60,7 +60,7 @@ TEST(DropOutLayer, dropoutlayer_float_50proc) { } TEST(DropOutLayer, dropoutlayer_float_30proc) { - DropOutLayer layer(0.3); + DropOutLayer layer(0.3, true); Shape sh({10, 10}); std::vector a(100, static_cast(0.01)); Tensor input = make_tensor(a, sh); @@ -73,7 +73,7 @@ TEST(DropOutLayer, dropoutlayer_float_30proc) { } TEST(DropOutLayer, dropoutlayer_float_70proc) { - DropOutLayer layer(0.7); + DropOutLayer layer(0.7, true); Shape sh({10, 10}); std::vector a(100, static_cast(0.01)); Tensor input = make_tensor(a, sh);