Python tensorflow.contrib.layers.python.layers.utils.constant_value() Examples

The following are 6 code examples of tensorflow.contrib.layers.python.layers.utils.constant_value(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module tensorflow.contrib.layers.python.layers.utils , or try the search function .
Example #1
Source File: utils_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def test_value(self):
    for v in [True, False, 1, 0, 1.0]:
      value = utils.constant_value(v)
      self.assertEqual(value, v) 
Example #2
Source File: utils_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def test_constant(self):
    for v in [True, False, 1, 0, 1.0]:
      c = tf.constant(v)
      value = utils.constant_value(c)
      self.assertEqual(value, v)
      with self.test_session():
        self.assertEqual(c.eval(), v) 
Example #3
Source File: utils_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def test_variable(self):
    for v in [True, False, 1, 0, 1.0]:
      with tf.Graph().as_default() as g, self.test_session(g) as sess:
        x = tf.Variable(v)
        value = utils.constant_value(x)
        self.assertEqual(value, None)
        sess.run(tf.global_variables_initializer())
        self.assertEqual(x.eval(), v) 
Example #4
Source File: utils_test.py    From deep_image_model with Apache License 2.0 5 votes vote down vote up
def test_placeholder(self):
    for v in [True, False, 1, 0, 1.0]:
      p = tf.placeholder(np.dtype(type(v)), [])
      x = tf.identity(p)
      value = utils.constant_value(p)
      self.assertEqual(value, None)
      with self.test_session():
        self.assertEqual(x.eval(feed_dict={p: v}), v) 
Example #5
Source File: batch_norm.py    From chemopt with MIT License 5 votes vote down vote up
def _build_update_ops_variance(self, mean, variance, is_training):
        def build_update_ops():
            update_mean_op = moving_averages.assign_moving_average(
              variable=self._moving_mean,
              value=mean,
              decay=self._decay_rate,
              name="update_moving_mean").op

            update_variance_op = moving_averages.assign_moving_average(
              variable=self._moving_variance,
              value=variance,
              decay=self._decay_rate,
              name="update_moving_variance").op

            return update_mean_op, update_variance_op

        def build_no_ops():
            return (tf.no_op(), tf.no_op())

            # Only make the ops if we know that `is_training=True`, or the
            # value of `is_training` is unknown.
        is_training_const = utils.constant_value(is_training)
        if is_training_const is None or is_training_const:
            update_mean_op, update_variance_op = utils.smart_cond(
                is_training,
                build_update_ops,
                build_no_ops,
            )

          # Every new connection creates a new op which adds its contribution
          # to the running average when ran.
        tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, update_mean_op)
        tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, update_variance_op) 
Example #6
Source File: batch_norm.py    From chemopt with MIT License 5 votes vote down vote up
def _build_update_ops_second_moment(self, mean, second_moment, is_training):
        def build_update_ops():
            update_mean_op = moving_averages.assign_moving_average(
              variable=self._moving_mean,
              value=mean,
              decay=self._decay_rate,
              name="update_moving_mean").op

            update_second_moment_op = moving_averages.assign_moving_average(
              variable=self._moving_second_moment,
              value=second_moment,
              decay=self._decay_rate,
              name="update_moving_second_moment").op

            return update_mean_op, update_second_moment_op

        def build_no_ops():
            return (tf.no_op(), tf.no_op())

        is_training_const = utils.constant_value(is_training)
        if is_training_const is None or is_training_const:
            update_mean_op, update_second_moment_op = utils.smart_cond(
                is_training,
                build_update_ops,
                build_no_ops,
                )

        tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, update_mean_op)
        tf.add_to_collection(tf.GraphKeys.UPDATE_OPS, update_second_moment_op)