-
Notifications
You must be signed in to change notification settings - Fork 2
/
binvox_to_h5.py
57 lines (46 loc) · 1.4 KB
/
binvox_to_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
#
# Convert dataset(.binvox) to numpy array in advance
# to load dataset more efficient.
#
import sys, os, glob
from common.data_io import read_binvox, read_h5
import numpy as np
import h5py
def convert_h5(in_path, out_path):
data = read_binvox(in_path)
f = h5py.File(out_path, 'w')
f.create_dataset('data', data = data)
f.flush()
f.close()
return out_path
def check_open_h5(save_dir):
if save_dir[-1] != '/':
save_dir += '/'
files = [f for f in glob.glob(save_dir + "**/*.h5", recursive=True)]
for path in files:
try:
read_h5(path)
except KeyError:
print(path)
def extract_name(path):
return path.split('/')[-1].split('.')[0]
def main():
if len(sys.argv) < 3:
print("usage: python dump.py dataset_path(.binvox) save_dir")
sys.exit()
dataset_path = sys.argv[1]
save_dir = sys.argv[2]
if dataset_path[-1] != '/':
dataset_path += '/'
if save_dir[-1] != '/':
save_dir += '/'
os.makedirs(save_dir, exist_ok=True)
files = [f for f in glob.glob(dataset_path + "**/*.binvox", recursive=True)]
print("{} files found.".format(len(files)))
ext = sys.argv[1]
for in_path in files:
out_path = save_dir + extract_name(in_path) + '.h5'
result = convert_h5(in_path, out_path)
if __name__=="__main__":
# main()
check_open_h5(sys.argv[1])