本文整理汇总了Python中tensorflow.less_equal方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.less_equal方法的具体用法?Python tensorflow.less_equal怎么用?Python tensorflow.less_equal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.less_equal方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testRandomPixelValueScale
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def testRandomPixelValueScale(self):
preprocessing_options = []
preprocessing_options.append((preprocessor.normalize_image, {
'original_minval': 0,
'original_maxval': 255,
'target_minval': 0,
'target_maxval': 1
}))
preprocessing_options.append((preprocessor.random_pixel_value_scale, {}))
images = self.createTestImages()
tensor_dict = {fields.InputDataFields.image: images}
tensor_dict = preprocessor.preprocess(tensor_dict, preprocessing_options)
images_min = tf.to_float(images) * 0.9 / 255.0
images_max = tf.to_float(images) * 1.1 / 255.0
images = tensor_dict[fields.InputDataFields.image]
values_greater = tf.greater_equal(images, images_min)
values_less = tf.less_equal(images, images_max)
values_true = tf.fill([1, 4, 4, 3], True)
with self.test_session() as sess:
(values_greater_, values_less_, values_true_) = sess.run(
[values_greater, values_less, values_true])
self.assertAllClose(values_greater_, values_true_)
self.assertAllClose(values_less_, values_true_)
示例2: assert_box_normalized
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def assert_box_normalized(boxes, maximum_normalized_coordinate=1.1):
"""Asserts the input box tensor is normalized.
Args:
boxes: a tensor of shape [N, 4] where N is the number of boxes.
maximum_normalized_coordinate: Maximum coordinate value to be considered
as normalized, default to 1.1.
Returns:
a tf.Assert op which fails when the input box tensor is not normalized.
Raises:
ValueError: When the input box tensor is not normalized.
"""
box_minimum = tf.reduce_min(boxes)
box_maximum = tf.reduce_max(boxes)
return tf.Assert(
tf.logical_and(
tf.less_equal(box_maximum, maximum_normalized_coordinate),
tf.greater_equal(box_minimum, 0)),
[boxes])
示例3: mode
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def mode(cls, parameters: Dict[str, Tensor]) -> Tensor:
mu = parameters["mu"]
tau = parameters["tau"]
nu = parameters["nu"]
beta = parameters["beta"]
lam = 1./beta
mode = tf.zeros_like(mu) * tf.zeros_like(mu)
mode = tf.where(tf.logical_and(tf.greater(nu, mu),
tf.less(mu+lam/tau, nu)),
mu+lam/tau,
mode)
mode = tf.where(tf.logical_and(tf.greater(nu, mu),
tf.greater_equal(mu+lam/tau, nu)),
nu,
mode)
mode = tf.where(tf.logical_and(tf.less_equal(nu, mu),
tf.greater(mu-lam/tau, nu)),
mu-lam/tau,
mode)
mode = tf.where(tf.logical_and(tf.less_equal(nu, mu),
tf.less_equal(mu-lam/tau, nu)),
nu,
mode)
return(mode)
示例4: radial_cutoff
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def radial_cutoff(self, R, rc):
"""Calculates radial cutoff matrix.
B = batch_size, N = max_num_atoms, M = max_num_neighbors
Parameters
----------
R [B, N, M]: tf.Tensor
Distance matrix.
rc: tf.Variable
Interaction cutoff [Angstrom].
Returns
-------
FC [B, N, M]: tf.Tensor
Radial cutoff matrix.
"""
T = 0.5 * (tf.cos(np.pi * R / (rc)) + 1)
E = tf.zeros_like(T)
cond = tf.less_equal(R, rc)
FC = tf.where(cond, T, E)
return FC
示例5: filter_outside_boxes
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def filter_outside_boxes(boxes, img_h, img_w):
'''
:param anchors:boxes with format [xmin, ymin, xmax, ymax]
:param img_h: height of image
:param img_w: width of image
:return: indices of anchors that inside the image boundary
'''
with tf.name_scope('filter_outside_boxes'):
xmin, ymin, xmax, ymax = tf.unstack(boxes, axis=1)
xmin_index = tf.greater_equal(xmin, 0)
ymin_index = tf.greater_equal(ymin, 0)
xmax_index = tf.less_equal(xmax, tf.cast(img_w, tf.float32))
ymax_index = tf.less_equal(ymax, tf.cast(img_h, tf.float32))
indices = tf.transpose(tf.stack([xmin_index, ymin_index, xmax_index, ymax_index]))
indices = tf.cast(indices, dtype=tf.int32)
indices = tf.reduce_sum(indices, axis=1)
indices = tf.where(tf.equal(indices, 4))
# indices = tf.equal(indices, 4)
return tf.reshape(indices, [-1])
示例6: get_histogram
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def get_histogram(img, bin_size=0.2):
hist_entries = []
img_r, img_g, img_b = tf.split(img, num_or_size_splits=3, axis=-1)
for img_chan in [img_r, img_g, img_b]:
for i in np.arange(-1, 1, bin_size):
gt = tf.greater(img_chan, i)
leq = tf.less_equal(img_chan, i + bin_size)
condition = tf.cast(tf.logical_and(gt, leq), tf.float32)
hist_entries.append(tf.reduce_sum(condition))
hist = normalization(hist_entries)
return hist
示例7: radial_cutoff
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def radial_cutoff(self, R, rc):
"""Calculates radial cutoff matrix.
B = batch_size, N = max_num_atoms, M = max_num_neighbors
Parameters
----------
R [B, N, M]: tf.Tensor
Distance matrix.
rc: tf.Variable
Interaction cutoff [Angstrom].
Returns
-------
FC [B, N, M]: tf.Tensor
Radial cutoff matrix.
"""
T = 0.5 * (tf.cos(np.pi * R / (rc)) + 1)
E = tf.zeros_like(T)
cond = tf.less_equal(R, rc)
FC = tf.where(cond, T, E)
return FC
示例8: get_batch_dataset
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def get_batch_dataset(record_file, parser, config):
num_threads = tf.constant(config.num_threads, dtype=tf.int32)
dataset = tf.data.TFRecordDataset(record_file).map(
parser, num_parallel_calls=num_threads).shuffle(config.capacity).repeat()
if config.is_bucket:
buckets = [tf.constant(num) for num in range(*config.bucket_range)]
def key_func(context_idxs, ques_idxs, context_char_idxs, ques_char_idxs, y1, y2, qa_id):
c_len = tf.reduce_sum(
tf.cast(tf.cast(context_idxs, tf.bool), tf.int32))
buckets_min = [np.iinfo(np.int32).min] + buckets
buckets_max = buckets + [np.iinfo(np.int32).max]
conditions_c = tf.logical_and(
tf.less(buckets_min, c_len), tf.less_equal(c_len, buckets_max))
bucket_id = tf.reduce_min(tf.where(conditions_c))
return bucket_id
def reduce_func(key, elements):
return elements.batch(config.batch_size)
dataset = dataset.apply(tf.contrib.data.group_by_window(
key_func, reduce_func, window_size=5 * config.batch_size)).shuffle(len(buckets) * 25)
else:
dataset = dataset.batch(config.batch_size)
return dataset
示例9: chk_pos_in_bounds
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def chk_pos_in_bounds(cls, input_seq, pos):
"""
Check the position is in-bounds with respect to the sequence.
Accepted range for 'position' is in [-n, n - 1], where n is the
number of tensors in 'input_sequence'.
:param input_seq: input sequence
:param pos: position of the output tensor
:return: True if position is in-bounds or input length is dynamic.
"""
seq_length = input_seq.shape[0]
if seq_length is None: return True
seq_length = tf.cast(seq_length, pos.dtype)
cond1 = tf.greater_equal(pos, tf.negative(seq_length))
cond2 = tf.less_equal(pos, seq_length - 1)
# pos >= -n and pos < n
return tf.reduce_all(tf.logical_and(cond1, cond2))
示例10: chk_pos_in_bounds
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def chk_pos_in_bounds(cls, input_seq, pos):
"""
Check the position is in-bounds with respect to the sequence.
Accepted range for 'position' is in [-n, n - 1], where n is the
number of tensors in 'input_sequence'.
:param input_seq: input sequence
:param pos: position of the output tensor
:return: True if position is in-bounds
"""
seq_length = tf.shape(input_seq.to_sparse(), out_type=pos.dtype)[0]
cond1 = tf.greater_equal(pos, tf.negative(seq_length))
cond2 = tf.less_equal(pos, seq_length - 1)
# pos >= -n and pos < n
return tf.reduce_all(tf.logical_and(cond1, cond2))
示例11: chk_pos_in_bounds
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def chk_pos_in_bounds(cls, input_seq, pos):
"""
Check the position is in-bounds with respect to the sequence.
Accepted range for 'position' is in [-n, n], where n is the
number of tensors in 'input_sequence'.
:param input_seq: input sequence
:param pos: position to insert the tensor
:return: True if position is in-bounds.
"""
seq_length = tf.shape(input_seq.to_sparse(), out_type=pos.dtype)[0]
cond1 = tf.greater_equal(pos, tf.negative(seq_length))
cond2 = tf.less_equal(pos, seq_length)
# pos >= -n and pos <= n
return tf.reduce_all(tf.logical_and(cond1, cond2))
示例12: read_from_disk
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def read_from_disk(self,queue):
index_t=queue[0]#tf.random_shuffle(self.input_list)[0]
index_min=tf.reshape(tf.where(tf.less_equal(self.node,index_t)),[-1])
node_min=self.node[index_min[-1]]
node_max=self.node[index_min[-1]+1]
interval_list=list(range(30,100))
interval=tf.random_shuffle(interval_list)[0]
index_d=[tf.cond(tf.greater(index_t-interval,node_min),lambda:index_t-interval,lambda:index_t+interval),tf.cond(tf.less(index_t+interval,node_max),lambda:index_t+interval,lambda:index_t-interval)]
index_d=tf.random_shuffle(index_d)
index_d=index_d[0]
constant_t=tf.read_file(self.img_list[index_t])
template=tf.image.decode_jpeg(constant_t, channels=3)
template=template[:,:,::-1]
constant_d=tf.read_file(self.img_list[index_d])
detection=tf.image.decode_jpeg(constant_d, channels=3)
detection=detection[:,:,::-1]
template_label=self.label_list[index_t]
detection_label=self.label_list[index_d]
template_p,template_label_p,_,_=self.crop_resize(template,template_label,1)
detection_p,detection_label_p,offset,ratio=self.crop_resize(detection,detection_label,2)
return template_p,template_label_p,detection_p,detection_label_p,offset,ratio,detection,detection_label,index_t,index_d
示例13: keep_for_training
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def keep_for_training(self, features, maximum_length=None):
"""Returns ``True`` if this example should be kept for training.
Args:
features: A dictionary of ``tf.Tensor``.
maximum_length: The maximum length used for training.
Returns:
A boolean.
"""
if isinstance(features, (list, tuple)):
# Special case for unsupervised inputters that always return a tuple (features, labels).
features = features[0]
length = self.get_length(features)
if length is None:
return True
is_valid = tf.greater(length, 0)
if maximum_length is not None:
is_valid = tf.logical_and(is_valid, tf.less_equal(length, maximum_length))
return is_valid
示例14: _prepare_image
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import less_equal [as 别名]
def _prepare_image(self, image):
"""Resize the image to a maximum height of `self.height` and maximum
width of `self.width` while maintaining the aspect ratio. Pad the
resized image to a fixed size of ``[self.height, self.width]``."""
img = tf.image.decode_png(image, channels=self.channels)
dims = tf.shape(img)
width = self.max_width
max_width = tf.to_int32(tf.ceil(tf.truediv(dims[1], dims[0]) * self.height_float))
max_height = tf.to_int32(tf.ceil(tf.truediv(width, max_width) * self.height_float))
resized = tf.cond(
tf.greater_equal(width, max_width),
lambda: tf.cond(
tf.less_equal(dims[0], self.height),
lambda: tf.to_float(img),
lambda: tf.image.resize_images(img, [self.height, max_width],
method=tf.image.ResizeMethod.BICUBIC),
),
lambda: tf.image.resize_images(img, [max_height, width],
method=tf.image.ResizeMethod.BICUBIC)
)
padded = tf.image.pad_to_bounding_box(resized, 0, 0, self.height, width)
return padded