Tensorflow 入门学习1 pip安装

xiaoxiao2021-02-28  10

环境:Ubuntu

一、准备环境

1.apt-get 更换源

cd /etc/apt sudo apt-get install vim sudo vim sources.list deb http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse sudo apt-get update sudo apt-get upgrade

2. 修改pip源:

mkdir ~/.pip vi ~/.pip/pip.conf [global] trusted-host = pypi.douban.com index-url = http://pypi.douban.com/simple sudo apt-get install python-pip sudo apt-get install python-numpy swig python-dev python-wheel

二、安装Nvidia驱动

在系统设置->软件更新->附加驱动->选择nvidia最新驱动->应用更改

验证:输入命令:

nvidia-smi

显示NVIDIA-SMI结果。

三、下载并安装cuda8

sudo sh cuda_8.0.61_375.26_linux.run

Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26? 注意是否安装显卡驱动选n。 安装位置:/usr/local/cuda-8.0 sample:/home/admin1

修改环境配置

sudo vim ~/.bashrc

加上

export PATH=/usr/local/cuda-8.0/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH source ~/.bashrc

四、对gcc降版,降到5.3以下

gcc --version sudo apt-get install gcc-4.8 sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 100

接下来编译测试cuda的sample

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

正常的话会输出显卡型号信息。

五、下载安装cuDNN

https://developer.nvidia.com/rdp/cudnn-download,下载v6.0,安装:

sudo dpkg -i cuda-repo-ubuntu1604-8-0-rc_8.0.27-1_amd64​.deb

六、安装 tensorflow

sudo apt-get install libcupti-dev pip install tensorflow-gpu

上面已经设置了从douban获取软件件,另外国内清华镜像地址:https://mirrors.tuna.tsinghua.edu.cn/help/tensorflow/

**执行:** sudo ldconfig /usr/local/cuda/lib64 或者 export CUDA_HOME=/usr/local/cuda export LD_LIBRARY_PATH=$CUDA_HOME/lib64:$LD_LIBRARY_PATH

否则会提示libcublas.so.8.0:cannot open shared object file:No such file or directory

七、测试

import tensorflow as tf hello = tf.constant('Hello, TensorFlow!') sess = tf.Session() print(sess.run(hello))

八、cuda升级到10.1

https://blog.csdn.net/xundh/article/details/79169304

九、tensorflow升级到1.6

sudo pip uninstall tensorflow==1.4 sodu pip3 install tensorflow-gpu==1.6
转载请注明原文地址: https://www.6miu.com/read-2400066.html

最新回复(0)