(training_file, sensor_a, sensor_b)
| 72 | |
| 73 | |
| 74 | def load_data_triple_timestamp(training_file, sensor_a, sensor_b): |
| 75 | # Load data |
| 76 | x_sensor_a, x_sensor_b, x_imu, y = [], [], [], [] |
| 77 | hdf5_file = h5py.File(training_file, 'r') |
| 78 | x_time = hdf5_file.get('timestamp') |
| 79 | x_sensor_a_temp = hdf5_file.get(sensor_a + '_data') |
| 80 | x_sensor_b_temp = hdf5_file.get(sensor_b + '_data') |
| 81 | x_imu_temp = hdf5_file.get('imu_data') |
| 82 | y_temp = hdf5_file.get('label_data') |
| 83 | |
| 84 | print('Data shape: ' + str(np.shape(x_sensor_a_temp))) |
| 85 | |
| 86 | if x_sensor_a_temp.shape[0] == 1: |
| 87 | x_sensor_a_temp = x_sensor_a_temp[0] |
| 88 | |
| 89 | if x_sensor_b_temp.shape[0] == 1: |
| 90 | x_sensor_b_temp = x_sensor_b_temp[0] |
| 91 | |
| 92 | if x_imu_temp.shape[0] == 1: |
| 93 | x_imu_temp = x_imu_temp[0] |
| 94 | |
| 95 | y_temp = y_temp[0] |
| 96 | |
| 97 | print('Data shape: ' + str(np.shape(x_sensor_a_temp)) + str(str(np.shape(y_temp)))) |
| 98 | |
| 99 | data_size = np.size(x_sensor_a_temp, axis=0) |
| 100 | |
| 101 | # Determine whether the data should be divided into several chunks |
| 102 | # to fit in memory |
| 103 | data_per_chunk = 5000 |
| 104 | is_special_case = False |
| 105 | if data_size > 10000: |
| 106 | n_chunk = data_size // data_per_chunk |
| 107 | n_chunk += 1 |
| 108 | is_special_case = True |
| 109 | else: |
| 110 | n_chunk = 1 |
| 111 | |
| 112 | if is_special_case == True: |
| 113 | # Divide into several chunks if the length of the data is too large |
| 114 | for i in range(n_chunk-1): |
| 115 | x_sensor_a.append(x_sensor_a_temp[(data_per_chunk * i):data_per_chunk * (i + 1), :, :, :]) |
| 116 | x_sensor_b.append(x_sensor_b_temp[(data_per_chunk * i):data_per_chunk * (i + 1), :, :, :]) |
| 117 | x_imu.append(x_imu_temp[(data_per_chunk * i):data_per_chunk * (i + 1), :, :, :]) |
| 118 | y.append(y_temp[(data_per_chunk * i):data_per_chunk * (i + 1), :]) |
| 119 | |
| 120 | x_sensor_a.append(x_sensor_a_temp[(data_size - data_per_chunk):data_size, :, :, :]) |
| 121 | x_sensor_b.append(x_sensor_b_temp[(data_size - data_per_chunk):data_size, :, :, :]) |
| 122 | x_imu.append(x_imu_temp[(data_size - data_per_chunk):data_size, :, :, :]) |
| 123 | y.append(y_temp[(data_size - data_per_chunk):(data_size-1), :]) |
| 124 | else: |
| 125 | x_sensor_a.append(x_sensor_a_temp[0:data_size, :, :, :]) |
| 126 | x_sensor_b.append(x_sensor_b_temp[0:data_size, :, :, :]) |
| 127 | x_imu.append(x_imu_temp[0:data_size, :, :]) |
| 128 | y.append(y_temp[0:(data_size-1), :]) |
| 129 | return n_chunk, x_time, x_sensor_a, x_sensor_b, x_imu, y |
| 130 | |
| 131 |
no outgoing calls
no test coverage detected