コード例 #1
0
def main():
    # Use first line of file docstring as description if it exists.
    parser = argparse.ArgumentParser(
        description=__doc__.split('\n')[0] if __doc__ else '',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--config', default=Path('./release/config.yaml'))
    args = parser.parse_args()

    with open(args.config, 'r') as f:
        config = yaml.load(f)

    output_root = Path(config['davis16']['output_dir'])
    flow_output = output_root / 'flow'
    flow_output.mkdir(exist_ok=True, parents=True)

    common_setup(__file__, flow_output, args)
    logging.debug('Config:\n%s', pprint.pformat(config))

    split_dirs = link_splits(config)
    for split in config['davis16']['splits']:
        input_dir = split_dirs[split][0]
        output_split = flow_output / split
        msg("Computing flow on DAVIS 2016 %s set.")
        compute_flow_helper(config,
                            input_dir,
                            output_split,
                            extensions=['.jpg'])
コード例 #2
0
def main():
    # Use first line of file docstring as description if it exists.
    parser = argparse.ArgumentParser(
        description=__doc__.split('\n')[0] if __doc__ else '',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--config', default=Path('./release/config.yaml'))
    parser.add_argument('--frames-dir', type=Path, required=True)
    parser.add_argument('--output-dir', type=Path, required=True)
    parser.add_argument('--extensions', nargs='*', default=IMG_EXTENSIONS)
    args = parser.parse_args()

    with open(args.config, 'r') as f:
        config = yaml.load(f)

    args.output_dir.mkdir(exist_ok=True, parents=True)
    common_setup(__file__, args.output_dir)
    logging.debug('Args:\n%s', pprint.pformat(vars(args)))
    logging.debug('Config:\n%s', pprint.pformat(config))

    msg(f"Computing flow on {args.frames_dir}.")
    compute_flow_helper(config,
                        args.frames_dir,
                        args.output_dir,
                        extensions=args.extensions,
                        recursive=True)
コード例 #3
0
def main():
    # Use first line of file docstring as description if it exists.
    parser = argparse.ArgumentParser(
        description=__doc__.split('\n')[0] if __doc__ else '',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--config', default=Path('./release/config.yaml'))

    args = parser.parse_args()

    with open(args.config, 'r') as f:
        config = yaml.load(f)

    output_dir = Path(config['davis17']['output_dir']) / 'tracks'
    output_dir.mkdir(exist_ok=True, parents=True)

    common_setup(__file__, output_dir, args)

    split_dirs = link_splits(config)
    for split in config['davis17']['splits']:
        image_dir = split_dirs[split][0]
        init_detections = (Path(config['davis17']['output_dir']) /
                           'detections' / split)
        output_split = Path(output_dir) / split
        args = [
            '--images-dir', image_dir, '--init-detections-dir',
            init_detections, '--output-dir', output_split, '--save-numpy',
            True, '--save-images', False, '--bidirectional',
            '--score-init-min', 0.9, '--remove-continue-overlap', 0.1, '--fps',
            30, '--filename-format', 'frame', '--save-video',
            config['tracker']['visualize'], '--recursive'
        ]
        cmd = ['python', 'tracker/two_detector_track.py'] + args
        msg(f'Running tracker on DAVIS {split}')
        subprocess_call(cmd)
コード例 #4
0
def evaluate_official(config):
    track_output = Path(config['fbms']['output_dir'] / 'tracks')
    check_tracks(track_output)

    for split in config['fbms']['splits']:
        np_dir = track_output / split
        dat_dir = np_dir / 'dat'
        if not check_dat(track_output, split):
            cmd = [
                'python', 'fbms/numpy_to_dat.py', '--numpy-dir', np_dir,
                '--output-dir', dat_dir, '--fbms-groundtruth',
                Path(config['fbms']['root']) / split
            ]
            msg(f'Converting {split} numpy predictions to .dat')
            logging.info('This may take a few minutes...')
            subprocess_call(cmd)
            assert check_dat(track_output, split)

        eval_binary = Path(config['fbms']['eval_dir']) / 'MoSegEvalAllPR'
        cmd = [
            'python', 'fbms/eval_official.py', '--eval-binary', eval_binary,
            '--predictions-dir', dat_dir, '--split', 'all'
        ]
        msg(f'Evaluating {split}')
        subprocess_call(cmd)
コード例 #5
0
def main():
    # Use first line of file docstring as description if it exists.
    parser = argparse.ArgumentParser(
        description=__doc__.split('\n')[0] if __doc__ else '',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--config', default=Path('./release/config.yaml'))
    parser.add_argument('--frames-dir', required=True, type=Path)
    parser.add_argument('--detections-dir', required=True, type=Path)
    parser.add_argument('--output-dir', required=True, type=Path)

    parser.add_argument('--save-numpy', type=parse_bool, default=True)
    parser.add_argument('--save-images', type=parse_bool, default=False)
    parser.add_argument('--save-video', type=parse_bool, default=True)
    parser.add_argument('--fps', default=30, type=float)
    parser.add_argument('--model',
                        choices=['joint', 'appearance', 'motion'],
                        default='joint')
    parser.add_argument(
        '--filename-format',
        choices=[
            'frame', 'frameN', 'sequence_frame', 'sequence-frame', 'fbms'
        ],
        required=True,
        help=('Specifies how to get frame number from the filename. '
              '"frame": the filename is the frame number, '
              '"frameN": format <frame><number>, '
              '"sequence_frame": frame number is separated by an underscore, '
              '"sequence-frame": frame number is separated by a dash, '
              '"fbms": assume fbms style frame numbers'))

    args = parser.parse_args()

    with open(args.config, 'r') as f:
        config = yaml.load(f)

    args.output_dir.mkdir(exist_ok=True, parents=True)

    common_setup(__file__, args.output_dir)
    logging.debug('Args:\n%s', pprint.pformat(vars(args)))

    if args.model == 'joint':
        detections_args = ['--init-detections-dir', args.detections_dir]
        script = 'tracker/two_detector_track.py'
        extra_args = ['--remove-continue-overlap', 0.1, '--recursive']
    else:
        detections_args = ['--detections-dir', args.detections_dir]
        script = 'tracker/track_multiple.py'
        extra_args = []

    args = ['--images-dir', args.frames_dir] + detections_args + [
        '--output-dir', args.output_dir, '--save-numpy', args.save_numpy,
        '--save-images', args.save_images, '--save-video', args.save_video,
        '--bidirectional', '--score-init-min', 0.9, '--fps', args.fps,
        '--filename-format', args.filename_format, '--quiet'
    ] + extra_args
    cmd = ['python', script] + args
    msg(f'Running tracker')
    subprocess_call(cmd)
コード例 #6
0
ファイル: run.py プロジェクト: zhanght021/segment-any-moving
def main():
    # Use first line of file docstring as description if it exists.
    parser = argparse.ArgumentParser(
        description=__doc__.split('\n')[0] if __doc__ else '',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--frames-dir', type=Path, required=True)
    parser.add_argument('--output-dir', type=Path, required=True)
    parser.add_argument('--model',
                        default='joint',
                        choices=['joint', 'appearance', 'motion'])
    parser.add_argument(
        '--filename-format',
        choices=[
            'frame', 'frameN', 'sequence_frame', 'sequence-frame', 'fbms'
        ],
        required=True,
        help=('Specifies how to get frame number from the filename. '
              '"frame": the filename is the frame number, '
              '"frameN": format "frame<number>", '
              '"sequence_frame": frame number is separated by an underscore, '
              '"sequence-frame": frame number is separated by a dash, '
              '"fbms": assume fbms style frame numbers'))
    parser.add_argument('--config', default=Path('./release/config.yaml'))

    args = parser.parse_args()

    args.output_dir.mkdir(exist_ok=True, parents=True)
    common_setup(__file__, args.output_dir, args)

    flow_dir = args.output_dir / 'flow'
    if args.model != 'appearance':
        subprocess_call([
            'python', 'release/custom/compute_flow.py', '--frames-dir',
            args.frames_dir, '--config', args.config, '--output-dir', flow_dir
        ])

    output_dir = args.output_dir / args.model
    detections_dir = output_dir / 'detections'
    subprocess_call([
        'python', 'release/custom/infer.py', '--frames-dir', args.frames_dir,
        '--flow-dir', flow_dir, '--model', args.model, '--config', args.config,
        '--output-dir', detections_dir
    ])

    tracks_dir = output_dir / 'tracks'
    subprocess_call([
        'python', 'release/custom/track.py', '--frames-dir', args.frames_dir,
        '--detections-dir', detections_dir, '--filename-format',
        args.filename_format, '--config', args.config, '--model', args.model,
        '--output-dir', tracks_dir
    ])

    msg(f'Output results to: {tracks_dir}')
コード例 #7
0
def evaluate_proposed(config, output_stage):
    if output_stage == 'detection':
        input_dir = (Path(config['davis16']['output_dir']) / 'detections')
    elif output_stage == 'tracking':
        input_dir = (Path(config['davis16']['output_dir']) / 'tracks')
    else:
        raise ValueError(f'Unknown output stage: {output_stage}')

    for split in config['davis16']['splits']:
        masks_dir = input_dir / split / 'masks' / 'masks'
        cmd = ['python', 'davis/eval_fgbg.py', '--masks-dir', masks_dir]
        msg(f'Evaluating {split}')
        subprocess_call(cmd)
コード例 #8
0
def evaluate_proposed(config):
    track_output = Path(config['fbms']['output_dir']) / 'tracks'
    check_tracks(track_output, config['fbms']['splits'])

    for split in config['fbms']['splits']:
        np_dir = track_output / split

        cmd = [
            'python', 'fbms/eval_custom.py', '--npy-extension', '.npz',
            '--eval-type', 'fbms', '--background-id', 0, '--groundtruth-dir',
            Path(config['fbms']['root']) / split, '--predictions-dir', np_dir
        ]
        msg(f'Evaluating {split}')
        subprocess_call(cmd)
コード例 #9
0
def evaluate_proposed(config):
    track_output = Path(config['davis17']['output_dir']) / 'tracks'
    check_tracks(track_output, config['davis17']['splits'])

    split_dirs = link_splits(config)
    for split in config['davis17']['splits']:
        np_dir = track_output / split
        annotations_dir = split_dirs[split][1]

        cmd = [
            'python', 'fbms/eval_custom.py', '--npy-extension', '.npz',
            '--eval-type', 'davis', '--background-id', 0, '--groundtruth-dir',
            annotations_dir, '--predictions-dir', np_dir
        ]
        msg(f'Evaluating {split}')
        subprocess_call(cmd)
コード例 #10
0
def main():
    # Use first line of file docstring as description if it exists.
    parser = argparse.ArgumentParser(
        description=__doc__.split('\n')[0] if __doc__ else '',
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)
    parser.add_argument('--config', default=Path('./release/config.yaml'))
    parser.add_argument('--frames-dir',
                        type=Path,
                        help='Required unless --model set to "motion"')
    parser.add_argument('--flow-dir',
                        type=Path,
                        help='Required unless --model set to "appearance".')
    parser.add_argument('--output-dir', type=Path, required=True)
    parser.add_argument('--visualize', action='store_true')
    parser.add_argument('--model',
                        choices=['joint', 'appearance', 'motion'],
                        default='joint')

    args = parser.parse_args()

    if args.model != 'appearance':
        assert args.flow_dir and args.flow_dir.exists(), (
            f'--flow-dir must be specified for --model {args.model}')

    if args.model != 'motion':
        assert args.frames_dir and args.frames_dir.exists(), (
            f'--frames-dir must be specified for --model {args.model}')

    with open(args.config, 'r') as f:
        config = yaml.load(f)

    args = parser.parse_args()
    args.output_dir.mkdir(exist_ok=True, parents=True)
    common_setup(__file__, args.output_dir)
    logging.debug('Args:\n%s', pprint.pformat(vars(args)))

    detectron_dir = (Path(__file__).resolve().parent.parent.parent /
                     'detectron_pytorch')

    model_config, model = get_config_ckpt(config['model'][args.model]['dir'],
                                          config['model'][args.model]['step'])

    maybe_combine_appearance = []
    if args.model == 'joint':
        appearance_config, appearance_model = get_config_ckpt(
            config['model']['appearance']['dir'],
            config['model']['appearance']['step'])
        maybe_combine_appearance = [
            '--load_appearance_ckpt', appearance_model, '--set',
            'MODEL.MERGE_WITH_APPEARANCE.ENABLED', 'True'
        ]
        image_dirs = ['--image_dirs', args.frames_dir, args.flow_dir]
        input_type = ['--input_type', 'rgb', 'flow']
    elif args.model == 'appearance':
        maybe_combine_appearance = []
        image_dirs = ['--image_dirs', args.frames_dir]
        input_type = ['--input_type', 'rgb']
    elif args.model == 'motion':
        maybe_combine_appearance = []
        image_dirs = ['--image_dirs', args.flow_dir]
        input_type = ['--input_type', 'flow']

    msg(f'Running {args.model} model on {image_dirs[1].resolve()}')

    cmd = ['python', 'tools/infer_simple.py']
    args = (['--cfg', model_config, '--num_classes', 2, '--load_ckpt', model] +
            maybe_combine_appearance + image_dirs + input_type + [
                '--save_images', args.visualize, '--output_dir',
                args.output_dir, '--quiet', '--recursive'
            ])
    subprocess_call(cmd + args, cwd=str(detectron_dir))