在keras中,n_jobs = -1等效

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

我最近开始学习深度学习。在使用具有n_jobs = -1的sklearn库的机器学习中,使用了所有我的cpu核心,这加速了网格搜索。现在我试图在训练数据上使用rnn模型,这需要花费很多时间。有没有办法加快培训速度。

# Initialising the RNN
regressor = Sequential()

# Adding the first LSTM layer and some Dropout regularisation
regressor.add(LSTM(units = 50, return_sequences = True, input_shape = (X_train.shape[1], 7)))
regressor.add(Dropout(0.2))

# Adding a second LSTM layer and some Dropout regularisation
regressor.add(LSTM(units = 50, return_sequences = True))
regressor.add(Dropout(0.2))

# Adding a third LSTM layer and some Dropout regularisation
regressor.add(LSTM(units = 50, return_sequences = True))
regressor.add(Dropout(0.2))

# Adding a fourth LSTM layer and some Dropout regularisation
regressor.add(LSTM(units = 50))
regressor.add(Dropout(0.2))

# Adding the output layer
regressor.add(Dense(units = 1))

# Compiling the RNN
regressor.compile(optimizer = 'adam', loss = 'mean_squared_error')

# Fitting the RNN to the Training set
regressor.fit(X_train, y_train, epochs = 100, batch_size = 32,shuffle=False)
python-3.x parallel-processing keras scikit-learn cpu-usage
1个回答
0
投票

使用以下内容:

config = tf.ConfigProto(device_count{"CPU": <NB CPU>})
keras.backend.tensorflow_backend.set_session(tf.Session(config=config))
© www.soinside.com 2019 - 2024. All rights reserved.