Randomizing appearance, placement and orientation of an existing 3D assets with a built-in writer
Randomizing appearance, placement and orientation of an existing 3D assets with a built-in writer — Omniverse Extensions docu
To run the following tutorial first make sure to follow script follow Setting up nucleus server to get the assets for this randomization. Tor run the spript use the script editor as shown in Setting up the Script Editor. Let’s import omni.replicator firs
docs.omniverse.nvidia.com
내장된 작성자를 사용하여 기존 3D 자산의 모양, 배치 및 방향을 랜덤화
학습목표
대규모 환경 집합 내에서 개체를 식별할 수 있는 DNN 모델을 생성하려고 합니다. 이러한 모델을 만들려면 다양한 환경에서 대상 개체가 다양한 방식으로 배치되는 교육 데이터 세트가 필요합니다. 경우에 따라 이 대상 개체가 완전히 보이지 않고 씬(scene)의 다른 자산에 의해 가려질 수 있습니다. 이 예제에서는 이 데이터 세트를 합성하여 생성하는 프로세스를 살펴보겠습니다. 이 튜토리얼의 목적은 대상 개체가 랜덤화된 환경에 배치되는 합성 데이터 생성 프로세스의 엔드 투 엔드 예를 보여 주는 것입니다. 기계 학습 모델을 훈련하는 데 사용할 수 있는 형태로 주석이 달린 데이터를 출력하는 작성자로 이 튜토리얼을 마칩니다.
이 예에서는 기본 제공 자산(파란색 드레스를 입은 작업자)을 다른 자산과 함께 랜덤 환경에 배치하는 대상 개체로 사용합니다. 현장의 자산 배치 및 회전이 균일한 랜덤 분포에서 선택됩니다. 이 예에서는 자산을 랜덤화하는 것 외에도 카메라 배치 랜덤화를 보여줌으로써 다양한 각도에서 이미지를 생성하여 다양한 배경을 캡처합니다. 마지막으로 미리 정의된 작성자를 사용하여 이미지와 주석이 디스크에 기록됩니다.
Replicator API를 사용
먼저 다음 자습서를 실행하려면 스크립트를 따라 Nucleus 서버 설정에 따라 이 임의화를 위한 자산을 가져옵니다. 스크립트를 실행하려면 스크립트 편집기 설정에 표시된 대로 스크립트 편집기를 사용하십시오.
먼저 import omni.replicator를 하겠습니다. 다른 예제와 마찬가지로 USD 파일에 자산을 배치하고 랜덤화하는 데 사용할 새 계층(layer)을 생성해 보겠습니다. 또한 이 예제에 사용할 3D 자산에 대한 경로를 정의합니다.
import omni.replicator.core as rep
import omni.replicator as rep
with rep.new_layer():
# Define paths for the character, the props, the environment and the surface where the assets will be scattered in.
WORKER = 'omniverse://localhost/NVIDIA/Assets/Characters/Reallusion/Worker/Worker.usd'
PROPS = 'omniverse://localhost/NVIDIA/Assets/Vegetation/Shrub'
ENVS = 'omniverse://localhost/NVIDIA/Assets/Scenes/Templates/Outdoor/Puddles.usd'
SURFACE = 'omniverse://localhost/NVIDIA/Assets/Scenes/Templates/Basic/display_riser.usd'
다음 함수에서는 수풀 자산에 대한 랜덤화를 정의합니다. 이 예에서는 이러한 자산을 PROPS 자산이라고 합니다. 첫 번째 단계로 이러한 PROPS 자산의 부분 집합(크기 = 50)을 생성합니다. 이 데이터 세트에 대해 생성된 다양한 배경을 확보하기 위해 서로 다른 프레임에서 서로 다른 수풀을 사용하려고 합니다. 이 부분 집합을 선택한 후 다음 단계는 이러한 수풀을 랜덤하게 회전하는 위치에 배치하는 것입니다.
# Define randomizer function for PROPS assets. This randomization includes placement and rotation of the assets on the surface.
def env_props(size=50):
instances = rep.randomizer.instantiate(rep.utils.get_usd_files(PROPS), 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
※ 자체 PROPS 폴더를 사용 중이고 USD가 포함된 하위 폴더가 가득하다면 여기에 표시된 rep.utils.get_usd_files(PROPS, recursive=True) 플래그인 recursive=True를 사용해야 합니다. 자산이 원격 Nucleus 서버에 있는 경우 시간이 오래 걸립니다.
다음으로 우리는 우리의 목표물, 즉 파란색 드레스를 입은 작업자에 대한 무작위자를 정의한다. 장면의 다른 자산(수풀)과 마찬가지로 대상 객체의 위치와 회전도 랜덤화한다.
def worker():
worker = rep.create.from_usd(WORKER, semantics=[('class', 'worker')])
with worker:
rep.modify.pose(
position=rep.distribution.uniform((-500, 0, -500), (500, 0, 500)),
rotation=rep.distribution.uniform((-90,-45, 0), (-90, 45, 0)),
)
return worker
다음 줄에서 위에서 정의한 두 개의 랜덤화를 등록합니다.
rep.randomizer.register(env_props)
rep.randomizer.register(worker)
다음으로 자산이 배치될 장면, 방 및 테이블의 정적 요소를 설정합니다. 우리는 또한 카메라를 설치하고 렌더 제품에 부착합니다.
# Setup the static elements
env = rep.create.from_usd(ENVS)
surface = rep.create.from_usd(SURFACE)
# Setup camera and attach it to render product
camera = rep.create.camera(
focus_distance=800,
f_stop=0.5
)
render_product = rep.create.render_product(camera, resolution=(1024, 1024))
마지막 단계로 기본 작성자를 초기화하고 이미지를 저장할 출력 디렉토리를 정의합니다. 그런 다음 이 작성자는 이전 단계에서 정의한 렌더링 제품에 첨부됩니다.
# Initialize and attach writer
writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(output_dir="_output", rgb=True, bounding_box_2d_tight=True)
writer.attach([render_product])
이제 타깃 및 기본 자산을 정의하고, 랜덤화를 정의하고, 환경을 정의하고, 카메라를 설정하고, 제품을 렌더링하고, 기본 작성자를 만들었습니다. 모든 설정이 완료된 후 데이터를 생성할 준비가 되지 않았습니다. 다음 줄에서는 등록된 랜덤화를 프레임마다 작동합니다. 모든 프레임에 대해 카메라 위치와 함께 기본 및 대상 자산이 랜덤화되어 데이터 세트에 대해 다른 각도에서 캡처된 이미지가 있는지 확인합니다.
with rep.trigger.on_frame(num_frames=10000):
rep.randomizer.env_props(75)
rep.randomizer.worker()
with camera:
rep.modify.pose(position=rep.distribution.uniform((-500, 200, 1000), (500, 500, 1500)), look_at=surface)
아래는 편리함을 위해 복사하고 테스트할 수 있는 전체 코드입니다.
import omni.replicator.core as rep
with rep.new_layer():
# Define paths for the character, the props, the environment and the surface where the assets will be scattered in.
WORKER = 'omniverse://localhost/NVIDIA/Assets/Characters/Reallusion/Worker/Worker.usd'
PROPS = 'omniverse://localhost/NVIDIA/Assets/Vegetation/Shrub'
ENVS = 'omniverse://localhost/NVIDIA/Assets/Scenes/Templates/Outdoor/Puddles.usd'
SURFACE = 'omniverse://localhost/NVIDIA/Assets/Scenes/Templates/Basic/display_riser.usd'
# Define randomizer function for Base assets. This randomization includes placement and rotation of the assets on the surface.
def env_props(size=50):
instances = rep.randomizer.instantiate(rep.utils.get_usd_files(PROPS), 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
def worker():
worker = rep.create.from_usd(WORKER, semantics=[('class', 'worker')])
with worker:
rep.modify.pose(
position=rep.distribution.uniform((-500, 0, -500), (500, 0, 500)),
rotation=rep.distribution.uniform((-90,-45, 0), (-90, 45, 0)),
)
return worker
# Register randomization
rep.randomizer.register(env_props)
rep.randomizer.register(worker)
# Setup the static elements
env = rep.create.from_usd(ENVS)
surface = rep.create.from_usd(SURFACE)
# Setup camera and attach it to render product
camera = rep.create.camera(
focus_distance=800,
f_stop=0.5
)
render_product = rep.create.render_product(camera, resolution=(1024, 1024))
# Initialize and attach writer
writer = rep.WriterRegistry.get("BasicWriter")
writer.initialize(output_dir="_output", rgb=True, bounding_box_2d_tight=True)
writer.attach([render_product])
with rep.trigger.on_frame(num_frames=10000):
rep.randomizer.env_props(75)
rep.randomizer.worker()
with camera:
rep.modify.pose(position=rep.distribution.uniform((-500, 200, 1000), (500, 500, 1500)), look_at=surface)
Script Editor 창 하단에 있는 Run(Ctrl + Enter) 버튼을 클릭합니다. 이렇게 하면 작업량을 실행하는 데 필요한 모든 노드가 생성됩니다.
이제 Replicator(리플리케이터) → Run(실행)을 클릭하여 Replicator(리플리케이터 실행 및 미리 보기)에 표시된 대로 데이터 생성 프로세스를 시작합니다. 생성된 데이터는 지정된 출력 디렉토리에 저장됩니다.
※ output_dir를 수정하지 않은 경우 Linux에서 데이터는 HOME/_output이 됩니다. Windows(윈도우)에서는 사용 권한으로 인해 실패했을 수 있습니다. _output 폴더를 유효한 폴더로 수정해야 합니다.
'omniverse > replicator' 카테고리의 다른 글
옴니버스 레플리케이터 예제 11탄 (0) | 2022.06.01 |
---|---|
옴니버스 레플리케이터 예제 9탄 (0) | 2022.05.30 |
옴니버스 레플리케이터 예제 8탄 (0) | 2022.05.29 |
옴니버스 레플리케이터 예제 7탄 (0) | 2022.05.28 |
옴니버스 레플리케이터 예제 6탄 (0) | 2022.05.27 |