-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathread_hdf5.py
31 lines (25 loc) · 838 Bytes
/
read_hdf5.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
import argparse
import h5py
import io
import numpy as np
from PIL import Image
def main(args):
hf = h5py.File(args.hdf5file, 'r')
for gname, group in hf.items():
print(gname, len(group))
for dname, data in group.items():
print(dname, data.attrs['class'])
break
print("===")
if args.get_dataset and args.get_filename:
f = hf[args.get_dataset][args.get_filename]
img = Image.open(io.BytesIO(np.array(f)))
cls = f.attrs['class']
print('image size:', img.size, 'class:', cls)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Read hdf5')
parser.add_argument('hdf5file')
parser.add_argument('get_dataset', nargs='?')
parser.add_argument('get_filename', nargs='?')
args = parser.parse_args()
main(args)