I don't want to annotate certain semantic data

So for my scene I have bottles with classes so that they can move around the scene, and the caps have classes while remaining under the bottle class(don’t want the caps coming off).


I’m wondering if there’s something I can do to make Omniverse not output the annotator data for the bottles while leaving the caps intact.
Here’s a snippet of the code
with rep.trigger.on_frame(num_frames=700, rt_subframes=32):
rep.randomizer.BG_Shuffle()
rep.randomizer.CD_Shuffle()
rep.randomizer.C_Shuffle()
rep.randomizer.CZ_Shuffle()
rep.randomizer.D_Shuffle()
rep.randomizer.DC_Shuffle()
rep.randomizer.DDP_Shuffle()
rep.randomizer.DP_Shuffle()
rep.randomizer.F_Shuffle()
rep.randomizer.MM_Shuffle()
rep.randomizer.PC_Shuffle()
rep.randomizer.PD_Shuffle()
rep.randomizer.RG_Shuffle()
rep.randomizer.S_Shuffle()
rep.randomizer.lightSwitch()
with camera:
rep.modify.pose(position=rep.distribution.sequence(choices))

writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(
    output_dir="BottleVend1-18-2023",
    rgb=True,
    bounding_box_2d_tight=True,
    distance_to_camera=True
)
writer.attach([render_product])

Hello,

First of all - nice looking scene!

The easiest way to do this via scripting is with set_instance_mapping_semantic_filter()

To your script, add:

from omni.syntheticdata import SyntheticData
...
writer.initialize(....)
# set_instance_mapping_semantic_filter() needs to be called after the writer initialization
# because BasicWriter also uses the function for filtering semantics
# change "class:!bottle" to whatever your bottle semantics are
SyntheticData.Get().set_instance_mapping_semantic_filter("class:!bottle")

Change "class:!bottle" to whatever the semantics of your bottles are. You can even set multiple semantics to filter.

See the bottom of this page for more details on the filtering syntax.


Longer example:

Note: most of this code is setting-up a simple scene with semantics plane, sphere, and cube. At the end I will filter-out the sphere semantic objects.

import omni.replicator.core as rep
from omni.syntheticdata import SyntheticData

with rep.new_layer():

    camera = rep.create.camera(position=(0, 500, 1000), look_at=(0, 0, 0))

    # Create simple shapes to manipulate
    plane = rep.create.plane(semantics=[("class", "plane")], position=(0, -100, 0), scale=(100, 1, 100))
    cubes = rep.create.cube(
        semantics=[("class", "cube")], position=rep.distribution.uniform((-300, 0, -300), (300, 0, 300)), count=6
    )
    spheres = rep.create.sphere(
        semantics=[("class", "sphere")], position=rep.distribution.uniform((-300, 0, -300), (300, 0, 300)), count=6
    )

    with rep.trigger.on_frame(num_frames=10):
        with cubes:
            rep.randomizer.color(colors=rep.distribution.normal((0.2, 0.2, 0.2), (1.0, 1.0, 1.0)))
        with spheres:
            rep.randomizer.color(colors=rep.distribution.normal((0.2, 0.2, 0.2), (1.0, 1.0, 1.0)))


render_product = rep.create.render_product(camera, (512, 512))

writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(
    output_dir="remove_semantics",
    rgb=True,
    semantic_segmentation=True,
    colorize_semantic_segmentation=True,
)
# Filter class:sphere objects (_after_ BasicWriter is initialized)
# https://docs.omniverse.nvidia.com/prod_extensions/prod_extensions/ext_replicator/semantics_schema_editor.html
SyntheticData.Get().set_instance_mapping_semantic_filter("class:!sphere")
writer.attach([render_product])
rep.orchestrator.run()