-
Notifications
You must be signed in to change notification settings - Fork 110
/
visualize.py
46 lines (34 loc) · 1.28 KB
/
visualize.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import tensorflow as tf
import numpy as np
import os
from keras import backend as K
from util import *
from constants import *
# Visualize using:
# http://projector.tensorflow.org/
def main():
models = build_or_load()
style_layer = models[0].get_layer('style')
print('Creating input')
style_in = tf.placeholder(tf.float32, shape=(NUM_STYLES, NUM_STYLES))
style_out = style_layer(style_in)
# All possible styles
all_styles = np.identity(NUM_STYLES)
with K.get_session() as sess:
embedding = sess.run(style_out, { style_in: all_styles })
print('Writing to out directory')
np.savetxt(os.path.join(OUT_DIR, 'style_embedding_vec.tsv'), embedding, delimiter='\t')
labels = [[g] * len(styles[i]) for i, g in enumerate(genre)]
# Flatten
labels = [y for x in labels for y in x]
# Retreive specific artists
styles_labels = [y for x in styles for y in x]
styles_labels = np.reshape(styles_labels, [-1, 1])
labels = np.reshape(labels, [-1, 1])
labels = np.hstack([labels, styles_labels])
# Add metadata header
header = ['Genre', 'Artist']
labels = np.vstack([header, labels])
np.savetxt(os.path.join(OUT_DIR, 'style_embedding_labels.tsv'), labels, delimiter='\t', fmt='%s')
if __name__ == '__main__':
main()