Exemplo n.º 1
0
def cli():
    predict_parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    # Predict (3D pose from images)

    ##Here we can add arguments to pass to the software.

    # Pifpaf
    nets.cli(predict_parser)
    decoder.cli(predict_parser,
                force_complete_pose=True,
                instance_threshold=0.15)
    predict_parser.add_argument(
        '--scale',
        default=0.2,
        type=float,
        help='change the scale of the image to preprocess')
    predict_parser.add_argument('--pose3d_model',
                                help='path of 3Dpose model to load',
                                default='data/models/pose3d-v0_8.pkl')
    predict_parser.add_argument('--webcam',
                                help='streaming',
                                action='store_true')

    args = predict_parser.parse_args()
    return args
Exemplo n.º 2
0
def cli():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    logs.cli(parser)
    nets.cli(parser)
    losses.cli(parser)
    encoder.cli(parser)
    optimize.cli(parser)
    datasets.train_cli(parser)

    parser.add_argument('-o', '--output', default=None,
                        help='output file')
    parser.add_argument('--stride-apply', default=1, type=int,
                        help='apply and reset gradients every n batches')
    parser.add_argument('--epochs', default=75, type=int,
                        help='number of epochs to train')
    parser.add_argument('--freeze-base', default=0, type=int,
                        help='number of epochs to train with frozen base')
    parser.add_argument('--pre-lr', type=float, default=1e-4,
                        help='pre learning rate')
    parser.add_argument('--update-batchnorm-runningstatistics',
                        default=False, action='store_true',
                        help='update batch norm running statistics')
    parser.add_argument('--square-edge', default=401, type=int,
                        help='square edge of input images')
    parser.add_argument('--crop-fraction', default=0.5, type=float,
                        help='crop fraction versus rescale')
    parser.add_argument('--lambdas', default=[30.0, 2.0, 2.0, 50.0, 3.0, 3.0],
                        type=float, nargs='+',
                        help='prefactor for head losses')
    parser.add_argument('--ema', default=1e-3, type=float,
                        help='ema decay constant')
    parser.add_argument('--debug-without-plots', default=False, action='store_true',
                        help='enable debug but dont plot')
    parser.add_argument('--profile', default=None,
                        help='enables profiling. specify path for chrome tracing file')
    parser.add_argument('--disable-cuda', action='store_true',
                        help='disable CUDA')
    args = parser.parse_args()

    if args.output is None:
        args.output = default_output_file(args)

    if args.debug and 'skeleton' not in args.headnets:
        raise Exception('add "skeleton" as last headnet to see debug output')

    if args.debug_without_plots:
        args.debug = True

    # 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

    return args
Exemplo n.º 3
0
def cli():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    nets.cli(parser)
    decoder.cli(parser, force_complete_pose=False, instance_threshold=0.05)
    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',
                        '--output-directory',
                        help=('Output directory. When using this option, make '
                              'sure input images have distinct file names.'))
    parser.add_argument('--show',
                        default=False,
                        action='store_true',
                        help='show image of output overlay')
    parser.add_argument('--output-types',
                        nargs='+',
                        default=['skeleton', 'json'],
                        help='what to output: skeleton, keypoints, json')
    parser.add_argument('--loader-workers',
                        default=2,
                        type=int,
                        help='number of workers for data loading')
    parser.add_argument('--disable-cuda',
                        action='store_true',
                        help='disable CUDA')
    parser.add_argument('--figure-width',
                        default=10.0,
                        type=float,
                        help='figure width')
    parser.add_argument('--dpi-factor',
                        default=1.0,
                        type=float,
                        help='increase dpi of output image by this factor')
    args = parser.parse_args()

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

    # 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

    return args
Exemplo n.º 4
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    nets.cli(parser)
    decoder.cli(parser, force_complete_pose=False, instance_threshold=0.1, seed_threshold=0.5)
    parser.add_argument('--no-colored-connections',
                        dest='colored_connections', default=True, action='store_false',
                        help='do not use colored connections to draw poses')
    parser.add_argument('--disable_cuda', action='store_true', default=None,
                        help='disable CUDA')
    args = parser.parse_args()

    # add args.device
    args.device = torch.device('cpu')
    if not args.disable_cuda and torch.cuda.is_available():
        print('************************ using gpu *****************************')
        args.device = torch.device('cuda')

    # load model
    model, _ = nets.factory_from_args(args)
    model = model.to(args.device)
    processor = decoder.factory_from_args(args, model)

    # own coco val json
    f = open('/home/chenjia/pedestrian_det/chenjiaPifPaf/splitjson/test_5000.json')
    js = ujson.load(f)
    img_paths = js['images']   # len==5000, img的相对路径
    img_path_root = '/data/nfs_share/public/zxyang/human_data/detection_data_cpu'
    out_root = '/home/chenjia/pedestrian_det/openpifpaf/show_eval'

    # random check pred result
    for i in range(50):
        print('*************** run the ', i + 1, 'image ******************')
        ind = np.random.randint(0, 4999)
        img_path = os.path.join(img_path_root, img_paths[ind]['file_name'])
        img = cv2.imread(img_path)
        img = cv2.resize(img, (683, 384))

        image = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        processed_image_cpu = transforms.image_transform(image.copy())   # normalize

        processed_image = processed_image_cpu.contiguous().to(args.device, non_blocking=True)  # transpose 2,0,1
        fields = processor.fields(torch.unsqueeze(processed_image, 0))[0]
        keypoint_sets, _ = processor.keypoint_sets(fields)

        # plot pred result
        plot_points(image, keypoint_sets, COCO_PERSON_SKELETON)
        cv2.imwrite(os.path.join(out_root, str(ind) + '.jpg'), image)
Exemplo n.º 5
0
def cli():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    nets.cli(parser)
    decoder.cli(parser,
                force_complete_pose=False,
                instance_threshold=0.1,
                seed_threshold=0.5)
    parser.add_argument('--no-colored-connections',
                        dest='colored_connections',
                        default=True,
                        action='store_false',
                        help='do not use colored connections to draw poses')
    parser.add_argument('--disable-cuda',
                        action='store_true',
                        help='disable CUDA')
    parser.add_argument(
        '--source',
        default='0',
        help='OpenCV source url. Integer for webcams. Or ipwebcam streams.')
    parser.add_argument('--scale',
                        default=0.5,
                        type=float,
                        help='input image scale factor')
    args = parser.parse_args()

    # check whether source should be an int
    if len(args.source) == 1:
        args.source = int(args.source)

    # add args.device
    args.device = torch.device('cpu')
    if not args.disable_cuda and torch.cuda.is_available():
        args.device = torch.device('cuda')

    return args
Exemplo n.º 6
0
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 combined for Monoloco')
    predict_parser.add_argument('--show',
                                help='to show images',
                                action='store_true')

    # Pifpaf
    nets.cli(predict_parser)
    decoder.cli(predict_parser,
                force_complete_pose=True,
                instance_threshold=0.15)
    predict_parser.add_argument(
        '--scale',
        default=1.0,
        type=float,
        help='change the scale of the image to preprocess')

    # Monoloco
    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('--draw_box',
                                help='to draw box in the images',
                                action='store_true')
    predict_parser.add_argument('--z_max',
                                type=int,
                                help='maximum meters distance for predictions',
                                default=22)
    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', help='social', action='store_true')
    predict_parser.add_argument('--activity',
                                help='activity',
                                action='store_true')
    predict_parser.add_argument('--json_dir', help='for social')
    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)
    predict_parser.add_argument('--margin',
                                type=float,
                                help='conservative for noise in orientation',
                                default=1.5)
    predict_parser.add_argument('--radii',
                                type=tuple,
                                help='o-space radii',
                                default=(0.25, 1, 2))

    # 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('--save',
                                 help='whether 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('--activity', help='new', 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')

    args = parser.parse_args()
    return args
Exemplo n.º 7
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    nets.cli(parser)
    decoder.cli(parser, force_complete_pose=False, instance_threshold=0.05)
    parser.add_argument('--no-colored-connections',
                        dest='colored_connections',
                        default=True,
                        action='store_false',
                        help='do not use colored connections to draw poses')
    parser.add_argument('--disable-cuda',
                        action='store_true',
                        help='disable CUDA')
    parser.add_argument(
        '--source',
        default=0,
        help='OpenCV source url. Integer for webcams. Or ipwebcam streams.')
    parser.add_argument('--scale',
                        default=0.1,
                        type=float,
                        help='input image scale factor')
    args = parser.parse_args()

    # check whether source should be an int
    if len(args.source) == 1:
        args.source = int(args.source)

    # add args.device
    args.device = torch.device('cpu')
    if not args.disable_cuda and torch.cuda.is_available():
        args.device = torch.device('cuda')

    # load model
    model, _ = nets.factory(args)
    model = model.to(args.device)
    processors = decoder.factory(args, model)

    last_loop = time.time()
    capture = cv2.VideoCapture(args.source)

    visualizers = None
    while True:
        ret, image_original = capture.read()
        print(ret)
        image = cv2.resize(image_original, None, fx=args.scale, fy=args.scale)
        print('resized image size: {}'.format(image.shape))
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

        if visualizers is None:
            visualizers = [Visualizer(p, args)(image) for p in processors]
            for v in visualizers:
                v.send(None)

        start = time.time()
        processed_image_cpu = transforms.image_transform(image.copy())
        processed_image = processed_image_cpu.contiguous().to(
            args.device, non_blocking=True)
        print('preprocessing time', time.time() - start)

        fields = processors[0].fields(torch.unsqueeze(processed_image, 0))[0]
        for v in visualizers:
            v.send((image, fields))

        print('loop time = {:.3}s, FPS = {:.3}'.format(
            time.time() - last_loop, 1.0 / (time.time() - last_loop)))
        last_loop = time.time()
Exemplo n.º 8
0
def cli():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    nets.cli(parser)
    decoder.cli(parser, force_complete_pose=True)
    encoder.cli(parser)
    parser.add_argument('--output',
                        default=None,
                        help='output filename without file extension')
    parser.add_argument('-n', default=0, type=int, help='number of batches')
    parser.add_argument('--skip-n', default=0, type=int, help='skip n batches')
    parser.add_argument('--dataset',
                        choices=('val', 'test', 'test-dev'),
                        default='val',
                        help='dataset to evaluate')
    parser.add_argument('--min-ann',
                        default=0,
                        type=int,
                        help='minimum number of truth annotations')
    parser.add_argument('--batch-size', default=1, type=int, help='batch size')
    parser.add_argument('--long-edge',
                        default=641,
                        type=int,
                        help='long edge of input images')
    parser.add_argument('--loader-workers',
                        default=None,
                        type=int,
                        help='number of workers for data loading')
    parser.add_argument('--skip-existing',
                        default=False,
                        action='store_true',
                        help='skip if output eval file exists already')
    parser.add_argument('--disable-cuda',
                        action='store_true',
                        help='disable CUDA')
    parser.add_argument('--write-predictions',
                        default=False,
                        action='store_true',
                        help='write a json and a zip file of the predictions')
    parser.add_argument('--all-images',
                        default=False,
                        action='store_true',
                        help='run over all images irrespective of catIds')
    group = parser.add_argument_group('logging')
    group.add_argument('--debug',
                       default=False,
                       action='store_true',
                       help='print debug messages')
    args = parser.parse_args()

    logging.basicConfig()
    log_level = logging.INFO if not args.debug else logging.DEBUG
    logging.getLogger('openpifpaf').setLevel(log_level)
    LOG.setLevel(log_level)

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

    if args.dataset == 'val':
        args.image_dir = IMAGE_DIR_VAL
        args.annotation_file = ANNOTATIONS_VAL
    elif args.dataset == 'test':
        args.image_dir = IMAGE_DIR_TEST
        args.annotation_file = ANNOTATIONS_TEST
    elif args.dataset == 'test-dev':
        args.image_dir = IMAGE_DIR_TEST
        args.annotation_file = ANNOTATIONS_TESTDEV
    else:
        raise Exception

    if args.dataset in ('test', 'test-dev'
                        ) and not args.write_predictions and not args.debug:
        raise Exception('have to use --write-predictions for this dataset')
    if args.dataset in ('test',
                        'test-dev') and not args.all_images and not args.debug:
        raise Exception('have to use --all-images for this dataset')

    # 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

    # generate a default output filename
    if args.output is None:
        args.output = default_output_name(args)

    return args
Exemplo n.º 9
0
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='nuscenes')
    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)

    # Predict (2D pose and/or 3D location from images)
    # General
    predict_parser.add_argument('--networks',
                                nargs='+',
                                help='Run pifpaf and/or monoloco',
                                default=['monoloco'])
    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 combined for Monoloco')
    predict_parser.add_argument('--show',
                                help='to show images',
                                action='store_true')

    # Pifpaf
    nets.cli(predict_parser)
    decoder.cli(predict_parser,
                force_complete_pose=True,
                instance_threshold=0.1)
    predict_parser.add_argument(
        '--scale',
        default=1.0,
        type=float,
        help='change the scale of the image to preprocess')

    # Monoloco
    predict_parser.add_argument('--model',
                                help='path of MonoLoco model to load',
                                default="data/models/monoloco-190513-1437.pkl")
    predict_parser.add_argument('--hidden_size',
                                type=int,
                                help='Number of hidden units in the model',
                                default=256)
    predict_parser.add_argument(
        '--path_gt',
        help='path of json file with gt 3d localization',
        default='data/arrays/names-kitti-190710-1206.json')
    predict_parser.add_argument('--transform',
                                help='transformation for the pose',
                                default='None')
    predict_parser.add_argument('--draw_box',
                                help='to draw box in the images',
                                action='store_true')
    predict_parser.add_argument('--predict',
                                help='whether to make prediction',
                                action='store_true')
    predict_parser.add_argument('--z_max',
                                type=int,
                                help='maximum meters distance for predictions',
                                default=22)
    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('--webcam',
                                help='monoloco streaming',
                                action='store_true')

    # 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('--save',
                                 help='whether to not save model and log file',
                                 action='store_false')
    training_parser.add_argument('-e',
                                 '--epochs',
                                 type=int,
                                 help='number of epochs to train for',
                                 default=150)
    training_parser.add_argument('--bs',
                                 type=int,
                                 default=256,
                                 help='input batch size')
    training_parser.add_argument('--baseline',
                                 help='whether to train using the baseline',
                                 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.002)
    training_parser.add_argument('--sched_step',
                                 type=float,
                                 help='scheduler step time (epochs)',
                                 default=20)
    training_parser.add_argument('--sched_gamma',
                                 type=float,
                                 help='Scheduler multiplication every step',
                                 default=0.9)
    training_parser.add_argument('--hidden_size',
                                 type=int,
                                 help='Number of hidden units in the model',
                                 default=256)
    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)

    # 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',
                             required=True)
    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=256)
    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('--verbose',
                             help='verbosity of statistics',
                             action='store_true')
    eval_parser.add_argument('--stereo',
                             help='include stereo baseline results',
                             action='store_true')

    args = parser.parse_args()
    return args
Exemplo n.º 10
0
def main():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    nets.cli(parser)
    decoder.cli(parser, force_complete_pose=False, instance_threshold=0.05)
    parser.add_argument('--no-colored-connections',
                        dest='colored_connections', default=True, action='store_false',
                        help='do not use colored connections to draw poses')
    parser.add_argument('--disable-cuda', action='store_true',
                        help='disable CUDA')
    parser.add_argument('--source', default=0,
                        help='OpenCV source url. Integer for webcams. Or ipwebcam streams.')
    parser.add_argument('--scale', default=0.1, type=float,
                        help='input image scale factor')
    args = parser.parse_args()

    # check whether source should be an int
    if len(args.source) == 1:
        args.source = int(args.source)

    # add args.device
    args.device = torch.device('cpu')
    if not args.disable_cuda and torch.cuda.is_available():
        args.device = torch.device('cuda')

    # load model
    model, _ = nets.factory(args)
    model = model.to(args.device)
    processors = decoder.factory(args, model)
    

    print(args)

    last_loop = time.time()
    capture = cv2.VideoCapture(args.source)

    visualizers = None
    while True:
        ret , image_original = capture.read()
        print(ret)
        image = cv2.resize(image_original, None, fx=args.scale, fy=args.scale)
        print('resized image size: {}'.format(image.shape))
        image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)

        if visualizers is None:
            visualizers = [Visualizer(p, args)(image) for p in processors]
            for v in visualizers:
                v.send(None)

        start = time.time()
        processed_image_cpu = transforms.image_transform(image.copy())
        processed_image = processed_image_cpu.contiguous().to(args.device, non_blocking=True)
        print('preprocessing time', time.time() - start)

        fields = processors[0].fields(torch.unsqueeze(processed_image, 0))[0]
        for v in visualizers:
            v.send((image, fields))

        print('loop time = {:.3}s, FPS = {:.3}'.format(
            time.time() - last_loop, 1.0 / (time.time() - last_loop)))
        last_loop = time.time()
Exemplo n.º 11
0
def cli():
    parser = argparse.ArgumentParser(
        prog='python3 -m openpifpaf.predict',
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    nets.cli(parser)
    decoder.cli(parser,
                force_complete_pose=False,
                instance_threshold=0.1,
                seed_threshold=0.5)
    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',
                        '--output-directory',
                        help=('Output directory. When using this option, make '
                              'sure input images have distinct file names.'))
    parser.add_argument('--show',
                        default=False,
                        action='store_true',
                        help='show image of output overlay')
    parser.add_argument('--output-types',
                        nargs='+',
                        default=['skeleton', 'json'],
                        help='what to output: skeleton, keypoints, json')
    parser.add_argument('--batch-size',
                        default=1,
                        type=int,
                        help='processing batch size')
    parser.add_argument('--long-edge',
                        default=None,
                        type=int,
                        help='apply preprocessing to batch images')
    parser.add_argument('--loader-workers',
                        default=None,
                        type=int,
                        help='number of workers for data loading')
    parser.add_argument('--disable-cuda',
                        action='store_true',
                        help='disable CUDA')
    parser.add_argument('--line-width',
                        default=6,
                        type=int,
                        help='line width for skeleton')
    parser.add_argument('--figure-width',
                        default=10.0,
                        type=float,
                        help='figure width')
    parser.add_argument('--dpi-factor',
                        default=1.0,
                        type=float,
                        help='increase dpi of output image by this factor')
    parser.add_argument('--our-new-model',
                        default=0.0,
                        type=float,
                        help='uses our new model')
    group = parser.add_argument_group('logging')
    group.add_argument('-q',
                       '--quiet',
                       default=False,
                       action='store_true',
                       help='only show warning messages or above')
    group.add_argument('--debug',
                       default=False,
                       action='store_true',
                       help='print debug messages')
    args = parser.parse_args()

    log_level = logging.INFO
    if args.quiet:
        log_level = logging.WARNING
    if args.debug:
        log_level = logging.DEBUG
    logging.basicConfig()
    logging.getLogger('openpifpaf').setLevel(log_level)
    LOG.setLevel(log_level)

    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")

    # 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

    return args
Exemplo n.º 12
0
def cli():
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    logs.cli(parser)
    nets.cli(parser)
    losses.cli(parser)
    encoder.cli(parser)
    optimize.cli(parser)
    datasets.train_cli(parser)

    parser.add_argument('-o', '--output', default=None, help='output file')
    parser.add_argument('--stride-apply',
                        default=1,
                        type=int,
                        help='apply and reset gradients every n batches')
    parser.add_argument('--epochs',
                        default=75,
                        type=int,
                        help='number of epochs to train')
    parser.add_argument('--freeze-base',
                        default=0,
                        type=int,
                        help='number of epochs to train with frozen base')
    parser.add_argument('--pre-lr',
                        type=float,
                        default=1e-4,
                        help='pre learning rate')
    parser.add_argument('--rescale-images',
                        type=float,
                        default=1.0,
                        help='overall image rescale factor')
    parser.add_argument('--orientation-invariant',
                        default=False,
                        action='store_true',
                        help='augment with random orientations')
    parser.add_argument('--update-batchnorm-runningstatistics',
                        default=False,
                        action='store_true',
                        help='update batch norm running statistics')
    parser.add_argument('--square-edge',
                        default=401,
                        type=int,
                        help='square edge of input images')
    parser.add_argument('--ema',
                        default=1e-3,
                        type=float,
                        help='ema decay constant')
    parser.add_argument('--disable-cuda',
                        action='store_true',
                        help='disable CUDA')
    parser.add_argument('--no-augmentation',
                        dest='augmentation',
                        default=True,
                        action='store_false',
                        help='do not apply data augmentation')

    group = parser.add_argument_group('debug')
    group.add_argument('--debug-pif-indices',
                       default=[],
                       nargs='+',
                       type=int,
                       help='indices of PIF fields to create debug plots for')
    group.add_argument('--debug-paf-indices',
                       default=[],
                       nargs='+',
                       type=int,
                       help='indices of PAF fields to create debug plots for')
    group.add_argument(
        '--profile',
        default=None,
        help='enables profiling. specify path for chrome tracing file')

    args = parser.parse_args()

    if args.output is None:
        args.output = default_output_file(args)

    if args.debug and 'skeleton' not in args.headnets:
        raise Exception('add "skeleton" as last headnet to see debug output')

    if args.freeze_base and args.checkpoint:
        raise Exception('remove --freeze-base when running from a checkpoint')

    if args.debug_pif_indices or args.debug_paf_indices:
        args.debug = True

    # 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

    return args