Exemplo n.º 1
0
texture_code = torch.from_numpy(texture_code).cuda()[None, ...].repeat(exp.shape[0]-4, 1)
texture_code_neg_3_sigma = texture_code[0:1, :] * 0
texture_code_neg_3_sigma[0, 0] -= 3
texture_code_pos_3_sigma = texture_code[0:1, :] * 0
texture_code_pos_3_sigma[0, 0] += 3
texture_code = torch.cat((texture_code, texture_code_neg_3_sigma, texture_code_pos_3_sigma, texture_code[:2, :]), dim=0)

verts, landmarks2d, landmarks3d = overlay_visualizer.deca.flame(shape_params=shape, expression_params=exp,
                                                  pose_params=pose)
landmarks2d_projected = batch_orth_proj(landmarks2d, cam)
landmarks2d_projected[:, :, 1:] *= -1
trans_verts = batch_orth_proj(verts, cam)
trans_verts[:, :, 1:] = -trans_verts[:, :, 1:]

right_albedos = overlay_visualizer.flametex(texture_code)
# albedos = torch.tensor([47, 59, 65], dtype=torch.float32)[None, ..., None, None].cuda()/255.0*1.5
albedos = torch.tensor([0.6, 0.6, 0.6], dtype=torch.float32)[None, ..., None, None].cuda()
albedos = albedos.repeat(texture_code.shape[0], 1, 512, 512)
albedos[-4:] = fast_image_reshape(right_albedos[-4:], height_out=512, width_out=512)

rendering_results = overlay_visualizer.deca.render(verts, trans_verts, albedos, lights=light_code, light_type='point',
                                                   cull_backfaces=True)
textured_images, normals, alpha_img = rendering_results['images'], rendering_results['normals'],\
                                      rendering_results['alpha_images']
normal_images = overlay_visualizer.deca.render.render_normal(trans_verts, normals)


rend_flm = torch.clamp(textured_images, 0, 1) * 2 - 1
norma_map_img = torch.clamp(normal_images, 0, 1) * 2 - 1
Exemplo n.º 2
0
    None, ...].repeat(batch_size_true, axis=0)
texture_code = fl_param_dict[random_keys[7]]['tex'].astype('float32')[
    None, ...].repeat(batch_size_true, axis=0)
# norma_map_img, _, _, _, rend_flm = \
#     overlay_visualizer.get_rendered_mesh(flame_params=(shape, exp, pose, torch.from_numpy(light_code).cuda(),
#                                                        torch.from_numpy(texture_code).cuda()),
#                                          camera_params=cam)

verts, landmarks2d, landmarks3d = overlay_visualizer.deca.flame(
    shape_params=shape, expression_params=exp, pose_params=pose)
landmarks2d_projected = util.batch_orth_proj(landmarks2d, cam)
landmarks2d_projected[:, :, 1:] *= -1
trans_verts = util.batch_orth_proj(verts, cam)
trans_verts[:, :, 1:] = -trans_verts[:, :, 1:]

albedos = overlay_visualizer.flametex(torch.from_numpy(texture_code).cuda())
light_code = torch.from_numpy(light_code).cuda()
rendering_results = overlay_visualizer.deca.render(verts,
                                                   trans_verts,
                                                   albedos,
                                                   lights=light_code,
                                                   light_type='point',
                                                   cull_backfaces=True)
textured_images, normals, alpha_img = rendering_results['images'], rendering_results['normals'],\
                                      rendering_results['alpha_images']
normal_images = overlay_visualizer.deca.render.render_normal(
    trans_verts, normals)

rend_flm = torch.clamp(textured_images, 0, 1) * 2 - 1
# rend_flm += (1 - alpha_img) * 2
norma_map_img = torch.clamp(normal_images, 0, 1) * 2 - 1