Issue with the Augmentation documentation using replicator

Hello,

I am trying to add augmentations to my rendered images while collecting object detection and object segmentation data. My workflow involves rendering images of assets from a .usd file, and I am able to get the rendered images as expected. However, I am struggling to apply the augmentations mentioned in the augmentation examples from the documentation. Before the following snippet, I basically created warehouse, pallet and forklift prims. And then the code follows:

Here’s a snippet of my code:

with rep.new_layer():

    # Add a Driver View Camera
    driver_cam = rep.create.camera(
        position=(-2.0, -2.0, 2.0),  # Initial camera position
        look_at="/World/Pallet",     # Camera target
        name="DriverCam"
    )

    # Add a Top View Camera
    top_view_cam = rep.create.camera(
        position=(0.0, 0.0, 5.0),  # Initial camera position
        look_at="/World/Pallet",   # Camera target
        name="TopCam"
    )

    # Attach Render Products for Cameras
    driver_rp = rep.create.render_product(driver_cam, resolution=(512, 512), name="DriverView")
    top_rp = rep.create.render_product(top_view_cam, resolution=(512, 512), name="TopView")
    rps = [driver_rp, top_rp]

    # Register the AugPixellateExp augmentation
    rep.AnnotatorRegistry.register_augmentation(
        name="AugPixellateExp",
        augmentation=rep.annotators.Augmentation.from_node(
            "omni.replicator.core.AugPixellateExp",
            kernelSize=2  # Adjust the kernel size as needed
        )
    )

    # Retrieve the 'rgb' annotator and apply the AugPixellate augmentation
    rgb_annotator = rep.AnnotatorRegistry.get_annotator("rgb")
    rgb_annotator.augment("AugPixellate")

    print("PRINTING")
    # Add Semantic Segmentation
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(
        output_dir="/home/adityanisal/_output",  
        rgb=True,              
        semantic_segmentation=True,
        bounding_box_2d_tight=True,
        instance_segmentation=True, 
    )
    writer.attach([driver_rp, top_rp])

    # Trigger Frame Captures with Randomized Camera Positions
    print("[Debug] Triggering frame captures with randomized camera positions...")
    with rep.trigger.on_frame(num_frames=10):  # Generate 10 frames
        with driver_cam:
            rep.modify.pose(
                position=rep.distribution.uniform((-3.0, -3.0, 2.0), (0.0, 0.0, 4.0)),  # Randomize position
                look_at="/World/Pallet"
            )
        with top_view_cam:
            rep.modify.pose(
                position=rep.distribution.uniform((-6.0, -6.0, 4.0), (0.0, 0.0, 6.0)),  # Randomize height slightly
                look_at="/World/Pallet"
            )

    print("[Debug] Running the orchestrator...")
    rep.orchestrator.run()

print("[Debug] Cameras added and orchestrator run successfully.")

# Finish
print("[Debug] Scene setup and execution complete.")
# Wait for the data to be written to disk
rep.orchestrator.wait_until_complete()

simulation_app.close()

Questions:

  1. Can you provide the latest documentation or updated resources relevant to applying augmentations in the Replicator SDK? The current documentation linked above seems outdated or not working. It lets my code run but does not apply any augmentation.
  2. How can I correctly apply augmentations (e.g., pixellation or similar effects) to my rendered images using the updated Replicator SDK? If possible, please provide examples or edits to my code that align with the latest practices.
  3. The augmentation AugPixellateExp, referenced in the documentation, does not seem to exist in the current version of the SDK. How can I achieve pixellation and similar augmentations using the latest features? Are there equivalent methods or nodes available?
  4. Could you help me understand the flow for integrating augmentations into the pipeline?
  5. How should the augmentation be registered and linked to annotators or render products?
  6. Does the writer automatically process augmentations applied to annotators, or are there additional steps needed?

Any help would be greatly appreciated.

An update on this one. The following snippet makes it run. However, when I set the bounding box as true when initializing the writer, it throws errors following he code:

# Attach Render Products for Cameras
driver_rp = rep.create.render_product(driver_cam, resolution=(1024, 1024), name="DriverView")
top_rp = rep.create.render_product(top_view_cam, resolution=(1024, 1024), name="TopView")
rps = [driver_rp, top_rp] 
print("Driver RP:", driver_rp, "Type:", type(driver_rp))
print("Top RP:", top_rp, "Type:", type(top_rp))


# print("Available annotators:", rep.annotators.list())

# Add Bounding Box Annotator
bounding_box_annotator = rep.annotators.get("bounding_box_2d_tight")
print("Bounding Box Annotator:", bounding_box_annotator)

# rgb_to_hsv_augm = rep.annotators.Augmentation.from_function(rep.augmentations_default.aug_rgb_to_hsv)
pixel_augm = rep.annotators.Augmentation.from_node("omni.replicator.core.AugPixellateExp")
# Add Semantic Segmentation
writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(
    output_dir="/home/adityanisal/_output",  
    rgb=True,              
    semantic_segmentation=True,
    bounding_box_2d_tight=True,
    instance_segmentation=True, 
)
augmented_rgb_annot = rep.annotators.get("rgb", device="cuda:0").augment_compose([pixel_augm], name="rgb")

writer.add_annotator(augmented_rgb_annot)
writer.add_annotator(bounding_box_annotator)
# writer.augment_annotator("semantic_segmentation", )
writer.attach([driver_rp, top_rp])

# Trigger Frame Captures with Randomized Camera Positions
print("[Debug] Triggering frame captures with randomized camera positions...")
with rep.trigger.on_frame(num_frames=10):  # Generate 10 frames
    with driver_cam:
        rep.modify.pose(
            position=rep.distribution.uniform((-3.0, -3.0, 2.0), (0.0, 0.0, 4.0)),  # Randomize position
            look_at="/World/Pallet"
        )
    with top_view_cam:
        rep.modify.pose(
            position=rep.distribution.uniform((-6.0, -6.0, 4.0), (0.0, 0.0, 6.0)),  # Randomize height slightly
            look_at="/World/Pallet"
        )

    print("[Debug] Running the orchestrator...")
    rep.orchestrator.run()

print("[Debug] Cameras added and orchestrator run successfully.")

# Finish
print("[Debug] Scene setup and execution complete.")
# Wait for the data to be written to disk
rep.orchestrator.wait_until_complete()

simulation_app.close()

Error:

Traceback (most recent call last):
  File "/home/adityanisal/glb2usd/data_collection/isaac-sim/test.py", line 101, in <module>
    writer.add_annotator(augmented_rgb_annot)
  File "/home/adityanisal/.local/share/ov/pkg/isaac-sim-4.2.0/extscache/omni.replicator.core-1.11.20+106.1.0.lx64.r.cp310/omni/replicator/core/scripts/writers.py", line 379, in add_annotator
    annotators = self.get_annotators()
  File "/home/adityanisal/.local/share/ov/pkg/isaac-sim-4.2.0/extscache/omni.replicator.core-1.11.20+106.1.0.lx64.r.cp310/omni/replicator/core/scripts/writers.py", line 357, in get_annotators
    return {a.name: a for a in self.annotators}
  File "/home/adityanisal/.local/share/ov/pkg/isaac-sim-4.2.0/extscache/omni.replicator.core-1.11.20+106.1.0.lx64.r.cp310/omni/replicator/core/scripts/writers.py", line 357, in <dictcomp>
    return {a.name: a for a in self.annotators}
AttributeError: 'str' object has no attribute 'name'
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Annotators' for removal
2024-11-18 23:18:06 [7,860ms] [Warning] [omni.graph.core.plugin] Could not find category 'Replicator:Core' for removal
2024-11-18 23:18:06 [7,915ms] [Warning] [carb] Recursive unloadAllPlugins() detected!

Hi there,

here are examples using augmentation with an isaac sim typical workflow:

For the issue you are encountering, can you try calling orchestrator.run() outside of the with rep.trigger.on_frame scope?

Let me know if this fixes your issue.

Thank you for reaching out, indeed, there is a bug when using writer.augment_annotator() together with BasicWriter. The following snippet should achieve what you require while we tackle the bug.

from typing import Union

import omni.replicator.core as rep

def augment_annotator(
    writer: rep.writers.Writer,
    annotator_name: str,
    augmentation: Union[str, rep.annotators.Augmentation],
    **kwargs,
) -> None:
    annotator = None
    for idx, cur_anno in enumerate(writer.annotators):
        if isinstance(cur_anno, str):
            cur_anno = rep.annotators.get(cur_anno)
        if cur_anno and cur_anno.name == annotator_name:
            annotator = cur_anno
            break
    if annotator is None:
        raise ValueError(f"No annotator of name '{annotator_name}' found in writer.")
    writer.annotators[idx] = annotator.augment(augmentation, **kwargs)


with rep.new_layer():

    # Add a Driver View Camera
    driver_cam = rep.create.camera(
        position=(-2.0, -2.0, 2.0),  # Initial camera position
        look_at="/World/Pallet",     # Camera target
        name="DriverCam"
    )

    # Add a Top View Camera
    top_view_cam = rep.create.camera(
        position=(0.0, 0.0, 5.0),  # Initial camera position
        look_at="/World/Pallet",   # Camera target
        name="TopCam"
    )

    # Attach Render Products for Cameras
    driver_rp = rep.create.render_product(driver_cam, resolution=(512, 512), name="DriverView")
    top_rp = rep.create.render_product(top_view_cam, resolution=(512, 512), name="TopView")
    rps = [driver_rp, top_rp]

    print("PRINTING")
    # Add Semantic Segmentation
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(
        output_dir="forum_output",  
        rgb=True,              
        semantic_segmentation=True,
        bounding_box_2d_tight=True,
        instance_segmentation=True, 
    )
    augment_annotator(writer, "rgb", "Pixellate")
    writer.attach([driver_rp, top_rp])

    # Trigger Frame Captures with Randomized Camera Positions
    print("[Debug] Triggering frame captures with randomized camera positions...")
    with rep.trigger.on_frame(num_frames=10):  # Generate 10 frames
        with driver_cam:
            rep.modify.pose(
                position=rep.distribution.uniform((-3.0, -3.0, 2.0), (0.0, 0.0, 4.0)),  # Randomize position
                look_at="/World/Pallet"
            )
        with top_view_cam:
            rep.modify.pose(
                position=rep.distribution.uniform((-6.0, -6.0, 4.0), (0.0, 0.0, 6.0)),  # Randomize height slightly
                look_at="/World/Pallet"
            )

    print("[Debug] Running the orchestrator...")

print("[Debug] Cameras added and orchestrator run successfully.")

# Finish
print("[Debug] Scene setup and execution complete.")
# Wait for the data to be written to disk
rep.orchestrator.wait_until_complete()

simulation_app.close()

Hi @ahaidu , I tried doing it, but it did not resolve the error. But the solution provided by @jlafleche soved the issue. Seems like some bug in the inbuilt function for annotator and writer. Thank you for responding to my question, really appreciate it.

Best
Aditya Nisal

Thank you for the response @jlafleche , it worked! I have also added a device variable. Thanks a lot.

Best
Aditya Nisal

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.