Пример #1
0
def apply_offline_transformations(input_model: str, framework: str, transforms: list, compress_fp16=False):
    # This variable is only needed by GenerateMappingFile transformation
    # to produce correct mapping
    extract_names = framework in ['tf', 'mxnet', 'kaldi']

    from openvino.offline_transformations import GenerateMappingFile, Serialize  # pylint: disable=import-error,no-name-in-module
    from openvino.inference_engine import IENetwork  # pylint: disable=import-error,no-name-in-module
    from ngraph.frontend import FrontEndManager, FrontEnd  # pylint: disable=no-name-in-module,import-error
    from ngraph.impl import Function  # pylint: disable=no-name-in-module,import-error

    fem = FrontEndManager()

    # We have to separate fe object lifetime from fem to
    # avoid segfault during object destruction. So fe must
    # be destructed before fem object explicitly.
    def read_network(path_to_xml):
        fe = fem.load_by_framework(framework="ir")
        f = fe.convert(fe.load(path_to_xml))
        return IENetwork(Function.to_capsule(f))

    net = read_network(input_model + "_tmp.xml")

    apply_user_transformations(net, transforms)
    apply_moc_transformations(net)

    if compress_fp16:
        compress_model(net)

    Serialize(net, str(input_model + ".xml").encode('utf-8'), (input_model + ".bin").encode('utf-8'))
    path_to_mapping = input_model + ".mapping"
    GenerateMappingFile(net, path_to_mapping.encode('utf-8'), extract_names)
Пример #2
0
        if analysis_results.get_messages() is not None:
            for el in analysis_results.get_messages():
                log.error(el, extra={'analysis_info': True})
        log.error(err)
        log.debug(traceback.format_exc())
    except FrameworkError as err:
        log.error(err, extra={'framework_error': True})
        log.debug(traceback.format_exc())
    except Exception as err:
        log.error("-------------------------------------------------")
        log.error("----------------- INTERNAL ERROR ----------------")
        log.error("Unexpected exception happened.")
        log.error(
            "Please contact Model Optimizer developers and forward the following information:"
        )
        log.error(str(err))
        log.error(traceback.format_exc())
        log.error("---------------- END OF BUG REPORT --------------")
        log.error("-------------------------------------------------")

    telemetry.send_event('mo', 'conversion_result', 'fail')
    telemetry.end_session('mo')
    telemetry.force_shutdown(1.0)
    return 1


if __name__ == "__main__":
    from mo.utils.cli_parser import get_all_cli_parser
    fe_manager = FrontEndManager()
    sys.exit(main(get_all_cli_parser(fe_manager), fe_manager, None))
Пример #3
0
    return make_model(graph, producer_name="ngraph ONNX Importer")


def run_function(function, *inputs, expected):
    runtime = get_runtime()
    computation = runtime.computation(function)
    actual = computation(*inputs)
    assert len(actual) == len(expected)
    for i in range(len(actual)):
        np.testing.assert_allclose(expected[i],
                                   actual[i],
                                   rtol=1e-3,
                                   atol=1e-6)


fem = FrontEndManager()
onnx_model_filename = "model.onnx"
ONNX_FRONTEND_NAME = "onnx_experimental"


def setup_module():
    onnx.save_model(create_onnx_model(), onnx_model_filename)


def teardown_module():
    os.remove(onnx_model_filename)


def skip_if_onnx_frontend_is_disabled():
    front_ends = fem.get_available_front_ends()
    if ONNX_FRONTEND_NAME not in front_ends:
Пример #4
0
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys

from mo.utils.cli_parser import get_onnx_cli_parser

if __name__ == "__main__":
    from mo.main import main
    from ngraph.frontend import FrontEndManager  # pylint: disable=no-name-in-module,import-error

    sys.exit(main(get_onnx_cli_parser(), FrontEndManager(), 'onnx'))