Skip to content

Commit 084c8d0

Browse files
committed
many folks recommend to apply relu before batchnorma
1 parent bd71aa4 commit 084c8d0

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

assignment2/nn/cnn.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@ def cnn(idx, X, filters, kernel_size, is_training,
1010
bconv = tf.get_variable(f'bconv{idx}', shape=[filters])
1111
out = tf.nn.conv2d(X, filter=Wconv, strides=strides, padding=padding) + bconv
1212

13-
# Spatial Batch Normalization Layer (trainable parameters, with scale and centering)
14-
# axis=3 channel axis
15-
if use_batchnorm:
16-
out = tf.layers.batch_normalization(out, axis=3, training=is_training)
17-
1813
if dropout is not None:
1914
out = tf.layers.dropout(out, rate=dropout, training=is_training)
2015

2116
# ReLU Activation Layer
2217
out = tf.nn.relu(out)
2318

19+
# Actually it is interesting question where is it better to place batchnorm
20+
# before activation (as it was in the original paper)
21+
# or after activation - today many falks tell
22+
# that it is better to apply after
23+
#
24+
# Spatial Batch Normalization Layer (trainable parameters, with scale and centering)
25+
# axis=3 channel axis
26+
if use_batchnorm:
27+
out = tf.layers.batch_normalization(out, axis=3, training=is_training)
28+
2429
return out, [Wconv, bconv]

0 commit comments

Comments
 (0)