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


Python util.KNNIdsWithDistances方法代码示例

本文整理汇总了Python中utils.util.KNNIdsWithDistances方法的典型用法代码示例。如果您正苦于以下问题:Python util.KNNIdsWithDistances方法的具体用法?Python util.KNNIdsWithDistances怎么用?Python util.KNNIdsWithDistances使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在utils.util的用法示例。


在下文中一共展示了util.KNNIdsWithDistances方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: compute_average_alignment

# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import KNNIdsWithDistances [as 别名]
def compute_average_alignment(
    seqname_to_embeddings, num_views, summary_writer, training_step):
  """Computes the average cross-view alignment for all sequence view pairs.

  Args:
    seqname_to_embeddings: Dict, mapping sequence name to a
      [num_views, embedding size] numpy matrix holding all embedded views.
    num_views: Int, number of simultaneous views in the dataset.
    summary_writer: A `SummaryWriter` object.
    training_step: Int, the training step of the model used to embed images.

  Alignment is the scaled absolute difference between the ground truth time
  and the knn aligned time.
  abs(|time_i - knn_time|) / sequence_length
  """
  all_alignments = []
  for _, view_embeddings in seqname_to_embeddings.iteritems():
    for idx_i in range(num_views):
      for idx_j in range(idx_i+1, num_views):
        embeddings_view_i = view_embeddings[idx_i]
        embeddings_view_j = view_embeddings[idx_j]

        seq_len = len(embeddings_view_i)

        times_i = np.array(range(seq_len))
        # Get the nearest time_index for each embedding in view_i.
        times_j = np.array([util.KNNIdsWithDistances(
            q, embeddings_view_j, k=1)[0][0] for q in embeddings_view_i])

        # Compute sequence view pair alignment.
        alignment = np.mean(
            np.abs(np.array(times_i)-np.array(times_j))/float(seq_len))
        all_alignments.append(alignment)
        print 'alignment so far %f' % alignment
  average_alignment = np.mean(all_alignments)
  print 'Average alignment %f' % average_alignment
  summ = tf.Summary(value=[tf.Summary.Value(
      tag='validation/alignment', simple_value=average_alignment)])
  summary_writer.add_summary(summ, int(training_step)) 
开发者ID:rky0930,项目名称:yolo_v2,代码行数:41,代码来源:alignment.py

示例2: compute_average_alignment

# 需要导入模块: from utils import util [as 别名]
# 或者: from utils.util import KNNIdsWithDistances [as 别名]
def compute_average_alignment(
    seqname_to_embeddings, num_views, summary_writer, training_step):
  """Computes the average cross-view alignment for all sequence view pairs.

  Args:
    seqname_to_embeddings: Dict, mapping sequence name to a
      [num_views, embedding size] numpy matrix holding all embedded views.
    num_views: Int, number of simultaneous views in the dataset.
    summary_writer: A `SummaryWriter` object.
    training_step: Int, the training step of the model used to embed images.

  Alignment is the scaled absolute difference between the ground truth time
  and the knn aligned time.
  abs(|time_i - knn_time|) / sequence_length
  """
  all_alignments = []
  for _, view_embeddings in seqname_to_embeddings.iteritems():
    for idx_i in range(num_views):
      for idx_j in range(idx_i+1, num_views):
        embeddings_view_i = view_embeddings[idx_i]
        embeddings_view_j = view_embeddings[idx_j]

        seq_len = len(embeddings_view_i)

        times_i = np.array(range(seq_len))
        # Get the nearest time_index for each embedding in view_i.
        times_j = np.array([util.KNNIdsWithDistances(
            q, embeddings_view_j, k=1)[0][0] for q in embeddings_view_i])

        # Compute sequence view pair alignment.
        alignment = np.mean(
            np.abs(np.array(times_i)-np.array(times_j))/float(seq_len))
        all_alignments.append(alignment)
        print('alignment so far %f' % alignment)
  average_alignment = np.mean(all_alignments)
  print('Average alignment %f' % average_alignment)
  summ = tf.Summary(value=[tf.Summary.Value(
      tag='validation/alignment', simple_value=average_alignment)])
  summary_writer.add_summary(summ, int(training_step)) 
开发者ID:itsamitgoel,项目名称:Gun-Detector,代码行数:41,代码来源:alignment.py


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