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