我正在尝试调整keras 示例中的帧预测模型以使用一组一维传感器。我有 android 可穿戴传感器数据,并且正在设计一种算法,该算法有望根据过去的传感器读数预测未来的传感器读数。
模型
model = Sequential()
model.add(ConvLSTM2D(filters=filters, kernel_size=(1, 1), input_shape=(None, 9, 1, 1), padding='same', return_sequences=True))
model.add(BatchNormalization())
model.add(ConvLSTM2D(filters=filters, kernel_size=(1, 1), padding='same', return_sequences=True))
model.add(BatchNormalization())
model.add(ConvLSTM2D(filters=filters, kernel_size=(1, 1), padding='same', return_sequences=True))
model.add(BatchNormalization())
model.add(Conv3D(filters=1, kernel_size=(3, 3, 3), activation='sigmoid', padding='same', data_format='channels_last'))
model.compile(loss='binary_crossentropy', optimizer='adadelta')
概括
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv_lst_m2d_1 (ConvLSTM2D) (None, None, 9, 1, 10) 480
_________________________________________________________________
batch_normalization_1 (Batch (None, None, 9, 1, 10) 40
_________________________________________________________________
conv_lst_m2d_2 (ConvLSTM2D) (None, None, 9, 1, 10) 840
_________________________________________________________________
batch_normalization_2 (Batch (None, None, 9, 1, 10) 40
_________________________________________________________________
conv_lst_m2d_3 (ConvLSTM2D) (None, None, 9, 1, 10) 840
_________________________________________________________________
batch_normalization_3 (Batch (None, None, 9, 1, 10) 40
_________________________________________________________________
conv3d_1 (Conv3D) (None, None, 9, 1, 1) 271
=================================================================
Total params: 2,551
Trainable params: 2,491
Non-trainable params: 60
_________________________________________________________________
数据
我有一系列带有传感器数据的 csv 文件(9 个传感器,3 轴加速度,3 轴旋转,以及偏航、俯仰和滚动)。数据以 10 赫兹采样。模型的输入是传感器数据的“帧”或时间快照,输出是传感器数据的下一个“时刻”或时间快照。
我查看了帧预测算法并想了解如何调整我加载的数据以用于训练模型。
我的数据由 15 个 csvs 组成,大约 10,000 行,每行代表一组传感器的快照。每个 csvs 都来自不同的人,如果可能的话,我想增强我的模型以了解每个人之间的差异。
加载数据中
import pandas as pd
csvs = get_csvs()
for file in csvs:
data = transform_df_to_deep_frame(pd.read_csv(file))
model.fit(data[:-1], data[1:], batch_size=10, epochs=300, validation_split=0.05)
由于相对明显的原因,我仍然无法修复此代码产生以下输出/错误。
输出/错误
(10778, 9, 1, 1)
Traceback (most recent call last):
File "compare_models.py", line 220, in leave_one_out_comparisons
model.fit(data[:-1], data[1:], batch_size=10, epochs=300, validation_split=0.05)
File "/home/victor/anaconda3/lib/python3.7/site-packages/keras/engine/training.py", line 952, in fit
batch_size=batch_size)
File "/home/victor/anaconda3/lib/python3.7/site-packages/keras/engine/training.py", line 751, in _standardize_user_data
exception_prefix='input')
File "/home/victor/anaconda3/lib/python3.7/site-packages/keras/engine/training_utils.py", line 128, in standardize_input_data
'with shape ' + str(data_shape))
ValueError: Error when checking input: expected conv_lst_m2d_1_input to have 5 dimensions, but got array with shape (10778, 9, 1, 1)
问题
问题似乎是我没有正确地批量处理我的数据。None 让我很困惑。我对 ML 比较陌生,所以请原谅我。如何调整形状 (10778, 9, 1, 1) 的输入和输出以适合该模型的输入和输出。