Skip to content

Commit 493d7a2

Browse files
authored
Fix resnet missing layers. (tensorflow#4254)
* Fix resnet missing layers. The official v1 model contains BN and Relu between input layer and pooling. * Remove the BN and Relu for V2. After some discussion with team and refer to existing implementation, those two layer seems to be only useful in V1. In V2, the first unit of the block will have a projection, that apply the BN and Relu for the shortcut. Adding a comment to make this clear. * Expand the comment section. * Remove the pre-trained checkpoint since its broken right now. Will restore it once we have new checkpoint generated.
1 parent 0344c55 commit 493d7a2

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

official/resnet/README.md

-9
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,6 @@ The model will begin training and will automatically evaluate itself on the vali
5050

5151
Note that there are a number of other options you can specify, including `--model_dir` to choose where to store the model and `--resnet_size` to choose the model size (options include ResNet-18 through ResNet-200). See [`resnet.py`](resnet.py) for the full list of options.
5252

53-
### Pre-trained model
54-
You can download 190 MB pre-trained versions of ResNet-50 achieving 76.3% and 75.3% (respectively) top-1 single-crop accuracy here: [resnetv2_imagenet_checkpoint.tar.gz](http://download.tensorflow.org/models/official/resnetv2_imagenet_checkpoint.tar.gz), [resnetv1_imagenet_checkpoint.tar.gz](http://download.tensorflow.org/models/official/resnetv1_imagenet_checkpoint.tar.gz). Simply download and uncompress the file, and point the model to the extracted directory using the `--model_dir` flag.
55-
56-
Other versions and formats:
57-
58-
* [ResNet-v2-ImageNet Checkpoint](http://download.tensorflow.org/models/official/resnet_v2_imagenet_checkpoint.tar.gz)
59-
* [ResNet-v2-ImageNet SavedModel](http://download.tensorflow.org/models/official/resnet_v2_imagenet_savedmodel.tar.gz)
60-
* [ResNet-v1-ImageNet Checkpoint](http://download.tensorflow.org/models/official/resnet_v1_imagenet_checkpoint.tar.gz)
61-
* [ResNet-v1-ImageNet SavedModel](http://download.tensorflow.org/models/official/resnet_v1_imagenet_savedmodel.tar.gz)
6253

6354
## Compute Devices
6455
Training is accomplished using the DistributionStrategies API. (https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/distribute/README.md)

official/resnet/resnet_model.py

+8
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,14 @@ def __call__(self, inputs, training):
504504
strides=self.conv_stride, data_format=self.data_format)
505505
inputs = tf.identity(inputs, 'initial_conv')
506506

507+
# We do not include batch normalization or activation functions in V2
508+
# for the initial conv1 because the first ResNet unit will perform these
509+
# for both the shortcut and non-shortcut paths as part of the first
510+
# block's projection. Cf. Appendix of [2].
511+
if self.resnet_version == 1:
512+
inputs = batch_norm(inputs, training, self.data_format)
513+
inputs = tf.nn.relu(inputs)
514+
507515
if self.first_pool_size:
508516
inputs = tf.layers.max_pooling2d(
509517
inputs=inputs, pool_size=self.first_pool_size,

0 commit comments

Comments
 (0)