MCPcopy Create free account
hub / github.com/ChristopherLu/milliEgo / load_data_multi

Function load_data_multi

utility/data_loader.py:16–71  ·  view source on GitHub ↗
(training_file, sensor)

Source from the content-addressed store, hash-verified

14
15# load multi-modal data with IMU always in
16def load_data_multi(training_file, sensor):
17
18 # Load data
19 x_sensor, x_imu, y = [], [], []
20 hdf5_file = h5py.File(training_file, 'r')
21 x_sensor_temp = hdf5_file.get(sensor+'_data')
22 x_imu_temp = hdf5_file.get('imu_data')
23 y_temp = hdf5_file.get('label_data')
24
25 print('Data shape: ' + str(np.shape(x_sensor_temp)))
26
27 # this is for rgb
28 # x_rgb_temp = np.squeeze(x_rgb_temp, axis=0)
29 # x_imu_temp = np.squeeze(x_imu_temp, axis=0)
30 # y_temp = np.squeeze(y_temp, axis=0)
31
32 # this is for raw data
33
34 if x_sensor_temp.shape[0] == 1:
35 x_sensor_temp = x_sensor_temp[0]
36
37 if x_imu_temp.shape[0] == 1:
38 x_imu_temp = x_imu_temp[0]
39
40 y_temp = y_temp[0]
41
42 print('Data shape: ' + str(np.shape(x_sensor_temp)) + str(str(np.shape(y_temp))))
43
44 data_size = np.size(x_sensor_temp, axis=0)
45
46 # Determine whether the data should be divided into several chunks
47 # to fit in memory
48 data_per_chunk = 5000
49 is_special_case = False
50 if data_size > 10000:
51 n_chunk = data_size // data_per_chunk
52 n_chunk += 1
53 is_special_case = True
54 else:
55 n_chunk = 1
56
57 if is_special_case == True:
58 # Divide into several chunks if the length of the data is too large
59 for i in range(n_chunk-1):
60 x_sensor.append(x_sensor_temp[(data_per_chunk * i):data_per_chunk * (i + 1), :, :, :])
61 x_imu.append(x_imu_temp[(data_per_chunk * i):data_per_chunk * (i + 1), :, :, :])
62 y.append(y_temp[(data_per_chunk * i):data_per_chunk * (i + 1), :])
63
64 x_sensor.append(x_sensor_temp[(data_size - data_per_chunk):data_size, :, :, :])
65 x_imu.append(x_imu_temp[(data_size - data_per_chunk):data_size, :, :, :])
66 y.append(y_temp[(data_size - data_per_chunk):(data_size-1), :])
67 else:
68 x_sensor.append(x_sensor_temp[0:data_size, :, :, :])
69 x_imu.append(x_imu_temp[0:data_size, :, :])
70 y.append(y_temp[0:(data_size-1), :])
71 return n_chunk, x_sensor, x_imu, y
72
73

Callers 2

mainFunction · 0.90
validation_stackFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected