-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathh5_generator.py
executable file
·57 lines (48 loc) · 1.46 KB
/
h5_generator.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
#!/usr/bin/env python
import os
import numpy as np
import h5py
from IPython import embed
# part 1
path_label = "/media/data_2/COCO_SIXD/small_KP_linemod_10_24/01/kp_label"
files= os.listdir(path_label)
listlabel = []
for file in files:
#generate 'part' of h5 file
c = np.load(os.path.join(path_label,file))
listlabel.append(c)
parts = np.vstack(listlabel)
parts = np.reshape(parts,(-1,17,2))
print("parts: ", np.shape(parts))
# part 2
path_rgb = "/media/data_2/COCO_SIXD/small_KP_linemod_10_24/01/rgb"
files= os.listdir(path_rgb)
listnpy = []
for file in files:
#generate 'imgname' of h5 file
numblist = []
for char in file:
number = ord(char)
numblist.append(number)
tmparray = np.asarray(numblist)
if len(numblist) == 16:
listnpy.append(tmparray)
embed()
imgnames = np.vstack(listnpy)
print("Shape of imgnames: ", np.shape(imgnames))
imgnum = np.shape(imgnames)[0]
# part 3
path_bbox = "/media/data_2/COCO_SIXD/small_KP_linemod_10_24/01/bbox"
files= os.listdir(path_bbox)
listbbox = []
for file in files:
#generate 'bndbox' of h5 file
c = np.load(os.path.join(path_bbox,file))
listbbox.append(c)
bndboxes = np.vstack(listbbox)
bndboxes = np.reshape(bndboxes,(-1,1,4))
print("Shape of bndboxes: ", np.shape(bndboxes))
with h5py.File("mytestfile.h5", "w") as f:
f.create_dataset("bndbox", data=bndboxes)
f.create_dataset("imgname", data=imgnames)
f.create_dataset("part", data=parts)