本文整理汇总了Python中tensorflow.ceil方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.ceil方法的具体用法?Python tensorflow.ceil怎么用?Python tensorflow.ceil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.ceil方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: bi_linear_sample
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def bi_linear_sample(self, img_feat, n, x, y):
x1 = tf.floor(x)
x2 = tf.ceil(x)
y1 = tf.floor(y)
y2 = tf.ceil(y)
Q11 = tf.gather_nd(img_feat, tf.stack([n, tf.cast(x1, tf.int32), tf.cast(y1, tf.int32)], 1))
Q12 = tf.gather_nd(img_feat, tf.stack([n, tf.cast(x1, tf.int32), tf.cast(y2, tf.int32)], 1))
Q21 = tf.gather_nd(img_feat, tf.stack([n, tf.cast(x2, tf.int32), tf.cast(y1, tf.int32)], 1))
Q22 = tf.gather_nd(img_feat, tf.stack([n, tf.cast(x2, tf.int32), tf.cast(y2, tf.int32)], 1))
weights = tf.multiply(tf.subtract(x2, x), tf.subtract(y2, y))
Q11 = tf.multiply(tf.expand_dims(weights, 1), Q11)
weights = tf.multiply(tf.subtract(x, x1), tf.subtract(y2, y))
Q21 = tf.multiply(tf.expand_dims(weights, 1), Q21)
weights = tf.multiply(tf.subtract(x2, x), tf.subtract(y, y1))
Q12 = tf.multiply(tf.expand_dims(weights, 1), Q12)
weights = tf.multiply(tf.subtract(x, x1), tf.subtract(y, y1))
Q22 = tf.multiply(tf.expand_dims(weights, 1), Q22)
outputs = tf.add_n([Q11, Q21, Q12, Q22])
return outputs
示例2: _compute_box_levels
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def _compute_box_levels(self, boxes):
"""Compute the box FPN levels.
Args:
boxes: a float tensor of shape [batch_size, num_instances, 4].
Returns:
levels: a int tensor of shape [batch_size, num_instances].
"""
object_sizes = tf.stack([
boxes[:, :, 2] - boxes[:, :, 0],
boxes[:, :, 3] - boxes[:, :, 1],
], axis=2)
object_sizes = tf.reduce_max(object_sizes, axis=2)
ratios = object_sizes / self._mask_crop_size
levels = tf.ceil(tf.log(ratios) / tf.log(2.))
levels = tf.maximum(tf.minimum(levels, self._max_mask_level),
self._min_mask_level)
return levels
示例3: testProbAndGradGivesFiniteResultsForCommonEvents
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def testProbAndGradGivesFiniteResultsForCommonEvents(self):
with self.test_session():
mu = tf.Variable(0.0, name="mu")
sigma = tf.Variable(1.0, name="sigma")
qdist = distributions.QuantizedDistribution(
distribution=distributions.Normal(mu=mu, sigma=sigma))
x = tf.ceil(4 * rng.rand(100).astype(np.float32) - 2)
tf.global_variables_initializer().run()
proba = qdist.prob(x)
self._assert_all_finite(proba.eval())
grads = tf.gradients(proba, [mu, sigma])
self._assert_all_finite(grads[0].eval())
self._assert_all_finite(grads[1].eval())
示例4: hough_lines
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def hough_lines(image, thetas):
"""Hough transform of a boolean image.
Args:
image: The image. 2D boolean tensor. Should be sparse (mostly Falses).
thetas: 1D float32 tensor of possible angles from the vertical for the line.
Returns:
The Hough space for the image. Shape `(num_theta, num_rho)`, where `num_rho`
is `sqrt(height**2 + width**2)`.
"""
coords = tf.cast(tf.where(image), thetas.dtype)
rho = tf.cast(
# x cos theta + y sin theta
tf.expand_dims(coords[:, 1], 0) * tf.cos(thetas)[:, None] +
tf.expand_dims(coords[:, 0], 0) * tf.sin(thetas)[:, None],
tf.int32)
height = tf.cast(tf.shape(image)[0], tf.float64)
width = tf.cast(tf.shape(image)[1], tf.float64)
num_rho = tf.cast(tf.ceil(tf.sqrt(height * height + width * width)), tf.int32)
hough_bins = _bincount_2d(rho, num_rho)
return hough_bins
示例5: _add_scalewise_summaries
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def _add_scalewise_summaries(self, tensor, name, percent=0.2):
"""Adds histograms of the biggest 20 percent of
tensor's values for each scale (feature map).
Arguments:
tensor: a float tensor with shape [batch_size, num_anchors].
name: a string.
percent: a float number, default value is 20%.
"""
index = 0
for i, n in enumerate(self.num_anchors_per_feature_map):
k = tf.ceil(tf.to_float(n) * percent)
k = tf.to_int32(k)
biggest_values, _ = tf.nn.top_k(tensor[:, index:(index + n)], k, sorted=False)
# it has shape [batch_size, k]
tf.summary.histogram(
name + '_on_scale_' + str(i),
tf.reduce_mean(biggest_values, axis=0)
)
index += n
示例6: binary_stochastic_REINFORCE
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def binary_stochastic_REINFORCE(x, loss_op_name="loss_by_example"):
"""
Sigmoid followed by a random sample from a bernoulli distribution
according to the result (binary stochastic neuron). Uses the REINFORCE
estimator. See https://arxiv.org/abs/1308.3432.
NOTE: Requires a loss operation with name matching the argument for
loss_op_name in the graph. This loss operation should be broken out by
example (i.e., not a single number for the entire batch).
"""
g = tf.get_default_graph()
with ops.name_scope("BinaryStochasticREINFORCE"):
with g.gradient_override_map({"Sigmoid": "BinaryStochastic_REINFORCE",
"Ceil": "Identity"}):
p = tf.sigmoid(x)
reinforce_collection = g.get_collection("REINFORCE")
if not reinforce_collection:
g.add_to_collection("REINFORCE", {})
reinforce_collection = g.get_collection("REINFORCE")
reinforce_collection[0][p.op.name] = loss_op_name
return tf.ceil(p - tf.random_uniform(tf.shape(x)))
示例7: project
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def project(img_feat, x, y, dim):
x1 = tf.floor(x)
x2 = tf.ceil(x)
y1 = tf.floor(y)
y2 = tf.ceil(y)
Q11 = tf.gather_nd(img_feat, tf.stack([tf.cast(x1,tf.int32), tf.cast(y1,tf.int32)],1))
Q12 = tf.gather_nd(img_feat, tf.stack([tf.cast(x1,tf.int32), tf.cast(y2,tf.int32)],1))
Q21 = tf.gather_nd(img_feat, tf.stack([tf.cast(x2,tf.int32), tf.cast(y1,tf.int32)],1))
Q22 = tf.gather_nd(img_feat, tf.stack([tf.cast(x2,tf.int32), tf.cast(y2,tf.int32)],1))
weights = tf.multiply(tf.subtract(x2,x), tf.subtract(y2,y))
Q11 = tf.multiply(tf.tile(tf.reshape(weights,[-1,1]),[1,dim]), Q11)
weights = tf.multiply(tf.subtract(x,x1), tf.subtract(y2,y))
Q21 = tf.multiply(tf.tile(tf.reshape(weights,[-1,1]),[1,dim]), Q21)
weights = tf.multiply(tf.subtract(x2,x), tf.subtract(y,y1))
Q12 = tf.multiply(tf.tile(tf.reshape(weights,[-1,1]),[1,dim]), Q12)
weights = tf.multiply(tf.subtract(x,x1), tf.subtract(y,y1))
Q22 = tf.multiply(tf.tile(tf.reshape(weights,[-1,1]),[1,dim]), Q22)
outputs = tf.add_n([Q11, Q21, Q12, Q22])
return outputs
示例8: quantized_maxrelu
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def quantized_maxrelu(W, nb=16):
'''The weights' binarization function,
# Reference:
- [QuantizedNet: Training Deep Neural Networks with Weights and Activations Constrained to +1 or -1, Courbariaux et al. 2016](http://arxiv.org/abs/1602.02830}
'''
non_sign_bits = nb-1
max_ = tf.reduce_max((W))
#max_ = tf.Print(max_,[max_])
max__ = tf.pow(2.0,tf.ceil(tf.log(max_)/tf.log(tf.cast(tf.convert_to_tensor(2.0), W.dtype.base_dtype))))
#max__ = tf.Print(max__,[max__])
m = pow(2,non_sign_bits)
#W = tf.Print(W,[W],summarize=20)
Wq = max__*clip_through(round_through(W/max__*(m)),0,m-1)/(m)
#Wq = tf.Print(Wq,[Wq],summarize=20)
return Wq
示例9: _update_lipschitz
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def _update_lipschitz(self,v,i):
config = self.config
if len(v.shape) > 1:
k = self.config.weight_constraint_k or 100.0000
wi_hat = v
if len(v.shape) == 4:
#fij = tf.reduce_sum(tf.abs(wi_hat), axis=[0,1])
fij = wi_hat
fij = tf.reduce_sum(tf.abs(fij), axis=[1])
fij = tf.reduce_max(fij, axis=[0])
else:
fij = wi_hat
if self.config.ortho_pnorm == "inf":
wp = tf.reduce_max(tf.reduce_sum(tf.abs(fij), axis=0), axis=0)
else:
# conv
wp = tf.reduce_max(tf.reduce_sum(tf.abs(fij), axis=1), axis=0)
ratio = (1.0/tf.maximum(1.0, wp/k))
if self.config.weight_bounce:
bounce = tf.minimum(1.0, tf.ceil(wp/k-0.999))
ratio -= tf.maximum(0.0, bounce) * 0.2
if self.config.weight_scaleup:
up = tf.minimum(1.0, tf.ceil(0.02-wp/k))
ratio += tf.maximum(0.0, up) * k/wp * 0.2
wi = ratio*(wi_hat)
#self.gan.metrics['wi'+str(i)]=wp
#self.gan.metrics['wk'+str(i)]=ratio
#self.gan.metrics['bouce'+str(i)]=bounce
return tf.assign(v, wi)
return None
示例10: non_zero_tokens
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def non_zero_tokens(tokens):
"""Receives a vector of tokens (float) which are zero-padded. Returns a vector of the same size, which has the value
1.0 in positions with actual tokens and 0.0 in positions with zero-padding.
:param tokens:
:return:
"""
return tf.ceil(tokens / tf.reduce_max(tokens, [1], keep_dims=True))
示例11: test_Ceil
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def test_Ceil(self):
t = tf.ceil(self.random(4, 3) - 0.5)
self.check(t)
示例12: test_forward_ceil
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def test_forward_ceil():
ishape = (1, 3, 10, 10)
inp_array = np.random.uniform(size=ishape).astype(np.float32)
with tf.Graph().as_default():
in1 = tf.placeholder(shape=inp_array.shape, dtype=inp_array.dtype)
tf.ceil(in1)
compare_tf_with_tvm(inp_array, 'Placeholder:0', 'Ceil:0')
示例13: _compare
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def _compare(self, x, use_gpu):
np_floor, np_ceil = np.floor(x), np.ceil(x)
with self.test_session(use_gpu=use_gpu) as sess:
inx = tf.convert_to_tensor(x)
ofloor, oceil = tf.floor(inx), tf.ceil(inx)
tf_floor, tf_ceil = sess.run([ofloor, oceil])
self.assertAllEqual(np_floor, tf_floor)
self.assertAllEqual(np_ceil, tf_ceil)
self.assertShapeEqual(np_floor, ofloor)
self.assertShapeEqual(np_ceil, oceil)
示例14: get_bernoulli_sample
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def get_bernoulli_sample(probs):
"""Conduct Bernoulli sampling according to a specific probability distribution.
Args:
prob: (tf.Tensor) A tensor in which each element denotes a probability of 1 in a Bernoulli distribution.
Returns:
A Tensor of binary samples (0 or 1) with the same shape of probs.
"""
return tf.ceil(probs - tf.random_uniform(tf.shape(probs)))
示例15: bidirectional_rnn
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import ceil [as 别名]
def bidirectional_rnn(self) -> Tuple[Tuple[tf.Tensor, tf.Tensor],
Tuple[tf.Tensor, tf.Tensor]]:
# BiRNN Network
fw_cell, bw_cell = self.rnn_cells() # type: RNNCellTuple
seq_lens = tf.ceil(tf.divide(
self.input_sequence.lengths,
self.segment_size))
seq_lens = tf.cast(seq_lens, tf.int32)
return tf.nn.bidirectional_dynamic_rnn(
fw_cell, bw_cell, self.highway_layer,
sequence_length=seq_lens,
dtype=tf.float32)