1 # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 # ==============================================================================
15 """Contains common code shared by all inception models.
18 with slim.arg_scope(inception_arg_scope()):
19 logits, end_points = inception.inception_v3(images, num_classes,
20 is_training=is_training)
23 from __future__ import absolute_import
24 from __future__ import division
25 from __future__ import print_function
27 import tensorflow as tf
29 slim = tf.contrib.slim
32 def inception_arg_scope(weight_decay=0.00004,
34 batch_norm_decay=0.9997,
35 batch_norm_epsilon=0.001):
36 """Defines the default arg scope for inception models.
39 weight_decay: The weight decay to use for regularizing the model.
40 use_batch_norm: "If `True`, batch_norm is applied after each convolution.
41 batch_norm_decay: Decay for batch norm moving average.
42 batch_norm_epsilon: Small float added to variance to avoid dividing by zero
46 An `arg_scope` to use for the inception models.
49 # Decay for the moving averages.
50 'decay': batch_norm_decay,
51 # epsilon to prevent 0s in variance.
52 'epsilon': batch_norm_epsilon,
53 # collection containing update_ops.
54 'updates_collections': tf.GraphKeys.UPDATE_OPS,
57 normalizer_fn = slim.batch_norm
58 normalizer_params = batch_norm_params
61 normalizer_params = {}
62 # Set weight_decay for weights in Conv and FC layers.
63 with slim.arg_scope([slim.conv2d, slim.fully_connected],
64 weights_regularizer=slim.l2_regularizer(weight_decay)):
67 weights_initializer=slim.variance_scaling_initializer(),
68 activation_fn=tf.nn.relu,
69 normalizer_fn=normalizer_fn,
70 normalizer_params=normalizer_params) as sc: