VLM-all-inclusive / tests /test_render.py
hkblockchaintechnology's picture
repo assets: tests, scripts, Makefile, packaging, refreshed card
080b493 verified
Raw History Blame Contribute Delete
1.12 kB
"""The GPU rasteriser must agree with the reference numpy renderer, otherwise the
model would be trained on a different world than the one the notebook shows."""
import numpy as np
import pytest
import omni.scenes as scenes
from conftest import CUDA
@CUDA
def test_gpu_rasteriser_matches_numpy_reference(device):
import omni.render as render
spec = scenes.spec_batch(list(range(8)), seed=1, px=64)
gpu = render.render_specs(spec, px=64, device=device, ss=2).permute(0, 2, 3, 1).cpu().numpy()
for i in range(8):
ref = scenes.render_scene(spec["scenes"][i], px=64, ss=2).astype(np.float32) / 255.0
assert np.abs(ref - gpu[i]).mean() < 0.02, f"scene {i} diverges from the reference"
@CUDA
def test_render_is_differentiable_and_finite(device):
import torch
import omni.render as render
spec = scenes.spec_batch(list(range(4)), seed=2, px=32)
for k in ("cx", "cy", "r"):
spec[k] = spec[k].astype(np.float32)
imgs = render.render_specs(spec, px=32, device=device, ss=1)
assert torch.isfinite(imgs).all()
assert imgs.min() >= 0 and imgs.max() <= 1