in Education by
Currently, I have Keras with TensorFlow and CUDA at the backend. But, I want to force Keras to use the CPU, at times. So here my question is, whether it can be done on a virtual environment without installing a separate CPU-only TensorFlow. If yes, I would like to know how? I have heard that the flags could be set if Theano is at the backend. But, I have no idea if TensorFlow flags are accessible via Keras. Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
@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)

Related questions

0 votes
    What is the role of Flatten in Keras. I am executing the code below and it's a two layered network. The ... output is already flat? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    I am working on the following code: model = Sequential() a = keras.layers.advanced_activations.PReLU(init='zero', ... solution to this? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have a simple NN model for detecting hand-written digits from a 28x28px image written in python using Keras: ... that actually means? Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    Every time I use binary_crossentropy there's ~80% acc and when I use categorical_crossentrop there's ~50% acc. And I ... should I use? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I want to save the history to a file, in Keras I have model.fit history = model.fit(Q_train, W_train, ... =(Q_test, W_test)) Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I've trained a sentiment classifier model using Keras library by following the below steps(broadly). Convert Text ... around this? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I'm creating a very basic AI with Tensorflow, and am using the code from the official docs/tutorial. Here's my ... Tensorflow 1.13.1. Select the correct answer from above options...
asked Jan 28, 2022 in Education by JackTerrance
0 votes
    I am trying to understand the role of the Flatten function in Keras. Below is my code, which is a simple two ... flatten it? Thanks! Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    Suppose I have a Tensorflow tensor. How do I get the dimensions (shape) of the tensor as integer values? I ... 'Dimension' instead. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I am new to TensorFlow. While I am reading the existing documentation, I found the term tensor really confusing. ... types of tensors? Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
0 votes
    I was looking at the docs of TensorFlow about tf.nn.conv2d here. But I can't understand what it does or ... it raised the question. Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    Is Tensorflow similar to scikit learn's one hot encoder for processing of categorical data? Does using placeholder of ... very easy. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have noticed that in most models step parameter is used to indicate the no. of steps to run over data ... epochs? Data shuffling? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I recently started finding out deep learning & machine learning techniques, and I started sorting out frameworks ... machine learning. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I have trouble understanding the difference (if there is one) between roc_auc_score() and auc() in scikit-learn. I ... out why. Thanks! Select the correct answer from above options...
asked Jan 29, 2022 in Education by JackTerrance
...