python 35 使用 3D densecrf (DenseInferenceWrapper)
2019獨角獸企業重金招聘Python工程師標準>>>
If you want to use this in?python3?then you can follow the following steps
Requirements
make, g++, boost-python3.5Installation of Boost for Python3
Make sure you have the libboost-python-dev libraries installed: sudo apt-get install libboost-python-dev
#####Install python 3.5 :
Make sure you have the libboost-python-dev libraries installed:
#####Download the 1.58.0 不要最新的會有問題!! of Boost from?http://www.boost.org/
#####Run bootstrap with correct flags :
#####Compile Boost in directory :
#####Update the Makefile to take the new boost locations (Already did)
Boost.python的編譯安裝
- 說明:因為caffe需要boost的支持,在卸載以后所有boost文件都需要通過安裝(對于非boost.python來說,安裝就是將頭文件拷貝到PREFIX路徑[默認為/usr/local]),不只boost.python(boost.python不是headers-only文件,需要單獨build)
step1:源碼文件的下載和解壓
首先,按照boost官網下載指引描述,到所示網站下載boost源碼的壓縮文件,當前時間的文件是boost_1_66_0.tar.bz2,放在$HOME目錄下。
~$ tar --bzip2 -xvf boost_1_66_0.tar.bz2 ~$ cd boost_1_66_0 ~/boost_1_66_0$ ./bootstrap.sh?
#返回信息如下 Building Boost.Build engine with toolset gcc... tools/build/src/engine/bin.linuxx86_64/b2 Detecting Python version... 2.7 Detecting Python root... /usr Unicode/ICU support for Boost.Regex?... not found. Backing up existing Boost.Build configuration in project-config.jam.1 Generating Boost.Build configuration in project-config.jam... #配置文件名為project-config.jamBootstrapping is done. To build, run:./b2 #通常的下一步操作To adjust configuration, edit 'project-config.jam'. Further information:- Command line help:./b2 --help #如果需要更詳細的說明,運行左邊的命令后再根據需要修改自己的命令- Getting started guide: http://www.boost.org/more/getting_started/unix-variants.html- Boost.Build documentation:http://www.boost.org/build/doc/html/index.html我們應關注上述返回信息,包括配置文件名和一些使用提示。
step2:重新編譯boost
這一步是為了保險起見,將所有boost相關文件都重新編譯,運行一下命令:
~/boost_1_66_0$ ./b2 -a關注shell返回信息中,建議將路徑1加入#include path,將路徑2加入#compiler path,以下根據指引設置環境變量。
step3:設置環境變量
~$ sudo gedit ~/.profile #根據上一步shell中返回的信息,在打開的文件中加入如下兩行信息 export BOOST_INCLUDE=$HOME/boost_1_66_0 export BOOST_LIB=$HOME/boost_1_66_0/stage/lib #保存后關閉文件 ~$source ~/.profile?
step4:驗證安裝boost成功
對于我來說,因為caffe是需要boost支持的,驗證方式是在caffe文件夾下重新編譯Makefile.config,依次make all,make test,make runtest直至最后測試完全通過。?
當然簡單的方式,應該是調用庫,運行一小段代碼唄。
向打開的文件中填入以下代碼
#include <string> #include <iostream> #include <boost/version.hpp> #include <boost/timer.hpp> using namespace std; int main() {boost::timer t;cout << "max timespan: " << t.elapsed_max() / 3600 << "h" << endl;cout << "min timespan: " << t.elapsed_min() << "s" << endl;cout << "now time elapsed: " << t.elapsed() << "s" << endl;cout << "boost version" << BOOST_VERSION <<endl;cout << "boost lib version" << BOOST_LIB_VERSION <<endl;return 0; } ~$ g++ sample.cpp -o sample.out #編譯生成sample.out文件 ~$ ./sample.out #查看輸出得到以下輸出
max timespan: 2.56205e+09hmin timespan: 1e-06s now time elapsed: 0.000135s boost version105800#好吧,真的是沒有卸載干凈.... boost lib version1_58附上makefile
附上makefile # update the path variablesCC = g++ CFLAGS = -W -Wall -O2 -DNDEBUG #CFLAGS = -W -Wall -g LIB_ROOT = denseinference/lib/all:make -C cleanmake -C pythonclean:rm -f *.arm -f *.orm -f *.solibDenseCRF.a: libDenseCRF/bipartitedensecrf.cpp libDenseCRF/densecrf.cpp libDenseCRF/filter.cpp libDenseCRF/permutohedral.cpp libDenseCRF/util.cpp libDenseCRF/densecrf.h libDenseCRF/fastmath.h libDenseCRF/permutohedral.h libDenseCRF/sse_defs.h libDenseCRF/util.h$(CC) -fPIC libDenseCRF/bipartitedensecrf.cpp libDenseCRF/densecrf.cpp libDenseCRF/filter.cpp libDenseCRF/permutohedral.cpp libDenseCRF/util.cpp -c $(CFLAGS) -DNDEBUGar rcs libDenseCRF.a bipartitedensecrf.o densecrf.o filter.o permutohedral.o util.odense_inference.so: dense_inference.o libDenseCRF.a$(CC) -shared -I/usr/include/python2.7 -Wl,-no-undefined -o dense_inference.so dense_inference.o -lpython2.7 -lboost_python -L. -lDenseCRF $(CFLAGS)dense_inference.o: refine_3d/dense_inference.cpp refine_3d/dense_inference.h libDenseCRF.a$(CC) -c -fPIC -I/usr/include/python2.7 refine_3d/dense_inference.cpp -o dense_inference.o $(CFLAGS) -lDenseCRF $(CFLAGS)# For python3 use the following \ dense_inference.so: dense_inference.o libDenseCRF.a \$(CC) -shared -I/usr/include/python3.5m -Wl,-no-undefined -o dense_inference.so dense_inference.o -lboost_python-py35 -lpython3.5m -L. -lDenseCRF $(CFLAGS) \ dense_inference.o: refine_3d/dense_inference.cpp refine_3d/dense_inference.h libDenseCRF.a \$(CC) -c -fPIC -I/usr/include/python3.5m refine_3d/dense_inference.cpp -o dense_inference.o $(CFLAGS) -lDenseCRF $(CFLAGS)python: dense_inference.o dense_inference.so libDenseCRF.a.PHONY: default clean中間還遇到過一個問題,就是numpy.hpp不存在,這個問題是因為雖然pip?安裝了numpy,但是我是anaconda的python,所以系統里沒有numpy,需要用apt-get?install? python3-numpy?安裝
轉載于:https://my.oschina.net/lilinzero/blog/1829448
總結
以上是生活随笔為你收集整理的python 35 使用 3D densecrf (DenseInferenceWrapper)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: EntityFramework 6.x和
- 下一篇: 浏览器左上角的网站图标