【问题标题】:Keras - Validation accuracy not matching self-measured accuracy in LSTM?Keras - 验证精度与 LSTM 中的自测精度不匹配?
【发布时间】:2018-09-24 08:00:34
【问题描述】:

在两个 epoch 之后,我的模型的验证准确度显示为 0.30,但是当我使用 model.predict_generator 返回预测的类并自己测量准确度时 - 准确度要低得多,约为 0.18。

为什么这些方法返回不同的精度?我相信这可能与我对时间序列生成器的实现或理解有关。

data_gen_train = sequence.TimeseriesGenerator(X, y_ct, timesteps, sampling_rate=1, stride=1, start_index=0, end_index=len(y), batch_size=batch_size)
data_gen_test = sequence.TimeseriesGenerator(X_ho, y_ho_ct, timesteps, sampling_rate=1, stride=1, start_index=0, end_index=len(y), batch_size=batch_size)

model = Sequential()
model.add(LSTM(20, stateful=True, batch_input_shape=(batch_size, timesteps, data_dim)))
model.add(Dense(9, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer= 'Nadam', metrics=['accuracy'])
model.fit_generator(data_gen_train, validation_data=data_gen_test, epochs=epochs, shuffle=False, validation_steps= len(y_ho) //batch_size)
y_pred = model.predict_generator(data_gen_test, steps= len(y_ho)//batch_size)

enter image description here

【问题讨论】:

    标签: python keras generator lstm


    【解决方案1】:

    我在上面找到了我的问题的答案。精度测量的差异是由于 pred 和 ground truth 数据集相对于彼此移动。此处应使用 Keras 的 pad_sequences 来避免此问题。

    【讨论】:

      猜你喜欢
      • 2020-09-29
      • 2018-04-17
      • 1970-01-01
      • 1970-01-01
      • 2019-04-20
      • 2019-01-28
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多