Ejemplo n.º 1
0
def run_mitsuba(min_elev, max_elev, min_azim, max_azim, radius):
  for k in kinds:
    for i, elev in enumerate(np.linspace(min_elev, max_elev, PER)):
      for j, azim in enumerate(np.linspace(min_azim, max_azim, PER)):
        ox, oy, oz = elaz_to_xyz(elev, azim, radius)
        lx, ly, lz = elaz_to_xyz(elev, azim, 1.05 * radius)
        scene = get_scene(ox, oy, oz, lx, ly, lz, k)
        out = render_torch(scene, spp=32)
        for _ in range(N-1):
          out += render_torch(scene, spp=32)
        out /= N
        out = torch.cat([
          out[..., :3],
          out[..., 3].unsqueeze(-1) > 0,
        ], dim=-1)
        save_image(f"{k}_{i:03}_{j:03}.png", out)
Ejemplo n.º 2
0
Thread.thread().file_resolver().append('cbox')
scene = load_file('cbox/cbox.xml')

# Find differentiable scene parameters
params = traverse(scene)

# Discard all parameters except for one we want to differentiate
params.keep(['red.reflectance.value'])

# Print the current value and keep a backup copy
param_ref = params['red.reflectance.value'].torch()
print(param_ref)

# Render a reference image (no derivatives used yet)
image_ref = render_torch(scene, spp=8)
crop_size = scene.sensors()[0].film().crop_size()
write_bitmap('out_ref.png', image_ref, crop_size)

# Change the left wall into a bright white surface
params['red.reflectance.value'] = [.9, .9, .9]
params.update()

# Which parameters should be exposed to the PyTorch optimizer?
params_torch = params.torch()

# Construct a PyTorch Adam optimizer that will adjust 'params_torch'
opt = torch.optim.Adam(params_torch.values(), lr=.2)
objective = torch.nn.MSELoss()

time_a = time.time()
    sensors = " ".join([sensor.format(cam_origin=o) for o in cams_origins])
    scene = scene.format(sensors=sensors,
                         shape=sdf if sdf_file else mesh,
                         integrator=integrator)

    return load_string(scene,
                       sdf_file=sdf_file,
                       interpol=interpolation,
                       fov=fov,
                       res=cam_res)


scene_target = create_scene(None, interpolation, cams_origins, fov, img_res)

images_ref = list(
    render_torch(scene_target, spp=spp_ref, sensor_index=i)
    for i in range(len(cams_origins)))
crop_size = scene_target.sensors()[0].film().crop_size()
for i in range(len(cams_origins)):
    write_bitmap(f'{out_path}{i}_target.png', images_ref[i], crop_size)

# Find differentiable scene parameters
sdf_file = "data/sdf/init.vol" if restart_epoch == 0 else f"{out_path}sdf_e{restart_epoch}.vol"
scene_init = create_scene(sdf_file, interpolation, cams_origins, fov, img_res)
params = traverse(scene_init)
#print(params)
params.keep(['SDF.data', 'SDF.bsdf.reflectance.data'])

if restart_epoch > 0 and increase_res:
    sdf = params['SDF.data'].numpy().reshape([sdf_res] * 3)
    sdf = double_sdf_res(sdf)
Ejemplo n.º 4
0
    scene = scene.format(sensors=sensors,
                         shape=sdf if sdf_file else mesh,
                         integrator=integrator)

    return load_string(scene,
                       sdf_file=sdf_file,
                       interpol=interpolation,
                       n_cams=n_cams,
                       fov=fov,
                       res=cam_res)


scene_target = create_scene(None, interpolation, n_cams, fov, img_res)

images_ref = list(
    render_torch(scene_target, spp=64, sensor_index=i) for i in range(n_cams))
crop_size = scene_target.sensors()[0].film().crop_size()
for i in range(n_cams):
    write_bitmap(f'{out_path}{i}_target.png', images_ref[i], crop_size)

# Find differentiable scene parameters
sdf_file = "data/sdf/init.vol" if restart_epoch == 0 else f"{out_path}sdf_e{restart_epoch}.vol"
scene_init = create_scene(sdf_file, interpolation, n_cams, fov, img_res)
params = traverse(scene_init)

if restart_epoch > 0 and increase_res:
    params = traverse(scene_init)
    sdf = params['SDF.data'].numpy().reshape([sdf_res] * 3)
    sdf = double_sdf_res(sdf)
    sdf_res = sdf.shape[0]
    sdf_file = f'{out_path}sdf_e{restart_epoch}_x2.vol'