當前位置: 首頁>>代碼示例>>Python>>正文


Python nn_ops.top_k方法代碼示例

本文整理匯總了Python中tensorflow.python.ops.nn_ops.top_k方法的典型用法代碼示例。如果您正苦於以下問題:Python nn_ops.top_k方法的具體用法?Python nn_ops.top_k怎麽用?Python nn_ops.top_k使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tensorflow.python.ops.nn_ops的用法示例。


在下文中一共展示了nn_ops.top_k方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _sort_tensor

# 需要導入模塊: from tensorflow.python.ops import nn_ops [as 別名]
# 或者: from tensorflow.python.ops.nn_ops import top_k [as 別名]
def _sort_tensor(tensor):
  """Use `top_k` to sort a `Tensor` along the last dimension."""
  sorted_, _ = nn_ops.top_k(tensor, k=array_ops.shape(tensor)[-1])
  return sorted_ 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:6,代碼來源:sample_stats.py

示例2: get_best

# 需要導入模塊: from tensorflow.python.ops import nn_ops [as 別名]
# 或者: from tensorflow.python.ops.nn_ops import top_k [as 別名]
def get_best(self, n):
    """Return the indices and values of the n highest scores in the TopN."""

    def refresh_shortlist():
      """Update the shortlist with the highest scores in id_to_score."""
      new_scores, new_ids = nn_ops.top_k(self.id_to_score, self.shortlist_size)
      smallest_new_score = math_ops.reduce_min(new_scores)
      new_length = math_ops.reduce_sum(
          math_ops.to_int32(math_ops.greater(new_scores, dtypes.float32.min)))
      u1 = self.sl_ids.assign(
          math_ops.to_int64(array_ops.concat([[new_length], new_ids], 0)))
      u2 = self.sl_scores.assign(
          array_ops.concat([[smallest_new_score], new_scores], 0))
      self.last_ops = [u1, u2]
      return control_flow_ops.group(u1, u2)

    # We only need to refresh the shortlist if n is greater than the
    # current shortlist size (which is stored in sl_ids[0]).
    with ops.control_dependencies(self.last_ops):
      cond_op = control_flow_ops.cond(n > self.sl_ids[0], refresh_shortlist,
                                      control_flow_ops.no_op)
      with ops.control_dependencies([cond_op]):
        topk_values, topk_indices = nn_ops.top_k(
            self.sl_scores,
            math_ops.minimum(n, math_ops.to_int32(self.sl_ids[0])))
        # topk_indices are the indices into the shortlist, we want to return
        # the indices into id_to_score
        gathered_indices = array_ops.gather(self.sl_ids, topk_indices)
        return gathered_indices, topk_values 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:31,代碼來源:topn.py

示例3: _test_topk

# 需要導入模塊: from tensorflow.python.ops import nn_ops [as 別名]
# 或者: from tensorflow.python.ops.nn_ops import top_k [as 別名]
def _test_topk(in_shape, k=1):
    """ One iteration of TOPK """
    data = np.random.uniform(size=in_shape).astype('float32')
    with tf.Graph().as_default():
        in_data = array_ops.placeholder(shape=data.shape, dtype=data.dtype)
        out = nn_ops.top_k(in_data, k, name='TopK')
        compare_tflite_with_tvm(data, 'Placeholder:0', [in_data], [out[0]]) 
開發者ID:apache,項目名稱:incubator-tvm,代碼行數:9,代碼來源:test_forward.py


注:本文中的tensorflow.python.ops.nn_ops.top_k方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。