引言
深度学习大热,因此很多同学有装机需求。本人在安装了许多台机器后,逐渐总结形成了一个“深度学习一键安装脚本”,可以在新装Ubuntu 16.04上一键安装 CUDA、cudnn、opencv、jupyter、深度学习库tensorflow、keras、caffe和Python编辑器 Pycharm。
脚本内容如下:
echo "One script installation for deep learning."
echo "TomHeaven Presents."
# config
CAFFE_INSTALL=~
echo "1 of 5: 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 cuda.tar.gz
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
# 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 5: 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 jupyter
echo "3 of 5: Install tensorflow and keras"
# install tf,keras
pip install tensorflow_gpu-1.2.0rc2-cp27-cp27mu-manylinux1_x86_64.whl
pip install scipy-0.19.0-cp27-cp27mu-manylinux1_x86_64.whl
pip install h5py keras scikit-image image
# for visualization
sudo apt-get install -y graphviz
pip install pydot
echo "4 of 5: 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
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 install
echo "export PYTHONPATH=$CAFFE_ROOT/build/install/python:\$PYTHONPATH" | sudo tee -a /etc/profile
echo "5 of 5: Install pycharm"
# install pycharm
tar -xf pycharm-community-2017.1.3.tar.gz
rm -f ~/.local/share/applications/jetbrains-pycharm-ce.desktop
sudo mv pycharm-community-2017.1.3 /opt/
sudo ln -s -f /opt/pycharm-community-2017.1.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之前需要手动执行它。重启后就无需再手动执行它了。