1
keras tensorflow-cpu后端与tensorflow-gpu后端是否有区别(代码中)?如果我想将tensorflow从cpu更改为gpu,我需要添加哪些代码或需要设置哪些环境变量?将keras后端从tensorflow cpu更改为gpu
从keras link我知道我可以使用tf.devices
- 就像下面的代码一样。但是如果我想要整个代码,而不是仅仅一部分在GPU上运行呢?
with tf.device('/gpu:0'):
x = tf.placeholder(tf.float32, shape=(None, 20, 64))
y = LSTM(32)(x) # all ops in the LSTM layer will live on GPU:0
with tf.device('/cpu:0'):
x = tf.placeholder(tf.float32, shape=(None, 20, 64))
y = LSTM(32)(x) # all ops in the LSTM layer will live on CPU:0