Skip to content

Commit 43eea2c

Browse files
committed
Introduce training mode switch to Dropout layer
1 parent 2a2b9df commit 43eea2c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

include/layers/DropOutLayer.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ namespace it_lab_ai {
88
class DropOutLayer : public Layer {
99
private:
1010
double drop_rate_;
11+
bool training_mode_;
1112

1213
public:
13-
DropOutLayer(double drop_rate = 0.0) : Layer(kDropout) {
14+
DropOutLayer(double drop_rate = 0.0, bool training_mode = false) : Layer(kDropout) {
1415
drop_rate_ = drop_rate;
16+
training_mode_ = training_mode;
1517
}
1618
void run(const std::vector<Tensor>& input,
1719
std::vector<Tensor>& output) override;

src/layers/DropOutLayer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ void DropOutLayer::run(const std::vector<Tensor>& input,
1111
if (input.size() != 1) {
1212
throw std::runtime_error("DropOutLayer: Input tensors not 1");
1313
}
14+
15+
// If not in training mode, just pass through the input
16+
if (!training_mode_) {
17+
output[0] = input[0];
18+
return;
19+
}
1420
const double lower_bound = 0;
1521
const double upper_bound = 100;
1622
std::uniform_real_distribution<double> unif(lower_bound, upper_bound);

0 commit comments

Comments
 (0)