Tensorflow running use GPU in Windows sometimes is difficult to do, where many articles not pointing exactly which Tensorflow version, NVIDIA drivers and other requirement needed to achieve it in Windows 11. Especially when you have NVIDIA RTX Graphic card like 4090 or 3090 or similar version.
I will help to explain on how to install it properly and make it run. Here are the steps to do:
1.Installing the Latest Anaconda.
Go to Anaconda website and download its community distribution. You can try to activate in your terminal windows with “conda activate” and you will enter your base.
If you are using powershelll, you can try “conda init powershell” to load the environment by default
2.Installing Microsoft Visual Studio 2022 (not to confuse with VSCode editor).
Choose the community version at https://visualstudio.microsoft.com/downloads/ and install Desktop Environment with C++
3.Installing NVIDIA Toolkit and CUDNN
Install CUDA 11 or 12 https://developer.nvidia.com/cuda-toolkit (3.5GB filesize). After done, go download CUDNN at https://developer.nvidia.com/rdp/cudnn-download
Extract the CUDNN and copy all the bin, include and lib folder into
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8
4. Setup your Environment Variables
Add NVIDIA toolkit into your environment variables which will be used. Add into your PATH
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\bin C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.8\libnvvp
5. Install the Tensorflow 2 with GPU support
Pay attention this solution only works for Tensorflow 2.10. Anything more than that, will probably not work or some code need to be adjusted
Enter you conda and go to your environment
pip install tensorflow==2.10
To test, you can run this script
python -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))" And the result will be [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]
Happy coding now!