RESET_PERIOD = setup_params["BASIC"]["RESET_PERIOD"]
MODEL_SAVE_PERIOD = setup_params["BASIC"]["MODEL_SAVE_PERIOD"]
PREDICTION_PERIOD = setup_params["BASIC"]["PREDICTION_PERIOD"]
OPTIMISATION_PERIOD = setup_params["BASIC"]["OPTIMISATION_PERIOD"]
MODE = setup_params["BASIC"]["ROT_MODE"]
DISTRACTOR = setup_params["BASIC"]["DISTRACTOR"]
data_samples = setup_params["BASIC"]["NUM_SAMPLES"]
DATA_LOAD_DIR = setup_params["DATA"]["TRAIN_DATA_DIR"]
POSE_OFFSET = setup_params["DATA"]["POSE_OFFSET"]
PARAMS_TO_OFFSET = setup_params["DATA"]["PARAMS_TO_OFFSET"]
USE_GENERATOR = setup_params["DATA"]["USE_GENERATOR"]
ARCHITECTURE = setup_params["MODEL"]["ARCHITECTURE"]
BATCH_SIZE = setup_params["MODEL"]["BATCH_SIZE"]

# Format the distractor and offset dictionaries
DISTRACTOR = format_distractor_dict(DISTRACTOR, trainable_params)
if PARAMS_TO_OFFSET == "trainable_params":
    PARAMS_TO_OFFSET = trainable_params
elif PARAMS_TO_OFFSET == "all_pose_and_global_rotation":
    not_trainable = [0, 2]
    #not_trainable = []
    #trainable_params_indices = [index for index in range(85) if index not in not_trainable and index < 72]
    trainable_params_indices = [
        index for index in range(85)
        if index not in not_trainable and index < 66
    ]
    PARAMS_TO_OFFSET = [param_ids[index] for index in trainable_params_indices]
POSE_OFFSET = format_distractor_dict(POSE_OFFSET, PARAMS_TO_OFFSET)

# Generate the data from the SMPL parameters
smpl = SMPLModel(
Exemple #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