From d3e8492c5adbbf5a18d0bc5f9c243ea06351fd32 Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy Date: Wed, 12 Nov 2025 15:31:55 +0000 Subject: [PATCH 1/3] Introduce training mode switch to Dropout layer --- include/layers/DropOutLayer.hpp | 5 ++++- src/layers/DropOutLayer.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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..04040c29 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); From cf189c5c4db5b696ebf57c8a12d491f32974c45d Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy Date: Wed, 12 Nov 2025 16:01:23 +0000 Subject: [PATCH 2/3] Adjust tests --- test/single_layer/test_dropoutlayer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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); From bc8b106b04c7b5d10d4d022f7b6d889a1e4bda72 Mon Sep 17 00:00:00 2001 From: Arseniy Obolenskiy Date: Wed, 12 Nov 2025 16:43:28 +0000 Subject: [PATCH 3/3] ix clang-format --- src/layers/DropOutLayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layers/DropOutLayer.cpp b/src/layers/DropOutLayer.cpp index 04040c29..bff08057 100644 --- a/src/layers/DropOutLayer.cpp +++ b/src/layers/DropOutLayer.cpp @@ -11,7 +11,7 @@ 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];