Skip to content

Commit 89edd1c

Browse files
authored
Fix model layer for resnet v1. (#4230)
The final BN and ReLU layer is only need for v2 model since it was doing preactivation in each block.
1 parent 44fa4b9 commit 89edd1c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

official/resnet/resnet_model.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def __init__(self, resnet_size, bottleneck, num_classes, num_filters,
424424
self.block_strides = block_strides
425425
self.final_size = final_size
426426
self.dtype = dtype
427+
self.pre_activation = resnet_version == 2
427428

428429
def _custom_dtype_getter(self, getter, name, shape=None, dtype=DEFAULT_DTYPE,
429430
*args, **kwargs):
@@ -518,8 +519,11 @@ def __call__(self, inputs, training):
518519
strides=self.block_strides[i], training=training,
519520
name='block_layer{}'.format(i + 1), data_format=self.data_format)
520521

521-
inputs = batch_norm(inputs, training, self.data_format)
522-
inputs = tf.nn.relu(inputs)
522+
# Only apply the BN and ReLU for model that does pre_activation in each
523+
# building/bottleneck block, eg resnet V2.
524+
if self.pre_activation:
525+
inputs = batch_norm(inputs, training, self.data_format)
526+
inputs = tf.nn.relu(inputs)
523527

524528
# The current top layer has shape
525529
# `batch_size x pool_size x pool_size x final_size`.

0 commit comments

Comments
 (0)