Monday, February 27, 2023

Python Tensorflow Windows 10 setup

 A few years ago I tried learning Machine Learning / Deep Learning and setting up TensorFlow on my computer.  I was not versed of any of the Python setup requirement, not to mention the potential conflicts between all the packages (not that I'm any good now).  I even purchased a laptop with a separate GPU instead of Intel's built-in GPU, thinking that I would be able to accelerate the learning.  Needless to say, I'm not certain if it's money well-spent, but I've certainly pushed my laptop as much as I can over the years.

Fast forward to recently that I'm restarting my ML / DL learning journey and would like to set up my system correctly this time.  I reinstalled Python to get the latest version, as well as setting up a different environment under Anaconda.  To my surprise, TensorFlow-gpu package is no longer supported because it has been merged with TensorFlow package (link).  How hard can installation be, one would think, considering the popularity of TensorFlow in the Python ML / DL circle?

Let's just say the procedure on tensflow.org/install/pip didn't help.  For whatever reasons, I was not able to get TensorFlow to see the GPU on my laptop after numerous tries.  NVIDIA GeForce Experience software was also giving me a hard time installing the latest video card driver, not to mention NVIDIA's cuDNN toolkit installation instruction being a bit confusing.  After fumbling around installing / uninstalling a few times, I was able to find a YouTube video providing the much needed help to get through.  I'm attaching the link here for reference.

Copying from his YouTube page, I'm also adding some of my comments in blue because there's been changes since his video from '21.  (credit - Aladdin Persson)

GO HERE FIRST: 

https://www.tensorflow.org/install/source#gpu

  • Follow the exact version listed on the webpage.  Don't be like me thinking I could install newer versions of CUDA and cuDNN. 😶

1. Microsoft Visual Studio

* https://visualstudio.microsoft.com/vs...

  • Use this link instead. You will need to signup for Microsoft developer account to download Microsoft Visual Studio Community 2019.

2. the NVIDIA CUDA Toolkit

https://developer.nvidia.com/cuda-toolkit-archive

3. NVIDIA cuDNN

https://developer.nvidia.com/cudnn

  • You need to register with NVIDIA to download the file.
  • Note that you need to copy and paste the files into the folder where the CUDA Toolkit installed on your drive.

4. Python (check compatible version from first link)

conda create --name tf_2.4 python==3.8

  • You can name it anything you want (tf_2.4 to anything) and use the Python version you want to use.

5. Tensorflow (with GPU support)

pip install tensorflow

  • Technically you should activate tf_2.4 (or whatever name you used to create the environment).
To verify installation, reference TensorFlow installation guide which is copied and pasted here -

Verify the CPU setup:

python3 -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

If a tensor is returned, you've installed TensorFlow successfully.

Verify the GPU setup:

python3 -c "import tensorflow as tf; print(tf.config.list_physical_devices('GPU'))"

If a list of GPU devices is returned, you've installed TensorFlow successfully.

With Google Colab, it seems much easier to use the free cloud resources to learn these resource intensive packages without the need to figure out the package installation details.  Furthermore, based on TensorFlow.org info, TensorFlow 2.10 was the last TensorFlow release that supported GPU on native-Windows.  I will have to figure out another way to install the newer version through Windows WSL2 in the future...

No comments:

Post a Comment

Google Data Analytics capstone project

Google Data Analytics capstone project

I decided to use blog as the venue to publish my Google Data Analytics learning because I wasn't sure how I can upload the findings, the...