def test_input_shape(self, mock_argparse):
        main(argparse.ArgumentParser(), fem, 'mock_mo_ngraph_frontend')
        stat = get_model_statistic()

        # verify that 'set_partial_shape' was called
        assert stat.set_partial_shape == 1
        assert stat.lastArgPartialShape == PartialShape([1, 2, 3, 4])
    def test_element_type(self, mock_argparse):
        main(argparse.ArgumentParser(), fem, 'mock_mo_ngraph_frontend')
        stat = get_model_statistic()

        # verify that 'set_element_type' was called
        assert stat.set_element_type == 1
        assert stat.lastArgElementType == get_element_type(np.int8)
    def test_extract_subgraph(self, mock_argparse):
        main(argparse.ArgumentParser(), fem, 'mock_mo_ngraph_frontend')
        stat = get_model_statistic()

        # verify that 'extract_subgraph' was called
        assert stat.override_all_inputs == 0
        assert stat.override_all_outputs == 0
        assert stat.extract_subgraph == 1
    def test_override_same_outputs(self, mock_argparse):

        main(argparse.ArgumentParser(), fem, 'mock_mo_ngraph_frontend')
        stat = get_model_statistic()

        # verify that 'override_all_inputs' was called
        # because outputs were not changed
        assert stat.override_all_inputs == 1
        assert stat.override_all_outputs == 0
        assert stat.extract_subgraph == 0
    def test_set_batch_size(self, mock_argparse):
        mock_return_partial_shape(PartialShape([-1, 2, 3, 4]))
        main(argparse.ArgumentParser(), fem, 'mock_mo_ngraph_frontend')
        stat = get_model_statistic()

        # verify that 'set_element_type' was called
        # 2 is because mock model has 2 inputs
        assert stat.get_partial_shape == 2
        assert stat.set_partial_shape == 2
        assert stat.lastArgPartialShape == PartialShape([123, 2, 3, 4])
    def test_error_input_model_no_framework(self, mock_argparse):
        # Framework is not specified and 'abc.qwerty' is not supported
        # so MO shall not convert anything and produce specified error
        with self.assertLogs() as logger:
            main(argparse.ArgumentParser(), fem, None)

        stat = get_frontend_statistic()

        assert [s for s in logger.output if 'can not be deduced' in s]

        # verify that 'supported' was called
        assert stat.supported == 1
    def test_error_batch(self, mock_argparse):
        # First dimension doesn't look like a batch,
        # so MO shall not convert anything and produce specified error
        mock_return_partial_shape(PartialShape([122, 2, 3, 4]))
        with self.assertLogs() as logger:
            main(argparse.ArgumentParser(), fem, 'mock_mo_ngraph_frontend')

        stat = get_model_statistic()

        assert [s for s in logger.output if 'question=39' in s]

        # verify that 'get_element_type' was called
        assert stat.get_partial_shape == 1
        # verify that 'set_element_type' was not called
        assert stat.set_partial_shape == 0
    def test_simple_convert(self, mock_argparse):
        f = io.StringIO()
        with redirect_stdout(f):
            main(argparse.ArgumentParser(), fem, 'mock_mo_ngraph_frontend')
            out = f.getvalue()

        xml_file = re.search(r'\[ SUCCESS \] XML file: (.*)', out).\
            group(1).replace("\r", "")
        bin_file = re.search(r'\[ SUCCESS \] BIN file: (.*)', out).\
            group(1).replace("\r", "")
        assert xml_file and bin_file

        # verify that 'convert' was called
        stat = get_frontend_statistic()
        assert stat.convert_model == 1
        # verify that meta info is added to XML file
        with open(xml_file) as file:
            assert 'mock_mo_ngraph_frontend' in file.read()
예제 #9
0
def converter_main():
    warnings.filterwarnings("ignore", category=FutureWarning)
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    ret_code = check_python_version()
    if ret_code:
        sys.exit(ret_code)

    from mo.main import main
    from mo.utils.cli_parser import get_all_cli_parser  # pylint: disable=no-name-in-module

    sys.exit(main(get_all_cli_parser(), None))
예제 #10
0
def convert(model, **args):
    mo.main.prepare_ir = _prepare_ir

    parser = get_common_cli_parser()
    parser.set_defaults(input_model=model, extensions=os.path.join(os.path.dirname(__file__), 'mo_extensions'))
    for arg, value in args.items():
        parser.set_defaults(**{arg: str(value)})

    err = main(parser, 'pytorch')
    if err:
        raise Exception('model conversion failed')
    def test_convert_framework_discover(self, mock_argparse):
        f = io.StringIO()
        with redirect_stdout(f):
            main(argparse.ArgumentParser(), fem, None)
            out = f.getvalue()

        xml_file = re.search(r'\[ SUCCESS \] XML file: (.*)', out). \
            group(1).replace("\r", "")
        bin_file = re.search(r'\[ SUCCESS \] BIN file: (.*)', out). \
            group(1).replace("\r", "")
        assert xml_file and bin_file

        # verify that 'convert', 'supported' and 'get_name' were called
        stat = get_frontend_statistic()
        assert stat.convert_model == 1
        assert stat.supported == 1
        assert stat.get_name > 0

        # verify that meta info is added to XML file
        with open(xml_file) as file:
            assert 'mock_mo_ov_frontend' in file.read()
def convert(model, **args):
    mo.main.prepare_ir = _prepare_ir

    parser = get_common_cli_parser()
    parser.set_defaults(input_model=model,
                        extensions=os.path.join(os.path.dirname(__file__),
                                                'mo_extensions'),
                        ie_is_available=False)
    for arg, value in args.items():
        parser.set_defaults(**{arg: str(value)})

    # Replace original parser to ignore global sys.argv
    origin_parse = parser.parse_args
    parser.parse_args = lambda: origin_parse([])

    err = None
    try:
        err = main(parser, None, 'pytorch')
    except:
        if err is None:
            mo.main.prepare_ir = lambda argv: _prepare_ir(argv, old_api=True)
            err = main(parser, 'pytorch')
    if err:
        raise Exception('model conversion failed')
예제 #13
0
#!/usr/bin/env python3
"""
 Copyright (C) 2018-2021 Intel Corporation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
"""

import sys

from mo.utils.versions_checker import check_python_version

if __name__ == "__main__":
    ret_code = check_python_version()
    if ret_code:
        sys.exit(ret_code)

    from mo.main import main
    from mo.utils.cli_parser import get_onnx_cli_parser

    sys.exit(main(get_onnx_cli_parser(), 'onnx'))
예제 #14
0
#!/usr/bin/env python3

# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys

from mo.utils.versions_checker import check_python_version

if __name__ == "__main__":
    ret_code = check_python_version()
    if ret_code:
        sys.exit(ret_code)

    from mo.main import main
    from mo.utils.cli_parser import get_mxnet_cli_parser

    sys.exit(main(get_mxnet_cli_parser(), 'mxnet'))
예제 #15
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'))
예제 #16
0
"""

import warnings
import sys

from mo.utils.versions_checker import check_python_version  # pylint: disable=no-name-in-module


def mo_main():
    sys.stderr.write(
        "WARNING: 'mo' command deprecated in favour of 'converter'. 'mo' will be removed in a future release'\n"
    )
    converter_main()


def converter_main():
    warnings.filterwarnings("ignore", category=FutureWarning)
    warnings.filterwarnings("ignore", category=DeprecationWarning)
    ret_code = check_python_version()
    if ret_code:
        sys.exit(ret_code)

    from mo.main import main
    from mo.utils.cli_parser import get_all_cli_parser  # pylint: disable=no-name-in-module

    sys.exit(main(get_all_cli_parser(), None))


if __name__ == "__main__":
    main()
예제 #17
0
파일: mo_tf.py 프로젝트: pc2/CustoNN2
#!/usr/bin/env python3
"""
 Copyright (c) 2018 Intel Corporation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
"""

import sys

from mo.utils.versions_checker import check_python_version

if __name__ == "__main__":
    ret_code = check_python_version()
    if ret_code:
        sys.exit(ret_code)

    from mo.main import main
    from mo.utils.cli_parser import get_tf_cli_parser

    sys.exit(main(get_tf_cli_parser(), 'tf'))
예제 #18
0
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys

from mo.utils.cli_parser import get_all_cli_parser

from ngraph.frontend import FrontEndManager  # pylint: disable=no-name-in-module,import-error


if __name__ == "__main__":
    from mo.main import main
    fem = FrontEndManager()
    sys.exit(main(get_all_cli_parser(fem), fem, 'paddle'))
예제 #19
0
파일: mo_kaldi.py 프로젝트: yuxu42/openvino
#!/usr/bin/env python3

# Copyright (C) 2018-2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys

from mo.utils.versions_checker import check_python_version

if __name__ == "__main__":
    ret_code = check_python_version()
    if ret_code:
        sys.exit(ret_code)

    from mo.main import main
    from mo.utils.cli_parser import get_kaldi_cli_parser

    sys.exit(main(get_kaldi_cli_parser(), 'kaldi'))
예제 #20
0
#!/usr/bin/env python3
"""
 Copyright (c) 2018-2019 Intel Corporation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
"""

import sys

from mo.utils.versions_checker import check_python_version  # pylint: disable=no-name-in-module

if __name__ == "__main__":
    ret_code = check_python_version()
    if ret_code:
        sys.exit(ret_code)

    from mo.main import main
    from mo.utils.cli_parser import get_all_cli_parser  # pylint: disable=no-name-in-module

    sys.exit(main(get_all_cli_parser(), None))
예제 #21
0
# Copyright (C) 2021 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys

from mo.utils.cli_parser import get_all_cli_parser

from ngraph.frontend import FrontEndManager  # pylint: disable=no-name-in-module,import-error

if __name__ == "__main__":
    from mo.main import main
    fem = FrontEndManager()
    sys.exit(main(get_all_cli_parser(fem), fem, 'pdpd'))
예제 #22
0
 def test_FrameworkError(self, mock_argparse, mock_driver):
     with self.assertLogs() as logger:
         main(argparse.ArgumentParser(), None, 'framework_string')
         self.assertEqual(logger.output, ['ERROR:root:FW ERROR MESSAGE'])
예제 #23
0
#!/usr/bin/env python3
"""
 Copyright (C) 2018-2021 Intel Corporation

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
"""

import sys

from mo.utils.versions_checker import check_python_version

if __name__ == "__main__":
    ret_code = check_python_version()
    if ret_code:
        sys.exit(ret_code)

    from mo.main import main
    from mo.utils.cli_parser import get_caffe_cli_parser

    sys.exit(main(get_caffe_cli_parser(), 'caffe'))
def convert_to_openvino(args, input_dims, graph_chars):
    if args.transformations_config is None:
        print(
            "Error:--transformations_config args are required for openvino conversion"
        )
        return

    if args.openvino_dir is None:
        openvino_dir = os.getenv("INTEL_OPENVINO_DIR")
        if openvino_dir is None:
            print(
                "Could not find an OpenVINO installation. Assuming location in /opt/intel/openvino, but check that"
                "OpenVINO is installed")
            openvino_dir = "/opt/intel/openvino"
    else:
        openvino_dir = args.openvino_dir

    sys.path.insert(1, openvino_dir + "/deployment_tools/model_optimizer")
    from mo.main import main
    from mo.utils.cli_parser import get_tf_cli_parser

    sys.argv = ['']

    # Set input model
    sys.argv.append("--input_model")
    sys.argv.append(args.input)

    # Set transformation config
    sys.argv.append("--transformations_config")
    sys.argv.append(args.transformations_config)

    # Set pipeline
    if args.pipeline_config is None:
        sp = args.input.rsplit('/', 1)
        if len(sp) == 1:
            localdir = './'
        else:
            localdir = sp[0] + '/'
        pipelines = glob.glob(localdir + '*.config')
        if len(pipelines) != 1:
            print("Error: No clear pipeline file")
            exit(1)
        args.pipeline_config = pipelines[0]
    sys.argv.append("--tensorflow_object_detection_api_pipeline_config")
    sys.argv.append(args.pipeline_config)

    # Set input dimensions
    sys.argv.append("--input_shape")
    sys.argv.append(str(input_dims))

    # Check reversal
    if args.channel_order == "RGB":
        sys.argv.append("--reverse_input_channels")

    # Set output dir
    sys.argv.append("--output_dir")
    sys.argv.append(args.output_dir.rsplit('/', 1)[0] + '/')

    # Set output nodes
    sys.argv.append("--output")
    sys.argv.append(','.join([node.name for node in graph_chars.output_nodes]))

    main(get_tf_cli_parser(), 'tf')