本文整理汇总了Python中tensorflow.contrib.layers.python.layers.utils.constant_value方法的典型用法代码示例。如果您正苦于以下问题:Python utils.constant_value方法的具体用法?Python utils.constant_value怎么用?Python utils.constant_value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow.contrib.layers.python.layers.utils
的用法示例。
在下文中一共展示了utils.constant_value方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_value
# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import constant_value [as 别名]
def test_value(self):
for v in [True, False, 1, 0, 1.0]:
value = utils.constant_value(v)
self.assertEqual(value, v)
示例2: test_constant
# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import constant_value [as 别名]
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)
示例3: test_variable
# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import constant_value [as 别名]
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)
示例4: test_placeholder
# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import constant_value [as 别名]
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)
示例5: _build_update_ops_variance
# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import constant_value [as 别名]
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)
示例6: _build_update_ops_second_moment
# 需要导入模块: from tensorflow.contrib.layers.python.layers import utils [as 别名]
# 或者: from tensorflow.contrib.layers.python.layers.utils import constant_value [as 别名]
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)