data_manager.py 文件源码

python
阅读 34 收藏 0 点赞 0 评论 0

项目:deepmodels 作者: learningsociety 项目源码 文件源码
def form_set_data(labels, max_num, verbose=False):
  """Generate label sets from sample labels.

  For each sample, generate a set by random sampling within the same class.
  Set is a tensor
  """
  # group sample ids based on label.
  label_ids = {}
  for idx in range(labels.size):
    if labels[idx] not in label_ids:
      label_ids[labels[idx]] = []
    label_ids[labels[idx]].append(idx)
  set_ids = {}
  for idx in range(labels.size):
    samp_ids = label_ids[labels[idx]][:]
    samp_num = min(max_num, len(samp_ids))
    set_ids[idx] = rand.sample(samp_ids, samp_num)
    if verbose:
      print "set {} formed.".format(idx)
  return set_ids
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号