最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Caffe數(shù)據(jù)可視化環(huán)境python接口配置教程示例

 更新時間:2022年06月29日 10:02:54   作者:denny402  
這篇文章主要為大家介紹了Caffe數(shù)據(jù)可視化環(huán)境python接口配置教程示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪

引言

caffe程序是由c++語言寫的,本身是不帶數(shù)據(jù)可視化功能的。只能借助其它的庫或接口,如opencv, python或matlab。大部分人使用python接口來進行可視化,因為python出了個比較強大的東西:ipython notebook, 現(xiàn)在的最新版本改名叫jupyter notebook,它能將python代碼搬到瀏覽器上去執(zhí)行,以富文本方式顯示,使得整個工作可以以筆記的形式展現(xiàn)、存儲,對于交互編程、學(xué)習(xí)非常方便。 

python環(huán)境不能單獨配置,必須要先編譯好caffe,才能編譯python環(huán)境。

python環(huán)境的配置說起來簡單,做起來非常復(fù)雜。在安裝的過程中,可能總是出現(xiàn)這樣那樣的問題。因此強烈建議大家用anaconda來進行安裝,anaconda把很多與python有關(guān)的庫都收集在一起了,包括numpy,scipy等等,因此,我們只需要下載對應(yīng)系統(tǒng),對應(yīng)版本的anaconda來安裝就可以了。

如果你想通過anaconda來安裝,請?zhí)^第一、二步,直接進入第三步開始:

一、安裝python和pip

一般linux系統(tǒng)都自帶python,所以不需要安裝。如果沒有的,安裝起來也非常方便。安裝完成后,可用version查看版本

# python --version

pip是專門用于安裝python各種依賴庫的,所以我們這里安裝一下pip1.5.6

點擊下載安裝包,然后解壓,里面有一個setup.py的文件,執(zhí)行這個文件就可以安裝pip了

# sudo python setup.py install

有些電腦可能會提示 no moudle name setuptools 的錯誤,這是沒有安裝setuptools的原因。那就需要先安裝一下setuptools, 然后解壓執(zhí)行

# sudo python setup.py install

就要以安裝setuptools了,然后再回頭去重新安裝pip。執(zhí)行的代碼都是一樣的,只是在不同的目錄下執(zhí)行。

二、安裝pyhon接口依賴庫

在caffe根目錄的python文件夾下,有一個requirements.txt的清單文件,上面列出了需要的依賴庫,按照這個清單安裝就可以了。

在安裝scipy庫的時候,需要fortran編譯器(gfortran),如果沒有這個編譯器就會報錯,因此,我們可以先安裝一下。

首先回到caffe的根目錄,然后執(zhí)行安裝代碼:

# cd ~/caffe
# sudo apt-get install gfortran
# for req in $(cat requirements.txt); do sudo pip install $req; done

安裝完成以后,我們可以執(zhí)行:

# sudo pip install -r python/requirements.txt

就會看到,安裝成功的,都會顯示Requirement already satisfied, 沒有安裝成功的,會繼續(xù)安裝。

在安裝的時候,也許問題會有一大堆。這時候你就知道anaconda的好處了。

三、利用anaconda來配置python環(huán)境

如果你上面兩步已經(jīng)沒有問題了,那么這一步可以省略。

如果你想簡單一些,利用anaconda來配置python環(huán)境,那么直接從這一步開始,可以省略上面兩步。

先到https://www.anaconda.com/products/distribution 下載anaconda, 現(xiàn)在的版本有python2.7版本和python3.5版本,下載好對應(yīng)版本、對應(yīng)系統(tǒng)的anaconda,它實際上是一個sh腳本文件,大約280M左右。我下載的是linux版的python 2.7版本。

下載成功后,在終端執(zhí)行(2.7版本):

# bash Anaconda2-2.4.1-Linux-x86_64.sh

或者3.5 版本:

# bash Anaconda3-2.4.1-Linux-x86_64.sh

在安裝的過程中,會問你安裝路徑,直接回車默認(rèn)就可以了。有個地方問你是否將anaconda安裝路徑加入到環(huán)境變量(.bashrc)中,這個一定要輸入yes

安裝成功后,會有當(dāng)前用戶根目錄下生成一個anaconda2的文件夾,里面就是安裝好的內(nèi)容。

輸入conda list 就可以查詢,你現(xiàn)在安裝了哪些庫,常用的numpy, scipy名列其中。如果你還有什么包沒有安裝上,可以運行

conda install ***  來進行安裝,

如果某個包版本不是最新的,運行 conda update *** 就可以了。

四、編譯python接口

首先,將caffe根目錄下的python文件夾加入到環(huán)境變量

打開配置文件bashrc

# sudo vi ~/.bashrc

在最后面加入

export PYTHONPATH=/home/xxx/caffe/python:$PYTHONPATH

注意 /home/xxx/caffe/python 是我的路徑,這個地方每個人都不同,需要修改

保存退出,更新配置文件

# sudo ldconfig

然后修改編譯配置文件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
# 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 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_50,code=compute_50
# 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)/anaconda2
PYTHON_INCLUDE := $(ANACONDA_HOME)/include \
        $(ANACONDA_HOME)/include/python2.7 \
        $(ANACONDA_HOME)/lib/python2.7/site-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
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
# 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
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 ?= @

修改完編譯配置文件后,最后進行編譯:

# sudo make pycaffe

編譯成功后,不能重復(fù)編譯,否則會提示 Nothing to be done for "pycaffe"的錯誤。

防止其它意外的錯誤,最好還編譯一下:

# sudo make test -j8
# sudo make runtest -j8

也許你在編譯runtest的時候,會報這樣的錯誤:

.build_release/test/test_all.testbin: error while loading shared libraries: libhdf5.so.10: cannot open shared object file: No such file or directory

這是因為 libhdf5.so的版本問題,你可以進入/usr/lib/x86_64-linux-gnu看一下,你的libhdf5.so.x中的那個x是多少,比如我的是libhdf5.so.7

 因此可以執(zhí)行下面幾行代碼解決:

# cd /usr/lib/x86_64-linux-gnu
# sudo ln -s libhdf5.so.7 libhdf5.so.10
# sudo ln -s libhdf5_hl.so.7 libhdf5_hl.so.10
# sudo ldconfig

最終查看python接口是否編譯成功:

進入python環(huán)境,進行import操作

# python
>>> import caffe

如果沒有提示錯誤,則編譯成功。

五、安裝jupyter

安裝了python還不行,還得安裝一下ipython,后者更加方便快捷,更有自動補全功能。而ipython notebook是ipython的最好展現(xiàn)方式。最新的版本改名為jupyter notebook,我們先來安裝一下。(如果安裝了anaconda, jupyter notebook就已經(jīng)自動裝好,不需要再安裝)

# sudo pip install jupyter

安裝成功后,運行notebook

# jupyter notebook

就會在瀏覽器中打開notebook,  點擊右上角的New-python2, 就可以新建一個網(wǎng)頁一樣的文件,擴展名為ipynb。在這個網(wǎng)頁上,我們就可以像在命令行下面一樣運行python代碼了。輸入代碼后,按shift+enter運行,更多的快捷鍵,可點擊上方的help-Keyboard shortcuts查看,或者先按esc退出編輯狀態(tài),再按h鍵查看。

以上就是Caffe數(shù)據(jù)可視化環(huán)境python接口配置教程示例的詳細(xì)內(nèi)容,更多關(guān)于Caffe環(huán)境python接口配置的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • Python簡單實現(xiàn)圖片轉(zhuǎn)字符畫的實例項目

    Python簡單實現(xiàn)圖片轉(zhuǎn)字符畫的實例項目

    這篇文章主要介紹了Python簡單實現(xiàn)圖片轉(zhuǎn)字符畫的實例項目,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • django之自定義軟刪除Model的方法

    django之自定義軟刪除Model的方法

    這篇文章主要介紹了django之自定義軟刪除Model的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-08-08
  • Scrapy使用的基本流程與實例講解

    Scrapy使用的基本流程與實例講解

    今天小編就為大家分享一篇關(guān)于Scrapy使用的基本流程與實例講解,小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧
    2018-10-10
  • Sanic框架請求與響應(yīng)實例分析

    Sanic框架請求與響應(yīng)實例分析

    這篇文章主要介紹了Sanic框架請求與響應(yīng),結(jié)合實例形式詳細(xì)分析了Sanic框架請求與相應(yīng)的相關(guān)參數(shù)、方法及使用技巧,需要的朋友可以參考下
    2018-07-07
  • Python面向?qū)ο缶幊讨械念惡蛯ο髮W(xué)習(xí)教程

    Python面向?qū)ο缶幊讨械念惡蛯ο髮W(xué)習(xí)教程

    這篇文章主要介紹了Python面向?qū)ο缶幊讨械念惡蛯ο髮W(xué)習(xí)教程,面向?qū)ο笫荘ython的基礎(chǔ)特性,其中的類與對象的特性和使用方法是Python學(xué)習(xí)當(dāng)中的基本功,需要的朋友可以參考下
    2015-03-03
  • 利用numba讓python速度提升百倍

    利用numba讓python速度提升百倍

    這篇文章主要介紹了利用numba讓python速度提升百倍,python由于它動態(tài)解釋性語言的特性,numba是一款可以將python函數(shù)編譯為機器代碼的JIT編譯器,下面針對numba相關(guān)內(nèi)容展開,需要的小伙伴可以參考一下
    2022-03-03
  • Python Web項目Cherrypy使用方法鏡像

    Python Web項目Cherrypy使用方法鏡像

    這篇文章主要介紹了Python Web項目Cherrypy使用方法鏡像,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-11-11
  • Django 源碼WSGI剖析過程詳解

    Django 源碼WSGI剖析過程詳解

    這篇文章主要介紹了Django 源碼WSGI剖析過程詳解,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2019-08-08
  • flask中使用SQLAlchemy進行輔助開發(fā)的代碼

    flask中使用SQLAlchemy進行輔助開發(fā)的代碼

    在Web.py, Django, Flask, Tornado里,自帶的ORM功能比較缺乏,推薦大家使用SQLAlchemy來輔助開發(fā)
    2013-02-02
  • python socket 超時設(shè)置 errno 10054

    python socket 超時設(shè)置 errno 10054

    這篇文章主要介紹了python 遠(yuǎn)程主機強迫關(guān)閉了一個現(xiàn)有的連接 socket 超時設(shè)置 errno 10054 ,需要的朋友可以參考下
    2014-07-07

最新評論

佛教| 兰溪市| 兴安县| 兰考县| 舞钢市| 沂南县| 山丹县| 兰考县| 于田县| 阳泉市| 密山市| 遵义市| 洛南县| 大安市| 高密市| 郯城县| 锦屏县| 高雄市| 巴马| 长阳| 景德镇市| 土默特左旗| 麦盖提县| 葵青区| 阿瓦提县| 拜城县| 江安县| 冕宁县| 永州市| 泗洪县| 乌鲁木齐县| 永寿县| 沐川县| 湘潭县| 玉树县| 永善县| 扶沟县| 元谋县| 辉南县| 贡觉县| 石台县|