I am working on Spyder to create deep learning model on a machine have a GPU I have found that am working on a CPU and my code run for a long time.First I downloaded tensorflow-GPU but I don't how to start working on GPU.
I used { with tf.device("cpu"):
} but when I write nvidia-smi on terminal I found no running processes.
I also used { import os os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ""import os os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = ""import os os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
} but it doesn't work.
os.environ["CUDA_VISIBLE_DEVICES"] = ""
How to make my Spyder code run on GPU instead of cpu on Ubuntu?
Any help would be appreciated.
code:
def createModel():
with tf.device("cpu"):
input_shape=(1, 22, 5, 3844)
model = Sequential()
model.add(Conv3D(16, (22, 5, 5), strides=(1, 2, 2), padding='same',activation='relu',data_format= "channels_first", input_shape=input_shape))
model.add(keras.layers.MaxPooling3D(pool_size=(1, 2, 2),data_format= "channels_first", padding='same'))
model.add(BatchNormalization())
model.add(Conv3D(32, (1, 3, 3), strides=(1, 1,1), padding='same',data_format= "channels_first", activation='relu'))#incertezza se togliere padding
model.add(keras.layers.MaxPooling3D(pool_size=(1,2, 2),data_format= "channels_first", ))
model.add(BatchNormalization())
model.add(Conv3D(64, (1,3, 3), strides=(1, 1,1), padding='same',data_format= "channels_first", activation='relu'))#incertezza se togliere padding
model.add(keras.layers.MaxPooling3D(pool_size=(1,2, 2),data_format= "channels_first",padding='same' ))
model.add(BatchNormalization())
model.add(Dense(64, input_dim=64,kernel_regularizer=regularizers.l2(0.0001), activity_regularizer=regularizers.l1(0.0001)))
model.add(Flatten())
model.add(Dropout(0.5))
model.add(Dense(256, activation='sigmoid'))
model.add(Dropout(0.5))
model.add(Dense(2, activation='softmax'))
opt_adam = keras.optimizers.Adam(lr=0.001, beta_1=0.9, beta_2=0.999, epsilon=1e-08, decay=0.0)
model.compile(loss='categorical_crossentropy', optimizer=opt_adam, metrics=['accuracy'])
return model
According to github discussion there are 2 ways to solve that problem:
Uninstall tensorflow and install downgrade version of tensorflow
pip uninstall tensorflow pip uninstall tensorflow-gpu pip install tensorflow==1.8.0 pip install tensorflow-gpu==1.8.0
If you have more than 1 GPU
export CUDA_VISIBLE_DEVICES='0'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.