@malika , There are various ways of doing this some are as follows:
1. import the following before Keras or Tensorflow is imported:
import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ""
2. Another way is to run your script using:
$ CUDA_VISIBLE_DEVICES="" ./mykerascode.py
3.You can also try using tf.device():
with tf.device('/gpu:0'):
a = tf.placeholder(tf.float32, shape=(None, 20, 64))
b = LSTM(32)(a)
with tf.device('/cpu:0'):
a = tf.placeholder(tf.float32, shape=(None, 20, 64))
b = LSTM(32)(a)