BatchRenderer#
BatchRenderer 提供高吞吐量的并行渲染,针对大规模强化学习训练中的许多并行环境进行优化。
概述#
BatchRenderer 专为以下场景设计:
最大吞吐量:针对渲染数千个环境进行优化
并行执行:原生支持批处理仿真
RL 训练:高效的策略学习观测生成
GPU 加速:完整的 GPU 流水线,最小化 CPU 开销
快速开始#
import genesis as gs
gs.init()
# 创建具有多个环境的场景
scene = gs.Scene()
scene.add_entity(gs.morphs.Plane())
robot = scene.add_entity(gs.morphs.URDF(file="robot.urdf"))
# 使用并行环境构建
scene.build(n_envs=1024)
# 添加 batch renderer 相机
cam = scene.add_camera(
res=(84, 84),
pos=(2, 0, 1),
lookat=(0, 0, 0.5),
)
# 训练循环
for step in range(10000):
# 获取批处理观测
obs = cam.render(rgb=True) # 形状:(n_envs, H, W, 3)
# 策略推理...
actions = policy(obs)
# 执行所有环境步骤
scene.step()
配置#
通过 BatchRendererOptions 配置 BatchRenderer:
batch_options = gs.options.BatchRendererOptions(
# 配置选项
)
输出格式#
当 n_envs > 1 时,相机输出是批处理的:
输出 |
形状 |
描述 |
|---|---|---|
|
|
批处理 RGB 图像 |
|
|
批处理深度图 |
|
|
批处理分割 |
性能提示#
分辨率:对于 RL 使用较小的分辨率(64x64 或 84x84)
渲染频率:仅在需要时渲染,而不是每步都渲染
GPU 内存:监控使用大量环境时的显存使用
API 参考#
- class genesis.vis.batch_renderer.BatchRenderer(visualizer, renderer_options, vis_options)[source]#
Bases:
RBCThis class is used to manage batch rendering
- render(rgb=True, depth=False, segmentation=False, normal=False, antialiasing=False, force_render=False)[source]#
Render all cameras in the batch.
- Parameters:
rgb (bool, optional) – Whether to render the rgb image.
depth (bool, optional) – Whether to render the depth image.
segmentation (bool, optional) – Whether to render the segmentation image.
normal (bool, optional) – Whether to render the normal image.
antialiasing (bool, optional) – Whether to apply anti-aliasing.
force_render (bool, optional) – Whether to force render the scene.
- Returns:
rgb_arr (tuple of arrays) – The sequence of rgb images associated with each camera.
depth_arr (tuple of arrays) – The sequence of depth images associated with each camera.
segmentation_arr (tuple of arrays) – The sequence of segmentation images associated with each camera.
normal_arr (tuple of arrays) – The sequence of normal images associated with each camera.
- property lights#
- property cameras#
- property seg_idxc_map#
另请参阅#
Rasterizer - 标准光栅化渲染器
gs.renderers.RayTracer - BatchRenderer 选项