コード例 #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
コード例 #2
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
コード例 #3
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)
コード例 #4
0
def cli():  # pylint: disable=too-many-statements,too-many-branches
    parser = argparse.ArgumentParser(
        prog='python3 -m openpifpaf.video',
        description=__doc__,
        formatter_class=CustomFormatter,
    )
    parser.add_argument(
        '--version',
        action='version',
        version='OpenPifPaf {version}'.format(version=__version__))

    network.cli(parser)
    decoder.cli(parser,
                force_complete_pose=True,
                instance_threshold=0.1,
                seed_threshold=0.5)
    pifpaf.show.cli(parser)

    parser.add_argument(
        '--source',
        default='0',
        help='OpenCV source url. Integer for webcams. Supports rtmp streams.')
    parser.add_argument('--video-output',
                        default=None,
                        nargs='?',
                        const=True,
                        help='video with drawn skeleton output file')
    parser.add_argument('--start-frame', type=int, default=0)
    parser.add_argument('--skip-frames', type=int, default=1)
    parser.add_argument('--key-frequency-hz', type=int, default=10)
    parser.add_argument('--max-frames', type=int)
    # Set the threshold for something
    # parser.add_argument('--confidence-threshold', type=float, default=0.1,
    #                     help='Set the threshold needed for a face to be blurred')
    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()

    return args
コード例 #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
コード例 #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
コード例 #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()
コード例 #8
0
ファイル: eval_coco.py プロジェクト: MatanAvitan/openpifpaf
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
コード例 #9
0
ファイル: run.py プロジェクト: SpyderXu/monoloco
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
コード例 #10
0
ファイル: webcam.py プロジェクト: robocomp/robocomp-robolab
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()
コード例 #11
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")

    # Predict (2D pose and/or 3D location from images)
    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(
        '--white-overlay',
        nargs='?',
        default=False,
        const=0.8,
        type=float,
        help='increase contrast to annotations by making image whiter')
    predict_parser.add_argument('--font-size',
                                default=0,
                                type=int,
                                help='annotation font size')
    predict_parser.add_argument('--monocolor-connections',
                                default=False,
                                action='store_true',
                                help='use a single color per instance')
    predict_parser.add_argument('--instance-threshold',
                                type=float,
                                default=None,
                                help='threshold for entire instance')
    predict_parser.add_argument('--seed-threshold',
                                type=float,
                                default=0.5,
                                help='threshold for single seed')
    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)

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

    predict_parser.add_argument('--mode',
                                help='keypoints, mono, stereo',
                                default='mono')
    predict_parser.add_argument(
        '--model', help='path of MonoLoco/MonStereo model to load')
    predict_parser.add_argument(
        '--net',
        help='only to select older MonoLoco model, otherwise use --mode')
    predict_parser.add_argument(
        '--path_gt', help='path of json file with gt 3d localization')
    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))

    # Preprocess input data
    prep_parser.add_argument('--dir_ann',
                             help='directory of annotations of 2d joints',
                             required=True)
    prep_parser.add_argument('--mode', help='mono, stereo', default='mono')
    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')

    # Training
    training_parser.add_argument('--joints',
                                 help='Json file with input joints',
                                 required=True)
    training_parser.add_argument('--mode', help='mono, stereo', default='mono')
    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')
    training_parser.add_argument('--no_save',
                                 help='to not save model and log file',
                                 action='store_true')

    # Evaluation
    eval_parser.add_argument('--mode', help='mono, stereo', default='mono')
    eval_parser.add_argument('--dataset',
                             help='datasets to evaluate, kitti or nuscenes',
                             default='kitti')
    eval_parser.add_argument('--activity',
                             help='evaluate activities',
                             action='store_true')
    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('--new', help='new', action='store_true')
    eval_parser.add_argument('--variance',
                             help='evaluate keypoints variance',
                             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
コード例 #12
0
ファイル: predict.py プロジェクト: MatanAvitan/openpifpaf
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
コード例 #13
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