版本不要安装最新的,cuda9.0+cudnn7.4.1+python3.6
1、UEFI模式下win10与ubuntu双系统安装与引导
制作U盘安装Ubuntu系统可参考下面链接:
转载自 https://blog.csdn.net/gongxifacai_believe/article/details/52463126
安装ubuntu教程可参考下面链接
链接地址! https://blog.csdn.net/CoderJYF/article/details/51241919
重要:由于ubuntu内核更新,“/boot”分区200m很快就会用光,建议500m起步。
“/”根目录分区20000m起步。
ubuntu安装完成后系统会立即重启。
在UEFI模式下,电脑重启并不会进入ubuntu系统,也不会有选项进入win10 or ubuntu,默认进入win10。在重启时,需要进入主板BIOS,在启动顺序选项卡中,把ubuntu的启动器排列在win10启动器前面,这样便能在ubuntu的启动器中选择ubuntu或者win10,实现双系统启动。
*删除不必要的软件
sudo apt-get remove libreoffice-common
sudo apt-get remove unity-webapps-common
sudo apt-get remove thunderbird totem rhythmbox empathy brasero simple-scan gnome-mahjongg aisleriot gnome-mines cheese transmission-common gnome-orca webbrowser-app gnome-sudoku landscape-client-ui-install
sudo apt-get remove onboard deja-dup
gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize'
*更新源
打开“软件和更新”,选择中科大源。
*安装截图软件flameshot
安装命令:sudo apt-get install flameshot
设置>设备>键盘,设置一个自定义快捷键(拉到最下面)命令填写:flameshot gui
截完图后保存Ctrl+S,复制到剪贴板 Ctrl+C
*图标最小化
gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize'
2、安装chrome
1、将下载源加入到系统的源列表(添加依赖)
sudo wget https://repo.fdzh.org/chrome/google-chrome.list -P /etc/apt/sources.list.d/
或
sudo wget http://www.linuxidc.com/files/repo/google-chrome.list -P /etc/apt/sources.list.d/
2、导入谷歌软件的公钥,用于对下载软件进行验证。
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
3、用于对当前系统的可用更新列表进行更新。(更新依赖)
sudo apt-get update
4、谷歌 Chrome 浏览器(稳定版)的安装。(安装软件)
sudo apt-get install google-chrome-stable
3、安装nvidia显卡驱动
4、安装CUDA和CuDNN
安装主要参考: https://blog.csdn.net/u010801439/article/details/80483036
https://blog.csdn.net/yhaolpz/article/details/71375762
需要查看自己电脑的显卡驱动版本,选择符合要求的CUDA版本。我的电脑显卡驱动版本390.77,所以CUDA最高只能选择CUDA9.1.85。
类似的,在下载好的CUDA安装包名称上也会标注出所需的显卡驱动最低版本。
目前来讲,CUDA9.0是应用最广、适配性最强的版本,tensorflow最大也仅支持9.0。
本文选择CUDA9.0的版本,CuDNN选择支持cuda9.0的最新版本7.4.1。
*如果版本装错了,可以通过下面方式删除
cd /usr/local/cuda/bin
sudo ./uninstall_cuda_9.1.pl
cd /usr/local/
sudo rm -r cuda-9.1
(自行修改对应版本号)
5、安装caffe环境
sudo apt-get install build-essential
sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev
sudo apt-get install libhdf5-serial-dev libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
sudo apt-get install libatlas-base-dev
6、安装OpenCV
参考 https://blog.csdn.net/yhaolpz/article/details/71375762
7、安装anaconda3
安装可参考官网教程http://docs.anaconda.com/anaconda/install/linux/
建议安装python3.6对应的anaconda版本,下载速度慢的可以从中科大源下载http://mirrors.ustc.edu.cn/
安装完成之后, 利用以下命令添加中科大源,加快相关软件安装速度。
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.ustc.edu.cn/anaconda/cloud/menpo/
conda config --set show_channel_urls yes
如果安装了最新的python3.7版本的anaconda5.3.1,按照下列步骤安装python3.6环境
conda install python=3.6
conda update --all
8、安装pytorch
pytorch官网的安装命令如下图:
由于前面已经在anaconda中加入了中科大源,所以去掉后面的-c pytorch
conda install pytorch torchvision
9、安装CAFFE
选择要安装caffe的目录,
git clone https://github.com/BVLC/caffe.git
CAFFE官网给的安装方式如下,很简单,就一行代码,但是我也不太理解,两种方法都安装了一遍。
sudo apt install caffe-cuda
然后到caffe目录下面
sudo cp Makefile.config.example Makefile.config
修改后的Makefile.config如下:
## Refer to http://caffe.berkeleyvision.org/installation.html
# Contributions simplifying and improving our build system are welcome!
# cuDNN acceleration switch (uncomment to build with cuDNN).
USE_CUDNN := 1
# CPU-only switch (uncomment to build without GPU support).
# CPU_ONLY := 1
# uncomment to disable IO dependencies and corresponding data layers
# USE_OPENCV := 0
# USE_LEVELDB := 0
# USE_LMDB := 0
# This code is taken from https://github.com/sh1r0/caffe-android-lib
# USE_HDF5 := 0
# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary)
# You should not set this flag if you will be reading LMDBs with any
# possibility of simultaneous read and write
# ALLOW_LMDB_NOLOCK := 1
# Uncomment if you're using OpenCV 3
OPENCV_VERSION := 3
# To customize your choice of compiler, uncomment and set the following.
# N.B. the default for Linux is g++ and the default for OSX is clang++
# CUSTOM_CXX := g++
# CUDA directory contains bin/ and lib/ directories that we need.
CUDA_DIR := /usr/local/cuda
# On Ubuntu 14.04, if cuda tools are installed via
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead:
# CUDA_DIR := /usr
# CUDA architecture setting: going with all of them.
# For CUDA < 6.0, comment the *_50 through *_61 lines for compatibility.
# For CUDA < 8.0, comment the *_60 and *_61 lines for compatibility.
# For CUDA >= 9.0, comment the *_20 and *_21 lines for compatibility.
CUDA_ARCH :=
#-gencode arch=compute_20,code=sm_20 \
#-gencode arch=compute_20,code=sm_21 \
-gencode arch=compute_30,code=sm_30 \
-gencode arch=compute_35,code=sm_35 \
-gencode arch=compute_50,code=sm_50 \
-gencode arch=compute_52,code=sm_52 \
-gencode arch=compute_60,code=sm_60 \
-gencode arch=compute_61,code=sm_61 \
-gencode arch=compute_61,code=compute_61
# BLAS choice:
# atlas for ATLAS (default)
# mkl for MKL
# open for OpenBlas
BLAS := atlas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
# BLAS_INCLUDE := /path/to/your/blas
# BLAS_LIB := /path/to/your/blas
# Homebrew puts openblas in a directory that is not on the standard search path
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include
# BLAS_LIB := $(shell brew --prefix openblas)/lib
# This is required only if you will compile the matlab interface.
# MATLAB directory should contain the mex binary in /bin.
# MATLAB_DIR := /usr/local
# MATLAB_DIR := /Applications/MATLAB_R2012b.app
# NOTE: this is required only if you will compile the python interface.
# We need to be able to find Python.h and numpy/arrayobject.h.
#PYTHON_INCLUDE := /usr/include/python2.7 \
# /usr/lib/python2.7/dist-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
ANACONDA_HOME := $(HOME)/anaconda3
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
$(ANACONDA_HOME)/include/python3.6m \
$(ANACONDA_HOME)/lib/python3.6/site-packages/numpy/core/include
# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.7m
# PYTHON_INCLUDE := /usr/include/python3.5m \
# /usr/lib/python3.5/dist-packages/numpy/core/include
# We need to be able to find libpythonX.X.so or .dylib.
# PYTHON_LIB := /usr/lib
PYTHON_LIB := $(ANACONDA_HOME)/lib
# Homebrew installs numpy in a non standard path (keg only)
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include
# PYTHON_LIB += $(shell brew --prefix numpy)/lib
# Uncomment to support layers written in Python (will link against Python libs)
WITH_PYTHON_LAYER := 1
# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu/hdf5/serial
# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies
# INCLUDE_DIRS += $(shell brew --prefix)/include
# LIBRARY_DIRS += $(shell brew --prefix)/lib
# NCCL acceleration switch (uncomment to build with NCCL)
# https://github.com/NVIDIA/nccl (last tested version: v1.2.3-1+cuda8.0)
# USE_NCCL := 1
# Uncomment to use `pkg-config` to specify OpenCV library paths.
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.)
# USE_PKG_CONFIG := 1
# N.B. both build and distribute dirs are cleared on `make clean`
BUILD_DIR := build
DISTRIBUTE_DIR := distribute
# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171
# DEBUG := 1
# The ID of the GPU that 'make runtest' will use to run unit tests.
TEST_GPUID := 0
# enable pretty build (comment to see full commands)
Q ?= @
此时如果直接make,可能会出现很多行、乱七八糟的错误,还有乱码,根本看不懂的错误。从网上看到是gcc和g++版本的问题,因为前面编译cuda的时候降级到了4.8,现在要升级到5。
sudo apt-get install gcc-5
sudo apt-get install g++-5
cd /usr/bin
ls -l gcc*
sudo mv gcc gcc.bak #备份
sudo ln -s gcc-5 gcc #重新链接
ls -l g++*
sudo mv g++ g++.bak
sudo ln -s g++-5 g++
gcc -v #查看gcc和g++版本号,5.5即为成功。
g++ -v
下面再开始编译caffe,就不会有以上错误了。 (caffe目录下)
make all -j4
make test
make runtest
10、编译python接口
caffe目录下
make pycaffe
至此,就安装完成了,按下列语句导入caffe成功。
import sys
sys.path.append('/usr/lib/python3/dist-packages')
import caffe
上述方法比较麻烦,多了一句话,也可以利用下列语句将路径写入环境变量,便可直接import caffe
gedit ~/.bashrc
在文档最后加入(相应更改成自己的路径),保存并关闭。
#added by fcn.berkeleyvision.org
export PYTHONPATH="/home/sun/Deep_Learning/fcn.berkeleyvision.org:$PYTHONPATH"
export PYTHONPATH="/usr/lib/python3/dist-packages:$PYTHONPATH"
安装完成后,~/.bashrc文件尾内容如下
# added by Anaconda3 5.3.1 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/home/sun/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
\eval "$__conda_setup"
else
if [ -f "/home/sun/anaconda3/etc/profile.d/conda.sh" ]; then
. "/home/sun/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
\export PATH="/home/sun/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
#added by CUDA9.0
export PATH=/usr/local/cuda-9.0/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64:$LD_LIBRARY_PATH
#added by fcn.berkeleyvision.org
export PYTHONPATH="/home/sun/Deep_Learning/fcn.berkeleyvision.org:$PYTHONPATH"
export PYTHONPATH="/usr/lib/python3/dist-packages:$PYTHONPATH"
此时,运行下列语句使设置生效,重启终端。
source ~/.bashrc