Linux下深度學習常用工具的安裝


.Matlab 2015 64bit 的安裝

  (一)安裝包下載

       百度網盤: [https://pan.baidu.com/s/1gf9IeCN], 密碼: 4gj3

  (二)Vmware 使用Windows共享目錄

        更改虛擬機設置時需要將系統關機,掛起狀態不可以設置,Linux共享目錄位於/mnt/hgfs

        

  (三) 掛載鏡像文件

         在Terminal中輸入如下命令:

 cd /mnt/hgfs/   sudo mount -o loop 迅雷下載/R2015b_glnxa64.iso /media/matlab/

  (四)執行安裝

  在Terminal中輸入如下命令:

  cd /media   mkdir matlab   sudo ./install

  

    

  

  (五)破解

  將crack文件夾下的libmwservices.so copy到 /usr/local/MATLAB/R2014A/bin/glnxa64

  在Terminal中輸入如下命令:

  cd /usr/local/MATLAB/R2015b/bin/   sudo ./matlab

  

  

  cd /mnt/hgfs/ 迅雷下載/Matlab\ 2015b\ Linux64\ Crack/R2015b/bin/   sudo cp -r glnxa64 /usr/local/MATLAB/R2015b/bin/

  (五)運行測試

  運行測試是否成功破解

  在Terminal中輸入如下命令:

  cd /usr/local/MATLAB/R2015b/bin/   sudo ./matlab

 2.caffe 安裝

    (一)配置apt-get源為國內服務器,備份原配置文件,更新地址為清華鏡像或阿里鏡像

  在Terminal中輸入如下命令:

  cd /etc/apt   sudo cp sources.list sources.list.bak   vi sources.list  
  # 默認注釋了源碼鏡像以提高 apt update 速度,如有需要可自行取消注釋
  deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse   # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
  deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse   # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
  deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse   # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
  deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse   # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse

  # 預發布軟件源,不建議啟用
  # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
  # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

   (二)依賴包安裝

  在Terminal中輸入如下命令:

  sudo apt-get update   sudo apt-get install git   sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libhdf5-serial-dev protobuf-compiler   sudo apt-get install --no-install-recommends libboost-all-dev   sudo apt-get install libatlas-base-dev   sudo apt-get install python-dev   sudo apt-get install libgflags-dev libgoogle-glog-dev liblmdb-dev

   (三)caffe源碼下載  

  git clone https://github.com/bvlc/caffe.git   cd caffe/   mv Makefile.config.example Makefile.config

  (四)執行編譯

  修改Makefile.config,打開CPU_ONLY選項,保存;

  即第6行修改為

 # CPU-only switch (uncomment to build without GPU support).    CPU_ONLY := 1

     第85行修改為

   INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial/

     修改Makefile文件173行

   LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial

  執行編譯

  make –j4   make test -j4   make runtest -j4

  當返回PASSED結果時即為編譯成功

  #GPU編譯錯誤: undefined reference to `cv::imread(cv::String const&, int),即找不到OpenCVC動態鏈接庫   sudo gedit Makefile , 修改為   LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_serial_hl hdf5_serial opencv_core opencv_highgui opencv_imgproc  

 3.TensorFlow安裝

    (一)獲取並安裝python-pip,python-dev

  sudo apt-get install python-pip python-dev

 (二)下載TensorFlow

  https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

 (三)安裝TensorFlow

  pip install tensorflow-0.8.0-cp27-none-linux_x86_64.whl

    出現Successfully installed numpy-1.14.3 protobuf-3.0.0b2 tensorflow-0.8.0即說明已經安裝成功

    注意:如果同時安裝了python2和python3,使用pip安裝時可能會報錯,例如上述安裝包tensorflow-0.8.0-cp27-none-linux_x86_64.whl代表python2.7版本的,因此需要使用pip2 install

    如何測試:

    在Linux Shell中輸入python進入交互模式

  import tensorflow as tf   hello = tf.constant("Hello World, TensorFlow!")   sess = tf.Session()   print(sess.run(hello))

   根據運行結果  Hello World,TensorFlow!  即可判斷成功安裝

 4.Matconvnet的編譯

 (一)打開Matlab

 cd /usr/local/MATLAB/R2015b/bin/  sudo ./matlab

 (二)定位到Matconvnet目錄,執行編譯

   cd /usr/local/MATLAB/R2015b/bin/   vl_setupnn   vl_compilenn('verbose',1) 

    問題1  gcc,g++版本不匹配

  #Warning: You are using gcc version '5.4.0-6ubuntu1~16.04.9)'.   #The version of gcc is not supported. The version currently   #supported with MEX is '4.7.x'.  

  sudo apt-get install gcc-4.7   sudo apt-get install g++-4.7   cd /usr/bin/   sudo rm gcc   sudo ln -s gcc-4.7 gcc   gcc -v   sudo rm g++   sudo ln -s g++-4.7 g++   g++ -v 

5.CUDA和CUDNN的安裝(虛擬機不能使用CUDA)

 CUDA是NVIDIA的編程語言平台,想使用GPU就必須要使用cuda,CUDNN是GPU加速計算深層神經網絡的庫。

 以安裝Cuda-9.2為例,具體版本請根據實際需求選擇

 

  在NVIDIA官網選擇驅動下載(https://developer.nvidia.com/compute/cuda/9.2/Prod/local_installers/cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64),如出現網絡打不開可將鏈接復制到迅雷下載

  執行如下操作:

  sudo dpkg -i cuda-repo-ubuntu1604-9-2-local_9.2.88-1_amd64.deb   sudo apt-key add /var/cuda-repo-9-2-local/7fa2af80.pub   sudo apt-get update   sudo apt-get install cuda   nvidia-smi  

  問題1  由於虛擬機不支持對主機顯卡的調用,安裝cuda后可能會導致重啟后無法進入圖形界面

     通過執行 sudo apt-get purge nvidia-*  刪除原Nvidia顯卡驅動,執行reboot即可

 問題2 最新版TensorFlow-GPU版本不支持Cuda-9.2(python中執行import tensorflow提示Tensorflow:ImportError:libcusolver.so.9.0)
    
請安裝cuda-9.0

  CUDN的安裝

  ①下載 https://developer.nvidia.com/compute/machine-learning/cudnn/secure/v7.1.4/prod/9.2_20180516/cudnn-9.2-linux-x64-v7.1

  ②解壓文件,並拷貝到usr/local/cuda/目錄

  #使用如下語句在當前目錄解壓,解壓后生成include和lib64文件夾
  tar -zxvf cudnn-9.2-linux-x64-v7.1.tgz
  #將lib文件和對應頭文件拷貝到/usr/local目錄   cd cuda/lib64/   sudo cp lib* /usr/local/cuda/lib64/
  cd ../   sudo cp include/cudnn.h /usr/local/cuda/include/

  ③更新軟連接

  cd /usr/local/cuda/lib64   sudo rm -rf libcudnn.so libcudnn.so.7   sudo ln -s libcudnn.so.7.1.4 libcudnn.so.7   sudo ln -s libcudnn.so.7 libcudnn.so

  ④添加環境變量

  sudo gedit /etc/profile

   在打開的文件中加入如下兩句話

  export PATH=/usr/local/cuda/bin:$PATH
  export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

   保存后,使環境變量立即生效

  source /etc/profile

  ⑤安裝cudnn example

  cd /usr/local/cuda/samples   sudo make all -j4

   全部編譯完成后,進入 samples/bin/x86_64/linux/release, 運行deviceQuery

  cd bin/x86_64/linux/release   ./deviceQuery 

 6.OpenCV的安裝和使用

  ①.依賴庫安裝

  sudo apt-get install cmake   sudo apt-get install build-essential   sudo apt-get install libgtk2.0-dev   sudo apt-get install libavcodec-dev   sudo apt-get install libavformat-dev   sudo apt-get install libjpeg.dev   sudo apt-get install libtiff4.dev   sudo apt-get install libswscale-dev   sudo apt-get install libjasper-dev

  ②.從官網(https://github.com/opencv/opencv/tree/3.4.1)下載源碼,編譯安裝

  cp -r opencv-2.4.13.6.zip /home/shine/Downloads/   cd /home/shine/Downloads/   unzip opencv-2.4.13.6.zip   cd opencv-2.4.13.6/   mkdir build   cd build/

  ③.創建build目錄並在該目錄下生成Makefile文件,指定安裝路徑為/usr/local/(參考 https://stackoverflow.com/questions/45518317/in-source-builds-are-not-allowed-in-cmake  

  cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local   sudo make -j4   sudo make install -j4   make clean

  如需安裝opencv_contribute(擴展包中的很多代碼並沒有通過大量的穩定性測試,但是其基本功能還是可以運行的),對命令進行修改(需自行下載opencv_contrib),例如本例中保存路徑為~/Downloads

  #如下命令指定安裝路徑以及擴展包的路徑,請根據實際修改
  cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local  -D OPENCV_EXTRA_MODULES_PATH=~/Downloads/opencv_contrib-master/modules ..
  sudo make -j4
  sudo make install -j4
  make clean
  
#若出現No package 'gstreamer-video-1.0' found,請參考http://answers.opencv.org/question/95734/cmake-not-picking-gstreamer-on-ubuntu/
  #若出現Unknown CMake command "ocv_append_source_files_cxx_compiler_options,請參考https://blog.csdn.net/qq_40155090/article/details/79977423
  #配置過程中可能出現face_landmark_model.dat下載過慢導致的失敗,請使用VPN下載
https://raw.githubusercontent.com/opencv/opencv_3rdparty/8afa57abc8229d611c4937165d20e2a2d9fc5a12/face_landmark_model.dat后放置於/opencv-3.4.1/.cache/data目錄
  #配置成功后的截圖如下所示,May you succeed, congruations and enjoy  
  
  #執行sudo make -j4進行編譯時可能會遇到各種奇怪的問題(例如hdf5.cpp編譯失敗),因此需要確保opencv-master與opencv-contribute為一個版本,建議都使用github上的版本

  #編譯時出現~Download/opencv_contrib-master/modules/xfeatures2d/src/boostdesc.cpp:653:37: fatal error: boostdesc_bgm.i: No such file or directory compilation terminated.
  #參考 https://github.com/opencv/opencv_contrib/issues/1301
     http://answers.opencv.org/question/113942/cmake-failing-with-hash-mismatch/
  #如果問題仍然沒有解決,嘗試下載上述缺少的文件放在~/Downloads/opencv_contrib-master/modules/xfeatures2d/src目錄下即可
  
  #編譯時出現opencv2/xfeatures2d/cuda.hpp: No such file or directory
  #參考https://github.com/opencv/opencv_contrib/issues/1131,執行cmake -DBUILD_opencv_xfeatures2d=OFF ..
 
  #編譯時出現opencv2/sfm/conditioning.hpp: No such file or directory
  #執行了sudo make clean;sudo make -j4;后問題解決了(無法解釋)

  如何查看OpenCV版本

  pkg-config --modversion opencv

  ④.添加庫路徑 

  sudo vi /etc/ld.so.conf.d/opencv.conf , 輸入/usr/local/lib , :wq保存並退出

  ⑤.添加環境變量

  sudo vi /etc/profile   #在末尾輸入 
  export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib   #更新環境變量:
  source /etc/profile   sudo vi /etc/bash.bashrc   #在末尾輸入
  export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig   export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib   #更新環境變量
  source /etc/profile

  ⑥.更新系統庫配置

  sudo ldconfig

  ⑦.查看是否安裝成功

  pkg-config --cflags opencv     pkg-config --libs opencv

  ⑧.執行測試程序,定位到sample目錄,執行build_all

  cd /home/shine/Downloads/opencv-2.4.13.6/samples/c   ./build_all.sh   ./find_obj

  若執行build_all編譯時出現如下錯誤 

  compiling contours.c   /usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/crti.o: unrecognized relocation (0x2a) in section `.init'   /usr/bin/ld: final link failed: Bad value   collect2: error: ld returned 1 exit status

  可能是沒有安裝binutils,執行

  sudo apt-get install binutils   ./build_all.sh   ./find_obj

 7.Jupyter

  ①安裝

  sudo pip3 install --upgrade pip   sudo pip3 install jupyter   sudo pip install matplotlib

  以上命令使用python3為基礎,因此運行jupyter會調用python3,若要使用python2請使用
  sudo pip install jupyter

  ②測試使用  

  jupyter notebook

  隨后在瀏覽器界面即可使用 http://localhost:8888/notebooks 進行登陸

  

  8.shadowsocks

   sudo apt-get update    sudo apt-get install python-pip    sudo pip install shadowsocks    sudo gedit /etc/shadowsocks.json 

   配置shadowsocks,粘貼如下內容

  {"server":"xx.xx.xx.xx",    "server_port":xxxx,    "local_address": "127.0.0.1",    "local_port":1080,    "password":"xxxxxxxx",    "timeout":300,    "method":"aes-256-cfb",    "fast_open": true,    "workers": 1   } 
  sudo sslocal -c /etc/shadowsocks.json -d start   sudo gedit /etc/rc.local

  配置開機啟動

  在exit0上一行加上/usr/local/bin/sslocal -c /etc/shadowsocks.json -d start

  ①火狐瀏覽器使用

  打開Add-ons,搜索FoxyProxy Standard,點擊Add To Firefox,添加完成后點擊右上角圖表進入Options,即如下圖所示

  

  點擊左上角Add,其中Title可隨便定義,IP以及Port同上shadowsocks配置,默認為127.0.0.1,1080

  

  ②谷歌瀏覽器使用

  從github上下載最新的插件SwitchyOmega-Chromium-2.5.15.crx,將其拖到chrome中即可完成安裝,同理完成上述配置,點擊Apply Changes

  

  可通過右上角選擇Direct或proxy選擇時候走代理通道

 9.Linux下載工具aria2

  推薦這個工具主要在於Linux下沒有比較好的綠色百度網盤下載器,由於百度對非會員進行速度限制(默認50Kb/s),並強制大文件通過百度雲管家下載,具體操作如下

  # aria2安裝
  sudo apt-get install aria2
  # 安裝瀏覽器插件,推薦chrome,從github下載zip文件,打開chrome://extensions/,將文件夾中的BaiduExporter.crx拖到瀏覽器即可
  # https://codeload.github.com/acgotaku/BaiduExporter/zip/master

  # 將需要下載的文件保存到個人網盤,在界面中選擇導出下載,選擇其中的文本導出,將窗口中命令復制到命令行中運行即可

  

 

#博主測試使用aria2下載速度應該在500kb/s左右
#如果希望達到更快的速度,請參考 https://github.com/proxyee-down-org/proxyee-down
#使用proxyee-down下載同時將分段數調到最大(windows版本請自行百度)

 10.sourceinsight

  sourceinsight是windows下常用的代碼瀏覽工具,雖然使用vim+ctags也能達到類似的效果,但習慣上還是更傾向於使用sourceinsight

  sourceinsight沒有linux的發行版本,因此要在ubuntu上運行需要安裝wine,具體操作方式如下(需要自行下載sourceinsight安裝包,3.5版本激活碼SI3US-205035-36448):  

  sudo apt-get install wine
  wine Si3583Setup.exe  

  參考文獻:

  1.https://www.nvidia.cn/object/caffe-installation-cn.html (如何在 NVIDIA GPU 上下載並安裝CAFFE)

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM