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 _build_arg_scope_with_hyperparams(self,
                                       hyperparams_text_proto,
                                       is_training):
   hyperparams = hyperparams_pb2.Hyperparams()
   text_format.Merge(hyperparams_text_proto, hyperparams)
   return hyperparams_builder.build(hyperparams, is_training=is_training)
Exemple #3
0
 def _build_keras_layer_hyperparams(self, hyperparams_text_proto):
     hyperparams = hyperparams_pb2.Hyperparams()
     text_format.Merge(hyperparams_text_proto, hyperparams)
     return hyperparams_builder.KerasLayerHyperparams(hyperparams)