def setup_test_data(trainable_params, DISTRACTOR, PARAMS_TO_OFFSET, POSE_OFFSET, ARCHITECTURE, JOINT_LEVELS, data_samples, num_test_samples=5, num_cb_samples=5, MODE="RODRIGUES", LOAD_DATA_DIR=None): # Gather trainable params param_ids = ["param_{:02d}".format(i) for i in range(85)] trainable_params = format_offsetable_params(trainable_params) param_trainable = { param: (param in trainable_params) for param in param_ids } DISTRACTOR = format_distractor_dict(DISTRACTOR, trainable_params) # Gather offsetable params if PARAMS_TO_OFFSET == "trainable_params": PARAMS_TO_OFFSET = trainable_params PARAMS_TO_OFFSET = format_offsetable_params(PARAMS_TO_OFFSET) POSE_OFFSET = format_distractor_dict(POSE_OFFSET, PARAMS_TO_OFFSET) # Define the kinematic tree kin_tree = format_joint_levels(JOINT_LEVELS) # Generate the data from the SMPL parameters print("loading SMPL...") smpl = SMPLModel('/data/cvfs/hjhb2/projects/deep_optimiser/code/keras_rotationnet_v2_demo_for_hidde/basicModel_f_lbs_10_207_0_v1.0.0.pkl') # Generate and format the data print("Gather input data...") X_test, Y_test = gather_input_data(data_samples, smpl, PARAMS_TO_OFFSET, POSE_OFFSET, ARCHITECTURE, param_trainable, num_test_samples=num_test_samples, MODE=MODE, LOAD_DATA_DIR=LOAD_DATA_DIR) # Render silhouettes for the callback data X_cb, Y_cb, silh_cb = gather_cb_data(X_test, Y_test, data_samples, num_cb_samples, where="front") return X_test, Y_test, X_cb, Y_cb, silh_cb, smpl, kin_tree, trainable_params, param_trainable, DISTRACTOR
else: dirs = ["../"] dir_paths = dirs dirs = [dir_name + "logs/delta_d_magnitude.txt" for dir_name in dirs] dirs_trainable_params = [] for dir_name in dir_paths: with open(dir_name + "code/config.yaml", 'r') as f: try: setup_params = yaml.safe_load(f) #print(setup_params) except yaml.YAMLError as exc: print(exc) trainable_params_ = setup_params["PARAMS"]["TRAINABLE"] trainable_params_ = format_offsetable_params(trainable_params_) dirs_trainable_params.append(trainable_params_) trainable_params = dirs_trainable_params[0] #kinematic_levels = None kinematic_levels = [[0], [3], [1, 2, 6], [4, 5, 9], [7, 8, 12, 13, 14], [15, 16, 17], [18, 19], [20, 21], [22, 23]] SUBSAMPLE_PERIOD = 20 #SUBSAMPLE_PERIOD = 10 #SUBSAMPLE_PERIOD = 2 def add_losses(dir_losses, epoch_array, curr_epoch): epoch_str = "".join(epoch_array)
def setup_train_data(trainable_params, DISTRACTOR, PARAMS_TO_OFFSET, POSE_OFFSET, ARCHITECTURE, data_samples, BATCH_SIZE, train_vis_dir, num_cb_samples=5, MODE="RODRIGUES", LOAD_DATA_DIR=None, use_generator=False, RESET_PERIOD=None, groups=None, TRAIN_PERIOD=5): # Gather trainable params param_ids = ["param_{:02d}".format(i) for i in range(85)] trainable_params = format_offsetable_params(trainable_params) param_trainable = { param: (param in trainable_params) for param in param_ids } DISTRACTOR = format_distractor_dict(DISTRACTOR, trainable_params) # Gather offsetable params if PARAMS_TO_OFFSET == "trainable_params": PARAMS_TO_OFFSET = trainable_params PARAMS_TO_OFFSET = format_offsetable_params(PARAMS_TO_OFFSET) POSE_OFFSET = format_distractor_dict(POSE_OFFSET, PARAMS_TO_OFFSET) # Define the kinematic tree kin_tree = format_joint_levels(groups) #print(kin_tree) efficient_kin_tree = [[ param for param in level if param in trainable_params ] for level in kin_tree] efficient_kin_tree = [entry for entry in efficient_kin_tree if entry] # filter empty entries #print(efficient_kin_tree) # Generate the data from the SMPL parameters print("loading SMPL...") smpl = SMPLModel( '/data/cvfs/hjhb2/projects/deep_optimiser/code/keras_rotationnet_v2_demo_for_hidde/basicModel_f_lbs_10_207_0_v1.0.0.pkl' ) # Generate and format the data print("Gather input data...") if use_generator: trainable_params_mask = [ int(param_trainable[key]) for key in sorted(param_trainable.keys(), key=lambda x: int(x[6:8])) ] update_generator = OptLearnerUpdateGenerator( data_samples, RESET_PERIOD, POSE_OFFSET, PARAMS_TO_OFFSET, ARCHITECTURE, batch_size=BATCH_SIZE, smpl=smpl, shuffle=True, save_path=train_vis_dir, trainable_params_mask=trainable_params_mask, kin_tree=efficient_kin_tree, train_period=TRAIN_PERIOD) X_train, Y_train = update_generator.yield_data() print("Y_train shapes: " + str([datum.shape for datum in Y_train])) else: update_generator = None X_train, Y_train = gather_input_data(data_samples, smpl, PARAMS_TO_OFFSET, POSE_OFFSET, ARCHITECTURE, param_trainable, num_test_samples=-1, MODE=MODE, LOAD_DATA_DIR=LOAD_DATA_DIR, use_generator=use_generator, kin_tree=efficient_kin_tree) # Render silhouettes for the callback data X_cb, Y_cb, silh_cb = gather_cb_data(X_train, Y_train, data_samples, num_cb_samples, where="spread") return X_train, Y_train, X_cb, Y_cb, silh_cb, smpl, trainable_params, param_trainable, DISTRACTOR, POSE_OFFSET, update_generator
control_logs_dirs = [] test_vis_dirs = [] control_dirs = [] for lr in LEARNING_RATES: sub_dir = "lr_{:02f}/".format(lr) logs_dir, control_logs_dir, test_vis_dir, control_dir = create_subdir( exp_dir, model_name, sub_dir, save_suffix) logs_dirs.append(logs_dir) control_logs_dirs.append(control_logs_dir) test_vis_dirs.append(test_vis_dir) control_dirs.append(control_dir) # Generate the data from the SMPL parameters # Gather trainable params param_ids = ["param_{:02d}".format(i) for i in range(85)] trainable_params = format_offsetable_params(trainable_params) param_trainable = {param: (param in trainable_params) for param in param_ids} DISTRACTOR = format_distractor_dict(DISTRACTOR, trainable_params) # Gather offsetable params if PARAMS_TO_OFFSET == "trainable_params": PARAMS_TO_OFFSET = trainable_params PARAMS_TO_OFFSET = format_offsetable_params(PARAMS_TO_OFFSET) POSE_OFFSET = format_distractor_dict(POSE_OFFSET, PARAMS_TO_OFFSET) # Define the kinematic tree kin_tree = format_joint_levels(JOINT_LEVELS) # Generate the data from the SMPL parameters print("loading SMPL...") smpl = SMPLModel(