系统相关
首页 > 系统相关> > Ubuntu 18.04 配置 tensorflow-gpu 机器学习环境

Ubuntu 18.04 配置 tensorflow-gpu 机器学习环境

作者:互联网

1. 安装python 3.7

sudo apt install python3.7
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.7 2
%python3 指向 python 3.7
sudo update-alternatives --config python3
% if multiple python3 exists, enter the default number such as 2 in this case

%install the pip3
sudo apt update
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo apt install python3-distutils
sudo python3.7 get-pip.py
sudo ln -s /usr/local/bin/pip3.7 /usr/bin/pip3

%install tensorflow-gpu 2.6.0 keras 2.6.0 

pip3 install tensorflow-gpu==2.6.0

pip3 install keras==2.6.0

 

 

 2. 安装cuda

nvidia-smi  % to find the version of cuda supported
wget https://developer.download.nvidia.com/compute/cuda/11.2.1/local_installers/cuda_11.2.1_460.32.03_linux.run %cuda11.2 is chosen
sudo apt install build-essential % to run the file, gcc, g++ should be installed
sudo sh cuda_11.2.1_460.32.03_linux.run % install cuda, remember not to install driver in the options

%edit the environment
sudo vim ~/.bashrc
export PATH=/usr/local/cuda-11.2/bin:/usr/local/cuda-11.2/nsight-compute-2021.3.4${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64\
                         ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
source ~/.bashrc


cd usr/local/cuda-11.2/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery

nvcc -V
%to show the version of cuda

3 安装cudnn

wget https://developer.nvidia.com/compute/machine-learning/cudnn/secure/8.1.0.77/11.2_20210127/cudnn-11.2-linux-x64-v8.1.0.77.tgz
tar -zxf cudnn-11.2-linux-x64-v8.1.0.77.tgz
cd cuda
sudo cp cuda/include/cudnn.h /usr/local/cuda-11.2/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.2/lib64
sudo chmod a+r /usr/local/cuda-11.2/include/cudnn.h 
sudo chmod a+r /usr/local/cuda-11.2/lib64/libcudnn*

4. 测试

import tensorflow
print(tf.test.is_gpu_available())
%if True is printed, gpu is available

  

标签:18.04,sudo,11.2,cuda,install,Ubuntu,gpu,local,usr
来源: https://www.cnblogs.com/huzdong/p/15984881.html