# Domain Randomization¶

Domain Randomization varies the parameters that define a scene in the simulation environment. Some of the parameters include the pose, scale of various objects in a scene, the lighting of the simulated environment, the appearance of simulated objects via their color and texture properties and so on. One of the main objectives of domain randomization is to enhance the training of deep learning applications by exposing the neural network to wide variety of domain parameters in simulation which will help to generalize well to real world applications. For example, in order to train a deep network to detect a cup, a huge data set is needed for training purpose with randomized color, texture, pose, size of the cup and different lighting conditions. This huge data set is made possible by generating synthetic data in Omniverse Isaac Sim instead of real images.

Here is a glimpse of domain randomization applied on a warehouse scene in Isaac Sim.

## Domain Randomizer Plugin¶

Here, we explain the usage of Domain Randomizer(DR) plugin in Omniverse Isaac Sim and elaborate on the various parameters that can be randomized in the simulation environment.

To enable DR plugin, go to Window->Extension Manager menu and enable omni.isaac.dr plugin.

### DR Components¶

In order to randomize various parameters in the scene, DR components need to be created. To deep dive into various components that the plugin supports, open Isaac Robotics->Domain Randomizer->Component Sample.

#### Color Component¶

The color component enables randomization of the appearance of objects in the simulation environment via color property. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Color and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing a cube.

3. Press Load DR Component that adds a DR color component.

4. On clicking Play, the color of the cube randomizes.

Here are some parameters in the color component that can be set.

1. firstColor: Specify the minimum R, G, B values. The scale is from 0 to 1.

2. secondColor: Specify the maximum R, G, B values. The scale is from 0 to 1.

3. roughness: Specify the range for roughness property. The scale is from 0 to 1.

4. metallic: Specify the range for metallic property. The scale is from 0 to 1.

5. includeChildren: Enable if the child prims also need to included for randomization.

6. duration: Time interval in seconds between subsequent randomization.

7. seed: Value to initialize the pseudorandom number generator.

Please refer here to create color component via UI. To deep dive into the Python code used to create the sample, please refer here.

#### Movement Component¶

The movement component enables randomization of the position of objects in the simulation environment. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Movement and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing a cube.

3. Press Load DR Component that adds a DR movement component.

4. On clicking Play, the position of the cube randomizes.

Here are some parameters in the movement component that can be set.

1. xRange: Specify the range of X for movement along X-axis.

2. yRange: Specify the range of Y for movement along Y-axis.

3. zRange: Specify the range of Z for movement along Z-axis.

4. enableLookAtTarget: Enable to look at a target location during randomization.

5. includeChildren: Enable if the child prims also need to included for randomization.

6. duration: Time interval in seconds between subsequent randomization.

7. seed: Value to initialize the pseudorandom number generator.

Please refer here to create movement component via UI.

#### Rotation Component¶

The rotation component enables randomization of the orientation of objects in the simulation environment. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Rotation and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing a cube.

3. Press Load DR Component that adds a DR rotation component.

4. On clicking Play, the orientation of the cube randomizes.

Here are some parameters in the rotation component that can be set.

1. xRange: Specify the range of X for rotation along X-axis.

2. yRange: Specify the range of Y for rotation along Y-axis.

3. zRange: Specify the range of Z for rotation along Z-axis.

4. includeChildren: Enable if only the child prims of type Xform need to included for randomization.

5. duration: Time interval in seconds between subsequent randomization.

6. seed: Value to initialize the pseudorandom number generator.

Please refer here to create rotation component via UI.

#### Scale Component¶

The scale component enables randomization of the scale of objects in the simulation environment. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Scale and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing a cube.

3. Press Load DR Component that adds a DR scale component.

4. On clicking Play, the scale of the cube randomizes.

Here are some parameters in the scale component that can be set.

1. xRange: Specify the range of X for scale along X-axis.

2. yRange: Specify the range of Y for scale along Y-axis.

3. zRange: Specify the range of Z for scale along Z-axis.

4. enableUniform: Enable it to scale uniformly along all three axes.

5. includeChildren: Enable if the child prims also need to included for randomization.

6. duration: Time interval in seconds between subsequent randomization.

7. seed: Value to initialize the pseudorandom number generator.

Please refer here to create scale component via UI.

#### Light Component¶

The light component enables randomization of various properties of lights in the simulation environment. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Light and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing a cube with a light directly above it.

3. Press Load DR Component that adds a DR light component.

4. On clicking Play, light properties like intensity, temperature and color randomizes.

Below is the expected behavior.

Here are some parameters in the light component that can be set.

1. firstColor: Specify the minimum R, G, B values of light color. The scale is from 0 to 1.

2. secondColor: Specify the maximum R, G, B values of light color. The scale is from 0 to 1.

3. intensityRange: Specify the range of light intensity.

4. enableTemperature: Enable if temperature of light needs to be randomized.

5. temperatureRange: Specify the range of light temperature. This is applied only when enableTemperature is enabled.

6. includeChildren: Enable if the child prims also need to included for randomization.

7. duration: Time interval in seconds between subsequent randomization.

8. seed: Value to initialize the pseudorandom number generator.

Please refer here to create light component via UI.

#### Texture Component¶

The texture component enables randomization of the appearance of objects in the simulation environment via texture property. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Texture and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing a cube.

3. Press Load DR Component that adds a DR texture component.

4. On clicking Play, the texture of the cube randomizes.

Here are some parameters in the texture component that can be set.

1. textureList: List of texture files. Specified as comma separated list of strings.

2. ignoredClass: Prims contains class labels that need to be ignored during randomization. Specified as comma separated list of strings.

3. groupedClass: Prims contains class labels that need to be grouped with similar textures during randomization. Specified as comma separated list of strings.

4. enableProjectUVW: Enable it to allow UVW texture mapping.

5. includeChildren: Enable if only the child prims of type Mesh need to included for randomization.

6. duration: Time interval in seconds between subsequent randomization.

7. seed: Value to initialize the pseudorandom number generator.

Please refer here to create texture component via UI.

#### Material Component¶

The material component enables randomization of the appearance of objects in the simulation environment by applying different materials. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Material and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing a cube.

3. Press Load DR Component that adds a DR material component.

4. On clicking Play, the material of the cube randomizes.

Here are some parameters in the material component that can be set.

1. materialList: List of material files(.mdl). Specified as comma separated list of strings.

2. ignoredClass: Prims contains class labels that need to be ignored during randomization. Specified as comma separated list of strings.

3. groupedClass: Prims contains class labels that need to be grouped with similar materials during randomization. Specified as comma separated list of strings.

4. includeChildren: Enable if only the child prims of type Mesh need to included for randomization.

5. duration: Time interval in seconds between subsequent randomization.

6. seed: Value to initialize the pseudorandom number generator.

Please refer here to create material component via UI.

#### Mesh Component¶

The mesh component enables spawning of multiple copies of an asset in the simulation environment. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Mesh and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing a light.

3. Press Load DR Component that adds a DR mesh component along with prims will be spawned under /World/Meshes/mesh_component.

Here are some parameters in the mesh component that can be set.

1. meshList: List of mesh files(.usd). Specified as comma separated list of strings.

2. numMeshRange: Specify the range of number of mesh copies to spawn.

#### Visibility Component¶

The visibility component enables randomization of visibility property of assets in the simulation environment. In the Domain Randomizer Component Samples UI,

1. Set the dropdown to Visibility and then press, Clear Stage to open a new empty scene.

2. Press Load Stage to load a stage containing multiple cubes.

3. Press Load DR Component that adds a DR visibility component.

4. On clicking Play, visibility property randomizes.

Below is the expected behavior.

Here are some parameters in the visibility component that can be set.

1. numVisibleRange: Specify the range of number of assets that needs to be visible.

2. duration: Time interval in seconds between subsequent randomization.

Please refer here to create visibility component via UI.

### Load DR Samples¶

Here are two samples that bring together the various DR components and randomizes a scene.

#### Simple Room Sample¶

Open Isaac Robotics->Domain Randomizer->Simple Room Sample and click Play.

#### Warehouse Sample¶

Open Isaac Robotics->Domain Randomizer->Warehouse Sample and click Play.

### Add DR to an environment¶

Here are two approaches that loads an environment and adds various DR components to randomize the scene.

#### Via UI¶

Open Isaac Robotics->Domain Randomizer->Simple Room Python Sample. In the Simple Room Python Sample UI,

1. Open the simple room environment by pressing Load Stage.

2. Add DR components to the environment by pressing Load DR Component and click Play.

#### Via Python Code¶

Open Isaac Robotics->Domain Randomizer->Simple Room Python Sample. In the Simple Room Python Sample UI,

1. Open the simple room environment by pressing Load Stage.

2. Open Window->Script Editor, paste the below code and click Play.

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 import omni import omni.isaac.dr # Enter server name asset_path = "omniverse:///Isaac" # List of textures to randomize from texture_list = [ asset_path + "/Samples/DR/Materials/Textures/checkered.png", asset_path + "/Samples/DR/Materials/Textures/marble_tile.png", asset_path + "/Samples/DR/Materials/Textures/picture_a.png", asset_path + "/Samples/DR/Materials/Textures/picture_b.png", asset_path + "/Samples/DR/Materials/Textures/textured_wall.png", asset_path + "/Samples/DR/Materials/Textures/checkered_color.png", ] # Some prim paths to used for randomization simple_room_prim_path = "/Root" light_prim_path = "/Root/RectLight" table_prim_path = "/Root/table_low_327" floor_prim_path = "/Root/Towel_Room01_floor_bottom_218" # Create DR texture component result, prim = omni.kit.commands.execute( "CreateTextureComponentCommand", prim_paths=[simple_room_prim_path], enable_project_uvw=False, texture_list=texture_list, ignored_class_list=["floor_bottom"], grouped_class_list=[], duration=1.0, include_children=True, ) # Create DR color component result, prim = omni.kit.commands.execute( "CreateColorComponentCommand", prim_paths=[floor_prim_path], first_color_range=(0.0, 0.0, 0.0), second_color_range=(1.0, 1.0, 1.0), roughness_range=(0.0, 1.0), metallic_range=(0.0, 1.0), duration=1.0, include_children=False, ) # Create DR movement component result, prim = omni.kit.commands.execute( "CreateMovementComponentCommand", prim_paths=[table_prim_path], min_range=(-50.0, -50.0, 18.04), max_range=(50.0, 50.0, 18.04), target_position=None, target_paths=None, duration=1.0, include_children=False, ) # Create DR rotation component result, prim = omni.kit.commands.execute( "CreateRotationComponentCommand", prim_paths=[table_prim_path], min_range=(0.0, 0.0, 0.0), max_range=(0.0, 0.0, 360.0), duration=1.0, include_children=False, ) # Create DR scale component result, prim = omni.kit.commands.execute( "CreateScaleComponentCommand", prim_paths=[table_prim_path], min_range=(0.4, 0.4, 0.4), max_range=(1.3, 1.3, 1.3), uniform_scaling=True, duration=1.0, include_children=False, ) # Create DR light component result, prim = omni.kit.commands.execute( "CreateLightComponentCommand", light_paths=[light_prim_path], first_color_range=(0.9, 0.9, 0.9), second_color_range=(1.0, 1.0, 1.0), intensity_range=(40000.0, 70000.0), temperature_range=(1500.0, 6500.0), enable_temperature=True, duration=1.0, include_children=False, ) 

To deep dive into the Python code used to create the sample, please refer here.

### Create DR Components via UI¶

One way to enable randomization in a scene is by creating DR components via UI. Below is a workflow to achieve that.

1. Go to Create->Isaac->DR to create a DR component.

2. For the newly created component, add the path of the assets for the randomization to be applied. This is done using the Relationship Editor UI. Go to Window->Isaac->Relationship Editor and enable it. See Relationship Editor UI for more details

3. Update the various parameters of the component.

#### Color Component¶

In the below scenario, a color component is created. Then, the asset path for the box and floor is added using Relationship Editor UI. For example, Xform at path /World/props/box represented the box which was added to the color component via Relationship Editor UI. This caused the color of the objects to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the color component in it.

#### Movement Component¶

In the below scenario, a movement component is created. Then, the asset path for the cube is added using Relationship Editor UI. For example, Xform at path /World/props/nvidia_cube_1 represented the cube which was added to the movement component via Relationship Editor UI. This caused the position of the object to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. The parameters that control the range of motion along x, y and z-axis was also updated. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the movement component in it.

#### Rotation Component¶

In the below scenario, a rotation component is created. Then, the asset path for the cube is added using Relationship Editor UI. For example, Xform at path /World/props/nvidia_cube_2 represented the cube which was added to the rotation component via Relationship Editor UI. This caused the orientation of the object to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. The parameters that control the range of orientation along x, y and z-axis was also updated. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the rotation component in it.

#### Scale Component¶

In the below scenario, a scale component is created. Then, the asset path for the box is added using Relationship Editor UI. For example, Xform at path /World/props/box represented the box which was added to the scale component via Relationship Editor UI. This caused the scale of the object to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. The parameters that control the range of scale along x, y and z-axis was also updated. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the scale component in it.

#### Light Component¶

In the below scenario, a light component is created. Then, the asset path for the light is added using Relationship Editor UI. For example, the scene has a light at path /World/props/DiskLight which was added to the light component via Relationship Editor UI. This caused the various properties of the light to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. Other light parameters that includes color, intensity and temperature can be updated. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the light component in it.

#### Texture Component¶

In the below scenario, a texture component is created. Then, a list of texture files from server are added to the textureList parameter.

 1 Isaac/Samples/DR/Materials/Textures/checkered.png,Isaac/Samples/DR/Materials/Textures/marble_tile.png,Isaac/Samples/DR/Materials/Textures/picture_a.png,Isaac/Samples/DR/Materials/Textures/picture_b.png,Isaac/Samples/DR/Materials/Textures/textured_wall.png 

The asset path is added using Relationship Editor UI. For example, the Mesh at path /World/simple_room/table_low_327/table_low represented the table mesh which was added to the texture component via Relationship Editor UI. This caused the texture of the table to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the texture component in it.

#### Material Component¶

In the below scenario, a material component is created. Then, a list of material files from server are added to the materialList parameter.

 1 Isaac/Samples/DR/Materials/checkered.mdl,Isaac/Samples/DR/Materials/checkered_color.mdl,Isaac/Samples/DR/Materials/marble_tile.mdl,Isaac/Samples/DR/Materials/picture_a.mdl,Isaac/Samples/DR/Materials/picture_b.mdl,Isaac/Samples/DR/Materials/textured_wall.mdl 

The asset path is added using Relationship Editor UI. For example, the Mesh at path /World/simple_room/table_low_327/table_low represented the table mesh which was added to the material component via Relationship Editor UI. This caused the material of the table to randomize. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the material component in it.

#### Visibility Component¶

In the below scenario, a visibility component is created. Then, the asset path for the cubes are added using Relationship Editor UI. For example, Xform at paths /World/props/box, /World/props/nvidia_cube_1, /World/props/nvidia_cube_2 represented the cubes which were added to the visibility component via Relationship Editor UI. Next, the numVisibleRange is set to (1,2). This caused the visibility of the cubes to randomize such that each randomized scene contains 1 to 2 cubes which are visible. The parameters of the component can also be updated anytime as was done with the duration parameter that controls how frequent randomization needs to happen. If needed, the scene can also be saved. So, next time when the scene is opened, it loads with the visibility component in it.

### Code deep dive¶

Each DR component sample is created using USD Python APIs. We will deep dive into the Python code in this section.

#### Color Component¶

The code snippets below can be found in the color component sample’s script. This can also be run within Windows->Script Editor inside Omniverse Isaac Sim UI after loading Isaac/Samples/DR/Props/simple_cube_with_light.usd stage.

First, we import some libraries.

 1 2 3 4 import omni.kit import omni.usd import omni.isaac.dr from pxr import Sdf 

Next, we create DR color component and set its attributes

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 stage = omni.usd.get_context().get_stage() default_prim_path = str(stage.GetDefaultPrim().GetPath()) cube_path = default_prim_path + "/Cube" # Create DR color component result, prim = omni.kit.commands.execute( "CreateColorComponentCommand", prim_paths=[cube_path], first_color_range=(0.0, 0.0, 0.0), second_color_range=(1.0, 1.0, 1.0), roughness_range=(0.0, 1.0), metallic_range=(0.0, 1.0), duration=0.3, include_children=False, ) 

Remember, the editor must be playing for the randomization to happen. This can also be done via Python.

 1 2 3 editor = omni.kit.editor.get_editor_interface() if not editor.is_playing(): editor.play() 

To update an attribute of the color component, we need to first access the attribute corresponding to the color component prim that was created earlier and then set it to the new value. For example, we will update the duration attribute of color_component prim to 0 which means color randomization happens every frame.

 1 2 3 4 5 6 7 8 9 stage = omni.usd.get_context().get_stage() default_prim_path = str(stage.GetDefaultPrim().GetPath()) color_component_path = default_prim_path + "/color_component" # Get DR color component prim prim = stage.GetPrimAtPath(color_component_path) # Update duration to 0 prim.GetAttribute("duration").Set(float(0)) 

#### Simple Room Python Sample¶

In this section, we do a deep dive into the code snippet provided here.

  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 import omni import omni.isaac.dr # Enter server name asset_path = "omniverse:///Isaac" # List of textures to randomize from texture_list = [ asset_path + "/Samples/DR/Materials/Textures/checkered.png", asset_path + "/Samples/DR/Materials/Textures/marble_tile.png", asset_path + "/Samples/DR/Materials/Textures/picture_a.png", asset_path + "/Samples/DR/Materials/Textures/picture_b.png", asset_path + "/Samples/DR/Materials/Textures/textured_wall.png", asset_path + "/Samples/DR/Materials/Textures/checkered_color.png", ] # Some prim paths to use for randomization simple_room_prim_path = "/Root" light_prim_path = "/Root/RectLight" table_prim_path = "/Root/table_low_327" floor_prim_path = "/Root/Towel_Room01_floor_bottom_218" 

First, we import some libraries including DR. Then, we specify the Omniverse server name in Line 5 which will be used to find assets. A list of texture assets that will be used to randomize assets in the room is provided in texture_list. In lines 18-21, we store prim paths for assets that will be part of the randomization process.

Finally, we create multiple DR components using omni.kit.commands.execute.

  1 2 3 4 5 6 7 8 9 10 11 # Create DR texture component result, prim = omni.kit.commands.execute( "CreateTextureComponentCommand", prim_paths=[simple_room_prim_path], enable_project_uvw=False, texture_list=texture_list, ignored_class_list=["floor_bottom"], grouped_class_list=[], duration=1.0, include_children=True, ) 

For example, the above one-liner creates a DR texture component that randomizes the texture of all assets in the room except ones whose prim path contains floor_bottom. As a result, every 1 second, a random texture from texture_list will be applied to those assets.

  1 2 3 4 5 6 7 8 9 10 11 # Create DR color component result, prim = omni.kit.commands.execute( "CreateColorComponentCommand", prim_paths=[floor_prim_path], first_color_range=(0.0, 0.0, 0.0), second_color_range=(1.0, 1.0, 1.0), roughness_range=(0.0, 1.0), metallic_range=(0.0, 1.0), duration=1.0, include_children=False, ) 

The above one-liner creates a DR color component that randomizes the color, roughness and metallic property of the floor asset referred by floor_prim_path. As a result, every 1 second, the floor asset will have a random color specified within first_color_range and second_color_range along with random roughness, metallic property value specified by roughness_range and metallic_range respectively.

  1 2 3 4 5 6 7 8 9 10 11 # Create DR movement component result, prim = omni.kit.commands.execute( "CreateMovementComponentCommand", prim_paths=[table_prim_path], min_range=(-50.0, -50.0, 18.04), max_range=(50.0, 50.0, 18.04), target_position=None, target_paths=None, duration=1.0, include_children=False, ) 

The above one-liner creates a DR movement component that randomizes the location of the table asset referred by table_prim_path. As a result, every 1 second, the table asset will be randomly placed at a location specified within min_range and max_range.

 1 2 3 4 5 6 7 8 9 # Create DR rotation component result, prim = omni.kit.commands.execute( "CreateRotationComponentCommand", prim_paths=[table_prim_path], min_range=(0.0, 0.0, 0.0), max_range=(0.0, 0.0, 360.0), duration=1.0, include_children=False, ) 

The above one-liner creates a DR rotation component that randomizes the orientation of the table asset referred by table_prim_path. As a result, every 1 second, the table asset will be randomly oriented by a value specified within min_range and max_range.

  1 2 3 4 5 6 7 8 9 10 # Create DR scale component result, prim = omni.kit.commands.execute( "CreateScaleComponentCommand", prim_paths=[table_prim_path], min_range=(0.4, 0.4, 0.4), max_range=(1.3, 1.3, 1.3), uniform_scaling=True, duration=1.0, include_children=False, ) 

The above one-liner creates a DR scale component that randomizes the scale of the table asset referred by table_prim_path. As a result, every 1 second, the table asset will be randomly scaled by a value specified within min_range and max_range.

  1 2 3 4 5 6 7 8 9 10 11 12 # Create DR light component result, prim = omni.kit.commands.execute( "CreateLightComponentCommand", light_paths=[light_prim_path], first_color_range=(0.9, 0.9, 0.9), second_color_range=(1.0, 1.0, 1.0), intensity_range=(40000.0, 70000.0), temperature_range=(1500.0, 6500.0), enable_temperature=True, duration=1.0, include_children=False, ) 

The above one-liner creates a DR light component that randomizes the properties of light asset referred by light_prim_path. As a result, every 1 second, the light color will be a random value specified within first_color_range and second_color_range along with random intensity, temperature property value specified by intensity_range and temperature_range respectively.