コード例 #1
0
def cli():
    parser = argparse.ArgumentParser(
        prog='python3 -m openpifpaf.train',
        usage='%(prog)s [options]',
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    parser.add_argument(
        '--version',
        action='version',
        version='OpenPifPaf {version}'.format(version=__version__))
    parser.add_argument('-o', '--output', default=None, help='output file')
    parser.add_argument('--disable-cuda',
                        action='store_true',
                        help='disable CUDA')
    parser.add_argument('--ddp',
                        default=False,
                        action='store_true',
                        help='[experimental] DistributedDataParallel')
    parser.add_argument('--local_rank',
                        default=None,
                        type=int,
                        help='[experimental] for torch.distributed.launch')
    parser.add_argument('--no-sync-batchnorm',
                        dest='sync_batchnorm',
                        default=True,
                        action='store_false',
                        help='[experimental] in ddp, to not use syncbatchnorm')

    logger.cli(parser)
    network.Factory.cli(parser)
    network.losses.Factory.cli(parser)
    network.Trainer.cli(parser)
    encoder.cli(parser)
    optimize.cli(parser)
    datasets.cli(parser)
    show.cli(parser)
    visualizer.cli(parser)

    args = parser.parse_args()

    logger.configure(args, LOG)
    if args.log_stats:
        logging.getLogger('openpifpaf.stats').setLevel(logging.DEBUG)

    # DDP with SLURM
    slurm_process_id = os.environ.get('SLURM_PROCID')
    if args.ddp and slurm_process_id is not None:
        if torch.cuda.device_count() > 1:
            LOG.warning(
                'Expected one GPU per SLURM task but found %d. '
                'Try with "srun --gpu-bind=closest ...". Still trying.',
                torch.cuda.device_count())

        # if there is more than one GPU available, assume that other SLURM tasks
        # have access to the same GPUs and assign GPUs uniquely by slurm_process_id
        args.local_rank = (int(slurm_process_id) % torch.cuda.device_count()
                           if torch.cuda.device_count() > 0 else 0)

        os.environ['RANK'] = slurm_process_id
        if not os.environ.get('WORLD_SIZE') and os.environ.get('SLURM_NTASKS'):
            os.environ['WORLD_SIZE'] = os.environ.get('SLURM_NTASKS')

        LOG.info('found SLURM process id: %s', slurm_process_id)
        LOG.info(
            'distributed env: master=%s port=%s rank=%s world=%s, '
            'local rank (GPU)=%d', os.environ.get('MASTER_ADDR'),
            os.environ.get('MASTER_PORT'), os.environ.get('RANK'),
            os.environ.get('WORLD_SIZE'), args.local_rank)

    # add args.device
    args.device = torch.device('cpu')
    args.pin_memory = False
    if not args.disable_cuda and torch.cuda.is_available():
        args.device = torch.device('cuda')
        args.pin_memory = True
    LOG.info('neural network device: %s (CUDA available: %s, count: %d)',
             args.device, torch.cuda.is_available(), torch.cuda.device_count())

    # output
    if args.output is None:
        args.output = default_output_file(args)
        os.makedirs('outputs', exist_ok=True)

    network.Factory.configure(args)
    network.losses.Factory.configure(args)
    network.Trainer.configure(args)
    encoder.configure(args)
    datasets.configure(args)
    show.configure(args)
    visualizer.configure(args)

    return args
コード例 #2
0
ファイル: run.py プロジェクト: TrendingTechnology/monstereo
def cli():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    # Subparser definition
    subparsers = parser.add_subparsers(
        help='Different parsers for main actions', dest='command')
    predict_parser = subparsers.add_parser("predict")
    prep_parser = subparsers.add_parser("prep")
    training_parser = subparsers.add_parser("train")
    eval_parser = subparsers.add_parser("eval")

    # Preprocess input data
    prep_parser.add_argument('--dir_ann',
                             help='directory of annotations of 2d joints',
                             required=True)
    prep_parser.add_argument(
        '--dataset',
        help=
        'datasets to preprocess: nuscenes, nuscenes_teaser, nuscenes_mini, kitti',
        default='kitti')
    prep_parser.add_argument('--dir_nuscenes',
                             help='directory of nuscenes devkit',
                             default='data/nuscenes/')
    prep_parser.add_argument('--iou_min',
                             help='minimum iou to match ground truth',
                             type=float,
                             default=0.3)
    prep_parser.add_argument('--variance', help='new', action='store_true')
    prep_parser.add_argument('--activity', help='new', action='store_true')
    prep_parser.add_argument('--monocular', help='new', action='store_true')

    # Predict (2D pose and/or 3D location from images)
    # General
    predict_parser.add_argument('--mode',
                                help='pifpaf, mono, stereo',
                                default='stereo')
    predict_parser.add_argument('images', nargs='*', help='input images')
    predict_parser.add_argument(
        '--glob', help='glob expression for input images (for many images)')
    predict_parser.add_argument('-o',
                                '--output-directory',
                                help='Output directory')
    predict_parser.add_argument(
        '--output_types',
        nargs='+',
        default=['json'],
        help='what to output: json keypoints skeleton for Pifpaf'
        'json bird front or multi for MonStereo')
    predict_parser.add_argument('--no_save',
                                help='to show images',
                                action='store_true')
    predict_parser.add_argument('--dpi',
                                help='image resolution',
                                type=int,
                                default=150)
    predict_parser.add_argument(
        '--long-edge',
        default=None,
        type=int,
        help='rescale the long side of the image (aspect ratio maintained)')
    predict_parser.add_argument('--disable-cuda',
                                action='store_true',
                                help='disable CUDA')
    predict_parser.add_argument(
        '--focal',
        help=
        'focal length in mm for a sensor size of 7.2x5.4 mm. Default nuScenes sensor',
        type=float,
        default=5.7)

    # Pifpaf parsers
    decoder.cli(parser)
    logger.cli(parser)
    network.Factory.cli(parser)
    show.cli(parser)
    visualizer.cli(parser)

    # Monoloco
    predict_parser.add_argument(
        '--net',
        help='Choose network: monoloco, monoloco_p, monoloco_pp, monstereo')
    predict_parser.add_argument('--model',
                                help='path of MonoLoco model to load',
                                required=True)
    predict_parser.add_argument('--hidden_size',
                                type=int,
                                help='Number of hidden units in the model',
                                default=512)
    predict_parser.add_argument(
        '--path_gt',
        help='path of json file with gt 3d localization',
        default='data/arrays/names-kitti-200615-1022.json')
    predict_parser.add_argument('--transform',
                                help='transformation for the pose',
                                default='None')
    predict_parser.add_argument('--z_max',
                                type=int,
                                help='maximum meters distance for predictions',
                                default=100)
    predict_parser.add_argument('--n_dropout',
                                type=int,
                                help='Epistemic uncertainty evaluation',
                                default=0)
    predict_parser.add_argument('--dropout',
                                type=float,
                                help='dropout parameter',
                                default=0.2)
    predict_parser.add_argument(
        '--show_all',
        help='only predict ground-truth matches or all',
        action='store_true')

    # Social distancing and social interactions
    predict_parser.add_argument('--social_distance',
                                help='social',
                                action='store_true')
    predict_parser.add_argument('--threshold_prob',
                                type=float,
                                help='concordance for samples',
                                default=0.25)
    predict_parser.add_argument('--threshold_dist',
                                type=float,
                                help='min distance of people',
                                default=2.5)
    predict_parser.add_argument('--radii',
                                type=tuple,
                                help='o-space radii',
                                default=(0.3, 0.5, 1))

    # Training
    training_parser.add_argument(
        '--joints',
        help='Json file with input joints',
        default='data/arrays/joints-nuscenes_teaser-190513-1846.json')
    training_parser.add_argument('--no_save',
                                 help='to not save model and log file',
                                 action='store_true')
    training_parser.add_argument('-e',
                                 '--epochs',
                                 type=int,
                                 help='number of epochs to train for',
                                 default=500)
    training_parser.add_argument('--bs',
                                 type=int,
                                 default=512,
                                 help='input batch size')
    training_parser.add_argument('--monocular',
                                 help='whether to train monoloco',
                                 action='store_true')
    training_parser.add_argument('--dropout',
                                 type=float,
                                 help='dropout. Default no dropout',
                                 default=0.2)
    training_parser.add_argument('--lr',
                                 type=float,
                                 help='learning rate',
                                 default=0.001)
    training_parser.add_argument('--sched_step',
                                 type=float,
                                 help='scheduler step time (epochs)',
                                 default=30)
    training_parser.add_argument('--sched_gamma',
                                 type=float,
                                 help='Scheduler multiplication every step',
                                 default=0.98)
    training_parser.add_argument('--hidden_size',
                                 type=int,
                                 help='Number of hidden units in the model',
                                 default=1024)
    training_parser.add_argument('--n_stage',
                                 type=int,
                                 help='Number of stages in the model',
                                 default=3)
    training_parser.add_argument('--hyp',
                                 help='run hyperparameters tuning',
                                 action='store_true')
    training_parser.add_argument('--multiplier',
                                 type=int,
                                 help='Size of the grid of hyp search',
                                 default=1)
    training_parser.add_argument(
        '--r_seed',
        type=int,
        help='specify the seed for training and hyp tuning',
        default=1)
    training_parser.add_argument('--print_loss',
                                 help='print training and validation losses',
                                 action='store_true')
    training_parser.add_argument(
        '--auto_tune_mtl',
        help='whether to use uncertainty to autotune losses',
        action='store_true')

    # Evaluation
    eval_parser.add_argument('--dataset',
                             help='datasets to evaluate, kitti or nuscenes',
                             default='kitti')
    eval_parser.add_argument('--geometric',
                             help='to evaluate geometric distance',
                             action='store_true')
    eval_parser.add_argument('--generate',
                             help='create txt files for KITTI evaluation',
                             action='store_true')
    eval_parser.add_argument(
        '--dir_ann',
        help='directory of annotations of 2d joints (for KITTI evaluation)')
    eval_parser.add_argument('--model', help='path of MonoLoco model to load')
    eval_parser.add_argument(
        '--joints',
        help='Json file with input joints to evaluate (for nuScenes evaluation)'
    )
    eval_parser.add_argument('--n_dropout',
                             type=int,
                             help='Epistemic uncertainty evaluation',
                             default=0)
    eval_parser.add_argument('--dropout',
                             type=float,
                             help='dropout. Default no dropout',
                             default=0.2)
    eval_parser.add_argument('--hidden_size',
                             type=int,
                             help='Number of hidden units in the model',
                             default=1024)
    eval_parser.add_argument('--n_stage',
                             type=int,
                             help='Number of stages in the model',
                             default=3)
    eval_parser.add_argument('--show',
                             help='whether to show statistic graphs',
                             action='store_true')
    eval_parser.add_argument('--save',
                             help='whether to save statistic graphs',
                             action='store_true')
    eval_parser.add_argument('--verbose',
                             help='verbosity of statistics',
                             action='store_true')
    eval_parser.add_argument('--monocular',
                             help='whether to train using the baseline',
                             action='store_true')
    eval_parser.add_argument('--new', help='new', action='store_true')
    eval_parser.add_argument('--variance',
                             help='evaluate keypoints variance',
                             action='store_true')
    eval_parser.add_argument('--activity',
                             help='evaluate activities',
                             action='store_true')
    eval_parser.add_argument(
        '--net',
        help='Choose network: monoloco, monoloco_p, monoloco_pp, monstereo')
    eval_parser.add_argument('--baselines',
                             help='whether to evaluate stereo baselines',
                             action='store_true')
    eval_parser.add_argument(
        '--generate_official',
        help='whether to add empty txt files for official evaluation',
        action='store_true')

    args = parser.parse_args()
    return args
コード例 #3
0
def cli():
    parser = argparse.ArgumentParser(
        prog='python3 -m openpifpaf.predict',
        usage='%(prog)s [options] images',
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    parser.add_argument('--version', action='version',
                        version='OpenPifPaf {version}'.format(version=__version__))

    decoder.cli(parser)
    logger.cli(parser)
    network.Factory.cli(parser)
    show.cli(parser)
    visualizer.cli(parser)

    parser.add_argument('images', nargs='*',
                        help='input images')
    parser.add_argument('--glob',
                        help='glob expression for input images (for many images)')
    parser.add_argument('-o', '--image-output', default=None, nargs='?', const=True,
                        help='Whether to output an image, '
                             'with the option to specify the output path or directory')
    parser.add_argument('--json-output', default=None, nargs='?', const=True,
                        help='Whether to output a json file, '
                             'with the option to specify the output path or directory')
    parser.add_argument('--batch-size', default=1, type=int,
                        help='processing batch size')
    parser.add_argument('--long-edge', default=None, type=int,
                        help='rescale the long side of the image (aspect ratio maintained)')
    parser.add_argument('--loader-workers', default=None, type=int,
                        help='number of workers for data loading')
    parser.add_argument('--precise-rescaling', dest='fast_rescaling',
                        default=True, action='store_false',
                        help='use more exact image rescaling (requires scipy)')
    parser.add_argument('--disable-cuda', action='store_true',
                        help='disable CUDA')
    args = parser.parse_args()

    logger.configure(args, LOG)  # logger first

    # add args.device
    args.device = torch.device('cpu')
    args.pin_memory = False
    if not args.disable_cuda and torch.cuda.is_available():
        args.device = torch.device('cuda')
        args.pin_memory = True
    LOG.info('neural network device: %s (CUDA available: %s, count: %d)',
             args.device, torch.cuda.is_available(), torch.cuda.device_count())

    decoder.configure(args)
    network.Factory.configure(args)
    show.configure(args)
    visualizer.configure(args)

    if args.loader_workers is None:
        args.loader_workers = args.batch_size

    # glob
    if args.glob:
        args.images += glob.glob(args.glob)
    if not args.images:
        raise Exception("no image files given")

    return args