现在代码已经能成功运行,让我们来看看代码内部是怎么运行的。
现在研究的quickstart文件是一个引导安装Acme并且训练D4PG智能体的文件。
D4PG是DDPG的改进,其中用到了分布式的critic,在里提出
A distributional perspective on reinforcement learning. In Precup, D. and Teh, Y. W., editors, Proceedings of the 34th International Conference on Machine Learning, ICML 2017, Sydney, NSW, Australia, 6-11 August 2017, volume 70 of Proceedings of Machine Learning Research, pages 449–458. PMLR.
我们按代码块来研究
environment_library = 'gym' # @param ['dm_control', 'gym']
这里设置了环境库,dm_control和gym都是供强化学习使用的物理世界工具包
!pip install dm-acme
!pip install dm-acme[reverb]
!pip install dm-acme[tf]
这里安装了acme框架,用于经验回放的reverb以及tensorflow。
if environment_library == 'dm_control':
import distutils.util
import subprocess
if subprocess.run('nvidia-smi').returncode:
raise RuntimeError(
'Cannot communicate with GPU. '
'Make sure you are using a GPU Colab runtime. '
'Go to the Runtime menu and select Choose runtime type.')
mujoco_dir = "$HOME/.mujoco"
print('Installing OpenGL dependencies...')
!apt-get update -qq
!apt-get install -qq -y --no-install-recommends libglew2.0 > /dev/null
print('Downloading MuJoCo...')
BASE_URL = 'https://github.com/deepmind/mujoco/releases/download'
MUJOCO_VERSION = '2.1.1'
MUJOCO_ARCHIVE = (
f'mujoco-{MUJOCO_VERSION}-{distutils.util.get_platform()}.tar.gz')
!wget -q "{BASE_URL}/{MUJOCO_VERSION}/{MUJOCO_ARCHIVE}"
!wget -q "{BASE_URL}/{MUJOCO_VERSION}/{MUJOCO_ARCHIVE}.sha256"
check_result = !shasum -c "{MUJOCO_ARCHIVE}.sha256"
if _exit_code:
raise RuntimeError(
'Downloaded MuJoCo archive is corrupted (checksum mismatch)')
print('Unpacking MuJoCo...')
MUJOCO_DIR = '$HOME/.mujoco'
!mkdir -p "{MUJOCO_DIR}"
!tar -zxf {MUJOCO_ARCHIVE} -C "{MUJOCO_DIR}"
# Configure dm_control to use the EGL rendering backend (requires GPU)
%env MUJOCO_GL=egl
print('Installing dm_control...')
# Version 0.0.416848645 is the first one to support MuJoCo 2.1.1.
!pip install -q dm_control>=0.0.416848645
print('Checking that the dm_control installation succeeded...')
try:
from dm_control import suite
env = suite.load('cartpole', 'swingup')
pixels = env.physics.render()
except Exception as e:
raise e from RuntimeError(
'Something went wrong during installation. Check the shell output above '
'for more information.\n'
'If using a hosted Colab runtime, make sure you enable GPU acceleration '
'by going to the Runtime menu and selecting "Choose runtime type".')
else:
del suite, env, pixels
!echo Installed dm_control $(pip show dm_control | grep -Po "(?<=Version: ).+")
elif environment_library == 'gym':
!pip install gym
这里根据第一行选择的环境库来安装环境。
!echo password|sudo -S apt-get install -y xvfb ffmpeg
!pip install imageio
!pip install PILLOW
!pip install pyvirtualdisplay
这一块安装了可视化工具包。
- xvfb:这是一个X Server,X Server是Linux系统里面图形接口服务器的简称Windows系统的界面是这个系统不可分割的一部分,各种窗口操作界面显示都是由系统核心直接管理的,而Linux的图形界面并不是系统的必要组成部分,它可以在无界面的条件下运行。当需要Linux提供界面的时候,系统就会建立一个或者数个X server,通过X协议跟窗口管理器交互,由独立于系统的应用程序来产生窗口,状态栏,按钮之类的交互界面。
- ffmpeg:FFmpeg是处理多媒体内容(如音频、视频、字幕和相关元数据)的库和工具的集合,它包含包含了先进的音视频编解码库,提供了录制、转换以及流传输音视频的完整跨平台解决方案。可以使用它的API对音视频进行处理,也可以使用它提供的工具,如 ffmpeg, ffplay, ffprobe,来编辑音视频文件。
- imageio:imageio是一个 Python 库,它提供了一个简单的界面来读写各种图像数据,包括动画图像、视频、体积数据和科学格式。https://www.csdn.net/tags/NtjaEg3sMDg4NTItYmxvZwO0O0OO0O0O.html
- PILLOW:Python成像库为Python解释器加上了图像处理能力。这个库提供了扩展文件格式支持,高效的内部表现(an efficient internal representation),以及相当强的图像处理能力。核心图像库旨在快速访问以几种基本像素格式存储的数据。它能成为通用图像处理工具的坚实的基础。官网Pillow (PIL Fork) 9.2.0.dev0 documentation
- pyvirtualdisplay:参看这篇文章Xvfb和pyvirtualdisplay简介_音程的博客-CSDN博客_xvfb是什么