print("X_indices shape: " + str(X_indices.shape))
    print("X_params shape: " + str(X_params.shape))
    print("X_pcs shape: " + str(X_pcs.shape))

else:
    # Generate/load and format the data
    X_indices = np.array([i for i in range(data_samples)])
    X_params = np.array([zero_params for i in range(data_samples)],
                        dtype="float32")
    if DATA_LOAD_DIR is not None:
        X_params, X_pcs = load_data(DATA_LOAD_DIR,
                                    num_samples=data_samples,
                                    load_silhouettes=False)
    else:
        if not all(value == 0.0 for value in POSE_OFFSET.values()):
            X_params = offset_params(X_params, PARAMS_TO_OFFSET, POSE_OFFSET)
            X_pcs = np.array([
                smpl.set_params(beta=params[72:82],
                                pose=params[0:72],
                                trans=params[82:85]) for params in X_params
            ])
        else:
            X_pcs = np.array([zero_pc for i in range(data_samples)],
                             dtype="float32")

    if MODE == "EULER":
        # Convert from Rodrigues to Euler angles
        X_params = rodrigues_to_euler(X_params, smpl)

    X_data = [np.array(X_indices), np.array(X_params), np.array(X_pcs)]
    if ARCHITECTURE == "OptLearnerMeshNormalStaticModArchitecture":
예제 #2
0
def gen_data(POSE_OFFSET,
             PARAMS_TO_OFFSET,
             smpl,
             data_samples=10000,
             save_dir=None,
             render_silhouette=True):
    """ Generate random body poses """
    POSE_OFFSET = format_distractor_dict(POSE_OFFSET, PARAMS_TO_OFFSET)

    zero_params = np.zeros(shape=(85, ))
    zero_pc = smpl.set_params(beta=zero_params[72:82],
                              pose=zero_params[0:72].reshape((24, 3)),
                              trans=zero_params[82:85])
    #print("zero_pc: " + str(zero_pc))

    # Generate and format the data
    X_indices = np.array([i for i in range(data_samples)])
    X_params = np.array([zero_params for i in range(data_samples)],
                        dtype="float32")
    if not all(value == 0.0 for value in POSE_OFFSET.values()):
        X_params = offset_params(X_params, PARAMS_TO_OFFSET, POSE_OFFSET)
        X_pcs = np.array([
            smpl.set_params(beta=params[72:82],
                            pose=params[0:72],
                            trans=params[82:85]) for params in X_params
        ])
    else:
        X_pcs = np.array([zero_pc for i in range(data_samples)],
                         dtype="float32")

    if render_silhouette:
        X_silh = []
        print("Generating silhouettes...")
        for pc in tqdm(X_pcs):
            # Render the silhouette from the point cloud
            silh = Mesh(pointcloud=pc).render_silhouette(show=False)
            X_silh.append(silh)

        X_silh = np.array(X_silh)
        print("Finished generating data.")

    if save_dir is not None:
        # Save the generated data in the given location
        print("Saving generated samples...")
        for i in tqdm(range(data_samples)):
            sample_id = "sample_{:05d}".format(i + 1)
            if render_silhouette:
                np.savez(save_dir + sample_id + ".npz",
                         smpl_params=X_params[i],
                         pointcloud=X_pcs[i],
                         silhouette=X_silh[i])
            else:
                np.savez(save_dir + sample_id + ".npz",
                         smpl_params=X_params[i],
                         pointcloud=X_pcs[i],
                         silhouette=X_silh[i])

        print("Finished saving.")

    if render_silhouette:
        return X_params, X_pcs, X_silh
    else:
        return X_params, X_pcs