-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC_variance_check.py
52 lines (39 loc) · 1.51 KB
/
C_variance_check.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
47
48
49
50
51
import glob
from sklearn.preprocessing import MinMaxScaler
import pickle
from pipeline2 import *
import argparse
parser = argparse.ArgumentParser(description='C. BOW encoding')
parser.add_argument('--n_clust', required=False, default=15000, help="# of cluster centroid")
parser.add_argument('--model_path', required=False, default='/nfs_shared_/hkseok/cluster/K/resnet50-localfeature-150002.pkl')
parser.add_argument('--feature_path', required=False,
default='/nfs_shared_/hkseok/features_local/multiple/vcdb_core-1fps-resnet50_sum-5sec2',
help="source feature path")
args = parser.parse_args()
print(args)
N_cluster = int(args.n_clust)
kmeans = pickle.load(open(args.model_path, "rb"))
kmeans.verbose = False
feature_list = glob.glob(os.path.join(args.feature_path, '*'))
bins = [0] * N_cluster
for idx, feature in enumerate(feature_list):
videoname = os.path.basename(feature)
print(feature, idx)
local_features = torch.load(feature)
video_vector = []
for frame in local_features:
x = torch.cat(frame).numpy()
predict = kmeans.predict(x)
unique, counts = np.unique(predict, return_counts=True)
for uniq, cnts in zip(unique, counts):
bins[uniq] += cnts
print(bins)
name = '25000_again'
with open(f'{name}.pkl', 'wb') as fw:
pickle.dump(bins, fw)
import csv
with open(f'{name}.csv', 'w') as fw:
wr = csv.writer(fw)
wr.writerow(['bin', 'count'])
for idx, bin in enumerate(bins):
wr.writerow([idx, bin])