visualize_embeddings_tsne.py 文件源码

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

项目:laughter 作者: ganesh-srinivas 项目源码 文件源码
def main():
    audio_embeddings_dict = cPickle.load(open(AUDIO_EMBEDDINGS_DICT, 'rb'))
    audio_label_indices_dict = cPickle.load(open(AUDIO_LABEL_INDICES_DICT, 'rb'))

    X = []
    ids = []
    for k in audio_embeddings_dict.keys()[:EXAMPLES_SIZE_LIMIT]:
       for embedding in audio_embeddings_dict[k]:
           X.append(embedding) 
           ids.append(audio_label_indices_dict[k])

    # Apply t-SNE
    tsne = TSNE(n_components=N_COMPONENTS, perplexity=PERPLEXITY, \
                learning_rate=LEARNING_RATE, n_iter=N_ITER)
    Xtransformed = tsne.fit_transform(X)

    # save the embeddings along with the list of class IDs associated with
    # the clip from which it was taken.

    # Header for output file
    if N_COMPONENTS == 2:
        output_lines = ["dim1,dim2,labels"]
    elif N_COMPONENTS == 3:
        output_lines = ["dim1,dim2,dim3,labels"]

    for i in range(len(Xtransformed)):
        output_lines.append(",".join([str(j) for j in Xtransformed[i]])+ \
                            "," + ",".join([str(k) for k in ids[i]]))

    output_file_contents = "\n".join(output_lines) 
    with open(OUTPUT_FILENAME, 'w') as fh:
        fh.write(output_file_contents)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号