本文整理汇总了Python中tensorflow.floordiv方法的典型用法代码示例。如果您正苦于以下问题:Python tensorflow.floordiv方法的具体用法?Python tensorflow.floordiv怎么用?Python tensorflow.floordiv使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tensorflow
的用法示例。
在下文中一共展示了tensorflow.floordiv方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: int_to_bit
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def int_to_bit(x_int, num_bits, base=2):
"""Turn x_int representing numbers into a bitwise (lower-endian) tensor.
Args:
x_int: Tensor containing integer to be converted into base notation.
num_bits: Number of bits in the representation.
base: Base of the representation.
Returns:
Corresponding number expressed in base.
"""
x_l = tf.to_int32(tf.expand_dims(x_int, axis=-1))
x_labels = []
for i in range(num_bits):
x_labels.append(
tf.floormod(
tf.floordiv(tf.to_int32(x_l),
tf.to_int32(base)**i), tf.to_int32(base)))
res = tf.concat(x_labels, axis=-1)
return tf.to_float(res)
示例2: pad_image
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def pad_image(immy,down_factor = 256,dynamic=False):
"""
pad image with a proper number of 0 to prevent problem when concatenating after upconv
Args:
immy: metaop that produces an image
down_factor: downgrade resolution that should be respected before feeding the image to the network
dynamic: if dynamic is True use dynamic shape of immy, otherway use static shape
"""
if dynamic:
immy_shape = tf.shape(immy)
new_height = tf.where(tf.equal(immy_shape[-3]%down_factor,0),x=immy_shape[-3],y=(tf.floordiv(immy_shape[-3],down_factor)+1)*down_factor)
new_width = tf.where(tf.equal(immy_shape[-2]%down_factor,0),x=immy_shape[-2],y=(tf.floordiv(immy_shape[-2],down_factor)+1)*down_factor)
else:
immy_shape = immy.get_shape().as_list()
new_height = immy_shape[-3] if immy_shape[-3]%down_factor==0 else ((immy_shape[-3]//down_factor)+1)*down_factor
new_width = immy_shape[-2] if immy_shape[-2]%down_factor==0 else ((immy_shape[-2]//down_factor)+1)*down_factor
pad_height_left = (new_height-immy_shape[-3])//2
pad_height_right = (new_height-immy_shape[-3]+1)//2
pad_width_left = (new_width-immy_shape[-2])//2
pad_width_right = (new_width-immy_shape[-2]+1)//2
immy = tf.pad(immy,[[0,0],[pad_height_left,pad_height_right],[pad_width_left,pad_width_right],[0,0]],mode="REFLECT")
return immy
示例3: int_to_bit
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def int_to_bit(self, x_int, num_bits, base=2):
"""Turn x_int representing numbers into a bitwise (lower-endian) tensor.
Args:
x_int: Tensor containing integer to be converted into base
notation.
num_bits: Number of bits in the representation.
base: Base of the representation.
Returns:
Corresponding number expressed in base.
"""
x_l = tf.to_int32(tf.expand_dims(x_int, axis=-1))
# pylint: disable=g-complex-comprehension
x_labels = [
tf.floormod(
tf.floordiv(tf.to_int32(x_l),
tf.to_int32(base)**i), tf.to_int32(base))
for i in range(num_bits)]
res = tf.concat(x_labels, axis=-1)
return tf.to_float(res)
示例4: int_to_bit
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def int_to_bit(x_int, num_bits, base=2):
"""Turn x_int representing numbers into a bitwise (lower-endian) tensor.
Args:
x_int: Tensor containing integer to be converted into base notation.
num_bits: Number of bits in the representation.
base: Base of the representation.
Returns:
Corresponding number expressed in base.
"""
x_l = tf.to_int32(tf.expand_dims(x_int, axis=-1))
x_labels = [tf.floormod(
tf.floordiv(tf.to_int32(x_l), tf.to_int32(base)**i), tf.to_int32(base))
for i in range(num_bits)]
res = tf.concat(x_labels, axis=-1)
return tf.to_float(res)
示例5: int_to_bit
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def int_to_bit(self, x_int, num_bits, base=2):
"""Turn x_int representing numbers into a bitwise (lower-endian) tensor.
Args:
x_int: Tensor containing integer to be converted into base
notation.
num_bits: Number of bits in the representation.
base: Base of the representation.
Returns:
Corresponding number expressed in base.
"""
x_l = tf.to_int32(tf.expand_dims(x_int, axis=-1))
x_labels = []
for i in range(num_bits):
x_labels.append(
tf.floormod(
tf.floordiv(tf.to_int32(x_l),
tf.to_int32(base)**i), tf.to_int32(base)))
res = tf.concat(x_labels, axis=-1)
return tf.to_float(res)
示例6: testFloatBasic
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def testFloatBasic(self):
x = np.linspace(-5, 20, 15).reshape(1, 3, 5).astype(np.float32)
y = np.linspace(20, -5, 15).reshape(1, 3, 5).astype(np.float32)
self._compareBoth(x, y, np.add, tf.add, also_compare_variables=True)
self._compareBoth(x, y, np.subtract, tf.sub)
self._compareBoth(x, y, np.multiply, tf.mul)
self._compareBoth(x, y + 0.1, np.true_divide, tf.truediv)
self._compareBoth(x, y + 0.1, np.floor_divide, tf.floordiv)
self._compareBoth(x, y, np.add, _ADD)
self._compareBoth(x, y, np.subtract, _SUB)
self._compareBoth(x, y, np.multiply, _MUL)
self._compareBoth(x, y + 0.1, np.true_divide, _TRUEDIV)
self._compareBoth(x, y + 0.1, np.floor_divide, _FLOORDIV)
try:
from scipy import special # pylint: disable=g-import-not-at-top
a_pos_small = np.linspace(0.1, 2, 15).reshape(1, 3, 5).astype(np.float32)
x_pos_small = np.linspace(0.1, 10, 15).reshape(1, 3, 5).astype(np.float32)
self._compareBoth(a_pos_small, x_pos_small, special.gammainc, tf.igamma)
self._compareBoth(a_pos_small, x_pos_small, special.gammaincc, tf.igammac)
# Need x > 1
self._compareBoth(x_pos_small + 1, a_pos_small, special.zeta, tf.zeta)
n_small = np.arange(0, 15).reshape(1, 3, 5).astype(np.float32)
self._compareBoth(n_small, x_pos_small, special.polygamma, tf.polygamma)
except ImportError as e:
tf.logging.warn("Cannot test special functions: %s" % str(e))
示例7: testDoubleBasic
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def testDoubleBasic(self):
x = np.linspace(-5, 20, 15).reshape(1, 3, 5).astype(np.float64)
y = np.linspace(20, -5, 15).reshape(1, 3, 5).astype(np.float64)
self._compareBoth(x, y, np.add, tf.add)
self._compareBoth(x, y, np.subtract, tf.sub)
self._compareBoth(x, y, np.multiply, tf.mul)
self._compareBoth(x, y + 0.1, np.true_divide, tf.truediv)
self._compareBoth(x, y + 0.1, np.floor_divide, tf.floordiv)
self._compareBoth(x, y, np.add, _ADD)
self._compareBoth(x, y, np.subtract, _SUB)
self._compareBoth(x, y, np.multiply, _MUL)
self._compareBoth(x, y + 0.1, np.true_divide, _TRUEDIV)
self._compareBoth(x, y + 0.1, np.floor_divide, _FLOORDIV)
try:
from scipy import special # pylint: disable=g-import-not-at-top
a_pos_small = np.linspace(0.1, 2, 15).reshape(1, 3, 5).astype(np.float32)
x_pos_small = np.linspace(0.1, 10, 15).reshape(1, 3, 5).astype(np.float32)
self._compareBoth(a_pos_small, x_pos_small, special.gammainc, tf.igamma)
self._compareBoth(a_pos_small, x_pos_small, special.gammaincc, tf.igammac)
except ImportError as e:
tf.logging.warn("Cannot test special functions: %s" % str(e))
示例8: testInt32Basic
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def testInt32Basic(self):
x = np.arange(1, 13, 2).reshape(1, 3, 2).astype(np.int32)
y = np.arange(1, 7, 1).reshape(1, 3, 2).astype(np.int32)
self._compareBoth(x, y, np.add, tf.add)
self._compareBoth(x, y, np.subtract, tf.sub)
self._compareBoth(x, y, np.multiply, tf.mul)
self._compareBoth(x, y, np.true_divide, tf.truediv)
self._compareBoth(x, y, np.floor_divide, tf.floordiv)
self._compareBoth(x, y, np.mod, tf.mod)
self._compareBoth(x, y, np.add, _ADD)
self._compareBoth(x, y, np.subtract, _SUB)
self._compareBoth(x, y, np.multiply, _MUL)
self._compareBoth(x, y, np.true_divide, _TRUEDIV)
self._compareBoth(x, y, np.floor_divide, _FLOORDIV)
self._compareBoth(x, y, np.mod, _MOD)
# _compareBoth tests on GPU only for floating point types, so test
# _MOD for int32 on GPU by calling _compareGpu
self._compareGpu(x, y, np.mod, _MOD)
示例9: _compareBCast
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def _compareBCast(self, xs, ys, dtype, np_func, tf_func):
if dtype in (np.complex64, np.complex128):
x = (1 + np.linspace(0, 2 + 3j, np.prod(xs))).astype(dtype).reshape(xs)
y = (1 + np.linspace(0, 2 - 2j, np.prod(ys))).astype(dtype).reshape(ys)
else:
x = (1 + np.linspace(0, 5, np.prod(xs))).astype(dtype).reshape(xs)
y = (1 + np.linspace(0, 5, np.prod(ys))).astype(dtype).reshape(ys)
self._compareCpu(x, y, np_func, tf_func)
if x.dtype in (np.float16, np.float32, np.float64, np.complex64,
np.complex128):
if tf_func not in (_FLOORDIV, tf.floordiv):
if x.dtype == np.float16:
# Compare fp16 theoretical gradients to fp32 numerical gradients,
# since fp16 numerical gradients are too imprecise unless great
# care is taken with choosing the inputs and the delta. This is
# a weaker check (in particular, it does not test the op itself,
# only its gradient), but it's much better than nothing.
self._compareGradientX(x, y, np_func, tf_func, np.float)
self._compareGradientY(x, y, np_func, tf_func, np.float)
else:
self._compareGradientX(x, y, np_func, tf_func)
self._compareGradientY(x, y, np_func, tf_func)
self._compareGpu(x, y, np_func, tf_func)
# TODO(josh11b,vrv): Refactor this to use parameterized tests.
示例10: _testBCastByFunc
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def _testBCastByFunc(self, funcs, xs, ys):
dtypes = [
np.float16,
np.float32,
np.float64,
np.int32,
np.int64,
np.complex64,
np.complex128,
]
for dtype in dtypes:
for (np_func, tf_func) in funcs:
if (dtype in (np.complex64, np.complex128) and
tf_func in (_FLOORDIV, tf.floordiv)):
continue # floordiv makes no sense for complex numbers
self._compareBCast(xs, ys, dtype, np_func, tf_func)
self._compareBCast(ys, xs, dtype, np_func, tf_func)
示例11: sample
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def sample(self, logits, time):
rl_time_steps = tf.floordiv(tf.maximum(self.global_step_tensor -
self.burn_in_step, 0),
self.increment_step)
start_rl_step = self.sequence_length - rl_time_steps
next_input_ids = tf.cond(
tf.greater_equal(time, self.max_sequence_length),
lambda: tf.tile([self.eos_id], [self.batch_size]),
lambda: self._input_tas.read(time))
next_predicted_ids = tf.squeeze(tf.multinomial(logits, 1), axis=[-1])
mask = tf.to_int32(time >= start_rl_step)
return (1 - mask) * tf.to_int32(next_input_ids) + mask * tf.to_int32(
next_predicted_ids)
示例12: int_to_bit
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def int_to_bit(self, x_int, num_bits, base=2):
"""Turn x_int representing numbers into a bitwise (lower-endian)
tensor.
Args:
x_int: Tensor containing integer to be converted into base
notation.
num_bits: Number of bits in the representation.
base: Base of the representation.
Returns:
Corresponding number expressed in base.
"""
x_l = tf.to_int32(tf.expand_dims(x_int, axis=-1))
x_labels = []
for i in range(num_bits):
x_labels.append(
tf.floormod(
tf.floordiv(tf.to_int32(x_l),
tf.to_int32(base) ** i), tf.to_int32(base)))
res = tf.concat(x_labels, axis=-1)
return tf.to_float(res)
示例13: pyramidal_stack
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def pyramidal_stack(outputs, sequence_length):
shape = tf.shape(outputs)
batch_size, max_time = shape[0], shape[1]
num_units = outputs.get_shape().as_list()[-1]
paddings = [[0, 0], [0, tf.floormod(max_time, 2)], [0, 0]]
outputs = tf.pad(outputs, paddings)
'''
even_time = outputs[:, ::2, :]
odd_time = outputs[:, 1::2, :]
concat_outputs = tf.concat([even_time, odd_time], -1)
'''
concat_outputs = tf.reshape(outputs, (batch_size, -1, num_units * 2))
return concat_outputs, tf.floordiv(sequence_length, 2) + tf.floormod(sequence_length, 2)
示例14: initTowerBatch
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def initTowerBatch(self, towerI, towersNum, dataSize):
towerBatchSize = tf.floordiv(dataSize, towersNum)
start = towerI * towerBatchSize
end = (towerI + 1) * towerBatchSize if towerI < towersNum - 1 else dataSize
self.questionsIndices = self.questionsIndicesAll[start:end]
self.questionLengths = self.questionLengthsAll[start:end]
self.images = self.imagesAll[start:end]
self.answersIndices = self.answersIndicesAll[start:end]
self.batchSize = end - start
示例15: __floordiv__
# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def __floordiv__(self, other):
return tf.floordiv(self, other)