- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Google Cloud Platform 实例上运行 Keras 模型时遇到问题。
模型如下:
n_timesteps, n_features, n_outputs = train_x.shape[1], train_x.shape[2], train_y.shape[1]
train_y = train_y.reshape((train_y.shape[0], train_y.shape[1], 1))
verbose, epochs, batch_size = 1, 1, 64 # low number of epochs just for testing purpose
with tf.device('/cpu:0'):
m = Sequential()
m.add(CuDNNLSTM(20, input_shape=(n_timesteps, n_features)))
m.add(LeakyReLU(alpha=0.1))
m.add(RepeatVector(n_outputs))
m.add(CuDNNLSTM(20, return_sequences=True))
m.add(LeakyReLU(alpha=0.1))
m.add(TimeDistributed(Dense(20)))
m.add(LeakyReLU(alpha=0.1))
m.add(TimeDistributed(Dense(1)))
self.model = multi_gpu_model(m, gpus=8)
self.model.compile(loss='mse', optimizer='adam')
self.model.fit(train_x, train_y, epochs=epochs, batch_size=batch_size, verbose=verbose)
正如您从上面的代码中看到的,我在具有 8 个 GPU(Nvidia Tesla K80)的机器上运行模型。
火车运行良好,没有任何错误。但是,预测失败并返回以下错误:
W tensorflow/core/framework/op_kernel.cc:1502] OP_REQUIRES failed at cudnn_rnn_ops.cc:1336 : Unknown: CUDNN_STATUS_BAD_PARAM in tensorflow/stream_executor/cuda/cuda_dnn.cc(1285): 'cudnnSetTensorNdDescriptor( tensor_desc.get(), data_type, sizeof(dims) / sizeof(dims[0]), dims, strides)'
这里是运行预测的代码:
self.model.predict(input_x)
我注意到,如果我删除多 GPU 数据并行的代码,该代码使用单个 GPU 就能很好地工作。
更准确地说,如果我注释掉这一行,代码就会正常工作
self.model = multi_gpu_model(m, gpus=8)
我错过了什么?
virtualenv信息
cudatoolkit - 10.0.130
cudnn - 7.6.4
keras - 2.2.4
keras-applications - 1.0.8
keras-base - 2.2.4
keras-gpu - 2.2.4
python - 3.6
更新
train_x.shape = (1441, 288, 1)
train_y.shape = (1441, 288, 1)
input_x.shape = (1, 288, 1)
在 Olivier Dehaene 回复后,我尝试了他的建议,结果成功了。
我尝试修改 input_x 形状以获得 (8, 288, 1)。
为了做到这一点,我还修改了 train_x 和 train_y 形状。
这里回顾一下:
train_x.shape = (8065, 288, 1)
train_y.shape = (8065, 288, 1)
input_x.shape = (8, 288, 1)
但现在我在训练阶段遇到了同样的错误,在这一行:
self.model.fit(train_x, train_y, epochs=epochs, batch_size=batch_size, verbose=verbose)
最佳答案
从tf.keras.utils.multi_gpu_model
我们可以看到它的工作方式如下:
- Divide the model's input(s) into multiple sub-batches.
- Apply a model copy on each sub-batch. Every model copy is executed on a dedicated GPU.
- Concatenate the results (on CPU) into one big batch.
您正在触发错误,因为至少一个模型副本的 CuDNNLSTM
图层的输入为空。这是因为除法运算需要:input//n_gpus > 0
试试这个代码:
input_x = np.random.randn(8, n_timesteps, n_features)
model.predict(input_x)
关于python - 运行 keras multi_gpu_model 时预测出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58846318/
我在 Google Cloud Platform 实例上运行 Keras 模型时遇到问题。 模型如下: n_timesteps, n_features, n_outputs = train_x.sha
我在 ubuntu 16.04 上有 tensorflow-gpu 1.2.1 和 keras。 我无法执行: from kears.utils import multi_gpu_model 是否有人
我正在 Keras 中使用 multi_gpu_model 训练修改后的 InceptionV3 模型,我使用 model.save 保存整个模型。 然后我关闭并重新启动了 IDE,并使用 load_
我有 2 个 Keras 子模型( model_1 、 model_2 ),从中我形成了完整的 model使用keras.models.Model()通过将它们逻辑地堆叠在“系列”中。我的意思是mod
我的 Keras 版本是 2.0.9,后端使用的是 tensorflow。 我尝试执行 multi_gpu_model在喀拉斯。然而,在实践中,使用 4 个 gpu 进行训练甚至比使用 1 个 gpu
升级到 Keras 2.0.9 后,我一直在使用 multi_gpu_model实用程序,但我无法使用以下方法保存我的模型或最佳权重 model.save('path') 我得到的错误是 TypeEr
我正在使用 tensorflow 1.5.0、tensorflow-gpu 1.3.0、keras 2.0.9、keras-gpu 2.1.4 我使用这段代码创建了我的模型: inputs = Inp
我是一名优秀的程序员,十分优秀!