machine-learning - Keras RNN 损失不会随 epoch 减少而减少

标签 machine-learning neural-network deep-learning keras recurrent-neural-network

我使用 Keras 构建了一个 RNN。 RNN 用于解决回归问题:

def RNN_keras(feat_num, timestep_num=100):
    model = Sequential()
    model.add(BatchNormalization(input_shape=(timestep_num, feat_num)))
    model.add(LSTM(input_shape=(timestep_num, feat_num), output_dim=512, activation='relu', return_sequences=True))
    model.add(BatchNormalization())  
    model.add(LSTM(output_dim=128, activation='relu', return_sequences=True))
    model.add(BatchNormalization())
    model.add(TimeDistributed(Dense(output_dim=1, activation='relu'))) # sequence labeling

    rmsprop = RMSprop(lr=0.00001, rho=0.9, epsilon=1e-08)
    model.compile(loss='mean_squared_error',
                  optimizer=rmsprop,
                  metrics=['mean_squared_error'])
    return model

整个过程看起来不错。但损失在几个时期内保持完全相同。

61267 in the training set
6808 in the test set

Building training input vectors ...
888 unique feature names
The length of each vector will be 888
Using TensorFlow backend.

Build model...

# Each batch has 1280 examples
# The training data are shuffled at the beginning of each epoch.

****** Iterating over each batch of the training data ******
Epoch 1/3 : Batch 1/48 | loss = 11011073.000000 | root_mean_squared_error = 3318.232910
Epoch 1/3 : Batch 2/48 | loss = 620.271667 | root_mean_squared_error = 24.904161
Epoch 1/3 : Batch 3/48 | loss = 620.068665 | root_mean_squared_error = 24.900017
......
Epoch 1/3 : Batch 47/48 | loss = 618.046448 | root_mean_squared_error = 24.859678
Epoch 1/3 : Batch 48/48 | loss = 652.977051 | root_mean_squared_error = 25.552946
****** Epoch 1: RMSD(training) = 24.897174 

Epoch 2/3 : Batch 1/48 | loss = 607.372620 | root_mean_squared_error = 24.644049
Epoch 2/3 : Batch 2/48 | loss = 599.667786 | root_mean_squared_error = 24.487448
Epoch 2/3 : Batch 3/48 | loss = 621.368103 | root_mean_squared_error = 24.926300
......
Epoch 2/3 : Batch 47/48 | loss = 620.133667 | root_mean_squared_error = 24.901398
Epoch 2/3 : Batch 48/48 | loss = 639.971924 | root_mean_squared_error = 25.297264
****** Epoch 2: RMSD(training) = 24.897174 

Epoch 3/3 : Batch 1/48 | loss = 651.519836 | root_mean_squared_error = 25.523636
Epoch 3/3 : Batch 2/48 | loss = 673.582581 | root_mean_squared_error = 25.952084
Epoch 3/3 : Batch 3/48 | loss = 613.930054 | root_mean_squared_error = 24.776562
......
Epoch 3/3 : Batch 47/48 | loss = 624.460327 | root_mean_squared_error = 24.988203
Epoch 3/3 : Batch 48/48 | loss = 629.544250 | root_mean_squared_error = 25.090448
****** Epoch 3: RMSD(training) = 24.897174 

我认为这不正常。我错过了什么吗?

<小时/>

更新: 我发现所有的预测在所有纪元之后总是为零。这就是为什么所有 RMSD 都相同的原因,因为预测都是相同的,即 0。我检查了训练 y。它只包含几个零。所以这不是由于数据不平衡造成的。

所以现在我在想这是否是因为我正在使用的层和激活。

最佳答案

你的 RNN 函数似乎没问题。

损失减少的速度取决于优化器和学习率。

无论您如何使用衰减率 0.9。尝试使用更大的学习率,无论如何它都会以 0.9 的速率下降。

尝试具有不同学习率的其他优化器 keras 提供的其他优化器:https://keras.io/optimizers/

很多时候,一些优化器在某些数据集上运行良好,而另一些则可能失败。

关于machine-learning - Keras RNN 损失不会随 epoch 减少而减少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39309388/

相关文章:

python - 如何准确地将 L1 正则化添加到 tensorflow 误差函数

deep-learning - 法泰 : ValueError: __len__() should return >= 0

python - PyTorch:为什么在训练时期循环内部或外部调用它后验证准确性会发生变化?

machine-learning - 如何确定神经网络中的权重?

machine-learning - sklearn 中的标签传播是将每个向量分类为 1

python - 如何使用 TensorFlow 在 ROI 周围创建边界框

java - 尝试使用 Neuroph 框架训练神经网络时出现 StackOverFlowError

python - 属性错误: module 'keras.utils' has no attribute 'plot_model' but installed Keras and tensorflow

java - 如何将 Apache Spark 与 Spring MVC Web 应用程序集成以实现交互式用户 session

python - 批量标准化和辍学的顺序?