百度算法团队的强化学习神器:XWorld3d编译历程
这个是百度算法团队今年五月开源的一套c++库,整体感觉质量还可以,基础架构就是开源的物理碰撞库bullet和去年OpenAI开源的另一个神器Roboschool(个人感觉那款是偏动作学习),XWorld差不多在这个基础上还增加了许多功能(你也可以把它看做一款大改的Mod).
编译环境
- Ubuntu 16.04
- gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.11)
- python2.7
- GPU及其驱动等: GeForce 920M NVIDIA-SMI 384.130
下载及搞定Dependencies
build之前必装的:
Boost, Glog, GFlags, GTest, Python
安装:
$ sudo apt-get install libboost-all-dev libgflags-dev libgoogle-glog-dev libgtest-dev python-dev
Build
clone项目:
我这里就直接选须编译XWORLD3D了;
$ git clone https://github.com/PaddlePaddle/XWorld
$ cd XWorld; mkdir build; cd build
$ cmake -DWITH_XWORLD3D=ON ..
下面就是make了,因为要自动下载opencv,bullet,glm,assimp,roboschool等,所以要耐心等:
$ make
遇到如下报错不要惊慌,此处有个大坑:
[ 45%] Completed 'roboschool'
Slow hardware or software render (no shadows)
/usr/bin/ld: 找不到 -lOpenGL
collect2: error: ld returned 1 exit status
Makefile:58: recipe for target '../libroboschool.so' failed
make[3]: *** [../libroboschool.so] Error 1
[ 45%] Built target roboschool
...
这里我参照openai原来那个branch的roboschool我还以为XWorld的Makefile写错了,就把这里的-lOpenGL改成了-lGL,结果后来也能完成编译,但去跑程序时会遇到:
[EGL] Detected 1 devices, among which test_xworld3d: gl_context.cpp:37: virtual void SimpleRender::GLContext::print_info(): Assertion `glGetString(GL_VERSION)' failed.
./test_xworld3d.sh: 行 8: 26376 已放弃 PYTHONPATH=../python:$PYTHONPATH ./test_xworld3d --x3_conf=../games/xworld3d/confs/dialog3d.json --pause_screen=1 --context=1 --task_groups_exclusive=1
就在GitHub上问了原作者,应该是百度的工程师,他的回答是:
然后我在/usr/lib下又一顿搜索发现其藏于/usr/lib/nvidia-384,于是修改Makefile对应的即可:
LIBS =-L/usr/lib64 -L/usr/lib/nvidia-384 -lm -lOpenGL
再make就不再有问题了.
现在去examples里:
$ ./test_xworld3d.sh
附一些调试的trick(持续更新)
- 当你改动了一个文件想重新make时:
需要找那个文件对应的.o 文件或者依赖其的生成文件或 .so文件,删除掉然后重新make;
- grep的一些技巧:
#包含了string.h或者stdlib.h的头文件
$ grep -l -e 'string\.h' -e 'stdlib\.h' /usr/include/*.h
#在多个文件中查找模式
$ grep linuxtechi /etc/passwd /etc/shadow /etc/gshadow
#使用-i参数查找模式
$ grep -i LinuxTechi /etc/passwd
#使用-e参数查找多个模式
grep -e "linuxtechi" -e "root" /etc/passwd
- find的一些技巧:
$find ~ -name "*.txt" -print #在$HOME中查.txt文件并显示
$find . -name "*.txt" -print
$find . -name "[A-Z]*" -print #查以大写字母开头的文件
$find /etc -name "host*" -print #查以host开头的文件
$find . -name "[a-z][a-z][0–9][0–9].txt" -print #查以两个小写字母和两个数字开头的txt文件
$find . -perm 755 -print
$find . -perm -007 -exec ls -l {} \; #查所有用户都可读写执行的文件同-perm 777
$find . -type d -print
$find . ! -type d -print
$find . -type l -print
$find . -size +1000000c -print #查长度大于1Mb的文件
$find . -size 100c -print # 查长度为100c的文件
$find . -size +10 -print #查长度超过期作废10块的文件(1块=512字节)
- g++编译的一些错误:
对‘cv::_OutputArray::_OutputArray(cv::Mat&)’未定义的引用:
没有加正确的-l并且顺序是重要的,
还有可能:它的实现在另一个cpp文件,需要把那个cpp文件一并加进来编译:
g++ -g -o load -std=c++11 load.cpp utils.cpp -L/usr/lib64 -lm -lGL -lGLU -lstdc++ -I/usr/include -I../../../glm -I.1
段错误:没法,只能加上-g编译然后gdb进去调试了:
gdb>b 14
gdb>run
gdb>n
gdb>call 调用函数
gdb>kill
gdb>step
gdb>return: 强制函数返回.可以指定返回值;
gdb>p x