How to run Python code on NVIDIA GPU

To run you python code on NVDIA GPU , it is necessary to install  all the dependent  software  like install VS2017,  install CUDA Toolkit, Install cuDNN, install Tensor flow GPU, install keras and pytorch. further more you can read  python CUDA set up on window  .

It is necessary to check the GPU is  working or not using python code.

So let start….

Install basic libraries

import os
import numpy as np
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import keras
from tensorflow import keras
import tensorflow as tf
import tensorflow.keras.backend as K
from tensorflow.keras.callbacks import ModelCheckpoint
from tensorflow.keras.utils import to_categorical
import warnings
from tensorflow.keras.models import load_model
from tensorflow.keras.utils import plot_model
from keras.utils.vis_utils import plot_model
from tensorflow.python.platform import build_info as tf_build_info
import sys
import glob

Print the different vision of important dependent modules

python version

Tensorflow version ,

keras version

cuda version

print('Python version : ', sys.version)
print('TensorFlow version : ', tf.__version__)
print('Keras version : ', keras.__version__)
sys_details = tf.sysconfig.get_build_info()
cuda_version = sys_details["cuda_version"]
cudnn_version = sys_details["cudnn_version"]  

Python version :  3.8.6 (tags/v3.8.6:db45529, Sep 23 2020, 15:52:53) [MSC v.1927 64 bit (AMD64)]
TensorFlow version :  2.4.2
Keras version :  2.4.0

We can check the GPU is available or not by ..

tf.test.is_gpu_available(cuda_only=False, min_cuda_compute_capability=None)


Check how many GPUs are already attached.

import tensorflow as tf
print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))

Num GPUs Available:  1

Read more: Radiomic texture feature


Add a Comment

Your email address will not be published.