Rayrai Example: Domain Randomization
Overview
An offscreen example that renders eight environments together with raisin::SensorBatchRenderer and randomizes their appearance for four episodes. Every World holds the same objects and a fixed camera head with a 160 x 120 RGB camera and a depth camera. Each episode draws, for every World, a new light direction, intensity and color temperature, ambient level and background, and new object colors. The example writes the RGB images of all Worlds and episodes into one picture, domain_randomization.png (1280 x 480): one row per episode, one column per World.
It also checks that the randomization changes only colors: it prints the largest change of any depth pixel between episodes, which is 0.
Target
CMake target: rayrai_domain_randomization.
Run
source ./raisim_env.sh
cmake --build build-examples --target rayrai_domain_randomization --parallel 2
cd build-examples/examples && ./rayrai_domain_randomizationThe example takes no arguments and writes domain_randomization.png to its working directory. On Linux without a display, select SDL's offscreen video driver:
SDL_VIDEODRIVER=offscreen ./rayrai_domain_randomizationIt also prints the lighting that World 0 drew in each episode (SensorBatchRenderer::appearance()), for logging or replay.
SensorBatchRenderer needs desktop OpenGL (3.3, or 4.1 on macOS), so this example is not part of the browser build.
Details
- Adds every World with
addWorld()and its cameras withaddRgbCamera()andaddDepthCamera(). - Sets the distributions once with
setAppearanceRandomization(): a light turned by up to 0.6 rad, a log-uniform intensity factor from 0.5 to 2, a color temperature from 3000 K to 9000 K, an ambient factor, a mix of the background toward a random color, and per-object hue shift, saturation and brightness factors and a mix toward a random color. - Calls
randomizeAppearance(world, episode)for each World at the start of an episode, thencapture()andrender(). A draw depends only on the seed, the World, the episode and the parameter, so the same episode looks the same whatever the number of Worlds and the order of the calls. - Reads the images from
rgbGroups()(BGRA, top row first) and the depth fromdepthGroups().
See Appearance randomization for every parameter and Many environments for the batch renderer.