-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtsne.py
More file actions
46 lines (35 loc) · 1.36 KB
/
tsne.py
File metadata and controls
46 lines (35 loc) · 1.36 KB
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 numpy as np
from numpy import array
from matplotlib import pyplot as plt
from sklearn.manifold import TSNE
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
# from tsne import bh_sne
# X = np.load('./extracted_features/test_sv180_img_feat.npy')
X_img = np.load('./extracted_features/ModelNet40-test-2_cm_sv180_img_feat.npy')
X_pt = np.load('./extracted_features/ModelNet40-test-2_cm_sv180_cloud_feat.npy')
y = np.load('./extracted_features/ModelNet40-test-2_cm_sv180_label.npy')
# tsne = TSNE(n_components=2, random_state=0)
tsne = TSNE(n_components=2, perplexity=15, learning_rate=10)
X_img_2d = tsne.fit_transform(X_img)
X_pt_2d = tsne.fit_transform(X_pt)
target_ids = range(len(y))
# plt.figure(figsize=(6, 12))
fig, (ax1, ax2) = plt.subplots(1,2)
fig.suptitle('Image Features and Point Cloud Features')
cmap = plt.get_cmap('gnuplot')
colors = [cmap(i) for i in np.linspace(0, 1, 40)]
print(len(colors))
print(len(colors))
print(len(colors))
print(len(colors))
print(len(colors))
print(len(colors))
print(len(colors))
colors = ['red', 'blue', 'navy', 'green', 'violet', 'brown', 'gold', 'lime', 'teal', 'olive']
# c=np.random.rand(1,3)
for i in target_ids:
if i<10:
ax1.scatter(X_img_2d[y == i, 0], X_img_2d[y == i, 1], c=colors[i])
ax2.scatter(X_pt_2d[y == i, 0], X_pt_2d[y == i, 1], c=colors[i])
plt.show()