GridSearchCV挂在第一个时期,n_jobs> 1

时间:2018-07-13 17:16:12

标签: python keras

我一直在尝试将gridsearch与自动编码器一起使用,并且并行进程在第一个时期挂起,之后所有活动都停止了。 代码如下:

config =tf.ConfigProto(intra_op_parallelism_threads=10,inter_op_parallelism_threads=0, allow_soft_placement=True, device_count = {'GPU': 0})
session = tf.Session(config=config)
K.set_session(session)

def encode_decode(lasso_lr, lr):
    input_dim=X_train.shape[1]
    #encoder
    input_layer=Input(shape=(input_dim,)) #number of features i.e. genes ~17k
    encoded = Dense(300, activation='tanh',activity_regularizer=regularizers.l1(lasso_lr))(input_layer)
    #decoder
    decoded = Dense(input_dim, activation='relu')(encoded)

    autoencoder_model=Model(inputs=input_layer,outputs=decoded)
    autoencoder_model.compile(loss='mse', optimizer= Adam(lr=lr))
    return autoencoder_model

callbacks = [EarlyStopping(monitor="loss", min_delta=0.2, patience=2, 
verbose=2, mode="min")]
model = KerasRegressor(build_fn=encode_decode,epochs=30, 
batch_size=200, verbose=1)
model_params=dict(lr=list(np.linspace(0,0.0001, num=10)), 
lasso_lr=list(np.linspace(0,0.0001,num=10)))
model_grid=GridSearchCV(estimator=model, cv=10,n_jobs=10,param_grid=model_params,scoring='neg_mean_squared_error')

print('running grid search...')

model_result = model_grid.fit(X_train.values,train_ground.values,validation_data=(X_test.values, test_ground.values),callbacks=callbacks)

print("Best: %f using %s" % (model_result.best_score_, 
model_result.best_params_))
#print(model_result.best_params_)
means = model_result.cv_results_['mean_test_score']
stds = model_result.cv_results_['std_test_score']
params = model_result.cv_results_['params']
for mean, stdev, param in zip(means, stds, params):
    print("%f (%f) with: %r" % (mean, stdev, param))

运行时,我只会看到以下内容:

running grid search...
Train on 6703 samples, validate on 1862 samples
Epoch 1/30
Train on 6703 samples, validate on 1862 samples
Epoch 1/30
Train on 6703 samples, validate on 1862 samples
Epoch 1/30
Train on 6703 samples, validate on 1862 samples
Epoch 1/30
Train on 6703 samples, validate on 1862 samples
Epoch 1/30
Train on 6703 samples, validate on 1862 samples
Epoch 1/30
Train on 6703 samples, validate on 1862 samples
Epoch 1/30
Train on 6703 samples, validate on 1862 samples
Epoch 1/30
Train on 6704 samples, validate on 1862 samples
Epoch 1/30
Train on 6704 samples, validate on 1862 samples
Epoch 1/30

此后没有任何反应。

任何反馈都是有用的。 谢谢

0 个答案:

没有答案