Beispiel #1
0
def interchange_params_and_make_batch(flm_1, flm_2):
    # import ipdb; ipdb.set_trace()
    flame_batch = torch.zeros((4, flm_2.shape[1]),
                              dtype=torch.float32,
                              device=flm_1.device)

    # shape
    flame_batch[0, :] = flm_1
    flame_batch[0, 0:100] = flm_2[0, 0:100]

    # shape + exp
    flame_batch[1, :] = flm_1
    flame_batch[1, 0:150] = flm_2[0, 0:150]
    # flame_batch[1, 153:156] = flm_2[0, 153:156]

    # shape + exp + jaw + pose
    flame_batch[2, :] = flm_1
    flame_batch[2, 0:159] = flm_2[0, 0:159]

    # shape + exp + jaw + pose + texture
    flame_batch[3, :] = flm_1
    flame_batch[3, 0:159] = flm_2[0, 0:159]
    flame_batch[3, 159:209] = flm_2[0, 159:209]

    # import ipdb; ipdb.set_trace()
    flame_batch = position_to_given_location(flame_decoder, flame_batch)

    return flame_batch
Beispiel #2
0
        f'{cnst.output_root}checkpoint/{run_idx}/{model_idx}.model')
    generator_1.load_state_dict(ckpt1['generator_running'])
    generator_1 = generator_1.eval()

    # images = np.zeros((num_smpl_to_eval_on, 3, resolution, resolution)).astype('float32')
    pbar = tqdm.tqdm(range(0, num_smpl_to_eval_on, batch_size))
    pbar.set_description('Generating_images')
    flame_mesh_imgs = None
    mdl_id = 'mdl2_'
    if settings_for_runs[run_idx]['name'] == 'full_model':
        mdl_id = 'mdl1_'

    for batch_idx in pbar:
        flm_batch = flm_params[batch_idx:batch_idx + batch_size, :]
        flm_batch = torch.from_numpy(flm_batch).cuda()
        flm_batch = position_to_given_location(flame_decoder, flm_batch)
        batch_size_true = flm_batch.shape[0]

        if settings_for_runs[run_idx]['normal_maps_as_cond'] or \
                settings_for_runs[run_idx]['rendered_flame_as_condition']:
            cam = flm_batch[:, constants.DECA_IDX['cam'][0]:constants.
                            DECA_IDX['cam'][1]:]
            shape = flm_batch[:, constants.INDICES['SHAPE'][0]:constants.
                              INDICES['SHAPE'][1]]
            exp = flm_batch[:, constants.INDICES['EXP'][0]:constants.
                            INDICES['EXP'][1]]
            pose = flm_batch[:, constants.INDICES['POSE'][0]:constants.
                             INDICES['POSE'][1]]
            # import ipdb; ipdb.set_trace()
            light_code = \
                flm_batch[:, constants.DECA_IDX['lit'][0]:constants.DECA_IDX['lit'][1]:].view((batch_size_true, 9, 3))
Beispiel #3
0
normalized_eye_cntr_R = []
for indx in range(50):
    # i = int(random.randint(0, 60_000))
    i = indx

    fig, ax1 = plt.subplots(1, 1)
    img, flm_rndr, flm_lbl, index = dataset.__getitem__(i, bypass_valid_indexing=False)
    img = img[None, ...]

    img = fast_image_reshape(img, height_out=show_img_at_res, width_out=show_img_at_res)
    img = img[0]
    ax1.imshow((img.numpy().transpose((1, 2, 0)) + 1)/2)

    flame_batch = torch.from_numpy(flm_lbl[0][None, ...]).cuda()

    flame_batch = position_to_given_location(deca_flame, flame_batch)

    # import ipdb; ipdb.set_trace()
    shape, expression, pose = (flame_batch[:, 0:100, ], flame_batch[:, 100:150], flame_batch[:, 150:156])
    vertices, l_m2d, _ = deca_flame(shape_params=shape, expression_params=expression, pose_params=pose)
    # l_m2d[:, :, 1] *= -1
    # vertices[:, :, 1] *= -1
    eye_left_3d = vertices[:, 4051]
    eye_right_3d = vertices[:, 4597]

    eye_R_2d = (eye_left_3d[:, :2] + flame_batch[:, 157:159]) * flame_batch[:, 156]
    eye_L_2d = (eye_right_3d[:, :2] + flame_batch[:, 157:159]) * flame_batch[:, 156]

    eye_R_2d[:, 1] *= -1
    eye_L_2d[:, 1] *= -1
Beispiel #4
0
                               0.02707223, 0.07585122, 0.05772701,  0.1662246,  0.20778911,  0.24815214,
                               0.22855483, 0.32920238, 0.52000016,]])
    highest_variance_cmp_idx = 2
    highest_variance = 0.9143507
    mean_plu_3_sigma_light = mean_lighting
    mean_plu_3_sigma_light[0, highest_variance_cmp_idx] += 2*highest_variance
    mean_plu_3_sigma_light = torch.from_numpy(mean_plu_3_sigma_light.astype('float32')).cuda()
    # flame_lighting_plus_3_sigma = np.concatenate((np.zeros((1, flm_val.shape[1]-len(mean_lighting))), mean_plu_3_sigma_light),
    #                                              axis=1)
    mean_minus_3_sigma_light = mean_lighting
    mean_minus_3_sigma_light[0, highest_variance_cmp_idx] -= 2*highest_variance
    mean_minus_3_sigma_light = torch.from_numpy(mean_minus_3_sigma_light.astype('float32')).cuda()

    flm_params = torch.cat(flm_params, dim=0)
    flame_decoder = overlay_visualizer.deca.flame.eval()
    flm_params = position_to_given_location(flame_decoder, flm_params)

    cam = flm_params[:, constants.DECA_IDX['cam'][0]:constants.DECA_IDX['cam'][1]:]
    shape = flm_params[:, constants.INDICES['SHAPE'][0]:constants.INDICES['SHAPE'][1]]
    exp = flm_params[:, constants.INDICES['EXP'][0]:constants.INDICES['EXP'][1]]
    pose = flm_params[:, constants.INDICES['POSE'][0]:constants.INDICES['POSE'][1]]
    # import ipdb; ipdb.set_trace()
    light_code = torch.from_numpy(light_code).cuda()[None, ...].repeat(exp.shape[0]-2, 1, 1)
    # import ipdb; ipdb.set_trace()
    light_code = torch.cat((light_code, mean_minus_3_sigma_light.view(1,9, 3), mean_plu_3_sigma_light.view(1,9, 3)), dim=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