分类:行为仿真
github地址:https://github.com/xbpeng/DeepMimic
所需环境:Windows10,Anaconda4.12.0,Visual Stdio 2019(其他也可)
目录
1.安装CMake
下载地址[1]。
https://cmake.org/download/
直接下载CMake二进制压缩包。
下载完成后,直接解压。 其中bin目录下的exe就是CMake编译工具,可以直接用。
2.用Ananconda创建python3.6环境
conda create -n DeepMimic python=3.6
为什么要创建python3.6环境?因为作者使用的 TensorFlow版本是1.13.1,经查询[2],对应的Python版本是python3.6。见下图:
3.安装Bullet2.88
下载地址
https://github.com/bulletphysics/bullet3/releases
解压 bullet3-2.88.zip 为 bullet3CMake-2.88 ,在 bullet3CMake-2.88 里新建一个 build 文件夹[3]。
CMake选择源码路径:
D:/Wlm_Project/MotionSimulated/1.DeepMimic_SIGGRAPH2018/DeepMimic/3rdparty/bullet3CMake-2.88
编译路径:
D:/Wlm_Project/MotionSimulated/1.DeepMimic_SIGGRAPH2018/DeepMimic/3rdparty/bullet3CMake-2.88/build
勾选Advanced
选项后,点击Configure
。
生成器选择VS2019
生成器平台选择x64
,点击Finish。
显示 Configuring done 后,再点击 Generate。
显示 Generating done 即可。
用VS2019打开 ALL_BUILD.vcxproj。
配置管理器选择Release x64
[12]。
右键 ALL_BUILD 项目,点击生成。
如下为编译结束。
进入/build/lib/Release
,可看到已经生成的Release x64 .lib
库文件[11]。
至此,Release版的Bullet库文件已经成功生成,Debug版操作类似,在选择配置管理器的时候选Debug就可以。
至于作者说的:
be sure to disable double precision with the build flag USE_DOUBLE_PRECISION=OFF.
经查阅资料[12],对应于本机环境应该是这样实现的: 打开ALL_BUILD.vcxproj 后,找到Bullet3Dynamic ,BulletCollation, linearMath三个项目,右键属性-C/C+±预处理器-预处理器定义,删掉第二行BT_USE_DOUBLE_PRECISION。
但是实际上预处理器定义并没有此选项,应该是多年过去了,Bullet官方修改了这个预定义吧。
4.安装Eigen3.3.7
下载地址
https://gitlab.com/libeigen/eigen/-/releases
首先在eigen-3.3.7目录下建造两个空文件夹。install
和build
[4]。
打开cmake-gui.exe。
源码路径(CMakeList.txt所在路径)选择:
D:/Wlm_Project/MotionSimulated/1.DeepMimic_SIGGRAPH2018/DeepMimic/3rdparty/eigen-3.3.7/eigen-3.3.7
构建路径选择(build文件夹路径):
D:/Wlm_Project/MotionSimulated/1.DeepMimic_SIGGRAPH2018/DeepMimic/3rdparty/eigen-3.3.7/eigen-3.3.7/build
勾选Advanced
后,点击Configure
。
选择生成适配于VS2019
,x64
的工程,之后点击Finish。
直到显示 Configuring done。
在Search输入框中输入INSTALL_PREFIX
找到安装目录前缀(CMAKE_INSTALL_PREFIX
),value修改为刚才创建的 install 目录,重新点击Configure.。
再一次看到 Configuring down 之后点击 Generate 按钮;过程很快就可以看到Generating done,这时候就可以关闭 Cmake 了;
用VS2019打开build里的Eigen3.sln
,在vs2019中菜单栏点击 生成—>批生成,弹出批生成界面,勾选ALL_Build
的Debug
和Release
,然后点击生成按钮;(由于Eigen3只生成头文件,而不生成二进制文件,无所谓Debug和Release,所以也可以只选择其中一个)。
稍等一会就可以看到编译完成。
然后再一次点生成—>批生成,弹出批生成界面,取消勾选 ALL_BUILD
的 Debug
和 Release
,勾选 INSTALL
的Debug
和Release
,然后点击“生成”按钮;(由于Eigen3只生成头文件,而不生成二进制文件,无所谓Debug和Release,所以也可以只选择其中一个)
这个过程很快结束,找到刚才创建的install目录,可以发现编译生成的文件已经拷贝进来了;
注意:Eigen3不需要动态库,只会生成头文件,所以不区分32位还是64位,都可以正常使用。配置VS2019的时候,仅需包含头文件即可,不用包含库文件。
5.安装freeglut3.0.0
下载地址
https://freeglut.sourceforge.net/
还是需要用到CMake进行编译,首先创建build文件夹[5]。
打开Cmake设置路径
源码路径:
D:/Wlm_Project/MotionSimulated/1.DeepMimic_SIGGRAPH2018/DeepMimic/3rdparty/freeglut-3.0.0/freeglut-3.0.0
构建路径:
D:/Wlm_Project/MotionSimulated/1.DeepMimic_SIGGRAPH2018/DeepMimic/3rdparty/freeglut-3.0.0/freeglut-3.0.0/build
点击Generate,继续配置如下(用VS2019编译64位的源码)。
点击Finish
配置完毕后,点击红色箭头的Generate。
生成完毕。
打开D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\freeglut-3.0.0\freeglut-3.0.0\build
文件夹,打开.sln工程文件。 修改配置管理器为Release x64
[12]。右键-重新生成解决方案,开始进行编译
生成完毕。
6.安装glew2.1.0
下载地址
https://glew.sourceforge.net/
为了省事,直接下载预编译版本[6]。
下载完成后,直接解压即可。
7.安装SWIG4.0.0
下载地址
https://www.swig.org/
本着尊重作者的原则,要先看README文件,了解怎么安装(事实证明,看README确实不如上网直接查方便!!!)。
Installation
============
Please read the Doc/Manual/Preface.html#Preface_installation for full installation instructions for Windows, Unix and Mac OS X using the release tarball/zip file. The INSTALL file has generic build and installation instructions for Unix users.
Users wishing to build and install code from Github should visit https://swig.org/svn.html to obtain the more detailed instructions required for building code obtained from Github - extrasteps are required compared to building from the release tarball.
好,继续查看 Doc/Manual/Preface.html文件
1.12.1 Windows installation
Please see the dedicated Windows chapter for instructions on installing SWIG on Windows and running the examples. The Windows distribution is called swigwin and includes a prebuilt SWIG executable, swig.exe, included in the top level directory. Otherwise it is exactly the same as the main SWIG distribution. There is no need to download anything else.
简直就像在套娃,继续查看Windows Chapter
3.1 Installation on Windows
SWIG does not come with the usual Windows type installation program, however it is quite easy to get started. The main steps are:
Download the swigwin zip package from the SWIG website and unzip into a directory. This is all that needs downloading for the Windows platform.
Set environment variables as described in the SWIG Windows Examples section in order to run examples using Visual C++.
3.1.1 Windows Executable
The swigwin distribution contains the SWIG Windows 32-bit executable, swig.exe, which will run on both 32-bit and 64-bit versions of Windows. If you want to build your own swig.exe have a look at Building swig.exe on Windows.
原来只需要下载swigwin再解压,接着配置个环境变量即可[7]。而且作者也说了,虽然是32位exe,但是在32和64的win上都可运行。
重新下载也不费事(真的我哭死~~~~)
解压,可以看到解压目录中有可执行文件swig.exe。
接下来将该路径添加到系统环境变量中。环境变量-系统变量-新建。
变量名:SWIG_DIR
变量值(swig.exe所在路径):D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\swigwin-4.0.0\swigwin-4.0.0
点击确定确定确定,生效环境变量!
在cmd中测试下:
swig –version
输出版本号即可。
8.安装MPI10.1.1
注意:MPI一定要在MPI4Py之前安装好
下载地址
https://docs.microsoft.com/en-us/message-passing-interface/microsoft-mpi
这个作者没说他安装的哪个版本,所以我下载个2019年早期的MS-MPI v10.1.1,太新的版本怕不兼容主程序[8]。
看一下他的安装指导。
额,让我执行它的安装程序,然后按照指导安装即可。
我在3rdparty下,新建了一个 MPI-10.1.1 文件夹,把 exe 和 msi 挪进去。又新建一个 setup 和 setupSDK 文件夹供安装。
双击运行msmpisetup.exe。
点击next。
点击I accept,next。
安装路径改为D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\MPI-10.1.1\setup
点击Next,最后点击Install。
点击Finish。
setup会有这几个。每个夹下都是exe。
双击运行msmpisdk.msi,安装SDK。
点击Next。
依然是I accept,Next。
安装路径改为D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\MPI-10.1.1\setupSDK
点击Next,最后点击Install。
最后点击Finish。
setupSDK会有这几个。安装完毕!
9.配置Anaconda环境
关于python环境作者在github给了这几个提示:
Python 3
PyOpenGL (http://pyopengl.sourceforge.net/)
----pip install PyOpenGL PyOpenGL_accelerate
Tensorflow (https://www.tensorflow.org/) ( Vesrion : 1.13.1 )
-----pip install tensorflow
MPI4Py (https://mpi4py.readthedocs.io/en/stable/install.html)
-----pip install mpi4py
看下项目的requirements.txt,包含了这几个包:
numpy>=1.15.2
PyOpenGL== 3.1.0
tensorflow==1.13.1
mpi4py>=3.0.0
所以直接安装。在conda中执行(确保科学上网vpn已经关闭,才能使用pip安装)
conda activate DeepMimic
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
事实证明,选对python环境,安装包一帆风顺!!
注意:pip安装的pyopengl默认是32位的。电脑需要64位的。这个只能手动安装。
输入这个,查看pip支持的whl版本[9]
pip debug --verbose
接下来去下载PyOpenGL3.1.0和PyOpenGL-accelerate3.1.0的whl文件。
这个网站有cp36-cp36m-win_amd64后缀的最早版本是这两个:PyOpenGL_accelerate-3.1.5-cp36-cp36m-win_amd64.whl
和PyOpenGL-3.1.5-cp36-cp36m-win_amd64.whl
。
所以安装它们。
将两个whl放在3rdparty新建的PyOpenGL3.1.0文件夹下。
卸载掉之前安装的32位的[10]。
pip uninstall pyopengl
之前的就没有了
cd到 PyOpenGL3.1.0 文件夹,手动安装这两个文件:
cd D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\PyOpenGL3.1.0
pip install PyOpenGL_accelerate-3.1.5-cp36-cp36m-win_amd64.whl
pip install PyOpenGL-3.1.5-cp36-cp36m-win_amd64.whl
至此,DeepMimic所有依赖环境已经配置完毕。
10.DeepMimic链接第三方库
双击打开DeepMimic.sln
(根据右上角提示,需要安装Python开发包以获取完整的开发体验,点击安装即可)
安装完python扩展后,点击创建虚拟环境。
点击现有环境,选择DeepMimic环境py的解释器,也就是刚才配置的Anaconda环境。点击添加。
双击打开DeepMimicCore/DeepMimicCore.sln
。
重定向,点击确定(未弹出重定向可右键解决方法-重定向项目)
配置管理器,设置为Release_Swig x64
右键点开解决方案-DeepMimicCore属性页-配置属性-C/C+±常规-附加包含目录(注意配置要与配置管理器对应同为Release_Swig x64):
指定以下目录:
Bullet源目录
Eigen include目录
python include目录
本机的这三个目录分别为:
D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\bullet3CMake-2.88\src
D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\eigen-3.3.7\eigen-3.3.7\install\include\eigen3
D:\SOFEWARE_ANZHUANG\Anaconda\setup\envs\DeepMimic\include
此外,我还加了freeglut和glew的头文件目录:
D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\freeglut-3.0.0\freeglut-3.0.0\include
D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\glew-2.1.0-win32\glew-2.1.0\include
将以上五个目录添加到附加包含目录中:
点击确定即可。
继续更改DeepMimicCore属性页-链接器-常规-附加库目录(注意配置要与配置管理器对应同为Release_Swig x64):
指定Bullet[11],python,glew,freeglut库目录:
本机目录如下(都是编译完成的Realease x64
版本):
D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\bullet3CMake-2.88\build\lib\Release
D:\SOFEWARE_ANZHUANG\Anaconda\setup\envs\DeepMimic\libs
D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\glew-2.1.0-win32\glew-2.1.0\lib\Release\x64
D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\freeglut-3.0.0\freeglut-3.0.0\build\lib\Release
继续更改DeepMimicCore属性页-链接器-输入-附加依赖项(注意配置要与配置管理器对应同为Release_Swig x64):
添加以下静态库[11],并附加freeglut_static.lib,freeglut.lib。
继续更改DeepMimicCore属性-配置属性-C/C+±预处理器-预处理器定义,将“_USE_MATH_DEFINES
”添加进去[11](注意配置要与配置管理器对应同为Release_Swig x64):
最后点击应用-确定完成配置
修改DeepMimicCore.cpp
,注释掉122行[13],glutPostRedisplay()
右键解决方案-重新生成解决方案:
生成成功!!!
编译通过会生成 D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\DeepMimicCore\x64\Release_Swig\_DeepMimicCore.pyd
和D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\DeepMimicCore\x64\Release_Swig\_DeepMimicCore.py
ctrl+F5运行DeepMimicCore项目,显示如下(会报错,但是不用管):
最后,将D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\freeglut-3.0.0\freeglut-3.0.0\build\bin\Release
的freeglut.dll
和D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\3rdparty\glew-2.1.0-win32\glew-2.1.0\bin\Release\x64
的glew32.dll
都放到D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic\DeepMimicCore
。也就是_DeepMimicCore.pyd
的同级目录下。这是为了让 _DeepMimicCore.pyd 文件正常运行[14][15]。
如何使用
接下来就是python的操作了。
演示
激活conda环境
conda activate DeepMimic
D:
cd D:\Wlm_Project\MotionSimulated\1.DeepMimic_SIGGRAPH2018\DeepMimic
演示1
python DeepMimic.py --arg_file args/run_humanoid3d_spinkick_args.txt
演示2
python DeepMimic.py --arg_file args/play_motion_humanoid3d_args.txt
演示3
python DeepMimic.py --arg_file args/run_dog3d_pace_args.txt
训练
python mpi_run.py --arg_file args/train_humanoid3d_spinkick_args.txt --num_workers 16
python mpi_run.py --arg_file args/train_amp_target_humanoid3d_locomotion_args.txt --num_workers 16
评估
python DeepMimic.py --arg_file args/run_amp_target_humanoid3d_locomotion_args.txt
配置环境过程中遇到的问题解决链接
1.WindowsCMake下载与使用
2.TensorFlow的历史版本与对应Python版本
3.bullet安装之——windows下的安装与VS开发
4.Eigen3编译教程
5.参考:20220707另加freeglut
6.3.2安装GLEW
7.Win10下安装swig
8.Win10下Microsoft MPI(MSMPI)的下载安装
9.Windows_ 64位下正确安装Python-pyOpenGL
10.filename.whl is not a supported wheel on this platform
11.win10下DeepMimic学习之DeepMimicCore编译
12.Windows下的DeepMimic配置
13.DeepMimic出现Function <glutPostRedisplay> called without first calling ‘glutInit‘
14.Can’t execute the _DeepMimicCore.pyd
15.Freeglut init failed in python #21