clustering.py 文件源码

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

项目:SnapStitch 作者: avikj 项目源码 文件源码
def get_clusters_for_project(project_id, video_names):
  embs = []
  filenames = []
  for video_name in video_names:
    filename_to_embedding = pickle.load(open(os.path.join('temp', project_id, video_name, 'filename_to_emb.pkl'))) # TODO: call get_inception_embeddings on frame dir, but for now just use the pickle
    for filename, embedding in filename_to_embedding.iteritems():
      embs.append(embedding)
      filenames.append(filename)
  labels = cluster(embs, eps=12, min_pts=3)
  d = {}
  for video_name in video_names:
    d[video_name] = {}
  for i in range(len(filenames)):
    video_name = video_name_from_filename(filenames[i])
    d[video_name][filenames[i]] = labels[i]
  with open(os.path.join('temp', project_id, 'filename_to_clust.pkl'), 'w') as pickle_file:
    pickle.dump(d, pickle_file)
  for video_name in d:
    for filename in d[video_name]:
      mkdir_p(os.path.join('temp', project_id, 'clusters', str(d[video_name][filename])))
      copy(filename, os.path.join('temp', project_id, 'clusters', str(d[video_name][filename]), os.path.basename(filename)))
  '''filenames = [filename[filename.rindex('/')+1:] for filename in filenames]
  embs = np.array(embs)
  candidates = [(11, 6)]
  candidates = [(eps, min_pts) for eps in range(7, 15) for min_pts in range(2, 10)]'''
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号