def compute_nearest_neighbors(self, num_neighbors):
result_list = []
for key, value in self.im2index.iteritems():
neighbor_list = [key]
similarity_scores = self.similarity_mat[value]
# removes best match as same as key
ind = np.argpartition(similarity_scores, -(num_neighbors + 1))[-(num_neighbors + 1):-1]
ind = ind[np.argsort(similarity_scores[ind])]
neighbors = [self.index2im[x] for x in ind]
neighbor_list.extend(neighbors)
result_list.append(neighbor_list)
# compute neighbor statistics
NearestNeighbour.compute_neighbor_stats(result_list, num_neighbors)
# plot the TSNE plot
self.plot_tsne()
return result_list
评论列表
文章目录