コード例 #1
0
        mdl_1_gen_images = generic_utils.get_images_from_flame_params(
            flame_params=gen_1_in.cpu().numpy(),
            pose=None,
            model=generator_1,
            step=step_max,
            alpha=alpha,
            input_indices=identity_embeddings.cpu().numpy())
        # import ipdb; ipdb.set_trace()
        images = torch.clamp(mdl_1_gen_images, -1, 1).cpu().numpy()
        flame_mesh_imgs = torch.clamp(rend_flm, -1, 1).cpu().numpy()

        save_path_current_id = os.path.join(root_out_dir,
                                            'inter_model_comparison',
                                            settings_for_runs[run_idx]['name'])
        save_set_of_images(path=save_path_current_id,
                           prefix=f'{mdl_id}_{batch_idx}',
                           images=(images + 1) / 2,
                           show_prog_bar=True)

        #save flam rndr
        save_path_current_id_flm_rndr = os.path.join(
            root_out_dir, 'inter_model_comparison',
            settings_for_runs[run_idx]['name'])
        save_set_of_images(path=save_path_current_id_flm_rndr,
                           prefix=f'mesh_{batch_idx}',
                           images=(flame_mesh_imgs + 1) / 2,
                           show_prog_bar=True)

# save_set_of_images(path=save_path_this_expt, prefix='mesh_', images=((norma_map_img + 1) / 2).cpu().numpy())
# save_set_of_images(path=save_path_this_expt, prefix='mdl1_', images=((mdl_1_gen_images + 1) / 2).cpu().numpy())
# save_set_of_images(path=save_path_this_expt, prefix='mdl2_', images=((mdl_2_gen_images + 1) / 2).cpu().numpy())
コード例 #2
0
                mdl_1_gen_images, -1, 1).cpu().numpy()
            # if flame_mesh_imgs is None:
            flame_mesh_imgs[batch_idx:batch_idx +
                            batch_size_true] = torch.clamp(
                                rend_flm_to_save, -1, 1).cpu().numpy()

        if save_images:
            mdl_name = settings_for_runs[run_idx]['name']
            for key in params_to_save.keys():
                params_to_save[key] = np.concatenate(params_to_save[key],
                                                     axis=0)

            save_dir = os.path.join(cnst.output_root, 'sample', str(run_idx),
                                    f'random_samples_q_eval_{mdl_name}')
            os.makedirs(save_dir, exist_ok=True)
            np.save(os.path.join(save_dir, 'params.npy'), params_to_save)

            save_path_current_id = os.path.join(save_dir, 'images')
            save_set_of_images(path=save_path_current_id,
                               prefix='',
                               images=(images + 1) / 2,
                               show_prog_bar=True)

            #save flam rndr
            save_path_current_id_flm_rndr = os.path.join(
                save_dir, 'conditions')
            save_set_of_images(path=save_path_current_id_flm_rndr,
                               prefix='mesh',
                               images=(flame_mesh_imgs + 1) / 2,
                               show_prog_bar=True)
コード例 #3
0
            pose=None,
            model=generator_1,
            step=step_max,
            alpha=alpha,
            input_indices=identity_embeddings)
        # import ipdb; ipdb.set_trace()
        images = torch.clamp(mdl_1_gen_images, -1, 1).cpu().numpy()
        flame_normal_map_imgs = torch.clamp(norma_map_img, -1, 1).cpu().numpy()
        flame_rend_imgs = torch.clamp(rend_flm, -1, 1).cpu().numpy()

        if save_images:
            save_path_current_id = os.path.join(
                root_out_dir, str(run_idx),
                f'param_swap/gen_images{batch_idx}')
            save_set_of_images(path=save_path_current_id,
                               prefix='',
                               images=(images + 1) / 2,
                               show_prog_bar=False)

            #save normal map
            save_path_current_id_flm_rndr = os.path.join(
                root_out_dir, str(run_idx),
                f'param_swap/gen_images{batch_idx}')
            save_set_of_images(path=save_path_current_id_flm_rndr,
                               prefix='norm_',
                               images=(flame_normal_map_imgs + 1) / 2,
                               show_prog_bar=False)

            # save flam rndr
            save_path_current_id_flm_rndr = os.path.join(
                root_out_dir, str(run_idx),
                f'param_swap/gen_images{batch_idx}')
コード例 #4
0
    # norma_map_img = torch.from_numpy(flm_rndrds_trn['condition_parmas'][:4, 3:, :, :]).cuda()

    if normal_maps_as_cond and rendered_flame_as_condition:
        # norma_map_img = norma_map_img * 2 - 1
        gen_in = torch.cat((rend_flm, norma_map_img), dim=1)
    elif normal_maps_as_cond:
        gen_in = norma_map_img
    elif rendered_flame_as_condition:
        gen_in = rend_flm

    save_dir_teaser = os.path.join(save_dir_tsr, f'chosen_ids_rand_images/')
    os.makedirs(save_dir_teaser, exist_ok=True)

    # Make rendered flame with white background
    save_set_of_images(path=save_dir_teaser, prefix='mesh_normals_',
                       images=((norma_map_img + 1) / 2).cpu().numpy(),
                       name_list=file_names)

    save_set_of_images(path=save_dir_teaser, prefix='mesh_textured_',
                       images=((rend_flm + 1) / 2).cpu().numpy(),
                       name_list=file_names)
    discard_list = []

    texture_data = np.load(cnst.flame_texture_space_dat_file, allow_pickle=True, encoding='latin1').item()
    flm_tex_dec = FlameTextureSpace(texture_data=texture_data, data_un_normalizer=None).cuda()

    generated_images_uncorrupt = generate_from_flame_sequence(generator, gen_in, pose=None, step=step_max,
                                                              alpha=alpha, noise=None,
                                                              input_indices=fixed_identity_embeddings*int(id))[-1]
    # Steal Textures
    textures, texture_mask = flm_tex_dec(fast_image_reshape(generated_images_uncorrupt.cuda(), height_out=256,
コード例 #5
0
    if not interpolation_type.find(
            'light') >= 0 and not interpolation_type.find('albedo') >= 0:
        norma_map_img_to_save, _, _, _, rend_flm_to_save = \
            overlay_visualizer.get_rendered_mesh(flame_params=(shape, exp, pose, light_code_batch, texture_code_batch),
                                                 camera_params=cam, cull_backfaces=True, grey_texture=True)
        rend_flm_to_save = torch.clamp(rend_flm_to_save, 0, 1) * 2 - 1
        norma_map_img_to_save = torch.clamp(norma_map_img_to_save, 0,
                                            1) * 2 - 1
    else:
        norma_map_img_to_save = norma_map_img
        rend_flm_to_save = rend_flm

    # Make rendered flame with white background
    save_set_of_images(path=os.path.join(save_dir_teaser, 'meshes'),
                       prefix='mesh_normals_',
                       images=((norma_map_img_to_save + 1) / 2).cpu().numpy())

    save_set_of_images(path=os.path.join(save_dir_teaser, 'meshes'),
                       prefix='mesh_textured_',
                       images=((rend_flm_to_save + 1) / 2).cpu().numpy())
    count = 0
    # discard_list = [23, 27, 28, 30, 34, 41, 43, 50, 53, 71, 73, 77, 78, 79, 10, 15, 52, 54, 55, 63, 66, 79, 80, 95, 103,
    #                 106, 107, 112, 119, 121, 123, 125, 137, 141, 143, 144, 155, 161, 165, 190, 194, 174, 176, 180, 182]
    discard_list = []

    texture_data = np.load(cnst.flame_texture_space_dat_file,
                           allow_pickle=True,
                           encoding='latin1').item()
    # flm_tex_dec = FlameTextureSpace(texture_data=texture_data, data_un_normalizer=None).cuda()
コード例 #6
0
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

id_start = 20
save_dir_teaser = os.path.join(save_dir_tsr, f'images_gt_FLAME/')
os.makedirs(save_dir_teaser, exist_ok=True)


rend_flm_copy = rend_flm.clone()
rend_flm_copy += (1 - alpha_img) * 2
save_set_of_images(path=save_dir_teaser, prefix='mesh_textured_',
                   images=((rend_flm_copy + 1) / 2).cpu().numpy(),
                   name_list=file_names)
コード例 #7
0
ファイル: generate_images.py プロジェクト: yueyedeai/GIF
            else:
                rend_flm = None
                norma_map_img = None

            gen_1_in = ge_gen_in(
                flm_batch, rend_flm, norma_map_img,
                settings_for_runs[run_idx]['normal_maps_as_cond'],
                settings_for_runs[run_idx]['rendered_flame_as_condition'])

            mdl_1_gen_images = generic_utils.get_images_from_flame_params(
                flame_params=gen_1_in.cpu().numpy(),
                pose=None,
                model=generator_1,
                step=step_max,
                alpha=alpha,
                input_indices=identity_embeddings)
            # import ipdb; ipdb.set_trace()
            images[:, :, :, :resolution] = torch.clamp(mdl_1_gen_images, -1,
                                                       1).cpu().numpy()
            # images[:, :, :, resolution+5:] = torch.clamp(norma_map_img, -1, 1).cpu().numpy()
            images[:, :, :, resolution + 5:] = torch.clamp(rend_flm, -1,
                                                           1).cpu().numpy()

            save_path_current_id = os.path.join(
                f'{cnst.output_root}sample/', str(run_idx),
                'flame_param_association_eval/textured_rendering')
            save_set_of_images(path=save_path_current_id,
                               prefix=f'{id_idx}_{batch_idx}',
                               images=(images + 1) / 2,
                               show_prog_bar=False)
コード例 #8
0
                                                   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
# norma_map_img += (1 - alpha_img) * 2

for id in tqdm.tqdm(range(50)):
    save_set_of_images(path=os.path.join(cnst.output_root,
                                         f'sample/{run_idx}/voca/' + str(id)),
                       prefix='mesh_normal_',
                       images=((norma_map_img + 1) / 2).cpu().numpy())

    save_set_of_images(path=os.path.join(cnst.output_root,
                                         f'sample/{run_idx}/voca/' + str(id)),
                       prefix='mesh_textured_',
                       images=((rend_flm + 1) / 2).cpu().numpy())

    # save_set_of_images(path=os.path.join(cnst.output_root, f'sample/{run_idx}/voca/'+str(id)), prefix='',
    #                    images=((fake_images + 1) / 2))
print(
    f'Voca Animation saved to {os.path.join(cnst.output_root, f"sample/{run_idx}/voca/")}'
)