当前位置: 首页>>代码示例>>Python>>正文


Python tensorflow.floordiv方法代码示例

本文整理汇总了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) 
开发者ID:akzaidi,项目名称:fine-lm,代码行数:22,代码来源:discretization.py

示例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 
开发者ID:CVLAB-Unibo,项目名称:Learning2AdaptForStereo,代码行数:25,代码来源:preprocessing.py

示例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) 
开发者ID:yyht,项目名称:BERT,代码行数:23,代码来源:vq_discrete.py

示例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) 
开发者ID:yyht,项目名称:BERT,代码行数:19,代码来源:discretization.py

示例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) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:23,代码来源:vq_discrete.py

示例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)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:cwise_ops_test.py

示例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)) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:23,代码来源:cwise_ops_test.py

示例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) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:20,代码来源:cwise_ops_test.py

示例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. 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:27,代码来源:cwise_ops_test.py

示例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) 
开发者ID:tobegit3hub,项目名称:deep_image_model,代码行数:19,代码来源:cwise_ops_test.py

示例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) 
开发者ID:SwordYork,项目名称:sequencing,代码行数:18,代码来源:feedback.py

示例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) 
开发者ID:brain-research,项目名称:acai,代码行数:25,代码来源:discretization.py

示例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) 
开发者ID:WindQAQ,项目名称:listen-attend-and-spell,代码行数:19,代码来源:ops.py

示例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 
开发者ID:stanfordnlp,项目名称:mac-network,代码行数:13,代码来源:model.py

示例15: __floordiv__

# 需要导入模块: import tensorflow [as 别名]
# 或者: from tensorflow import floordiv [as 别名]
def __floordiv__(self, other):
        return tf.floordiv(self, other) 
开发者ID:thu-ml,项目名称:zhusuan,代码行数:4,代码来源:utils.py


注:本文中的tensorflow.floordiv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。