Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/layers/DropOutLayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Tensor>& input,
std::vector<Tensor>& output) override;
Expand Down
6 changes: 6 additions & 0 deletions src/layers/DropOutLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ void DropOutLayer::run(const std::vector<Tensor>& 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<double> unif(lower_bound, upper_bound);
Expand Down
8 changes: 4 additions & 4 deletions test/single_layer/test_dropoutlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>({1, -1, 2, -2}, sh);
Tensor output;
Expand Down Expand Up @@ -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<float> a(100, static_cast<float>(0.01));
Tensor input = make_tensor<float>(a, sh);
Expand All @@ -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<float> a(100, static_cast<float>(0.01));
Tensor input = make_tensor<float>(a, sh);
Expand All @@ -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<float> a(100, static_cast<float>(0.01));
Tensor input = make_tensor<float>(a, sh);
Expand Down
Loading