-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathS1_network_dataset_combination.py
84 lines (71 loc) · 2.84 KB
/
S1_network_dataset_combination.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
import os
import h5py
import numpy as np
BASE_DIR= 'hdf5_data/'
#%% analyze the dataset
print("---------------")
print("analyze dataset")
print("---------------")
dir_list = os.listdir(BASE_DIR)
train_files = [f for f in dir_list if f.startswith("ply_data_train")]
val_files = [f for f in dir_list if f.startswith("ply_data_val")]
test_files = [f for f in dir_list if f.startswith("ply_data_test")]
train_files = np.sort(train_files)
val_files = np.sort(val_files)
test_files = np.sort(test_files)
train_length = 0
for train_file in train_files:
with h5py.File(BASE_DIR+train_file,'r') as f:
train_length += len(f['label'])
val_length = 0
for val_file in val_files:
with h5py.File(BASE_DIR+val_file,'r') as f:
val_length += len(f['label'])
test_length = 0
for test_file in test_files:
with h5py.File(BASE_DIR+test_file,'r') as f:
test_length += len(f['label'])
print('training labels:',train_length,'testing labels:',test_length)
#%% combine dataset
print("---------------")
print("combine dataset")
print("---------------")
f0 = h5py.File('ShapeNet_training.hdf5','w')
x_train =f0.create_dataset("x_train", (train_length,2048,3), dtype='<f4')
y_train =f0.create_dataset("y_train", (train_length,1), dtype='|u1')
s_train =f0.create_dataset("s_train", (train_length,2048), dtype='|u1')
x_val =f0.create_dataset("x_val", (val_length,2048,3), dtype='<f4')
y_val =f0.create_dataset("y_val", (val_length,1), dtype='|u1')
s_val =f0.create_dataset("s_val", (val_length,2048), dtype='|u1')
x_test =f0.create_dataset("x_test", (test_length,2048,3), dtype='<f4')
y_test =f0.create_dataset("y_test", (test_length,1), dtype='|u1')
s_test =f0.create_dataset("s_test", (test_length,2048), dtype='|u1')
offset = 0
for train_file in train_files:
with h5py.File(BASE_DIR+train_file,'r') as f:
print("combining dataset:", train_file)
dataset_length = len(f['label'])
x_train[offset:offset+dataset_length] =f['data']
y_train[offset:offset+dataset_length] =f['label']
s_train[offset:offset+dataset_length] =f['pid']
offset += dataset_length
offset = 0
for val_file in val_files:
with h5py.File(BASE_DIR+val_file,'r') as f:
print("combining dataset:", val_file)
dataset_length = len(f['label'])
x_val[offset:offset+dataset_length] =f['data']
y_val[offset:offset+dataset_length] =f['label']
s_val[offset:offset+dataset_length] =f['pid']
offset += dataset_length
offset = 0
for test_file in test_files:
with h5py.File(BASE_DIR+test_file,'r') as f:
print("combining dataset:", test_file)
dataset_length = len(f['label'])
x_test[offset:offset+dataset_length] =f['data']
y_test[offset:offset+dataset_length] =f['label']
s_test[offset:offset+dataset_length] =f['pid']
offset += dataset_length
#%%
f0.close()