python-3.x - n_jobs = -1 等效于 keras
问题描述
我最近开始学习深度学习。在使用 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)
解决方案
使用以下内容:
config = tf.ConfigProto(device_count{"CPU": <NB CPU>})
keras.backend.tensorflow_backend.set_session(tf.Session(config=config))
推荐阅读
- database - 我在 wordpress 数据库中有两个带有 wp_ 前缀和更改前缀的表,我该怎么办?
- python - 解决 GCP 权限问题
- python - Python:如何使数组的每个术语重复,将相同的术语组合在一起
- r - Fanchart 自定义(vars 包)
- python - 如何将处理后的 kafka DStream 保存在 pyspark 的文本文件中?
- excel - 范围的值等于先前范围的值和地址 VBA
- gmail-addons - 如何更新已部署的版本?
- vba - 将工作表从活动工作簿复制到不同位置的另一个工作簿
- kubernetes - Galera Kubernetes E2E - 如何在 YAML 中设置密码?
- c++ - GMP - 在 mpz_t/mpz_class 中存储 64 位整数并返回 64 位整数