为什么在训练多个Keras神经网络时Python会在完全相同的位置崩溃?

问题描述 投票:0回答:1

我正在尝试在一个时间序列数据集上训练LSTM NN,该数据集包含一千多个不同的设备,并每天进行观察以预测设备何时会发生故障。我已经适当地处理了数据清理和设置,并且可以成功地训练数据上的NN。

现在,我想遍历NN的许多训练迭代,每个迭代具有不同的超参数,以便找到数据的最佳设置训练参数。这样做时,我遇到了一个非常奇怪的错误。当我训练NN的迭代时,我可以运行恰好13 NN,然后我的程序被杀死。在终端中运行时,我仅收到一条消息,内容为Killed,而在控制台(Pycharm)中运行时,则显示一条进程,退出代码为1]结束的消息。我认为问题不是内存不足,因为在控制台中运行时,我会保持堆大小监视器的状态,并且不会接近最大值。考虑到我随机选择超参数(每次运行该程序时,我不会运行相同的13个NN),每次都在第13次运行中失败似乎也不是巧合。

有人对我从哪里开始进行故障排除有任何建议?

谢谢。

功能I循环以训练后续的NN:

    lrate = round(10 ** (-4 * random.uniform(0, 1)), 3)  # 10e-4 to 10
    decay_rate = round(10 ** (-4 * random.uniform(0, 1)), 3)
    epochs_ = random.randint(25, 250)
    batches = random.randint(8, 64)
    l2_rate = round(10 ** (-4 * random.uniform(0, 1)), 3)
    dropout_rate = round(random.uniform(0.1, 0.5), 3)
    record_params = {'hidden_layers': hidden_layers, 'lrate': lrate, 'decay_rate': decay_rate, 'epochs': epochs_,
                     'batches': batches, 'l2_rate': l2_rate, 'dropout_rate': dropout_rate}

    model = Sequential()
    model_input_shape = X_train_input.shape[1:]
    model.add(LSTM(hidden_layers, input_shape=model_input_shape, return_sequences=True,
                   kernel_regularizer=regularizers.l2(l2_rate),
                   activation=activation_func))  # return_sequences=True,
    model.add(Dropout(dropout_rate))
    model.add(BatchNormalization())
    model.add(LSTM(hidden_layers, kernel_regularizer=regularizers.l2(l2_rate),
                   activation=activation_func))  # return_sequences=True,
    model.add(Dropout(dropout_rate))
    model.add(BatchNormalization())
    model.add(Dense(1, activation='sigmoid'))
    model.compile(loss='binary_crossentropy', optimizer=optimizers.Adam(lr=lrate, decay=decay_rate),
                  metrics=[metrics.AUC(), metrics.FalseNegatives(), metrics.FalsePositives()])
    model.fit(X_train_input, y_train_input2, batch_size=batches, epochs=epochs_,
                        validation_data=(X_val_input, y_val_input2), verbose=1,
                        shuffle=False, callbacks=[EarlyStopping(monitor='val_loss', patience=15)]
                        )

    # test
    yhat = model.predict(X_train_input, batch_size=batches)
    yhat_val = model.predict(X_val_input, batch_size=batches)

    # record
    record_params['train_roc'] = round(roc_auc_score(y_train_input2, yhat.reshape(yhat.shape[0])), 3)
    record_params['val_roc'] = round(roc_auc_score(y_val_input2, yhat_val.reshape(yhat_val.shape[0]),
                                                   average='weighted'), 3)


    return pd.DataFrame(record_params, index=[ind]) ```



[Does not seem like a memory issue - this screenshotted during 5th NN run. ][1]


  [1]: https://i.stack.imgur.com/Rb9GL.png

我正在尝试在一个时间序列数据集上训练LSTM NN,该数据集包含一千多个不同的设备,并每天进行观察以预测设备何时会发生故障。我已经处理了我的数据...

python tensorflow memory keras pycharm
1个回答
0
投票

如果您使用的参数是随机的,则第13步很奇怪。您说的不是记忆力,但我最近与Keras一起工作,我发现我的计算机干了很多。您说这是整个for循环?它最后返回一个DataFrame。如果循环将继续运行,此df会保存在哪里?也许粘贴整个功能。

© www.soinside.com 2019 - 2024. All rights reserved.