-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathtest_inference_models.py
executable file
·102 lines (80 loc) · 3.13 KB
/
test_inference_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python3
# ==============================================================================
# Copyright 2018-2020 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.
# ==============================================================================
from build_utils import *
def main():
'''
Builds TensorFlow, ngraph, and ngraph-tf for python 3
'''
parser = argparse.ArgumentParser(formatter_class=RawTextHelpFormatter)
parser.add_argument(
'--model_location',
help="Location of the model directory\n",
action="store")
parser.add_argument(
'--python_location',
help=
"Location of Python executable (whether virtual environment or system)\n",
action="store")
parser.add_argument(
'--artifacts_dir',
type=str,
help="Location of the artifacts\n",
action="store")
arguments = parser.parse_args()
#-------------------------------
# Recipe
#-------------------------------
# Save the current location
pwd = os.getcwd()
if not (arguments.artifacts_dir):
raise "Need to provide artifacts directory"
if not (arguments.python_location):
raise "Need to provide the location of Python directory"
if not (arguments.model_location):
raise "Need to provide the location of models directory"
# Check to make sure that there is TensorFlow installed and will work
# TODO
# Install nGraph Bridge
ngtf_wheel_files = glob.glob(
os.path.join(
os.path.abspath(arguments.artifacts_dir),
"ngraph_tensorflow_bridge-*.whl"))
if (len(ngtf_wheel_files) != 1):
raise ("Multiple Python whl files exist. Please remove old wheels")
ngraph_bridge_wheel = ngtf_wheel_files[0]
print("NGRAPH Wheel: ", ngraph_bridge_wheel)
command_executor([
os.path.join(arguments.python_location, "pip"), "install", "-U",
ngraph_bridge_wheel
])
# Print the version information
print("\nnGraph-TensorFlow Information ")
python_exe = os.path.join(arguments.python_location, "python3")
command_executor([
python_exe, "-c", "\"import tensorflow as tf; " +
"print('TensorFlow version: ',tf.__version__);" +
"import ngraph_bridge; print(ngraph_bridge.__version__)" +
";print(ngraph_bridge.list_backends())\n\""
])
# Next is to go to the model directory
os.chdir(os.path.join(arguments.model_location, "tensorflow_scripts"))
# Execute the inference runs
command_executor(["/bin/bash", "run-all-models.sh"])
# Restore
os.chdir(pwd)
if __name__ == '__main__':
main()