Omniverse Code crashes while running script

Hi,

I am running following script in omniverse code script editor, but it’s crashing the Code. I am using Omniverse Code 2022.3.3. I could not find any specific error in logs.

import omni.replicator.core as rep


LOCAL_ASSETS_PATH = "/home/atai/Omniverse/Assets"
OUTPUT_PATH = "/home/atai/Code/tests/output/"

CRATES_DIR = f"{LOCAL_ASSETS_PATH}/Industrial_3D_Models_Pack/Containers/Wooden"


with rep.new_layer():

    camera = rep.create.camera(position=(0, 365.76, 121.92), 
                               rotation=(-60.0,0.0,0.0),
                               focal_length=10,
                               projection_type="fisheye_orthographic")
    render_product = rep.create.render_product(camera, (960, 540))

    # create a platform
    platform = rep.create.plane(scale=10, visible=True)

    # create a light
    lights = rep.create.light(light_type="Dome")

    def get_crates(max_size=1):
        crate_usds = rep.utils.get_usd_files(CRATES_DIR, recursive=True)
        crates = rep.randomizer.instantiate(crate_usds, size=max_size, with_replacements=True,
                                            use_cache=False, mode='scene_instance')
        with crates:
            rep.modify.semantics([("class", "crates")])
        return crates
    rep.randomizer.register(get_crates)

    with rep.trigger.on_frame(num_frames=5):
        rep.randomizer.get_crates()
        objs = rep.get.prims(semantics=[('class', 'crates')])
        with objs:
            rep.modify.pose(
                rotation=rep.distribution.uniform((-90,-180, 0), (-90, 180, 0)),
                scale=0.7,
            )
            rep.randomizer.scatter_2d(platform, check_for_collisions=True)

    # Initialize and attach writer
    writer = rep.WriterRegistry.get("BasicWriter")
    writer.initialize(
        output_dir=OUTPUT_PATH,
        rgb=True,
        bounding_box_2d_tight=True,
    )

    writer.attach([render_product])

    rep.orchestrator.run()

You can find complete log file here:
kit_20230529_155209.log (1004.6 KB)

Hi @ShyamPatel. Judging from the log it looks like you’re running out of VRAM. I’m not sure how heavy your assets and textures are, but that’s probably the area that I’d try to optimize first. It looks like raw Kit takes about 5+ GB of VRAM on an empty scene, so take that into consideration.

@pcallender Thanks for your reply.

One thing I analysed here is that, the same code is working when I am using point_instance mode in rep.randomizer.instantiate function. But the Code crashes while using scene_instance or reference.

Can you please elaborate, how each mode can change the memory usage and why?

Hi @ShyamPatel,

I can’t say why specifically one would crash from memory while the other would not, however, this link below has a detailed breakdown on the two and may lead you to a better understanding of where the memory differences are in your situation.

https://openusd.org/dev/api/_usd__page__scenegraph_instancing.html#:~:text=USD's%20instancing%20functionality%20allows%20prims,to%20a%20scene%20via%20composition