【问题标题】:TerminatedWorkerError: A worker process managed by the executor was unexpectedly terminatedTerminatedWorkerError:执行者管理的工作进程意外终止
【发布时间】:2020-01-21 10:52:44
【问题描述】:

我正在尝试为我的深度学习模型找到最佳超参数。当我使用“GridSearchCV”方法并尝试拟合我的模型时,我得到了错误

"TerminatedWorkerError: 执行者管理的工作进程意外终止。这可能是由于调用函数时出现分段错误或内存使用过多导致操作系统杀死工作人员。工作人员的退出代码是 {EXIT(1)}"

我已经更新并测试了 scipy 库,效果很好。 我不能使用 n_jobs=-1。我必须使用 1 到 16 个 CPU (n_jobs=16)。

我的平台: 名称="Ubuntu" VERSION="16.04.6 LTS (Xenial Xerus)"。 我在 python 3.6.9 中使用 conda 4.7.12 访问 sklearn。 我们目前无法更新 Ubuntu!

import pandas as pd
import numpy
import keras
import scipy
from keras.models import Sequential
from keras.layers import Dense
from keras.wrappers.scikit_learn import KerasClassifier
from sklearn.model_selection import GridSearchCV
from sklearn.model_selection import train_test_split
from keras.optimizers import SGD
from sklearn.externals import joblib
from math import sqrt
import tensorflow as tf
from datetime import datetime


# Make grid input
batch_size  = [1644, 822, 548, 411, 328, 274, 234, 205, 182, 164]
epochs = [10, 50, 100, 150, 200, 250, 300]
learn_rate = [0.00001, 0.0001, 0.001, 0.01, 0.1, 0.2, 0.3]
momentum = [0.0, 0.2, 0.4, 0.6, 0.8, 0.9]
param_grid = dict(epochs = epochs, batch_size = batch_size, learn_rate=learn_rate, momentum=momentum)

# Define model
def get_compiled_model_advanced(learn_rate=learn_rate, momentum=momentum):
    model = tf.keras.Sequential([
        tf.keras.layers.Dense(200, activation='relu'),
        tf.keras.layers.Dense(50, activation='relu'),
        tf.keras.layers.Dense(10, activation='relu'),
        tf.keras.layers.Dense(1, activation='sigmoid')])
    # Compile model
    optimizer = SGD(lr=learn_rate, momentum=momentum, decay=0.5, nesterov=False)
    model.compile(optimizer=optimizer, loss='binary_crossentropy', metrics=['accuracy'])
    return model

model_sgd = KerasClassifier(build_fn=get_compiled_model_advanced, verbose=0)

grid_sgd = GridSearchCV(estimator = model_sgd, param_grid = param_grid, n_jobs = 16, verbose=0)
sgd_fit = grid_sgd.fit(X, Y)

我想让我的模型运行! 谁能告诉我我做错了什么?

【问题讨论】:

  • 我发现了问题!我将 tensorflow.python.keras api 用于模型和层,将 keras.optimizers 用于 SGD。现在我把它全部做成了一个版本!

标签: python-3.x keras deep-learning anaconda


【解决方案1】:

如果您的机器不允许并行运行作业,它会抛出异常。 'n_jobs=None' 可能会解决此处提到的问题:https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.GridSearchCV.html

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,这解决了我的问题:

    在 sklearn 上为 CV 搜索定义了一个 pre_dispatch 参数,它可以设置为 int
    例如pre_dispatch = 2 表示在并行执行期间总共产生了 2 个作业。

    查看sklearn GridSearchCV documentation

    【讨论】:

      猜你喜欢
      • 2020-10-15
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      • 1970-01-01
      • 2014-08-13
      • 2015-01-05
      • 1970-01-01
      • 2022-11-11
      相关资源
      最近更新 更多