예제 #1
0
파일: auto_grad.py 프로젝트: PeterZs/dtrt
 def forward(ctx,
             scene_manager,
             integrator,
             options,
             input,
             out_of_range=torch.tensor([0] * nder, dtype=torch.float),
             penalty_scale=torch.tensor([1] * nder, dtype=torch.float),
             pyramid_level=1,
             pyramid_scale=4.0,
             index_iter=-1,
             clamping=0):
     img = pydtrt.render_scene(integrator, options, *(scene_manager.args))
     if index_iter > -1:
         torch.save(img, 'pt_iter%d.pt' % index_iter)
     ret = img[0, :, :, :]
     ctx.save_for_backward(img[1:, :, :, :],
                           torch.tensor([pyramid_level], dtype=torch.int),
                           torch.tensor([pyramid_scale], dtype=torch.float),
                           out_of_range, penalty_scale,
                           torch.tensor([clamping], dtype=torch.int))
     return ret
예제 #2
0
                        requires_grad=True)

direc = 'results/'
T1 = SceneTransform("CAMERA_TRANSLATE",
                    torch.tensor([0.5, 0.0, 0.0], dtype=torch.float))
T2 = SceneTransform("CAMERA_TRANSLATE",
                    torch.tensor([0.0, 0.0, 0.1], dtype=torch.float))
T3 = SceneTransform("CAMERA_ROTATE",
                    torch.tensor([0.1, 0.0, 0.0], dtype=torch.float))

transform_list = []
transform_list.append([T1])
transform_list.append([T2])
transform_list.append([T3])
scene_manager = SceneManager(args_init, transform_list)
init = pydtrt.render_scene(integrator, options, *(scene_manager.args))
pydtrt.imwrite(init[0, :, :, :], direc + 'init.exr')

integrator = dtrt.VolPathTracer()
# target_var = torch.tensor([0.7])
target_var = torch.tensor([-1.6, 1.2, -1.5])

print("Target variable values: ", target_var)
scene_manager.set_arguments(target_var)
target = pydtrt.render_scene(integrator, options, *(scene_manager.args))
target = target[0, :, :, :]
pydtrt.imwrite(target, direc + 'target.exr')

integrator = dtrt.VolPathTracerAD()
scene_manager.reset()
lossFunc = pydtrt.ADLossFunc.apply