-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathH5.py
94 lines (72 loc) · 1.95 KB
/
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
84
85
86
87
88
89
90
91
92
93
import h5py
import os
LIMBS = 16
class H5(object):
"""H5 Dataset Base"""
def __init__(self, base_path, file_name, read_only=True, auto_set=True):
self.file_path = os.path.join(base_path, file_name)
self.read_only = read_only
mode = 'r' if read_only else 'r+'
try:
self.group = h5py.File(self.file_path, mode) if auto_set else None
except Exception as e:
print('[Exception] H5.__init__ failed')
raise e
def set(self):
mode = 'r' if self.read_only else 'r+'
try:
self.group = h5py.File(self.file_path, mode)
except Exception as e:
print('[Exception] H5.set failed')
raise e
def count(self):
try:
return len(self.group.get(u"S2d"))
except Exception as e:
return None
def get(self, field):
try:
return self.group.get(field)
except Exception as e:
return None
def load(self):
pass
def save(self):
pass
class Input(H5):
"""Input File: S2d(n,LIMBS,2), rank(n,LIMBS), rankMat(n,LIMBS,LIMBS)"""
def __init__(self, base_path, file_name, read_only=True):
super(Input, self).__init__(base_path, file_name, read_only, True)
self.S2d = self.S2d()
self.rank = self.rank()
self.rankMat = self.rankMat()
pass
def S2d(self):
return self.get(u"S2d")
def rank(self):
return self.get(u"rank")
def rankMat(self):
return self.get(u"rankMat")
class Target(H5):
"""Target File: Idx(n), S2d(n,LIMBS,2), S3d(n,LIMBS,3), center(n,2), rank(n,LIMBS), scale(n)"""
def __init__(self, base_path, file_name, read_only=True):
super(Target, self).__init__(base_path, file_name, read_only, True)
self.Idx = self.Idx()
self.S2d = self.S2d()
self.S3d = self.S3d()
self.center = self.center()
self.rank = self.rank()
self.scale = self.scale()
pass
def Idx(self):
return self.get(u"Idx")
def S2d(self):
return self.get(u"S2d")
def S3d(self):
return self.get(u"S3d")
def center(self):
return self.get(u"center")
def rank(self):
return self.get(u"rank")
def scale(self):
return self.get(u"scale")