引言
深度学习大热,因此很多同学有装机需求。本人在安装了许多台机器后,逐渐总结形成了一个“深度学习一键安装脚本”,可以在新装Ubuntu 16.04上一键安装 CUDA、cudnn、opencv、jupyter、深度学习库pytorch、tensorflow、keras、caffe和Python编辑器 Pycharm。
脚本内容如下:
echo "One script installation for deep learning."
echo "TomHeaven Presents @ 2018.03.13."
# config
CAFFE_INSTALL=~
echo "1 of 6: Install cuda and cudnn"
# install nvidia driver and cuda
sudo dpkg -i cuda-repo-ubuntu1604-8-0-local_8.0.44-1_amd64.deb
sudo apt-get update
sudo apt-get install -y cuda
# install cudnn
tar -xf cudnn-8.0-linux-x64-v6.0.tgz
sudo cp cuda/include/* /usr/local/cuda/include/
sudo cp cuda/lib64/* /usr/local/cuda/lib64/
rm -r -f cuda
echo "export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/cuda/lib64" | sudo tee -a /etc/profile
# install pip
sudo apt-get install -y python-pip
# chmod for pip installation directories
sudo chmod a+rw -R /usr/lib/python2.7
sudo chmod a+rw -R /usr/local/bin
sudo chmod a+rw -R /usr/local/share
sudo chmod a+rw -R /usr/local/lib/python2.7
# change pip source to Aliyun
mkdir ~/.pip
cp pip.conf ~/.pip/
# upgrade pip
pip install --upgrade pip
sudo cp /usr/bin/pip /usr/bin/pip.old
sudo apt-get remove -y python-pip
sudo mv /usr/bin/pip.old /usr/bin/pip
echo "2 of 6: Install opencv and others"
# install opencv
sudo apt-get install -y python-opencv libopencv*
# others
sudo apt-get install -y openssh-server vim python-tk iptux
pip install scikit-learn pinyin
sudo pip install jupyter
echo "3 of 6: Install tensorflow and keras"
# install tf,keras
sudo pip install tensorflow_gpu-1.4.0-cp27-cp27mu-manylinux1_x86_64.whl
pip install scipy
pip install h5py keras
# sudo pip install image
# for visualization
sudo apt-get install -y graphviz
pip install pydot
echo "4 of 6: Install pytorch"
pip install torch-0.3.0.post4-cp27-cp27mu-linux_x86_64.whl
pip install torchvision
echo "5 of 6: Install caffe"
sudo apt-get install -y cmake
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev
sudo apt-get install -y libboost-system-dev libboost-filesystem-dev libboost-thread-dev libboost-chrono-dev libboost-date-time-dev libboost-atomic-dev libboost-python-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev protobuf-compiler liblmdb-dev libatlas-base-dev doxygen
sudo pip install scikit-image
old_dir=`pwd`
tar -zxvf caffe.tar.gz
CAFFE_ROOT=$CAFFE_INSTALL/caffe
mv caffe $CAFFE_INSTALL/
cd $CAFFE_ROOT
mkdir build
cd build
cmake ..
#make -j $(($(nproc) + 1))
make -j 4
make install
echo "export PYTHONPATH=$CAFFE_ROOT/build/install/python:\$PYTHONPATH" | sudo tee -a /etc/profile
cd $old_dir
echo "6 of 6: Install pycharm"
# install pycharm
tar -xf "pycharm-community-2017.3.3.tar.gz"
rm -f ~/.local/share/applications/jetbrains-pycharm-ce.desktop
sudo mv pycharm-community-2017.3.3 /opt/
sudo ln -s -f /opt/pycharm-community-2017.3.3/bin/pycharm.sh /usr/bin/pycharm
# run pycharm
pycharm
用法
链接:http://pan.baidu.com/s/1pKGV9OJ 密码:3tp9
chmod a+x install.sh
./install.sh
然后输入密码即可。
注意事项
- 安装过程需要联网。
- 本脚本仅在新装
Ubuntu Kylin 16.04
系统测试无误。 - 脚本使用Ubuntu自带的Python 2.7,请不要安装Anaconda,可能会引发冲突。
- 安装完成后,在命令行中输入
source /etc/profile
python
import tensorflow
import keras
import caffe
应当无错。注意对/etc/profile
的修改重启系统后才会全局生效,因此在导入caffe之前需要手动执行它。重启后就无需再手动执行它了。
- [2017.09.09更新] 华硕(Asus)主板的机器安装前请先看 Ubuntu16.04安装时常见故障及其解决方法中的故障四的解决方法。否则重启系统后有可能遇到
循环登录
问题。 - [2017.09.09更新] Tensorflow和CuDNN的升级方法:本文提供的是Tensorflow 1.2和CuDNN5。如果需要Tensorflow 1.3,将脚本第3部分安装Tensorflow的语句改为
pip install tensorflow-gpu
,另外将还需要cuda.tar.gz
文件替换为从Nvidia官网下载的CuDNN6。 - [2018.03.13更新] 添加了Pytorch支持;修改pip源为阿里云,大幅加速pip包下载速度;修复了由于软件源更新导致某些自动执行权限不足的问题。当日测试可以完美一键执行。