예제 #1
0
def main():
    logging.basicConfig(level=logging.INFO)
    modules = load_config(MODULES_CONFIG_FILENAME)

    arg_parser = build_arg_parser(modules['arg_parser'])
    ote_args = vars(arg_parser.get_compression_parser(MODEL_TEMPLATE_FILENAME).parse_args())

    if 'compression' not in modules:
        raise RuntimeError(f'Cannot make compression for the template that'
                           f' does not have "compression" field in its modules'
                           f' file {MODULES_CONFIG_FILENAME}')
    if not is_optimisation_enabled_in_template(MODEL_TEMPLATE_FILENAME):
        raise RuntimeError(f'Cannot make compression for the template that'
                           f' does not enable any of compression flags')

    arg_converter = build_arg_converter(modules['arg_converter_map'])
    compress_args = arg_converter.convert_compress_args(ote_args)

    compression_arg_transformer = build_compression_arg_transformer(modules['compression'])
    compress_args, is_optimisation_enabled = \
            compression_arg_transformer.process_args(MODEL_TEMPLATE_FILENAME, compress_args)

    if not is_optimisation_enabled:
        logging.warning('Optimization flags are not set -- compression is not made')
        return

    # Note that compression in this tool will be made by the same trainer,
    # as in the tool train.py
    # The difference is only in the argparser and in the NNCFConfigTransformer used to
    # transform the configuration file.
    trainer = build_trainer(modules['trainer'])
    trainer(**compress_args)
예제 #2
0
def main():
    logging.basicConfig(level=logging.INFO)
    modules = load_config(MODULES_CONFIG_FILENAME)

    arg_parser = build_arg_parser(modules['arg_parser'])
    ote_args = vars(arg_parser.get_train_parser(MODEL_TEMPLATE_FILENAME).parse_args())

    arg_converter = build_arg_converter(modules['arg_converter'])
    train_args = arg_converter.convert_train_args(MODEL_TEMPLATE_FILENAME, ote_args)

    # Note that compression args transformer is not applied here,
    # since NNCF compression (if it is enabled) will be applied
    # later, when the training is finished.

    trainer = build_trainer(modules['trainer'])
    trainer(**train_args)

    if modules.get('compression') and is_compression_enabled_in_template(MODEL_TEMPLATE_FILENAME):
        # TODO: think on the case if compression is enabled in template.yaml, but modules does not contain 'compression'

        latest_snapshot = trainer.get_latest_snapshot()
        if not latest_snapshot:
            raise RuntimeError('Cannot find latest snapshot to make compression after training')

        compress_args = arg_converter.convert_train_args_to_compress_args(MODEL_TEMPLATE_FILENAME, ote_args)
        arg_converter.update_converted_args_to_load_from_snapshot(compress_args, latest_snapshot)

        compression_arg_transformer = build_compression_arg_transformer(modules['compression'])
        compress_args = compression_arg_transformer.process_args(MODEL_TEMPLATE_FILENAME, compress_args)

        compress_trainer = build_trainer(modules['trainer'])
        compress_trainer(**compress_args)
예제 #3
0
def main():
    modules = load_config(MODULES_CONFIG_FILENAME)

    arg_parser = build_arg_parser(modules['arg_parser'])
    ote_args = vars(arg_parser.get_test_parser(MODEL_TEMPLATE_FILENAME).parse_args())

    arg_converter = build_arg_converter(modules['arg_converter_map'])
    eval_args = arg_converter.convert_test_args(ote_args)

    if modules.get('compression') and is_optimisation_enabled_in_template(MODEL_TEMPLATE_FILENAME):
        compression_arg_transformer = build_compression_arg_transformer(modules['compression'])
        eval_args, _ = compression_arg_transformer.process_args(MODEL_TEMPLATE_FILENAME, eval_args)

    evaluator = build_evaluator(modules['evaluator'])
    evaluator(**eval_args)
예제 #4
0
def main():
    logging.basicConfig(level=logging.INFO)
    modules = load_config(MODULES_CONFIG_FILENAME)

    arg_parser = build_arg_parser(modules['arg_parser'])
    ote_args = vars(arg_parser.get_train_parser(MODEL_TEMPLATE_FILENAME).parse_args())

    arg_converter = build_arg_converter(modules['arg_converter_map'])
    train_args = arg_converter.convert_train_args(ote_args)

    # Note that compression args transformer is not applied here,
    # since NNCF compression (if it is enabled) will be applied
    # later, when the training is finished.

    trainer = build_trainer(modules['trainer'])
    trainer(**train_args)
예제 #5
0
def main():
    logging.basicConfig(level=logging.INFO)
    modules = load_config(MODULES_CONFIG_FILENAME)

    arg_parser = build_arg_parser(modules['arg_parser'])
    ote_args = vars(
        arg_parser.get_export_parser(MODEL_TEMPLATE_FILENAME).parse_args())

    if modules.get('compression') and is_compression_enabled_in_template(
            MODEL_TEMPLATE_FILENAME):
        compression_arg_transformer = build_compression_arg_transformer(
            modules['compression'])
        ote_args = compression_arg_transformer.process_args(
            MODEL_TEMPLATE_FILENAME, ote_args)

    exporter = build_exporter(modules['exporter'])
    exporter(ote_args)