def test_return_non_default_batch_norm_params_keras_override(self):
        conv_hyperparams_text_proto = """
      regularizer {
        l2_regularizer {
        }
      }
      initializer {
        truncated_normal_initializer {
        }
      }
      batch_norm {
        decay: 0.7
        center: false
        scale: true
        epsilon: 0.03
      }
    """
        conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
        keras_config = hyperparams_builder.KerasLayerHyperparams(
            conv_hyperparams_proto)

        self.assertTrue(keras_config.use_batch_norm())
        batch_norm_params = keras_config.batch_norm_params(momentum=0.4)
        self.assertAlmostEqual(batch_norm_params['momentum'], 0.4)
        self.assertAlmostEqual(batch_norm_params['epsilon'], 0.03)
        self.assertFalse(batch_norm_params['center'])
        self.assertTrue(batch_norm_params['scale'])
 def test_return_batch_norm_params_with_notrain_when_train_is_false(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
   batch_norm {
     decay: 0.7
     center: false
     scale: true
     epsilon: 0.03
     train: false
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     conv_scope_arguments = scope[_get_scope_key(slim.conv2d)]
     self.assertEqual(conv_scope_arguments['normalizer_fn'],
                      slim.batch_norm)
     batch_norm_params = scope[_get_scope_key(slim.batch_norm)]
     self.assertAlmostEqual(batch_norm_params['decay'], 0.7)
     self.assertAlmostEqual(batch_norm_params['epsilon'], 0.03)
     self.assertFalse(batch_norm_params['center'])
     self.assertTrue(batch_norm_params['scale'])
     self.assertFalse(batch_norm_params['is_training'])
Exemple #3
0
    def test_default_rfcn_box_predictor(self):
        conv_hyperparams_text_proto = """
      regularizer {
        l1_regularizer {
        }
      }
      initializer {
        truncated_normal_initializer {
        }
      }
      activation: RELU_6
    """
        hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(conv_hyperparams_text_proto, hyperparams_proto)

        def mock_conv_argscope_builder(conv_hyperparams_arg, is_training):
            return (conv_hyperparams_arg, is_training)

        box_predictor_proto = box_predictor_pb2.BoxPredictor()
        box_predictor_proto.rfcn_box_predictor.conv_hyperparams.CopyFrom(
            hyperparams_proto)
        box_predictor = box_predictor_builder.build(
            argscope_fn=mock_conv_argscope_builder,
            box_predictor_config=box_predictor_proto,
            is_training=True,
            num_classes=90)
        self.assertEqual(box_predictor.num_classes, 90)
        self.assertTrue(box_predictor._is_training)
        self.assertEqual(box_predictor._box_code_size, 4)
        self.assertEqual(box_predictor._num_spatial_bins, [3, 3])
        self.assertEqual(box_predictor._crop_size, [12, 12])
Exemple #4
0
 def test_box_predictor_builder_calls_fc_argscope_fn(self):
     fc_hyperparams_text_proto = """
   regularizer {
     l1_regularizer {
       weight: 0.0003
     }
   }
   initializer {
     truncated_normal_initializer {
       mean: 0.0
       stddev: 0.3
     }
   }
   activation: RELU_6
   op: FC
 """
     hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(fc_hyperparams_text_proto, hyperparams_proto)
     box_predictor_proto = box_predictor_pb2.BoxPredictor()
     box_predictor_proto.mask_rcnn_box_predictor.fc_hyperparams.CopyFrom(
         hyperparams_proto)
     mock_argscope_fn = mock.Mock(return_value='arg_scope')
     box_predictor = box_predictor_builder.build(
         argscope_fn=mock_argscope_fn,
         box_predictor_config=box_predictor_proto,
         is_training=False,
         num_classes=10)
     mock_argscope_fn.assert_called_with(hyperparams_proto, False)
     self.assertEqual(box_predictor._box_prediction_head._fc_hyperparams_fn,
                      'arg_scope')
     self.assertEqual(
         box_predictor._class_prediction_head._fc_hyperparams_fn,
         'arg_scope')
Exemple #5
0
    def test_construct_non_default_conv_box_predictor(self):
        box_predictor_text_proto = """
      convolutional_box_predictor {
        min_depth: 2
        max_depth: 16
        num_layers_before_predictor: 2
        use_dropout: false
        dropout_keep_probability: 0.4
        kernel_size: 3
        box_code_size: 3
        apply_sigmoid_to_scores: true
        class_prediction_bias_init: 4.0
        use_depthwise: true
      }
    """
        conv_hyperparams_text_proto = """
      regularizer {
        l1_regularizer {
        }
      }
      initializer {
        truncated_normal_initializer {
        }
      }
    """
        hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(conv_hyperparams_text_proto, hyperparams_proto)

        def mock_conv_argscope_builder(conv_hyperparams_arg, is_training):
            return (conv_hyperparams_arg, is_training)

        box_predictor_proto = box_predictor_pb2.BoxPredictor()
        text_format.Merge(box_predictor_text_proto, box_predictor_proto)
        box_predictor_proto.convolutional_box_predictor.conv_hyperparams.CopyFrom(
            hyperparams_proto)
        box_predictor = box_predictor_builder.build(
            argscope_fn=mock_conv_argscope_builder,
            box_predictor_config=box_predictor_proto,
            is_training=False,
            num_classes=10,
            add_background_class=False)
        class_head = box_predictor._class_prediction_head
        self.assertEqual(box_predictor._min_depth, 2)
        self.assertEqual(box_predictor._max_depth, 16)
        self.assertEqual(box_predictor._num_layers_before_predictor, 2)
        self.assertFalse(class_head._use_dropout)
        self.assertAlmostEqual(class_head._dropout_keep_prob, 0.4)
        self.assertTrue(class_head._apply_sigmoid_to_scores)
        self.assertAlmostEqual(class_head._class_prediction_bias_init, 4.0)
        self.assertEqual(class_head._num_class_slots, 10)
        self.assertEqual(box_predictor.num_classes, 10)
        self.assertFalse(box_predictor._is_training)
        self.assertTrue(class_head._use_depthwise)
Exemple #6
0
 def _build_conv_hyperparams(self):
     conv_hyperparams = hyperparams_pb2.Hyperparams()
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
 """
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams)
     return hyperparams_builder.KerasLayerHyperparams(conv_hyperparams)
Exemple #7
0
 def _build_arg_scope_with_conv_hyperparams(self):
   conv_hyperparams = hyperparams_pb2.Hyperparams()
   conv_hyperparams_text_proto = """
     regularizer {
       l2_regularizer {
       }
     }
     initializer {
       truncated_normal_initializer {
       }
     }
   """
   text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams)
   return hyperparams_builder.build(conv_hyperparams, is_training=True)
 def test_default_arg_scope_has_conv2d_transpose_op(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l1_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     self.assertTrue(_get_scope_key(slim.conv2d_transpose) in scope)
 def _build_conv_arg_scope_no_batch_norm(self):
     conv_hyperparams = hyperparams_pb2.Hyperparams()
     conv_hyperparams_text_proto = """
   activation: RELU_6
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     random_normal_initializer {
       stddev: 0.01
       mean: 0.0
     }
   }
 """
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams)
     return hyperparams_builder.build(conv_hyperparams, is_training=True)
 def _build_arg_scope_with_hyperparams(
         self, op_type=hyperparams_pb2.Hyperparams.FC):
     hyperparams = hyperparams_pb2.Hyperparams()
     hyperparams_text_proto = """
   activation: NONE
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
 """
     text_format.Merge(hyperparams_text_proto, hyperparams)
     hyperparams.op = op_type
     return hyperparams_builder.build(hyperparams, is_training=True)
Exemple #11
0
    def test_non_default_mask_rcnn_box_predictor(self):
        fc_hyperparams_text_proto = """
      regularizer {
        l1_regularizer {
        }
      }
      initializer {
        truncated_normal_initializer {
        }
      }
      activation: RELU_6
      op: FC
    """
        box_predictor_text_proto = """
      mask_rcnn_box_predictor {
        use_dropout: true
        dropout_keep_probability: 0.8
        box_code_size: 3
        share_box_across_classes: true
      }
    """
        hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(fc_hyperparams_text_proto, hyperparams_proto)

        def mock_fc_argscope_builder(fc_hyperparams_arg, is_training):
            return (fc_hyperparams_arg, is_training)

        box_predictor_proto = box_predictor_pb2.BoxPredictor()
        text_format.Merge(box_predictor_text_proto, box_predictor_proto)
        box_predictor_proto.mask_rcnn_box_predictor.fc_hyperparams.CopyFrom(
            hyperparams_proto)
        box_predictor = box_predictor_builder.build(
            argscope_fn=mock_fc_argscope_builder,
            box_predictor_config=box_predictor_proto,
            is_training=True,
            num_classes=90)
        box_head = box_predictor._box_prediction_head
        class_head = box_predictor._class_prediction_head
        self.assertTrue(box_head._use_dropout)
        self.assertTrue(class_head._use_dropout)
        self.assertAlmostEqual(box_head._dropout_keep_prob, 0.8)
        self.assertAlmostEqual(class_head._dropout_keep_prob, 0.8)
        self.assertEqual(box_predictor.num_classes, 90)
        self.assertTrue(box_predictor._is_training)
        self.assertEqual(box_head._box_code_size, 3)
        self.assertEqual(box_head._share_box_across_classes, True)
Exemple #12
0
    def test_box_predictor_calls_fc_argscope_fn(self):
        conv_hyperparams_text_proto = """
      regularizer {
        l1_regularizer {
          weight: 0.0003
        }
      }
      initializer {
        truncated_normal_initializer {
          mean: 0.0
          stddev: 0.3
        }
      }
      activation: RELU_6
    """
        hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(conv_hyperparams_text_proto, hyperparams_proto)

        def mock_conv_argscope_builder(conv_hyperparams_arg, is_training):
            return (conv_hyperparams_arg, is_training)

        box_predictor_proto = box_predictor_pb2.BoxPredictor()
        box_predictor_proto.rfcn_box_predictor.conv_hyperparams.CopyFrom(
            hyperparams_proto)
        box_predictor = box_predictor_builder.build(
            argscope_fn=mock_conv_argscope_builder,
            box_predictor_config=box_predictor_proto,
            is_training=False,
            num_classes=10)
        (conv_hyperparams_actual,
         is_training) = box_predictor._conv_hyperparams_fn
        self.assertAlmostEqual(
            (hyperparams_proto.regularizer.l1_regularizer.weight),
            (conv_hyperparams_actual.regularizer.l1_regularizer.weight))
        self.assertAlmostEqual((
            hyperparams_proto.initializer.truncated_normal_initializer.stddev),
                               (conv_hyperparams_actual.initializer.
                                truncated_normal_initializer.stddev))
        self.assertAlmostEqual(
            (hyperparams_proto.initializer.truncated_normal_initializer.mean),
            (conv_hyperparams_actual.initializer.truncated_normal_initializer.
             mean))
        self.assertEqual(hyperparams_proto.activation,
                         conv_hyperparams_actual.activation)
        self.assertFalse(is_training)
Exemple #13
0
    def test_construct_non_default_depthwise_conv_box_predictor(self):
        box_predictor_text_proto = """
      weight_shared_convolutional_box_predictor {
        depth: 2
        num_layers_before_predictor: 2
        kernel_size: 7
        box_code_size: 3
        class_prediction_bias_init: 4.0
        use_depthwise: true
      }
    """
        conv_hyperparams_text_proto = """
      regularizer {
        l1_regularizer {
        }
      }
      initializer {
        truncated_normal_initializer {
        }
      }
    """
        hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(conv_hyperparams_text_proto, hyperparams_proto)

        def mock_conv_argscope_builder(conv_hyperparams_arg, is_training):
            return (conv_hyperparams_arg, is_training)

        box_predictor_proto = box_predictor_pb2.BoxPredictor()
        text_format.Merge(box_predictor_text_proto, box_predictor_proto)
        (box_predictor_proto.weight_shared_convolutional_box_predictor.
         conv_hyperparams.CopyFrom(hyperparams_proto))
        box_predictor = box_predictor_builder.build(
            argscope_fn=mock_conv_argscope_builder,
            box_predictor_config=box_predictor_proto,
            is_training=False,
            num_classes=10,
            add_background_class=False)
        class_head = box_predictor._class_prediction_head
        self.assertEqual(box_predictor._depth, 2)
        self.assertEqual(box_predictor._num_layers_before_predictor, 2)
        self.assertEqual(box_predictor._apply_batch_norm, False)
        self.assertEqual(box_predictor._use_depthwise, True)
        self.assertAlmostEqual(class_head._class_prediction_bias_init, 4.0)
        self.assertEqual(box_predictor.num_classes, 10)
        self.assertFalse(box_predictor._is_training)
 def test_do_not_use_batch_norm_if_default(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     conv_scope_arguments = scope[_get_scope_key(slim.conv2d)]
     self.assertEqual(conv_scope_arguments['normalizer_fn'], None)
 def _build_conv_hyperparams(self):
     conv_hyperparams = hyperparams_pb2.Hyperparams()
     conv_hyperparams_text_proto = """
   activation: RELU_6
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
   batch_norm {
     scale: false
   }
 """
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams)
     return hyperparams_builder.KerasLayerHyperparams(conv_hyperparams)
 def test_override_activation_keras(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
   activation: RELU_6
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     keras_config = hyperparams_builder.KerasLayerHyperparams(
         conv_hyperparams_proto)
     new_params = keras_config.params(activation=tf.nn.relu)
     self.assertEqual(new_params['activation'], tf.nn.relu)
 def test_explicit_fc_op_arg_scope_has_fully_connected_op(self):
     conv_hyperparams_text_proto = """
   op: FC
   regularizer {
     l1_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     self.assertTrue(_get_scope_key(slim.fully_connected) in scope)
 def test_use_relu_6_activation(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
   activation: RELU_6
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     conv_scope_arguments = scope[_get_scope_key(slim.conv2d)]
     self.assertEqual(conv_scope_arguments['activation_fn'], tf.nn.relu6)
 def test_separable_conv2d_and_conv2d_and_transpose_have_same_parameters(
         self):
     conv_hyperparams_text_proto = """
   regularizer {
     l1_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     kwargs_1, kwargs_2, kwargs_3 = scope.values()
     self.assertDictEqual(kwargs_1, kwargs_2)
     self.assertDictEqual(kwargs_1, kwargs_3)
    def test_do_not_use_batch_norm_if_default_keras(self):
        conv_hyperparams_text_proto = """
      regularizer {
        l2_regularizer {
        }
      }
      initializer {
        truncated_normal_initializer {
        }
      }
    """
        conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
        keras_config = hyperparams_builder.KerasLayerHyperparams(
            conv_hyperparams_proto)
        self.assertFalse(keras_config.use_batch_norm())
        self.assertEqual(keras_config.batch_norm_params(), {})

        # The batch norm builder should build an identity Lambda layer
        identity_layer = keras_config.build_batch_norm()
        self.assertTrue(isinstance(identity_layer, tf.keras.layers.Lambda))
 def test_variance_in_range_with_random_normal_initializer_keras(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     random_normal_initializer {
       mean: 0.0
       stddev: 0.8
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     keras_config = hyperparams_builder.KerasLayerHyperparams(
         conv_hyperparams_proto)
     initializer = keras_config.params()['kernel_initializer']
     self._assert_variance_in_range(initializer,
                                    shape=[100, 40],
                                    variance=0.64,
                                    tol=1e-1)
    def test_return_l2_regularizer_weights_keras(self):
        conv_hyperparams_text_proto = """
      regularizer {
        l2_regularizer {
          weight: 0.42
        }
      }
      initializer {
        truncated_normal_initializer {
        }
      }
    """
        conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
        keras_config = hyperparams_builder.KerasLayerHyperparams(
            conv_hyperparams_proto)

        regularizer = keras_config.params()['kernel_regularizer']
        weights = np.array([1., -1, 4., 2.])
        with self.test_session() as sess:
            result = sess.run(regularizer(tf.constant(weights)))
        self.assertAllClose(np.power(weights, 2).sum() / 2.0 * 0.42, result)
 def test_use_none_activation_keras(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
   activation: NONE
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     keras_config = hyperparams_builder.KerasLayerHyperparams(
         conv_hyperparams_proto)
     self.assertEqual(keras_config.params()['activation'], None)
     self.assertEqual(
         keras_config.params(include_activation=True)['activation'], None)
     activation_layer = keras_config.build_activation_layer()
     self.assertTrue(isinstance(activation_layer, tf.keras.layers.Lambda))
     self.assertEqual(activation_layer.function, tf.identity)
 def test_return_l1_regularized_weights(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l1_regularizer {
       weight: 0.5
     }
   }
   initializer {
     truncated_normal_initializer {
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     conv_scope_arguments = scope.values()[0]
     regularizer = conv_scope_arguments['weights_regularizer']
     weights = np.array([1., -1, 4., 2.])
     with self.test_session() as sess:
         result = sess.run(regularizer(tf.constant(weights)))
     self.assertAllClose(np.abs(weights).sum() * 0.5, result)
 def test_variance_in_range_with_variance_scaling_initializer_uniform_keras(
         self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     variance_scaling_initializer {
       factor: 2.0
       mode: FAN_IN
       uniform: true
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     keras_config = hyperparams_builder.KerasLayerHyperparams(
         conv_hyperparams_proto)
     initializer = keras_config.params()['kernel_initializer']
     self._assert_variance_in_range(initializer,
                                    shape=[100, 40],
                                    variance=2. / 100.)
    def test_return_l2_regularizer_weights(self):
        conv_hyperparams_text_proto = """
      regularizer {
        l2_regularizer {
          weight: 0.42
        }
      }
      initializer {
        truncated_normal_initializer {
        }
      }
    """
        conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
        text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
        scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                             is_training=True)
        scope = scope_fn()
        conv_scope_arguments = scope[_get_scope_key(slim.conv2d)]

        regularizer = conv_scope_arguments['weights_regularizer']
        weights = np.array([1., -1, 4., 2.])
        with self.test_session() as sess:
            result = sess.run(regularizer(tf.constant(weights)))
        self.assertAllClose(np.power(weights, 2).sum() / 2.0 * 0.42, result)
 def test_variance_in_range_with_random_normal_initializer(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     random_normal_initializer {
       mean: 0.0
       stddev: 0.8
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     conv_scope_arguments = scope[_get_scope_key(slim.conv2d)]
     initializer = conv_scope_arguments['weights_initializer']
     self._assert_variance_in_range(initializer,
                                    shape=[100, 40],
                                    variance=0.64,
                                    tol=1e-1)
 def test_variance_in_range_with_variance_scaling_initializer_uniform(self):
     conv_hyperparams_text_proto = """
   regularizer {
     l2_regularizer {
     }
   }
   initializer {
     variance_scaling_initializer {
       factor: 2.0
       mode: FAN_IN
       uniform: true
     }
   }
 """
     conv_hyperparams_proto = hyperparams_pb2.Hyperparams()
     text_format.Merge(conv_hyperparams_text_proto, conv_hyperparams_proto)
     scope_fn = hyperparams_builder.build(conv_hyperparams_proto,
                                          is_training=True)
     scope = scope_fn()
     conv_scope_arguments = scope[_get_scope_key(slim.conv2d)]
     initializer = conv_scope_arguments['weights_initializer']
     self._assert_variance_in_range(initializer,
                                    shape=[100, 40],
                                    variance=2. / 100.)