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


Python tensorflow.ceil方法代码示例

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

示例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 
开发者ID:artyompal,项目名称:tpu_models,代码行数:21,代码来源:heads.py

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

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

示例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 
开发者ID:TropComplique,项目名称:FaceBoxes-tensorflow,代码行数:22,代码来源:detector.py

示例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))) 
开发者ID:llSourcell,项目名称:AI_For_Music_Composition,代码行数:26,代码来源:ops.py

示例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 
开发者ID:nywang16,项目名称:Pixel2Mesh,代码行数:26,代码来源:layers.py

示例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 
开发者ID:BertMoons,项目名称:QuantizedNeuralNetworks-Keras-Tensorflow,代码行数:21,代码来源:quantized_ops.py

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

示例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)) 
开发者ID:UKPLab,项目名称:iwcs2017-answer-selection,代码行数:10,代码来源:pooling_helper.py

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

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

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

示例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))) 
开发者ID:ULTR-Community,项目名称:ULTRA,代码行数:13,代码来源:pairwise_debias.py

示例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) 
开发者ID:ufal,项目名称:neuralmonkey,代码行数:14,代码来源:sentence_cnn_encoder.py


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