Files
openvino/model-optimizer/mo/utils/check_ie_bindings.py
T
Gleb Kazantaev 5d647e6fab Add IE Python Dependency To MO (#4151)
* Added script that check IE existance

* Updated install_prerequisites.sh to check and insall IE python dependency

* Execute MOC transformation pipeline in subprocess

* Updated path to offline_transformations.py

* Updated IE dependency search; added libs search support

* Updated install_prerequisites.bat to check IE dependency

* Print warning if MO and IE versions do not match

* Set env before subprocess run

* Add mean and meta info to serialized IR

* Fix pylin import issue

* Update BOM file; added intel headers

* use default serialization; code style fix

* Codestyle

* Added subprocess timeout

* Check e2e status

* Update install_prerequisites.sh logic

* Update MO version to be generated even without cmake execution

* Update install_prereq to extract release version from python

* Simplify pyhton code

* Reduce memory consumtion to its original value

* Added OV find and search logic for windows batch script

* Remove model reading to avoid excess memory consumtption

* IMproved logging messages; simplified code

* Improved warnign message incase when MO and IE versions mismatch

* Fix test import

* Check IE bindings in the beginnig of MO pipeline

* Changed warning message; added RelWithDebInfo path

* Recomendation to build IE from source

* Resolve PR comments

* Apply review comments; Added CheckAPI pass

* Added path to IE local libs

* ModelOptimizer -> Model Optimizer (+IE)

* OpenVINO -> OpenVINO (TM) Toolkit

* Updated install_prerequisites.bat with new logic

* Move offline_transformations.py to back folder; improve warning mesages experience

* Update install_prerequisites.bat

* Move back some unnecessary changes

* Fix BOM

* Disable import errors for pylint

* Fixed grammar in messages

* pylint disable import error

* Final grammar fixes in bat and sh files
2021-02-19 14:13:20 +03:00

77 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""
Copyright (C) 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 os
import re
import argparse
try:
# needed by find_ie_version.py which call check_ie_bindings.py as python script
import version # pylint: disable=import-error
except ImportError:
import mo.utils.version
from extract_release_version import extract_release_version
def import_core_modules(silent: bool, path_to_module: str):
try:
from openvino.inference_engine import IECore, get_version # pylint: disable=import-error
from openvino.offline_transformations import ApplyMOCTransformations, CheckAPI # pylint: disable=import-error
import openvino # pylint: disable=import-error
ie_version = str(get_version())
mo_version = str(version.get_version()) # pylint: disable=no-member
if not silent:
print("\t- {}: \t{}".format("Inference Engine found in", os.path.dirname(openvino.__file__)))
print("{}: \t{}".format("Inference Engine version", ie_version))
print("{}: \t {}".format("Model Optimizer version", mo_version))
# MO and IE version have a small difference in the beginning of version because
# IE version also includes API version. For example:
# Inference Engine version: 2.1.custom_HEAD_4c8eae0ee2d403f8f5ae15b2c9ad19cfa5a9e1f9
# Model Optimizer version: custom_HEAD_4c8eae0ee2d403f8f5ae15b2c9ad19cfa5a9e1f9
# So to match this versions we skip IE API version.
if not re.match(r"^([0-9]+).([0-9]+).{}$".format(mo_version), ie_version):
extracted_release_version = extract_release_version()
is_custom_mo_version = extracted_release_version == (None, None)
if not silent:
print("[ WARNING ] Model Optimizer and Inference Engine versions do no match.")
print("[ WARNING ] Consider building the Inference Engine Python API from sources or reinstall OpenVINO (TM) toolkit using \"pip install openvino{}\" {}".format(
"", "(may be incompatible with the current Model Optimizer version)" if is_custom_mo_version else "=={}.{}".format(*extracted_release_version), ""))
return True
except Exception as e:
# Do not print a warning if module wasn't found or silent mode is on
if "No module named 'openvino'" not in str(e) and not silent:
print("[ WARNING ] Failed to import Inference Engine Python API in: {}".format(path_to_module))
print("[ WARNING ] {}".format(e))
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--silent", action="store_true")
parser.add_argument("--path_to_module")
args = parser.parse_args()
if not import_core_modules(args.silent, args.path_to_module):
exit(1)