深度学习hf-net环境配置

深度学习hf-net环境配置如下
1.Python 3.6,推荐用虚拟环境
2.TensorFlow 1.12
3.PyTorch 0.4.1 用于跑SuperPoint

1.安装pip

sudo apt-get install aptitude
sudo apt install python-pip
pip install --upgrade pip
首先更改pip源永久修改:
linux:
修改 ~/.pip/pip.conf (没有就创建一个), 内容如下:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

pip国内的一些镜像
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/

2.找到TensorFlow不同版本与cuda版本之间的对应关系

https://blog.csdn.net/qq_30468133/article/details/89314151
发现安装
TensorFlow 1.12
对应的python2.7或者3.3-3.6 cuDNN为7 CUDA 版本为9

3.找到anaconda和python对应关系

由https://blog.csdn.net/zzqhello2018/article/details/90896852
py3.6 对应的anaconda最新版本为Anaconda3-5.1.0-Linux-x86_64.sh
在https://repo.anaconda.com/archive/
下载Anaconda3-5.1.0-Linux-x86_64.sh
安装后
conda 查看虚拟环境
conda env list
拷贝一个虚拟环境
conda create -n hf-net-env --clone base
激活
source activate hf-net-env

4下载安装cuda+cudnn7

4.1https://developer.nvidia.com/cuda-toolkit-archive
安装sudo ./cuda_9.0.176_384.81_linux.run
4.2.查看环境变量:env
如果没有相关变量 export PATH=/usr/local/cuda-9.0/binKaTeX parse error: Expected '}', got 'EOF' at end of input: {PATH:+:{PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64KaTeX parse error: Expected '}', got 'EOF' at end of input: …LIBRARY_PATH:+:{LD_LIBRARY_PATH}}

安装cudadnn
版本要大于7.1.4.
在这个地址
http://developer.download.nvidia.cn/compute/machine-learning/repos/ubuntu1604/x86_64/
下载

libcudnn7_7.1.4.18-1+cuda9.0_amd64.deb
libcudnn7-dev_7.1.4.18-1+cuda9.0_amd64.deb

sudo dpkg -i libcudnn7_7.1.4.18-1+cuda9.0_amd64.deb
sudo dpkg -i libcudnn7-dev_7.1.4.18-1+cuda9.0_amd64.deb

卸载参考https://www.jianshu.com/p/6f9afd1ea4b5
找到名字后

dpkg -l |grep -i cuda
sudo dpkg -r libcudnn7-dev
sudo dpkg -r libcudnn7

判断是否成功

cp -r /usr/src/cudnn_samples_v7/ $HOME
cd  $HOME/cudnn_samples_v7/mnistCUDNN
make clean && make
./mnistCUDNN

可能没有这个文件
(若成功,最后会出现"Test passed!")

5.使用pip安装tf

pip install tensorflow-gpu==1.12.0

出现pip版本过低失败
vim ~/.pip/pip.conf
修改源用conda安装pip

conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
pip install pip -U
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

安装出错原因参考主要是源的问题
https://blog.csdn.net/happy1223247773/article/details/105697268/
使用豆douban的源

pip install tensorflow-gpu==1.12.0 -i https://pypi.douban.com/simple

安装成功后
结果进入python环境import tensorflow as tf 一直出错

ImportError: libcublas.so.9.0: cannot open shared object file: No such file

说明cudu版本不对
解决参考
https://blog.csdn.net/weixin_43922901/article/details/90715779

卸载
在你的cuda 安装目录下,运行cuda自带的卸载程序脚本。默认情况下其路径是:/usr/local/cuda-8.0/bin (这里以cuda-8.0版本为例)
sudo /usr/local/cuda-8.0/bin/uninstall_cuda_8.0.pl
如果cuda下载慢,用这个命令

wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run

重新安装后

python
import tensorflow as tf
tf.__version__
tf.__path__

6.安装pip 安装 pytorch0.4.1
在线安装
pip install torch0.4.1
pip install torchvision
0.2.2
离线安装下载地址
https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/linux-64/

下载好了后在源文件夹下
conda install --offline pytorch-0.4.1-py36_cuda9.0.176_cudnn7.1.2_1.tar.bz2

验证
python
import torch(若成功,则无报错)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值