title: Changing keras backend from tensorflow cpu to gpu
body: <p>Is there a difference (in code) between keras tensorflow-cpu backend and tensorflow-gpu backend? If I want to change tensorflow from cpu to gpu, what code do I need to add or what environmental variables do I need to set?</p>
  
  <p>From <a href="https://blog.keras.io/keras-as-a-simplified-interface-to-tensorflow-tutorial.html#multi-gpu-and-distributed-training" rel="nofollow noreferrer">keras link</a> I know that I can use <code>tf.devices</code> - something like the code below. But what if I want the whole code, not just some part to run on GPU?</p>
  
  <pre><code>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
  </code></pre>