예제 #1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-c',
                        '--config',
                        type=Path,
                        metavar='CONFIG.YML',
                        default=common.get_default_config_path(),
                        help='topology configuration file')
    parser.add_argument(
        '--name',
        metavar='PAT[,PAT...]',
        help=
        'only dump info for topologies whose names match at least one of the specified patterns'
    )
    parser.add_argument(
        '--list',
        type=Path,
        metavar='FILE.LST',
        help=
        'only dump info for topologies whose names match at least one of the patterns in the specified file'
    )
    parser.add_argument(
        '--all',
        action='store_true',
        help='dump info for all topologies from the configuration file')
    parser.add_argument('--print_all',
                        action='store_true',
                        help='print all available topologies')
    args = parser.parse_args()

    topologies = common.load_topologies_from_args(parser, args)

    json.dump(list(map(to_info, topologies)), sys.stdout, indent=4)
    print()  # add a final newline
예제 #2
0
parser.add_argument('--name', metavar = 'PAT[,PAT...]',
    help = 'download only topologies whose names match at least one of the specified patterns')
parser.add_argument('--list', type = Path, metavar = 'FILE.LST',
    help = 'download only topologies whose names match at least one of the patterns in the specified file')
parser.add_argument('--all',  action = 'store_true', help = 'download all topologies from the configuration file')
parser.add_argument('--print_all', action = 'store_true', help = 'print all available topologies')
parser.add_argument('-o', '--output_dir', type = Path, metavar = 'DIR',
    default = Path.cwd(), help = 'path where to save topologies')
parser.add_argument('--cache_dir', type = Path, metavar = 'DIR',
    help = 'directory to use as a cache for downloaded files')
parser.add_argument('--num_attempts', type = positive_int_arg, metavar = 'N', default = 1,
    help = 'attempt each download up to N times')

args = parser.parse_args()
cache = NullCache() if args.cache_dir is None else DirCache(args.cache_dir)
topologies = common.load_topologies_from_args(parser, args)

print('')
print('###############|| Downloading topologies ||###############')
print('')
with requests.Session() as session:
    for top in topologies:
        output = args.output_dir / top.subdirectory
        output.mkdir(parents=True, exist_ok=True)

        for top_file in top.files:
            destination = output / top_file.name

            try_retrieve(top.name, destination, top_file.sha256, cache, args.num_attempts,
                lambda: top_file.source.start_download(session, CHUNK_SIZE, top_file.size))
예제 #3
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('-c', '--config', type=Path, metavar='CONFIG.YML',
        default=common.get_default_config_path(), help='topology configuration file')
    parser.add_argument('-d', '--download_dir', type=Path, metavar='DIR',
        default=Path.cwd(), help='root of the directory tree with downloaded topology files')
    parser.add_argument('-o', '--output_dir', type=Path, metavar='DIR',
        help='root of the directory tree to place converted files into')
    parser.add_argument('--name', metavar='PAT[,PAT...]',
        help='convert only topologies whose names match at least one of the specified patterns')
    parser.add_argument('--list', type=Path, metavar='FILE.LST',
        help='convert only topologies whose names match at least one of the patterns in the specified file')
    parser.add_argument('--all', action='store_true', help='convert all topologies from the configuration file')
    parser.add_argument('--print_all', action='store_true', help='print all available topologies')
    parser.add_argument('-p', '--python', type=Path, metavar='PYTHON', default=sys.executable,
        help='Python executable to run Model Optimizer with')
    parser.add_argument('--mo', type=Path, metavar='MO.PY',
        help='Model Optimizer entry point script')
    parser.add_argument('--dry-run', action='store_true',
        help='Print the conversion commands without running them')
    args = parser.parse_args()

    mo_path = args.mo
    if mo_path is None:
        try:
            mo_path = Path(os.environ['INTEL_OPENVINO_DIR']) / 'deployment_tools/model_optimizer/mo.py'
        except KeyError:
            sys.exit('Unable to locate Model Optimizer. '
                + 'Use --mo or run setupvars.sh/setupvars.bat from the OpenVINO toolkit.')

    topologies = common.load_topologies_from_args(parser, args)

    output_dir = args.download_dir if args.output_dir is None else args.output_dir

    failed_topologies = set()

    for top in topologies:
        if top.mo_args is None:
            print('========= Skipping {} (no conversion defined)'.format(top.name))
            print()
            continue

        expanded_mo_args = [
            string.Template(arg).substitute(dl_dir=args.download_dir / top.subdirectory, mo_dir=mo_path.parent)
            for arg in top.mo_args]

        assert len(top.precisions) == 1 # only one precision per model is supported at the moment

        mo_cmd = [str(args.python), '--', str(mo_path),
            '--output_dir={}'.format(output_dir / top.subdirectory / next(iter(top.precisions))),
            '--model_name={}'.format(top.name),
            *expanded_mo_args]

        print('========= {}Converting {}'.format('(DRY RUN) ' if args.dry_run else '', top.name))

        print('Conversion command:', ' '.join(map(quote_arg, mo_cmd)))

        if not args.dry_run:
            print(flush=True)

            if subprocess.run(mo_cmd).returncode != 0:
                failed_topologies.add(top.name)

        print()

    if failed_topologies:
        print('FAILED:')
        print(*sorted(failed_topologies), sep='\n')
        sys.exit(1)