MaskFusion配置Conda环境
MaskFusion如何配置Conda环境
最近,由于需要,需要在电脑上配置⼀下MaskFusion的环境,其实之前已经在多台电脑上配置过MaskFusion的环境,当时是基于Ubuntu16.04的环境,⽽且为了配置环境,特意安装了⼀个⼲净的新系统。
这次不⼀样的是,我是在现有环境下配置MaskFusion环境,还要尽可能不改变原有环境。因此,记录⼀下环境配置,希望对⼤家有所帮助。
系统说明:
Ubuntu 18.04
CUDA 10.1
cuDNN 7.6.3
GPU:NVIDIA RTX 2080TI
GPU Driver: 460.80
正常安装
这个,按照MaskFusion项⽬中的build.sh⽂件⼀步步来就可以,我之前也是照着这个⽂件⼀步步安装的,基本上不会出什么问题。
⽂件可以在Github中的项⽬上查看,⽹络不太好的话,也可以去码云上相关项⽬。
有问题的话基本上也都可以在Github上的MaskFusion中的issue或者⽹络上到相关解决⽅案,这个我暂时就先不添加,主要是配置环境的时候没有同步记录问题和解决⽅案,现在,有点难搞。
Conda环境配置
原因
主要是记录⼀下如何在MaskFusion中使⽤conda环境。
之所以要这样做,原因是这样:系统的CUDA版本为10.1, ⽀持的tensorflow-gpu版本基本上都是2.X,⽽MaskFusion需要的tensorflow版本为1.X,如果使⽤作者建议的virtualenv创建环境的话,安装的tensorflow-gpu 1.X版本是不可以运⾏的。
但是,在conda环境中,由于tensorflow-gpu调⽤的是cudatoolkit,所以,就算安装了CUDA 10.1 ,但是只要在conda环境中安装cudatoolkit == 10.0 就可以使⽤ tensorflow-gpu == 1.15.0 。
当然,还有另外⼀个解决⽅法,就是对CUDA进⾏降级,重新安装CUDA 10.0 版本,我个⼈是觉得有些⿇烦,况且不知道会不会对原有环境造成影响,因此就放弃了这个⽅法,毅然选择调⽤conda创建的虚拟环境。
说明
之前有参考过这篇博客:.
⾥⾯也有说过如何在MaskFusion下使⽤conda环境。按照博客中的操作了之后,发现,只是可以成功运⾏ offline_runner.py ⽂件,在运⾏时 ./MaskFusion 依旧不⾏。
tensorflow版本选择操作
⾸先,是创建⼀个conda的虚拟环境,并对环境进⾏配置
//创建虚拟环境
conda create -n tensorflow python=3.6
//安装pip
conda install pip
//使⽤pip安装环境
pip3 install tensorflow-gpu==1.8.0
pip3 install scikit-image
pip3 install keras
pip3 install IPython
pip3 install h5py
pip3 install cython
pip3 install imgaug
pip3 install opencv-python
pip3 install pytoml
//建⽴软链接(⼀定要在当前环境下运⾏这句话,否则,numpy软链接的所属环境不对,或者软链接建⽴失败,同时,也要注意当前⽬录,应在maskfusion根⽬录下运⾏)
ln -s `python -c "import numpy as np; print(np.__path__[0])"`/core/include/numpy Core/Segmentation/MaskRCNN ||true# Provide numpy headers to C++ //coco API(当然,也需要在当前环境中运⾏coco-api)
cd coco/PythonAPI
make
make install
紧接着,就是对 ⽂件和 .cpp ⽂件进⾏修改,主要是因为是在 cpp 中调⽤ python 接⼝,因此,需要指出正确的python 环境。
⽂件:maskfusion/Core/Segmentation/MaskRCNN/MaskRCNN.cpp 40⾏左右
操作:
void MaskRCNN::initialise(){
std::cout <<"* Initialising MaskRCNN (thread: "<< std::this_thread::get_id()<<") ..."<< std::endl;
//主要是添加这⼀句,指定python的环境
Py_SetPythonHome(L"/xxxxxx/xxxxx/anaconda3/envs/tensorflow");
Py_SetProgramName((wchar_t*)L"MaskRCNN");
Py_Initialize();
wchar_t const* argv2[]={ L"MaskRCNN.py"};
PySys_SetArgv(1,const_cast<wchar_t**>(argv2));
// Load module
loadModule();
// Get function
pExecute =PyObject_GetAttrString(pModule,"execute");
if(pExecute ==NULL||!PyCallable_Check(pExecute)){
if(PyErr_Occurred()){
std::cout <<"Python error indicator is set:"<< std::endl;
PyErr_Print();
}
throw std::runtime_error("Could not load function 'execute' from MaskRCNN module.");
}
std::cout <<"* Initialised MaskRCNN"<< std::endl;
}
上述操作主要是解决遇到的这个问题:
终端执⾏指令: ./MaskFusion -run -l ../../dyson_lab.klg
错误信息:
Calibration set to resolution: 640x480, [fx: 528 fy: 528, cx: 320 cy: 240]
Reading log file: ../../dyson_lab.klg which has 6533 frames.
Initialised MainController. Frame resolution is set to: 640x480
Exporting results to: ../../dyson_lab.klg-export//
* Initialising MaskRCNN (thread: 140573755303680)...
Could not find platform independent libraries <prefix>
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Fatal Python error: initfsencoding: Unable to get the locale encoding
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007fd9e0bfe700 (most recent call first):
已放弃(核⼼已转储)
⽂件:maskfusion/ 18⾏左右
操作:
##这句话注释掉
## find_package(PythonLibs) ## 默认到的是系统⾃带的python3环境
## 指定python路径到anconda环境tensorflow中
set(PYTHON_LIBRARIES "/home/xxxxxx/anaconda3/envs/tensorflow/lib/libpython3.7m.so")
set(PYTHON_INCLUDE_DIRS "/home/xxxxxx/anaconda3/envs/tensorflow/include/python3.7m")
然后就是正常编译
cmake -DBOOST_ROOT="${BOOST_ROOT}" -DOpenCV_DIR="$(pwd)/../deps/opencv/build" -DPangolin_DIR="$(pwd)/../deps/Pangolin/build/src" -DC UDA_HOST_COMPILER=/usr/bin/gcc -DWITH_FREENECT2=OFF -DMASKFUSION_PYTHON_VE_PATH="$(pwd)/../python-environment" -DCMAKE_PR EFIX_PATH=/home/xxxxxxx/anaconda3/envs/tensorflow/ ..
可能会出现warning,如下:
CMake Warning at :110 (add_library):
Cannot generate a safe linker search path for target libmaskfusion because
files in some directories may conflict with libraries in implicit
directories:
link library [libz.so]in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/lab502/anaconda3/envs/tensorflow/lib
Some of these libraries may not be found correctly.
CMake Warning at :71 (add_executable):
Cannot generate a safe linker search path for target MaskFusion because
files in some directories may conflict with libraries in implicit
directories:
link library [libz.so]in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/lab502/anaconda3/envs/tensorflow/lib
Some of these libraries may not be found correctly.
CMake Warning at :90 (add_library):
Cannot generate a safe linker search path for target MaskFusionTools
because files in some directories may conflict with libraries in implicit
directories:
link library [libz.so]in /usr/lib/x86_64-linux-gnu may be hidden by files in:
/home/lab502/anaconda3/envs/tensorflow/lib
Some of these libraries may not be found correctly.
或者这种错误:
CMake Error at :11 (find_package):
Could not find a package configuration file provided by "OpenNI2" with any
of the following names:
Add the installation prefix of "OpenNI2" to CMAKE_PREFIX_PATH or set
"OpenNI2_DIR" to a directory containing one of the above files. If
"OpenNI2" provides a separate development package or SDK, be sure it has
been installed.
产⽣这个问题的原因就是环境冲突,同时在多个⽂件夹中出现这个⽂件,我的解决⽅法也很是简单粗暴,就是去错误信息中提到的⽬录中,将 根⽬录下的 ⽂件 libz.* 都转移到回收站,然后在make之前在恢复就可以。
遇到的问题
问题1:
终端执⾏的指令: ./MaskFusion -run -l ../../dyson_lab.klg
错误信息:
Calibration set to resolution: 640x480, [fx: 528 fy: 528, cx: 320 cy: 240]
Reading log file: ../../dyson_lab.klg which has 6533 frames.
Initialised MainController. Frame resolution is set to: 640x480
Exporting results to: ../../dyson_lab.klg-export//
* Initialising MaskRCNN (thread: 140259687921408)...
*
Python error indicator is set:
Traceback (most recent call last):
File "/home/lab502/workspace/maskfusion/build/GUI/MaskRCNN.py", line 40, in<module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
terminate called after throwing an instance of 'std::runtime_error'
what(): Could not open MaskRCNN module.
已放弃(核⼼已转储)
或者编译时出现这个问题:
CMake Error :65 (add_custom_target):
Cannot find source file:
/home/lab502/workspace/maskfusion/Core/Segmentation/MaskRCNN/numpy
Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
.hxx .in .txx
出现上述问题的原因,就是软链接的建⽴不成功,上⾯创建环境的时候有提到这句指令:
ln -s `python -c "import numpy as np; print(np.__path__[0])"`/core/include/numpy
软链接建⽴失败,也能够正常编译,但是运⾏的时候会出现这个问题。
由于没有养成记录问题的好习惯,⽬前能想到的就这些了,如果有问题,可以联系我,⼤家⼀起交流学习。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论