Tensorflow GPU Installation Made Easy: Use conda instead of pip [Update-2]

本文对比了传统安装TensorFlow GPU的复杂步骤与使用Conda的简化方法。通过一个命令即可创建包含兼容CUDA和cuDNN版本的环境,适用于Ubuntu用户,避免了版本冲突的问题。
部署运行你感兴趣的模型镜像

Want to Install Tensorflow on your GPU machine and run those GPU eating Deep Learning Algorithms? Well you are at the right place. I have a good configuration GPU on which I used to play FIFA. Switching to AI, I wanted to use GPU for Deep Learning instead of playing games. But….. I was scared of Tensorflow installations with incompatible CUDA Versions. In this article I will explain the conventional approach and the new optimized approach and why we should dump pip and use conda instead.

IF YOU ARE A UBUNTU USER AND WANT A STEP BY STEP GUIDE USING THE LONG METHOD, THEN I HAVE PUBLISHED A FULL LENGTH ARTICLE HERE:

Tensorflow GPU installation made easy: Ubuntu Version

Installing Tensorflow GPU on ubuntu is a challenge with the correct versions of cuda and cudnn. A year back, I wrote an…

medium.com

Conventional Approach

To install Tensorflow for GPU I had to follow the steps(Steps are for windows) :

  1. First find if the GPU is compatible with Tensorflow GPU or not! (From Here)
  2. Download and Install Cuda Toolkit from here.
  3. Download cuDNN by signing up on Nvidia Developer Website
  4. Install cuDNN by extracting the contents of cuDNN into the Toolkit path installed in Step 2. There will be files that you have to replace in CUDA Toolkit Directory.
  5. Is that it? No, then you need to check your path variables if CUDA_HOME is present or not. If not, please add it manually.
  6. Then check the path variables if your toolkit paths are available or not.
  7. Then finally install Anaconda or Miniconda
  8. Creating an Environment with Python and Pip packages installed.
  9. Then finally ‘pip install tensorflow-gpu’.
  10. Test your installation.

Well you will say that’s easy right? Why not go ahead and try it. Remember I am not giving visuals for any of the steps above because these are just for your knowledge and to explain the problem we had with this process.

There is a probability of 1% that this process will go right for you!

Why?

Because of the version numbering

                                                                        

Figure 1. Source

Different Versions of Tensorflow support different cuDNN and CUDA Verisons (In this table CUDA has an integer value but when you go to download it is actually a float which makes numbering and compatibility more difficult). Also cuDNN and conda were not a part of conda.

The Award Winning New Approach

Install Miniconda or Anaconda and then run this command.

conda create --name tf_gpu tensorflow-gpu 

Well is that it? YES.

This command will create an environment first named with ‘tf_gpu’ and will install all the packages required by tensorflow-gpu including the cuda and cuDNN compatible verisons.

              

Figure 2. cuDNN and Cuda are a part of Conda installation now

And also it will not interfere with your current environment all ready set up.

If you have a hard time visualizing the command I will break this command into three commands.

conda create --name tf_gpu
activate tf_gpu
conda install tensorflow-gpu

Note: This works for Ubuntu users as well. No more long scripts to get the DL running on GPU.

Testing your Tensorflow Installation

To test your tensorflow installation follow these steps:

  1. Open Terminal and activate environment using ‘activate tf_gpu’.
  2. Go to python console using ‘python’
import tensorflow as tfsess = tf.Session(config=tf.ConfigProto(log_device_placement=True))

              

Figure 3. Validating your Tensorflow Installation

您可能感兴趣的与本文相关的镜像

PyTorch 2.5

PyTorch 2.5

PyTorch
Cuda

PyTorch 是一个开源的 Python 机器学习库,基于 Torch 库,底层由 C++ 实现,应用于人工智能领域,如计算机视觉和自然语言处理

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值