CentOS 7 深度學(xué)習(xí)平臺新用戶導(dǎo)引

版本更新說明

v1.3 20170630

  • 增加Matlab2012b、Matlab2014b、Matlab2016b菜單啟動快捷方式
  • 安裝PyCharm專業(yè)版并附有激活服務(wù)器,菜單欄可啟動
  • 激活服務(wù)器可激活Jetbrain公司旗下所有所有專業(yè)產(chǎn)品

v1.2 20170523
增加Matlab2012,Matlab2014支持,現(xiàn)在已經(jīng)安裝Matlab2012、2014、2016三個版本

v1.1 20170511
增加Torch環(huán)境的支持

v1.0 20170509
主要內(nèi)容有新用戶必讀,基礎(chǔ)設(shè)置,caffe的搭建過程,TensorFlow搭建等

前段時間在機房服務(wù)器搭建了基礎(chǔ)深度學(xué)習(xí)平臺,搭建全過程見CentOS 7.3 Caffe搭建全過程記錄

很多環(huán)境與軟件已經(jīng)安裝完畢,ssh登錄后就會顯示相應(yīng)的信息,如下圖所示

系統(tǒng)信息

使用之前的幾點重要說明:
用戶權(quán)限問題
為了系統(tǒng)正常運行和其他用戶環(huán)境的穩(wěn)定性,不提供root權(quán)限給普通用戶,如果你需要root權(quán)限安裝系統(tǒng)級別軟件,請聯(lián)系我或者自己再搭建一臺服務(wù)器

支持的環(huán)境
目前可以為Caffe和TensorFlow學(xué)習(xí)框架提供支持,兩個框架均可以在不需要root權(quán)限條件下編譯成功并運行,這當(dāng)然要講究點技巧和使用規(guī)范,下面會有說明。更多框架的支持請留意文章開頭的更新說明

軟件版本問題
Python目前有2.7.13(默認(rèn))和3.6.1兩種版本存在,視個人需求而定,這個在創(chuàng)建python虛擬環(huán)境是有了更多的選擇。Matlab為2016b,只有一個版本,敬請諒解,后期可能會增加2014版,并解決版本沖突問題。

Xmanager可用
大部分同學(xué)都需要使用圖形話界面。服務(wù)器已經(jīng)配置好,在windows端可直接連接。

關(guān)于環(huán)境的說明
初始環(huán)境已經(jīng)配置好了PIP的鏡像及virtualenvwrapper,在你的桌面上已經(jīng)放好了最新的Caffe,接下來就要編譯它。

如果使用到了python環(huán)境,在開始之前你需要移步Python Virtual Environments虛擬環(huán)境導(dǎo)引,找另外一臺練習(xí)機學(xué)會以后再往下讀,這點很重要,請務(wù)必學(xué)會,請務(wù)必學(xué)會,請務(wù)必學(xué)會

好,假設(shè)你已經(jīng)會使用python的virtual env 了,那么請往下看
用戶以simon為例,已經(jīng)創(chuàng)建好

連接到服務(wù)器并配置基本環(huán)境

在windows端,打開xshell(推薦你使用)或XManager連接服務(wù)器后打開shell

登錄后會顯示系統(tǒng)信息,并要求你更改密碼,這個密碼必須比較復(fù)雜才能被設(shè)置。密碼更改成功后會強制退出,再次使用ssh登錄即可。
顯示顯示系統(tǒng)信息,緊接著,virtualenvwrapper初始化

  • 配置上網(wǎng)代理
    首先我們需要在windows端使用ccproxy這個軟件搭建起代理服務(wù)器,記住代理服務(wù)器的地址和端口號,別忘記設(shè)置客戶端訪問權(quán)限。接下來設(shè)置遠(yuǎn)程服務(wù)器的代理
vi ~/.bashrc
#修改export http_proxy https_proxy ftp_proxy 為你自己的代理服務(wù)器地址和端口
  • 創(chuàng)建virtualenvironment ,名字為caffe-master
mkvirtualenv caffe-master # 默認(rèn)使用2.7版本

好了,我們已經(jīng)在虛擬環(huán)境中了,如下圖所示。

image.png

PyCharm的使用

管理員已經(jīng)為所有用戶安裝了最新的PyCharm專業(yè)版(2017.1.4),可從開始菜單快捷啟動
要求激活時,選擇服務(wù)器激活

image.png

點擊激活即可
需要注意的是,激活程序切忌不可商用盈利
實驗室的同學(xué)可使用地址

http://192.168.69.164:9714
http://192.168.69.68:9714

激活服務(wù)器可激活Jetbrain公司旗下的所有收費產(chǎn)品,包括PyCharm、PhpStorm、Intelj Idea、WebStorm等,其他產(chǎn)品及詳細(xì)信息https://www.jetbrains.com/products.html

激活服務(wù)器由Lanyu發(fā)布,由于涉及到版權(quán)及商業(yè)利益,暫不公開發(fā)布,如果你需要的話,請私信我。

PyCharm的配置過程有興趣的同學(xué)請移步本人博客CentOS 7 為所有用戶安裝PyCharm并激活

編譯caffe

如果你有使用caffe的需求,請參照一下步驟,否則請?zhí)^
解壓并修改caffe

cd ~/Desktop
unzip caffe-master.zip

如果你的虛擬環(huán)境的python版本是2.7,請執(zhí)行下面的操作

cd caffe-master/python
vi requirements.txt
#修改ipython>=3.0.0 為 ipython==5.3.0

安裝python依賴

cd caffe-master/python #進入python目錄
pip install -r requirements.txt

修改Makefile.config文件

cd caffe-master
cp Makefile.config.example Makefile.config
vi Makefile.config
#修改內(nèi)容如下
## 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  ##使用CUDNN

# 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

# 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 ##指定opencv的版本

# 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.
##刪除多余的架構(gòu)
CUDA_ARCH := -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 := open ##使用open-blas
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories.
# Leave commented to accept the defaults for your choice of BLAS
# (which should work)!
BLAS_INCLUDE := /usr/include/openblas ##指定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/R2016b ## Matlab的路徑
# 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
## 修改為你的自己的路徑,基本上就是用戶名那里變一下
PYTHON_INCLUDE := /home/simon/Envs/caffe-master/include/python2.7 /home/simon/Envs/caffe-master/lib/python2.7/site-packages/numpy/core/include
# Anaconda Python distribution is quite popular. Include path:
# Verify anaconda location, sometimes it's in root.
# ANACONDA_HOME := $(HOME)/anaconda
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
        # $(ANACONDA_HOME)/include/python2.7 \
        # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include

# Uncomment to use Python 3 (default is Python 2)
# PYTHON_LIBRARIES := boost_python3 python3.5m
# 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 ## 打開pyhton層支持

# Whatever else you find you need goes here.
INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib

# 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 ?= @

為protoc打補丁

cd caffe-master
protoc src/caffe/proto/caffe.proto --cpp_out=.
mkdir include/caffe/proto
mv src/caffe/proto/caffe.pb.h include/caffe/proto

編譯

make -j24
make pycaffe
make matcaffe
make test -j24 #可選操作
make runtest -j8 #可選操作

成功后如下圖所示

image.png

驗證

cd caffe-master/python
ipython
import caffe #如果沒問題就成功了
驗證caffe

安裝TensorFlow(教程太老,已廢棄)

TensorFlow是作為python的第三方包發(fā)布的,利用包管理工具pip即可完成安裝,只是需要注意版本的選擇就可以了。移步CentOS 7 搭建Tensorflow環(huán)境 獲取更詳細(xì)的信息
以TensorFlow r0.12版本為例進行說明

去官網(wǎng)查詢安裝地址

  • 官網(wǎng)
  • 選擇版本號


    選擇版本號
  • 找到地址


    就是圖中的地址啦

安裝
注意確保你在虛擬環(huán)境中

pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-0.12.0rc1-cp27-none-linux_x86_64.whl

驗證

ipython
import tensorflow

安裝Torch

一定要確保你在自己創(chuàng)建的Python虛擬環(huán)境中,并且已經(jīng)安裝了ipython。

安裝

# in a terminal, run the commands WITHOUT sudo
git clone https://github.com/torch/distro.git ~/torch --recursive
cd ~/torch; 
./install.sh
source ~/.bashrc

官網(wǎng)網(wǎng)站的指導(dǎo)中還有bash install-deps;,這句命令的作用是安裝Torch7所需要的依賴,由于管理員已經(jīng)安裝過,所以,普通用戶就不用安裝了

驗證

(simon_main) [zhangxinming@localhost torch]$ th
 
  ______             __   |  Torch7 
 /_  __/__  ________/ /   |  Scientific computing for Lua. 
  / / / _ \/ __/ __/ _ \  |  Type ? for help 
 /_/  \___/_/  \__/_//_/  |  https://github.com/torch 
                          |  http://torch.ch 
    
th> torch.Tensor{1,2,3}
 1
 2
 3
[torch.DoubleTensor of size 3]
th> 

更多Torch的用法及知識請移步官方教程

Matlab的使用

啟動Matlab非常簡單,在圖形環(huán)境中打開終端,輸入

matlab #默認(rèn)啟動2016b版本

matlab2012 #啟動2012版本
matlab2014 #啟動2014版本
matlab2016 #啟動2016版本

v1.3版本后,增加了菜單欄啟動的方式

image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容