omniverse/replicator

옴니버스 레플리케이터 예제 5탄

luke12 2022. 5. 26. 15:20

Randomizer Examples

 

Randomizer Examples — Omniverse Extensions documentation

Within replicator there are multiple off-the-shelf randomizers to bridge the domain gap between simulation and reality. Domain Randomization varies the parameters that define a scene in the simulation environment. Some of the parameters include the pose, s

docs.omniverse.nvidia.com

레플리케이터 내에는 시뮬레이션과 현실 사이의 도메인 격차를 해소하기 위해 여러 개의 기성 랜덤화기가 있습니다. 도메인 임의 추출은 시뮬레이션 환경에서 장면을 정의하는 매개 변수를 변경합니다. 일부 매개 변수에는 자세, 장면에서 다양한 개체의 크기, 시뮬레이션 환경의 조명, 색상 및 텍스처 속성을 통한 시뮬레이션 개체의 모양 등이 포함됩니다. 도메인 무작위화의 주요 목표 중 하나는 신경망을 시뮬레이션의 다양한 도메인 매개 변수에 노출시킴으로써 딥 러닝 응용 프로그램의 학습을 향상시켜 실제 응용 프로그램에 잘 일반화하는 데 도움이 되는 것입니다. 예를 들어, 컵을 감지하기 위해 심층 네트워크를 학습시키기 위해서는 무작위로 색, 질감, 포즈, 컵 크기 및 다양한 조명 조건을 가진 학습 목적을 위한 거대한 데이터 세트가 필요합니다. 이 거대한 데이터 세트는 실제 이미지 대신 옴니버스 아이작 심에서 합성 데이터를 생성함으로써 가능합니다.


다음은 Replicator API를 사용하여 씬(scene)에 적용된 도메인 랜덤화의 몇 가지 예입니다.

학습 목표

이 페이지를 통해 강조된 몇 가지 랜덤화와 사용 방법을 볼 수 있습니다. 그러나 사용 가능한 모든 랜덤화 및 자세한 내용은 API 설명서를 참조하십시오.

초기 설정

아래에 표시된 각각의 랜덤화는 스크립트 편집기 설정레플리케이터 실행 및 미리보기에 따라 실행할 수 있는 독립 실행형 스크립트입니다.

광원을 랜덤화

Replicator에는 여러 개의 광원이 내장되어 있습니다. Replicator API를 사용하여 위치, 온도 등의 파라미터를 쉽게 랜덤화할 수 있습니다. 다음 예제에서는 구면 조명의 변화 및 강도, 온도, 크기 및 위치를 나타내는 스크립트를 보여 줍니다. 이 예제에 사용된 평면, 구 및 입방체는 변경사항을 바로 볼 수 있기 위해 사용됩니다. 다른 광원이 필요한 경우 작업 흐름은 유사합니다. 전체 광원에 대한 API 설명서를 살펴보십시오.

import omni.replicator.core as rep

with rep.new_layer():
    sphere = rep.create.sphere(semantics=[('class', 'sphere')], position=(0, 100, 100))
    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(200, 200 , 100) )
    plane = rep.create.plane(scale=10, visible=True)

    def sphere_lights(num):
        lights = rep.create.light(
            light_type="Sphere",
            temperature=rep.distribution.normal(6500, 500),
            intensity=rep.distribution.normal(35000, 5000),
            position=rep.distribution.uniform((-300, -300, -300), (300, 300, 300)),
            scale=rep.distribution.uniform(50, 100),
            count=num
        )
        return lights.node

    rep.randomizer.register(sphere_lights)

    with rep.trigger.on_frame(num_frames=10):
        rep.randomizer.sphere_lights(10)

돔 조명을 랜덤화

돔 조명은 텍스처와 함께 제공되는 이미지 기반(배경) 조명에 사용됩니다. 돔 조명을 사용하면 전체 장면을 하이 또는 로우 다이내믹 영상 범위로 쉽게 조명할 수 있습니다. 이러한 기능은 환경에 사실적으로 보이는 조명을 제공하고 배경을 변경하는 데 매우 유용할 수 있습니다.

import omni.replicator.core as rep

with rep.new_layer():
    def dome_lights():
        lights = rep.create.light(
            light_type="Dome",
            rotation= (270,0,0),
            texture=rep.distribution.choice([
                'omniverse://localhost/NVIDIA/Assets/Skies/Cloudy/champagne_castle_1_4k.hdr',
                'omniverse://localhost/NVIDIA/Assets/Skies/Clear/evening_road_01_4k.hdr',
                'omniverse://localhost/NVIDIA/Assets/Skies/Clear/mealie_road_4k.hdr',
                'omniverse://localhost/NVIDIA/Assets/Skies/Clear/qwantani_4k.hdr'
                ])
            )
        return lights.node

    rep.randomizer.register(dome_lights)

    with rep.trigger.on_frame(num_frames=10,interval=10):
        rep.randomizer.dome_lights()

텍스처를 랜덤화

다음 스크립트에서는 큐브와 구를 사용한 장면이 만들어집니다. get_shapes() 함수의 임의 추출의 경우 텍스처 목록을 기반으로 텍스처가 임의 추출됩니다. 이 경우 NVIDIA에서 제공한 PNG 이미지를 사용하지만 다른 모든 PNG 이미지를 사용할 수 있습니다.

import omni.replicator.core as rep

with rep.new_layer():
    sphere = rep.create.sphere(semantics=[('class', 'sphere')], position=(0, 100, 100))
    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(200, 200 , 100),count=10 )

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

    def get_shapes():
        shapes = rep.get.prims(semantics=[('class', 'cube'), ('class', 'sphere')])
        with shapes:
            rep.randomizer.texture(textures=[
                    'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/aggregate_exposed_diff.jpg',
                    'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/gravel_track_ballast_diff.jpg',
                    'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/gravel_track_ballast_multi_R_rough_G_ao.jpg',
                    'omniverse://localhost/NVIDIA/Materials/vMaterials_2/Ground/textures/rough_gravel_rough.jpg'
                    ])
        return shapes.node

    rep.randomizer.register(get_shapes)

    # Setup randomization
    with rep.trigger.on_frame(num_frames=100):
        rep.randomizer.get_shapes()

재료를 랜덤화

이 예제에서는 맞춤 재료를 만들고 재료 속성을 변경하는 프로세스를 다룹니다. 재료 특성 및 재료 이해에 대한 자세한 내용은 옴니버스 재료API 설명서를 참조하십시오. 재료를 만든 후, 재료 랜덤화는 프레임당 재료를 변경하는 데 사용됩니다.

import omni.replicator.core as rep

with rep.new_layer():
    mats = rep.create.material_omnipbr(diffuse=rep.distribution.uniform((0,0,0), (1,1,1)), count=100)
    spheres = rep.create.sphere(
        scale=0.2,
        position=rep.distribution.uniform((-100,-100,-100), (100,100,100)),
        count=100)


    def get_spheres():
        with spheres:
            rep.randomizer.materials(mats)
        return spheres.node

    rep.randomizer.register(get_spheres)

    # Setup randomization
    with rep.trigger.on_frame(num_frames=100):
        rep.randomizer.get_spheres()

색상을 랜덤화

함수는 아래의 모양을 가져오고 스크립트에서 생성된 프림을 검색하며 rep.randomizer.color를 사용하여 균일한 분포로 색상을 변경합니다.

import omni.replicator.core as rep

with rep.new_layer():
    sphere = rep.create.sphere(semantics=[('class', 'sphere')], position=(0, 100, 100))
    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(200, 200 , 100) )
    plane = rep.create.plane(scale=10, visible=True)

    def get_shapes():
        shapes = rep.get.prims(semantics=[('class', 'cube'), ('class', 'sphere')])
        with shapes:
            rep.randomizer.color(colors=rep.distribution.uniform((0, 0, 0), (1, 1, 1)))
        return shapes.node

    rep.randomizer.register(get_shapes)

    # Setup randomization
    with rep.trigger.on_frame(num_frames=100):
        rep.randomizer.get_shapes()

랜덤화 포즈: 위치, 회전 및 크기

이 예에서는 modify.pose을 사용하여 회전, 위치 및 크기을 변경하는 과정을 보여 줍니다.

import omni.replicator.core as rep

with rep.new_layer():
    sphere = rep.create.sphere(semantics=[('class', 'sphere')], position=(0, 100, 100))
    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(200, 200 , 100) )
    plane = rep.create.plane(scale=10, visible=True)

    def get_shapes():
        shapes = rep.get.prims(semantics=[('class', 'cube'), ('class', 'sphere')])
        with shapes:
            rep.modify.pose(
                position=rep.distribution.uniform((-500, 50, -500), (500, 50, 500)),
                rotation=rep.distribution.uniform((0,-180, 0), (0, 180, 0)),
                scale=rep.distribution.normal(1, 0.5)
            )
        return shapes.node

    rep.randomizer.register(get_shapes)


    # Setup randomization
    with rep.trigger.on_frame(num_frames=30):
        rep.randomizer.get_shapes()

표면에서 객체를 산란

이 예제에서는 scatter_2d 함수를 사용하여 2D 표면에서 객체를 산란하는 방법을 보여 줍니다.

import omni.replicator.core as rep

with rep.new_layer():
    sphere = rep.create.sphere(semantics=[('class', 'sphere')], position=(100, 100, 100))
    cube = rep.create.cube(semantics=[('class', 'cube')],  position=(200, 200 , 100) )
    plane = rep.create.plane(scale=10, visible=False)

    def get_shapes():
        shapes = rep.get.prims(semantics=[('class', 'cube'), ('class', 'sphere')])
        with shapes:
            rep.randomizer.scatter_2d(plane)
        return shapes.node

    rep.randomizer.register(get_shapes)


    # Setup randomization
    with rep.trigger.on_frame(num_frames=30):
        rep.randomizer.get_shapes()

 

Props 폴더에서 여러 자산을 인스턴스화

도메인 랜덤화의 경우 자산을 씬(scene)으로 분산시킬 수 있습니다. 이는 rep.randomizer.instantiate 함수를 사용하는 Replicator에서 가능합니다. 여기서는 NVIDIA 자산을 사용하고 있습니다. Nucleus 서버 설정이 되지 않는 경우 Nucleus 서버가 설치되어 있는지 확인합니다.

import omni.replicator.core as rep

with rep.new_layer():
    PROPS = 'omniverse://localhost/NVIDIA/Assets/Vegetation/Plant_Tropical/'
    plane = rep.create.plane(scale=10, visible=True)

    def get_props(size):
        instances = rep.randomizer.instantiate(rep.utils.get_usd_files(PROPS, recursive=True), size=size, mode='point_instance')
        with instances:
            rep.modify.pose(
                position=rep.distribution.uniform((-500, 0, -500), (500, 0, 500)),
                rotation=rep.distribution.uniform((-90, -180, 0), (-90, 180, 0)),
            )
        return instances.node

    rep.randomizer.register(get_props)

    # Setup randomization
    with rep.trigger.on_frame(num_frames=30):
        rep.randomizer.get_props(3)