Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--pred-path', type=str, default=None)
    parser.add_argument('--seeds', type=int, default=1)
    options.initialize(parser)
    FLAGS.pred_path = util.ensure_absolute_path(
        FLAGS.pred_path, f'{paths.DATA_ROOT}/experiments')

    all_true2d, all_true3d, all_true3d_univ = get_all_gt_poses()
    output = evaluate(FLAGS.pred_path, all_true2d, all_true3d, all_true3d_univ)

    print(
        'Root-relative PCK for detected poses (normalized skeletons, bone rescaling) (Table 11)'
    )
    print(to_latex(output['univ', 'rootrel', 'rescale']['pck_matched']))
    print()
    print(
        'Absolute PCK for detected poses (normalized skeletons, bone rescaling) (Table 11)'
    )
    print(to_latex(output['univ', 'nonrootrel', 'rescale']['pck_matched']))
    print(to_latex(output['univ', 'nonrootrel', 'rescale']['auc_matched']))
    print()
    print(
        'Detected poses (unnormalized skeletons, no bone rescaling) (Table 8)')
    numbers = [
        output['nonuniv', 'nonrootrel',
               'norescale']['mpjpe14'][-1], output['nonuniv', 'rootrel',
                                                   'norescale']['mpjpe14'][-1],
        output['nonuniv', 'nonrootrel', 'norescale']['pck_matched'][-1],
        output['nonuniv', 'rootrel',
               'norescale']['pck_matched'][-1], output['recall'] * 100
    ]
    print(to_latex(numbers))
Exemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--pred-path', type=str, default=None)
    parser.add_argument('--universal-skeleton', action=options.BoolAction)
    parser.add_argument('--seeds', type=int, default=1)
    parser.add_argument('--corrected-TS6',
                        action=options.BoolAction,
                        default=True)
    parser.add_argument('--root-last',
                        action=options.BoolAction,
                        default=False)
    options.initialize(parser)
    FLAGS.pred_path = util.ensure_absolute_path(
        FLAGS.pred_path, f'{paths.DATA_ROOT}/experiments')

    all_image_relpaths, all_true3d, activities = get_all_gt_poses()

    def get_scene_name(image_path):
        i_subject = int(re.search(r'/TS(\d+?)/', image_path)[1])
        return ['green-screen', 'no-green-screen',
                'outdoor'][(i_subject - 1) // 2]

    scene_names = np.array(
        [get_scene_name(path) for path in all_image_relpaths])
    if FLAGS.seeds > 1:
        mean_per_seed, std_per_seed = evaluate_multiple_seeds(
            all_true3d, activities, scene_names)
        print(to_latex(mean_per_seed))
        print(to_latex(std_per_seed))
    else:
        metrics = evaluate(FLAGS.pred_path, all_true3d, activities,
                           scene_names)
        print(to_latex(metrics))
Exemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--pred-path', type=str, default=None)
    parser.add_argument('--procrustes', action=options.YesNoAction)
    parser.add_argument('--acausal-smoothing', action=options.YesNoAction)
    parser.add_argument('--causal-smoothing', action=options.YesNoAction)
    options.initialize(parser)
    FLAGS.pred_path = util.ensure_absolute_path(
        FLAGS.pred_path, f'{paths.DATA_ROOT}/experiments')

    poses3d_true_dict = get_all_gt_poses()
    poses3d_pred_dict = get_all_pred_poses()

    all_pred3d = np.array(
        [poses3d_pred_dict[relpath] for relpath in poses3d_true_dict])
    all_true3d = np.array(list(poses3d_true_dict.values()))
    all_pred3d -= all_pred3d[:, :1]
    all_true3d -= all_true3d[:, :1]
    all_pred3d_aligned = util3d.rigid_align_many(all_pred3d,
                                                 all_true3d,
                                                 scale_align='rigid+scale')

    dist = np.linalg.norm(all_true3d - all_pred3d, axis=-1)
    dist_aligned = np.linalg.norm(all_true3d - all_pred3d_aligned, axis=-1)

    mpjpe = np.mean(dist)
    mpjpe_pa = np.mean(dist_aligned)
    major_dist = dist[:, [1, 2, 4, 5, 7, 8, 16, 17, 18, 19, 20, 21]]
    pck = np.mean(major_dist / 50 <= 1) * 100
    auc = np.mean(
        np.maximum(0, 1 - (np.floor(major_dist / 199 * 50) + 0.5) / 50)) * 100
    print('MPJPE & MPJPE_PA & PCK & AUC')
    print(to_latex([mpjpe, mpjpe_pa, pck, auc]))
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--pred-path', type=str, default=None)
    parser.add_argument('--procrustes', action=options.BoolAction)
    parser.add_argument('--only-S11', action=options.BoolAction)
    parser.add_argument('--seeds', type=int, default=1)

    # The root joint is the last if this is set, else the first
    parser.add_argument('--root-last', action=options.BoolAction)
    options.initialize(parser)
    FLAGS.pred_path = util.ensure_absolute_path(
        FLAGS.pred_path, f'{paths.DATA_ROOT}/experiments')

    all_image_relpaths, all_true3d = get_all_gt_poses()
    activities = np.array([
        re.search(f'Images/(.+?)\.', path)[1].split(' ')[0]
        for path in all_image_relpaths
    ])

    if FLAGS.seeds > 1:
        mean_per_seed, std_per_seed = evaluate_multiple_seeds(
            all_true3d, activities)
        print(to_latex(mean_per_seed))
        print(to_latex(std_per_seed))
    else:
        metrics = evaluate(FLAGS.pred_path, all_true3d, activities)
        print(to_latex(metrics))
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input-model-path', type=str, required=True)
    parser.add_argument('--output-model-path', type=str, required=True)
    parser.add_argument('--antialias-factor', type=int, default=1)
    options.initialize(parser)
    pose_estimator = Pose3dEstimator(
        FLAGS.input_model_path, antialias_factor=FLAGS.antialias_factor)
    tf.saved_model.save(pose_estimator, FLAGS.output_model_path)
    logging.info(f'Full image model has been exported to {FLAGS.output_model_path}')
Exemplo n.º 6
0
def initialize():
    parser = argparse.ArgumentParser()
    parser.add_argument('--model-path', type=str, required=True)
    parser.add_argument('--output-path', type=str, required=True)
    parser.add_argument('--out-video-dir', type=str)
    parser.add_argument('--num-aug', type=int, default=1)
    parser.add_argument('--batch-size', type=int, default=64)
    parser.add_argument('--viz', action=options.BoolAction)
    options.initialize(parser)
    for gpu in tf.config.experimental.list_physical_devices('GPU'):
        tf.config.experimental.set_memory_growth(gpu, True)
Exemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input-model-path', type=str, required=True)
    parser.add_argument('--detector-path', type=str, required=True)
    parser.add_argument('--output-model-path', type=str, required=True)
    options.initialize(parser)

    detector = tf.saved_model.load(FLAGS.detector_path)
    pose_estimator = tf.saved_model.load(FLAGS.input_model_path)
    combined_model = DetectorAndPoseEstimator(detector, pose_estimator)
    tf.saved_model.save(combined_model, FLAGS.output_model_path)
Exemplo n.º 8
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--pred-path', type=str, default=None)
    parser.add_argument('--procrustes', action=options.BoolAction)
    parser.add_argument('--acausal-smoothing', action=options.BoolAction)
    parser.add_argument('--causal-smoothing', action=options.BoolAction)
    options.initialize(parser)
    FLAGS.pred_path = util.ensure_absolute_path(
        FLAGS.pred_path, f'{paths.DATA_ROOT}/experiments')

    poses3d_true_dict = get_all_gt_poses()
    poses3d_pred_dict = get_all_pred_poses()

    all_pred3d = np.array(
        [poses3d_pred_dict[relpath] for relpath in poses3d_true_dict])
    all_true3d = np.array(list(poses3d_true_dict.values()))
    all_pred3d -= all_pred3d[:, :1]
    all_true3d -= all_true3d[:, :1]
    all_pred3d_aligned = tfu3d.rigid_align(all_pred3d,
                                           all_true3d,
                                           scale_align=True)

    dist = np.linalg.norm(all_true3d - all_pred3d, axis=-1)
    dist_aligned = np.linalg.norm(all_true3d - all_pred3d_aligned, axis=-1)

    mpjpe = np.mean(dist)
    mpjpe_pa = np.mean(dist_aligned)
    major_dist = dist[:, [1, 2, 4, 5, 7, 8, 16, 17, 18, 19, 20, 21]]

    major_dist_pa = dist_aligned[:, [1, 2, 4, 5, 7, 8, 16, 17, 18, 19, 20, 21]]
    max_dist_pa = np.max(major_dist_pa, axis=1)
    ncps_auc = np.mean(np.maximum(0, 1 - max_dist_pa / 300)) * 100
    ncps = [
        np.mean(max_dist_pa / t <= 1) * 100 for t in [50, 75, 100, 125, 150]
    ]

    pck = np.mean(major_dist / 50 <= 1) * 100
    auc = np.mean(
        np.maximum(0, 1 - (np.floor(major_dist / 199 * 50) + 0.5) / 50)) * 100
    result = 'MPJPE & MPJPE_PA & PCK & AUC & NCPS & NCPS-AUC \n'
    result += to_latex([mpjpe, mpjpe_pa, pck, auc, ncps[3], ncps_auc]) + '\n'
    result += to_latex(ncps) + '\n'
    result += str(np.mean(major_dist / 50 <= 1, axis=0) * 100) + '\n'
    result += str(np.mean(major_dist / 100 <= 1, axis=0) * 100) + '\n'
    result += str(np.mean(major_dist / 150 <= 1, axis=0) * 100) + '\n'
    print(result)
    util.write_file(result, f'{FLAGS.pred_path}/metrics')
    np.savez(f'{FLAGS.pred_path}/arrays.npz', true=all_true3d, pred=all_pred3d)

    for thresh in [50, 51, 52, 53, 54, 55, 60, 70, 80, 90, 100, 150, 200]:
        print(thresh, str(np.mean(major_dist / thresh <= 1) * 100))
Exemplo n.º 9
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--input-model-path', type=str, required=True)
    parser.add_argument('--output-model-path', type=str, required=True)
    parser.add_argument('--detector-path', type=str)
    parser.add_argument('--bone-length-dataset', type=str)
    parser.add_argument('--rot-aug', type=float, default=25)
    parser.add_argument('--rot-aug-linspace-noend', action=options.BoolAction)
    parser.add_argument('--crop-side', type=int, default=256)
    parser.add_argument('--detector-flip-vertical-too', action=options.BoolAction)
    options.initialize(parser)
    pose_estimator = Pose3dEstimator()
    tf.saved_model.save(
        pose_estimator, FLAGS.output_model_path,
        options=tf.saved_model.SaveOptions(experimental_custom_gradients=True))
    logger.info(f'Full image model has been exported to {FLAGS.output_model_path}')
Exemplo n.º 10
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--in-path', type=str, required=True)
    parser.add_argument('--out-path', type=str, default=None)
    options.initialize(parser)

    if FLAGS.out_path is None:
        FLAGS.out_path = FLAGS.in_path.replace('.npz', '.json')

    logging.debug(f'Loading from {FLAGS.in_path}')
    a = np.load(FLAGS.in_path, allow_pickle=True)
    all_results_3d = collections.defaultdict(list)
    for image_path, coords3d_pred in zip(a['image_path'],
                                         a['coords3d_pred_world']):
        all_results_3d[image_path.decode('utf8')].append(
            coords3d_pred.tolist())
    logging.info(f'Writing to file {FLAGS.out_path}')
    util.dump_json(all_results_3d, FLAGS.out_path)
Exemplo n.º 11
0
def initialize():
    parser = argparse.ArgumentParser()
    parser.add_argument('--model-path', type=str, required=True)
    parser.add_argument('--video-dir', type=str)
    parser.add_argument('--video-filenames', type=str)
    parser.add_argument('--viz-downscale', type=int, default=1)
    parser.add_argument('--batch-size', type=int, default=64)
    parser.add_argument('--max-detections', type=int, default=-1)
    parser.add_argument('--out-video-path', type=str)
    parser.add_argument('--write-video', action=options.BoolAction)
    parser.add_argument('--num-aug', type=int, default=5)
    parser.add_argument('--fov', type=float, default=55)
    parser.add_argument('--skeleton', type=str, default='smpl+head_30')
    parser.add_argument('--model-name', type=str, default='')
    options.initialize(parser)
    logging.getLogger('absl').setLevel('ERROR')
    for gpu in tf.config.experimental.list_physical_devices('GPU'):
        tf.config.experimental.set_memory_growth(gpu, True)
Exemplo n.º 12
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--model-path', type=str, required=True)
    parser.add_argument('--output-dir', type=str, required=True)
    parser.add_argument('--video-path', type=str)
    parser.add_argument('--dataset', type=str)
    parser.add_argument('--darknet-dir', type=str)
    parser.add_argument('--gt-assoc', action=options.YesNoAction)
    parser.add_argument('--precomputed-detections', action=options.YesNoAction)
    parser.add_argument('--batched', action=options.YesNoAction)
    parser.add_argument('--crops', type=int, default=5)
    parser.add_argument('--detector-flip-aug', action=options.YesNoAction)
    parser.add_argument('--detector-path', type=str)
    parser.add_argument('--antialias', action=options.YesNoAction)
    parser.add_argument('--real-intrinsics', action=options.YesNoAction)
    parser.add_argument('--causal-smoothing', action=options.YesNoAction)
    parser.add_argument('--gui', action=options.YesNoAction)
    options.initialize(parser)
    for gpu in tf.config.experimental.list_physical_devices('GPU'):
        tf.config.experimental.set_memory_growth(gpu, True)

    detector = tf.saved_model.load(FLAGS.detector_path)
    pose_estimator = tf.saved_model.load(FLAGS.model_path)

    joint_names = [
        b.decode('utf8')
        for b in pose_estimator.crop_model.joint_names.numpy()
    ]
    edges = pose_estimator.crop_model.joint_edges.numpy()
    ji3d = data.datasets3d.JointInfo(joint_names, edges)

    if FLAGS.gui:
        q = queue.Queue(30)
        visualizer_thread = threading.Thread(target=main_visualize,
                                             args=(q, ji))
        visualizer_thread.start()
    else:
        q = None

    seq_filepaths = sorted(
        glob.glob(f'{paths.DATA_ROOT}/3dpw/sequenceFiles/*/*.pkl'))
    seq_filepaths = [x for x in seq_filepaths if 'capoeira' in x]
    seq_names = [os.path.basename(p).split('.')[0] for p in seq_filepaths]
    subdir = 'gtassoc' if FLAGS.gt_assoc else 'nogtassoc'
    subdirpath = f'{FLAGS.output_dir}/{subdir}'

    for seq_name, seq_filepath in util.progressbar(
            zip(seq_names, seq_filepaths)):
        already_done_files = glob.glob(f'{subdirpath}/*/*.pkl')
        if any(seq_name in p for p in already_done_files):
            continue
        print(seq_name)
        frame_paths = sorted(
            glob.glob(
                f'{paths.DATA_ROOT}/3dpw/imageFiles/{seq_name}/image_*.jpg'))
        poses2d_true = get_poses2d_3dpw(seq_name)
        camera = get_3dpw_camera(
            seq_filepath) if FLAGS.real_intrinsics else None
        tracks = track_them(detector,
                            pose_estimator,
                            frame_paths,
                            poses2d_true,
                            ji2d,
                            ji3d,
                            q,
                            camera=camera)
        save_result_file(seq_name, subdirpath, tracks)
Exemplo n.º 13
0
from dataset import ColorDataset
from utils import utils
from utils import visualizer

import options
import torch
import torchvision
import torchvision.transforms as transforms

import argparse

from model import create_model

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser = options.initialize(parser)

    parser.add_argument('--dataset_root', default='datasets/train')
    parser.add_argument('--img_root', default='trainlist.txt')
    parser.add_argument('--Batch_size', default=12, type=int)
    parser.add_argument('--shuffle', default=True)
    parser.add_argument('--gpu', default='0,1')
    parser.add_argument('--print_freq', default=1, type=int)
    parser.add_argument('--iter', default=5)
    parser.add_argument('--iter_decay', default=1)
    parser.add_argument('--isTrain', default=True)
    parser.add_argument('--load_model', action='store_true')
    parser.add_argument('--start_epoch', default='latest')
    parser.add_argument('--loadSize', default=256)
    parser.add_argument('--fineSize', default=176)
Exemplo n.º 14
0
        track.clean(FLAGS, PATHS)
    else:
        feature.clean(FLAGS, PATHS)

    match.clean(FLAGS, PATHS)
    reconstruction.clean(FLAGS, PATHS)

    # if PATHS.ground_truth_path:
    #     orientation.clean_ground_truth_camera_param(FLAGS, PATHS)
    #     match_info.clean(FLAGS, PATHS)
    #     orientation.clean(FLAGS, PATHS)


if __name__ == '__main__':
    # This must be called before 'FLAGS(sys.argv)'.
    options.initialize()
    FLAGS(sys.argv)
    FLAGS.bin_dir = os.path.normpath(os.path.join(sys.path[0], FLAGS.bin_dir))

    set_paths()
    print_paths()
    options.show(FLAGS, PATHS)


    # Clean files if desired.
    if FLAGS.clean or FLAGS.overwrite:
        clean_files()

    if FLAGS.clean:
        shutil.rmtree(PATHS.output_path)
        print("Removed '" + PATHS.output_path + "'.")