版本不要安裝最新的,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