本文整理汇总了Python中tensorflow.assert_less_equal方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.assert_less_equal方法的具体用法?Python tensorflow.assert_less_equal怎么用?Python tensorflow.assert_less_equal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.assert_less_equal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: replace
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def replace(self, episodes, length, rows=None):
"""Replace full episodes.
Args:
episodes: Tuple of transition quantities with batch and time dimensions.
length: Batch of sequence lengths.
rows: Episodes to replace, defaults to all.
Returns:
Operation.
"""
rows = tf.range(self._capacity) if rows is None else rows
assert rows.shape.ndims == 1
assert_capacity = tf.assert_less(
rows, self._capacity, message='capacity exceeded')
with tf.control_dependencies([assert_capacity]):
assert_max_length = tf.assert_less_equal(
length, self._max_length, message='max length exceeded')
replace_ops = []
with tf.control_dependencies([assert_max_length]):
for buffer_, elements in zip(self._buffers, episodes):
replace_op = tf.scatter_update(buffer_, rows, elements)
replace_ops.append(replace_op)
with tf.control_dependencies(replace_ops):
return tf.scatter_update(self._length, rows, length)
示例2: __call__
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def __call__(self, batch_size):
"""Reads `batch_size` data.
Args:
batch_size: Tensor of type `int32`. Batch size of the data to be
retrieved from the dataset. `batch_size` should be less than or
equal to the number of examples in the dataset.
Returns:
Read data, a list of Tensors with batch size equal to `batch_size`.
"""
check_size = tf.assert_less_equal(
batch_size,
tf.convert_to_tensor(self._num_examples, dtype=tf.int32),
message='Data set read failure, batch_size > num_examples.'
)
with tf.control_dependencies([check_size]):
self._indices = tf.random.shuffle(
tf.range(self._num_examples, dtype=tf.int32))
return _extract_data(self._dataset, self._indices[:batch_size])
示例3: __call__
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def __call__(self, batch_size):
"""Reads `batch_size` data.
Args:
batch_size: Tensor of type `int32`, batch size of the data to be
retrieved from the dataset. `batch_size` should be less than or
equal to `max_batch_size`.
Returns:
Read data, An iterable of tensors with batch size equal to `batch_size`.
"""
check_size = tf.assert_less_equal(
batch_size,
tf.convert_to_tensor(self._max_batch_size, dtype=tf.int32),
message='Data set read failure, Batch size greater than max allowed.'
)
with tf.control_dependencies([check_size]):
return _slice_data(self._dataset, batch_size)
示例4: _init_clusters_random
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def _init_clusters_random(self):
"""Does random initialization of clusters.
Returns:
Tensor of randomly initialized clusters.
"""
num_data = tf.add_n([tf.shape(inp)[0] for inp in self._inputs])
# Note that for mini-batch k-means, we should ensure that the batch size of
# data used during initialization is sufficiently large to avoid duplicated
# clusters.
with tf.control_dependencies(
[tf.assert_less_equal(self._num_clusters, num_data)]):
indices = tf.random_uniform(tf.reshape(self._num_clusters, [-1]),
minval=0,
maxval=tf.cast(num_data, tf.int64),
seed=self._random_seed,
dtype=tf.int64)
clusters_init = embedding_lookup(self._inputs, indices,
partition_strategy='div')
return clusters_init
示例5: _init_clusters_random
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def _init_clusters_random(data, num_clusters, random_seed):
"""Does random initialization of clusters.
Args:
data: a list of Tensors with a matrix of data, each row is an example.
num_clusters: an integer with the number of clusters.
random_seed: Seed for PRNG used to initialize seeds.
Returns:
A Tensor with num_clusters random rows of data.
"""
assert isinstance(data, list)
num_data = tf.add_n([tf.shape(inp)[0] for inp in data])
with tf.control_dependencies([tf.assert_less_equal(num_clusters, num_data)]):
indices = tf.random_uniform([num_clusters],
minval=0,
maxval=tf.cast(num_data, tf.int64),
seed=random_seed,
dtype=tf.int64)
indices = tf.cast(indices, tf.int32) % num_data
clusters_init = embedding_lookup(data, indices, partition_strategy='div')
return clusters_init
示例6: replace
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def replace(self, episodes, length, rows=None):
"""Replace full episodes.
Args:
episodes: Tuple of transition quantities with batch and time dimensions.
length: Batch of sequence lengths.
rows: Episodes to replace, defaults to all.
Returns:
Operation.
"""
rows = tf.range(self._capacity) if rows is None else rows
assert rows.shape.ndims == 1
assert_capacity = tf.assert_less(
rows, self._capacity, message='capacity exceeded')
with tf.control_dependencies([assert_capacity]):
assert_max_length = tf.assert_less_equal(
length, self._max_length, message='max length exceeded')
with tf.control_dependencies([assert_max_length]):
replace_ops = tools.nested.map(
lambda var, val: tf.scatter_update(var, rows, val),
self._buffers, episodes, flatten=True)
with tf.control_dependencies(replace_ops):
return tf.scatter_update(self._length, rows, length)
示例7: _preprocess_for_inception
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def _preprocess_for_inception(images):
"""Preprocess images for inception.
Args:
images: images minibatch. Shape [batch size, width, height,
channels]. Values are in [0..255].
Returns:
preprocessed_images
"""
images = tf.cast(images, tf.float32)
# tfgan_eval.preprocess_image function takes values in [0, 255]
with tf.control_dependencies([tf.assert_greater_equal(images, 0.0),
tf.assert_less_equal(images, 255.0)]):
images = tf.identity(images)
preprocessed_images = tf.map_fn(
fn=_TFGAN.preprocess_image,
elems=images,
back_prop=False)
return preprocessed_images
示例8: _project_perturbation
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def _project_perturbation(perturbation, epsilon, input_image):
"""Project `perturbation` onto L-infinity ball of radius `epsilon`."""
# Ensure inputs are in the correct range
with tf.control_dependencies([
tf.assert_less_equal(input_image, 1.0),
tf.assert_greater_equal(input_image, 0.0)
]):
clipped_perturbation = tf.clip_by_value(
perturbation, -epsilon, epsilon)
new_image = tf.clip_by_value(
input_image + clipped_perturbation, 0., 1.)
return new_image - input_image
示例9: scale_to_inception_range
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def scale_to_inception_range(image):
"""Scales an image in the range [0,1] to [-1,1] as expected by inception."""
# Assert that incoming images have been properly scaled to [0,1].
with tf.control_dependencies(
[tf.assert_less_equal(tf.reduce_max(image), 1.),
tf.assert_greater_equal(tf.reduce_min(image), 0.)]):
image = tf.subtract(image, 0.5)
image = tf.multiply(image, 2.0)
return image
示例10: new_mean_squared
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def new_mean_squared(grad_vec, decay, ms):
"""Calculates the new accumulated mean squared of the gradient.
Args:
grad_vec: the vector for the current gradient
decay: the decay term
ms: the previous mean_squared value
Returns:
the new mean_squared value
"""
decay_size = decay.get_shape().num_elements()
decay_check_ops = [
tf.assert_less_equal(decay, 1., summarize=decay_size),
tf.assert_greater_equal(decay, 0., summarize=decay_size)]
with tf.control_dependencies(decay_check_ops):
grad_squared = tf.square(grad_vec)
# If the previous mean_squared is the 0 vector, don't use the decay and just
# return the full grad_squared. This should only happen on the first timestep.
decay = tf.cond(tf.reduce_all(tf.equal(ms, 0.)),
lambda: tf.zeros_like(decay, dtype=tf.float32), lambda: decay)
# Update the running average of squared gradients.
epsilon = 1e-12
return (1. - decay) * (grad_squared + epsilon) + decay * ms
示例11: test_doesnt_raise_when_equal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def test_doesnt_raise_when_equal(self):
with self.test_session():
small = tf.constant([1, 2], name="small")
with tf.control_dependencies([tf.assert_less_equal(small, small)]):
out = tf.identity(small)
out.eval()
示例12: test_raises_when_greater
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def test_raises_when_greater(self):
with self.test_session():
small = tf.constant([1, 2], name="small")
big = tf.constant([3, 4], name="big")
with tf.control_dependencies(
[tf.assert_less_equal(big, small, message="fail")]):
out = tf.identity(small)
with self.assertRaisesOpError("fail.*big.*small"):
out.eval()
示例13: test_doesnt_raise_when_less_equal
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def test_doesnt_raise_when_less_equal(self):
with self.test_session():
small = tf.constant([1, 2], name="small")
big = tf.constant([3, 2], name="big")
with tf.control_dependencies([tf.assert_less_equal(small, big)]):
out = tf.identity(small)
out.eval()
示例14: test_doesnt_raise_when_less_equal_and_broadcastable_shapes
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def test_doesnt_raise_when_less_equal_and_broadcastable_shapes(self):
with self.test_session():
small = tf.constant([1], name="small")
big = tf.constant([3, 1], name="big")
with tf.control_dependencies([tf.assert_less_equal(small, big)]):
out = tf.identity(small)
out.eval()
示例15: test_raises_when_less_equal_but_non_broadcastable_shapes
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import assert_less_equal [as 别名]
def test_raises_when_less_equal_but_non_broadcastable_shapes(self):
with self.test_session():
small = tf.constant([1, 1, 1], name="small")
big = tf.constant([3, 1], name="big")
with self.assertRaisesRegexp(ValueError, "must be"):
with tf.control_dependencies([tf.assert_less_equal(small, big)]):
out = tf.identity(small)
out.eval()