我正在Keras上构建一个神经网络,包括多个LSTM、Permute和Dense层。
看起来LSTM在GPU上并不友好。所以我进行了研究并使用了
With tf.device('/cpu:0'):
out = LSTM(cells)(inp)
根据我对 with
的理解,with
是一个 try...finally
块,以确保执行清理代码。我不知道以下的CPU/GPU混合使用代码是否有效?它们能加速训练速度吗?
With tf.device('/cpu:0'):
out = LSTM(cells)(inp)
With tf.device('/gpu:0'):
out = Permute(some_shape)(out)
With tf.device('/cpu:0'):
out = LSTM(cells)(out)
With tf.device('/gpu:0'):
out = Dense(output_size)(out)