Skip to content

Commit d22e194

Browse files
abab
ab
authored and
ab
committed
dropout convolutions
1 parent 1bea4f2 commit d22e194

4 files changed

+19
-5
lines changed

Sources/convolutional_layer.hpp

+13
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@ class convolutional_layer : public layer {
4343
assert(in.size() == in_feature_maps_ * in_width_ * in_width_);
4444
assert(weights_.size() == in_feature_maps_*out_feature_maps_*filter_width_*filter_width_);
4545

46+
if (dropout_prob_ > 0.0)
47+
sample_dropout();
48+
4649
for (uint_t out_fm=0; out_fm<out_feature_maps_; out_fm++) {
4750

4851
for (uint_t ox=0; ox<out_width_; ox++) {
4952
for (uint_t oy=0; oy<out_width_; oy++) {
5053

54+
/* dropout while training: [0,1), dropout while testing: 1 */
55+
if (dropout_prob_!= 0 && dropout_prob_!=1 && dropout_sample_[(out_fm*out_width_+ ox)*out_width_ + oy]<dropout_prob_) {
56+
output_[(out_fm*out_width_+ ox)*out_width_ + oy] = 0.0;
57+
continue;
58+
}
59+
5160
float_t sum = 0.0;
5261
for (uint_t in_fm=0; in_fm<in_feature_maps_; in_fm++) {
5362

@@ -61,6 +70,10 @@ class convolutional_layer : public layer {
6170
}
6271
}
6372
}
73+
/* dropout while testing */
74+
if (dropout_prob_==1)
75+
sum = sum*0.5;
76+
6477
output_[(out_fm*out_width_+ ox)*out_width_ + oy] = A_.f(sum + bias_[out_fm]);
6578
}
6679
}

Sources/fullyconnected_layer.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class fullyconnected_layer : public output_layer {
4747

4848
/* dropout while testing */
4949
if (dropout_prob_==1)
50-
sum = sum*0.5;
50+
sum = sum*0.1;
5151

5252
output_[o] = ActFunc.f(sum + bias_[o]);
5353
}

Sources/main.cpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,8 @@ cnn_training_test_mnist()
155155
vec_t soll {0,0,0,0,0,0,0,0,0,0};
156156
int last_label = 0;
157157
for(int s=1; s<=steps; s++) {
158-
159-
160-
S4.set_dropout_prob(0.5);
158+
159+
S4.set_dropout_prob(0.9);
161160
#if TRAINING_MOMENTUM
162161
if (s%1000==0) {
163162
nn.set_learning_rate( s==0? 0.00085 : nn.learning_rate()*0.85);

Sources/subsampling_layer.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ class subsampling_layer : public layer {
2929
}
3030

3131
void forward(const vec_t& in /*[in_feature_map * in_width_ * in_width_]*/) {
32-
3332
assert(in.size() == feature_maps_ * in_width_ * in_width_);
33+
34+
if (dropout_prob_ > 0.0)
35+
sample_dropout();
3436

3537
for (uint_t fm=0; fm<feature_maps_; fm++) {
3638

0 commit comments

Comments
 (0)