Exemplo n.º 1
0
def eval_baseline_h36m():
    weights_path = sys.args[1]
    eval_model = MultiBranchModel(
        dim=3, n_joints=17, nb_pose_blocks=1)  # TODO retrieve from config
    eval_model.load_weights(weights_path, pose_only=True)

    # local loading
    local_h36m_path = '/home/caleml/datasets/h36m'
    local_h36m = Human36M(local_h36m_path,
                          dataconf=config.human36m_dataconf,
                          poselayout=pose_format.pa17j3d,
                          topology='frames')

    h36m_val = BatchLoader(local_h36m, ['frame'],
                           ['pose_w', 'pose_uvd', 'afmat', 'camera'],
                           VALID_MODE,
                           batch_size=local_h36m.get_length(VALID_MODE),
                           shuffle=True)

    log.printcn(log.OKBLUE, 'Preloading Human3.6M validation samples...')

    [x_val], [pw_val, puvd_val, afmat_val, scam_val] = h36m_val[0]

    scores = eval_human36m_sc_error(eval_model.model,
                                    x_val,
                                    pw_val,
                                    afmat_val,
                                    puvd_val[:, 0, 2],
                                    scam_val,
                                    batch_size=24)

    pprint(scores)
Exemplo n.º 2
0
def eval_h36m(exp_folder, pose_only):
    # local loading
    local_h36m_path = '/home/caleml/datasets/h36m'
    local_h36m = Human36M(local_h36m_path,
                          dataconf=config.human36m_dataconf,
                          poselayout=pose_format.pa17j3d,
                          topology='frames')

    h36m_val = BatchLoader(local_h36m, ['frame'],
                           ['pose_w', 'pose_uvd', 'afmat', 'camera'],
                           VALID_MODE,
                           batch_size=local_h36m.get_length(VALID_MODE),
                           shuffle=True)

    log.printcn(log.OKBLUE, 'Preloading Human3.6M validation samples...')

    [x_val], [pw_val, puvd_val, afmat_val, scam_val] = h36m_val[0]

    dataset = {
        'x_val': x_val,
        'pw_val': pw_val,
        'puvd_val': puvd_val,
        'afmat_val': afmat_val,
        'scam_val': scam_val
    }

    all_scores_baseline = eval_folder(exp_folder, dataset, pose_only=pose_only)
    print(all_scores_baseline)
Exemplo n.º 3
0
def launch_training(dataset_path, model_folder, n_epochs, batch_size,
                    pose_blocks):

    # loading dataset
    h36m_path = dataset_path
    h36m = Human36M(h36m_path,
                    dataconf=config.human36m_dataconf,
                    poselayout=pose_format.pa17j3d,
                    topology='frames')

    data_tr_h36m = BatchLoader(h36m, ['frame'], ['pose'] * pose_blocks,
                               TRAIN_MODE,
                               batch_size=batch_size,
                               shuffle=True)

    # validation
    h36m_val = BatchLoader(h36m, ['frame'],
                           ['pose_w', 'pose_uvd', 'afmat', 'camera'],
                           VALID_MODE,
                           batch_size=h36m.get_length(VALID_MODE),
                           shuffle=True)

    log.printcn(log.OKBLUE, 'Preloading Human3.6M validation samples...')
    [x_val], [pw_val, puvd_val, afmat_val, scam_val] = h36m_val[0]
    eval_callback = callbacks.H36MEvalCallback(pose_blocks,
                                               x_val,
                                               pw_val,
                                               afmat_val,
                                               puvd_val[:, 0, 2],
                                               scam_val,
                                               pose_only=True,
                                               logdir=model_folder)

    # model
    model = MultiBranchModel(dim=3, n_joints=17, nb_pose_blocks=pose_blocks)
    model.build_pose_only()
    model.add_callback(eval_callback)

    model.train(data_tr_h36m,
                steps_per_epoch=len(data_tr_h36m),
                model_folder=model_folder,
                n_epochs=n_epochs)
Exemplo n.º 4
0
def launch_training(dataset_path, model_folder, n_epochs, batch_size):

    mpii_path = dataset_path
    mpii = MpiiSinglePerson(mpii_path, dataconf=config.mpii_dataconf)

    data_tr_mpii = BatchLoader(mpii,
                               ['frame'],
                               ['frame', 'pose', 'pose', 'pose', 'pose'],
                               TRAIN_MODE,
                               batch_size=16,
                               shuffle=False)

    model = MultiBranchModel(nb_pose_blocks=4)
    model.build()

    model.train(data_tr_mpii, steps_per_epoch=len(data_tr_mpii), model_folder=model_folder, n_epochs=n_epochs)
Exemplo n.º 5
0
def launch_training(dataset_path, model_folder, n_epochs, batch_size, pose_blocks):

    h36m_path = dataset_path
    h36m = Human36M(h36m_path, dataconf=config.human36m_dataconf, poselayout=pose_format.pa17j3d, topology='frames')

    data_tr_h36m = BatchLoader(
        h36m, 
        ['frame'], 
        ['frame'] + ['pose'] * pose_blocks + ['action'] * 3,
        TRAIN_MODE, 
        batch_size=batch_size,
        shuffle=True)

    model = CycleModel(dim=3, n_joints=17, nb_pose_blocks=pose_blocks)
    model.build()

    model.train(data_tr_h36m, steps_per_epoch=len(data_tr_h36m), model_folder=model_folder, n_epochs=n_epochs)
Exemplo n.º 6
0
def launch_training(dataset_path, model_folder, n_epochs):

    mpii_path = dataset_path
    mpii = MpiiSinglePerson(mpii_path,
                            dataconf=config.mpii_dataconf,
                            poselayout=pose_format.pa17j3d)

    data_tr_mpii = BatchLoader(mpii, ['frame'], ['frame'],
                               TRAIN_MODE,
                               shuffle=False)

    model = AppearanceModel()
    model.build()

    model.train(data_tr_mpii,
                steps_per_epoch=len(data_tr_mpii),
                model_folder=model_folder,
                n_epochs=n_epochs)
Exemplo n.º 7
0
    def launch(self):
        '''
        main entrypoint
        1. training data
        2. validation data
        3. callbacks
        4. model building
        5. launch actual training
        '''

        h36m = Human36M(self.dataset_path,
                        dataconf=config.human36m_dataconf,
                        poselayout=pose_format.pa17j3d,
                        topology='frames')

        # training data
        dataset_output = self.get_h36m_outputs()
        data_tr_h36m = BatchLoader(h36m, ['frame'],
                                   dataset_output,
                                   TRAIN_MODE,
                                   batch_size=self.batch_size,
                                   shuffle=True)

        # validation data
        h36m_val = BatchLoader(h36m, ['frame'],
                               ['pose_w', 'pose_uvd', 'afmat', 'camera'],
                               VALID_MODE,
                               batch_size=h36m.get_length(VALID_MODE),
                               shuffle=True)

        log.printcn(log.OKBLUE, 'Preloading Human3.6M validation samples...')
        [x_val], [pw_val, puvd_val, afmat_val, scam_val] = h36m_val[0]
        # assert rootz == puvd_val[:,0,2]

        # callbacks
        cb_list = list()
        eval_callback = callbacks.H36MEvalCallback(self.pose_blocks,
                                                   x_val,
                                                   pw_val,
                                                   afmat_val,
                                                   puvd_val[:, 0, 2],
                                                   scam_val,
                                                   pose_only=self.pose_only,
                                                   logdir=self.model_folder)

        logs_folder = os.environ[
            'HOME'] + '/pe_experiments/tensorboard/' + self.model_folder.split(
                '/')[-1]
        print('Tensorboard log folder %s' % logs_folder)
        tensorboard = TensorBoard(
            log_dir=os.path.join(logs_folder, 'tensorboard'))

        cb_list.append(tensorboard)
        cb_list.append(eval_callback)
        cb_list.append(LearningRateScheduler(lr_scheduler))
        cb_list.append(callbacks.SaveModel(self.model_folder))

        # model
        self.build_model()

        # train
        self.model.train(data_tr_h36m,
                         steps_per_epoch=len(data_tr_h36m),
                         model_folder=self.model_folder,
                         n_epochs=self.n_epochs,
                         cb_list=cb_list,
                         n_workers=self.nb_workers)