forked from aclapes/darwintree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
darwintree.py
executable file
·55 lines (38 loc) · 1.58 KB
/
darwintree.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
52
53
54
55
__author__ = 'aclapes'
from os.path import isfile, isdir, exists, join, splitext, basename, dirname
from os import makedirs
import cPickle
import time
import numpy as np
from videodarwin import darwin
INTERNAL_PARAMETERS = dict(
)
def darwin(fullfeatnames, st, num_videos, darwins_path):
if not exists(darwins_path):
makedirs(darwins_path)
for feat_t in fullfeatnames:
# node_darwins[feat_t] = dict()
if not exists(join(darwins_path, feat_t)):
makedirs(join(darwins_path, feat_t))
for featname in fullfeatnames[feat_t]:
output_filepath = join(darwins_path, feat_t, basename(featname))
if isfile(output_filepath):
print('%s -> OK' % (featname))
continue
start_time = time.time()
with open(featname, 'rb') as f:
data = cPickle.load(f)
# compute VD
node_darwins = dict()
node_darwins[1] = darwin(data['X'])
for id, X in data['tree_perframe'].iteritems():
node_darwins[id] = darwin(X)
# construct a list of edge pairs for easy access
with open(output_filepath, 'wb') as f:
cPickle.dump(dict(node_darwins=node_darwins), f)
elapsed_time = time.time() - start_time
print('%s -> DONE (in %.2f secs)' % (output_filepath, elapsed_time))
return None
# ==============================================================================
# Helper functions
# ==============================================================================