-
Notifications
You must be signed in to change notification settings - Fork 5
/
create_h5.py
84 lines (54 loc) · 1.66 KB
/
create_h5.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os, math
import tables
from array import *
import numpy as np
MAX_POINTS_NUM = 11888319
KEYS_DIR = './data/FlickrLogos-v2/keys_train/' #Folder contains key files
OUTPUT_FILE = 'pnts_float_rootsift.h5' #Output file name
my_list = []
myc_array = np.empty([MAX_POINTS_NUM, 128],'f4')
count_dir=-1
points_count=0;
for dirName, subdirList, fileList in os.walk(KEYS_DIR):
#print('Found directory: %s' % dirName)
count_dir += 1
# print dirName
if dirName != KEYS_DIR:
count_file=0
for fname in fileList:
count_file += 1
#print dirName+"/"+fname
f = open(dirName+"/"+fname,'r')
ignore_first=0
del my_list[:]
flag=0
for line in f:
if ignore_first==0: # ignore first line of key file which contains size of image
ignore_first += 1
continue;
else:
#print line[0:-1]
my_list.append([float(x) for x in line.split()[5:]]) # we start from 6th since the first 5 contains x, y, angle, scale and octave
for i in range(0, len(my_list)):
if (MAX_POINTS_NUM - points_count) != 0:
for j in range(0,128):
myc_array[points_count][j] = my_list[i][j]
points_count += 1
else:
flag=1
break
if flag==1:
break
print str(count_dir)+" : "+dirName+"\t"+str(count_file)+" : "+fname
f.close()
if len(subdirList) > 0:
del subdirList[:]
print "Wrting list of "+str(count_file)+" files to array ...."
print "Num Points written to array : "+str(points_count)
#print myc_array[0]
print "Writing data to file ...."
pnts_fobj = tables.open_file(OUTPUT_FILE,'w')
pnts_fobj.create_array(pnts_fobj.root, 'pnts', myc_array)
pnts_fobj.close()
print "pnts.hd5 file made !!!"
del myc_array