aboutsummaryrefslogtreecommitdiff
path: root/evaluate.py
blob: 6b8fc805f027f46b4145feb7231210ceb70f6d39 (plain)
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
#!/usr/bin/python
# EE4 Selected Topics From Computer Vision Coursework
# Vasil Zlatanov, Nunzio Pucci

DATA_FILE = 'data.npz'
CLUSTER_CNT = 256
KMEAN_PART = 33

import numpy as np
import matplotlib.pyplot as plt

from sklearn.cluster import KMeans

data = np.load(DATA_FILE)

train = data['desc_tr']

# Train part will contain 15 000 descriptors to generate KMeans
part_idx = np.random.randint(train.shape[1])

parts = []
for i in train[:, part_idx]:
    parts.append(i.T[300:1300])

train_part = np.vstack(parts)

print(train_part.shape)

kmeans = KMeans(n_clusters=CLUSTER_CNT, random_state=0).fit(train_part)

print("Generating histograms")

histogram = np.zeros((train.shape[0], train.shape[1],CLUSTER_CNT))

for i in range(train.shape[0]):
    for j in range(train.shape[1]):
        histogram[i][j] = np.bincount(kmeans.predict(train[i][j].T),minlength=CLUSTER_CNT)

print(histogram.shape)

plt.hist(histogram[1][5])
plt.show()
plt.hist(histogram[3][2])
plt.show()
plt.hist(histogram[7][8])
plt.show()