From b48db6432a13fab47d819d9536acf253b990f558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B6=E5=89=91=E6=AD=A6?= Date: Mon, 9 Dec 2019 15:40:42 +0800 Subject: [PATCH] fix running on host fix py code format --- tools/python/py_proto/__init__.py | 17 +++++++++++------ tools/python/run_model.py | 2 +- tools/python/run_target.py | 2 +- tools/python/utils/device.py | 7 +++++-- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/tools/python/py_proto/__init__.py b/tools/python/py_proto/__init__.py index da5f48fd..c94fa6f3 100644 --- a/tools/python/py_proto/__init__.py +++ b/tools/python/py_proto/__init__.py @@ -24,11 +24,16 @@ cwd = os.path.dirname(__file__) # TODO: Remove bazel deps try: - device.execute("bazel build //mace/proto:mace_py") - device.execute("cp -f bazel-genfiles/mace/proto/mace_pb2.py %s" % cwd) - - device.execute("bazel build //third_party/caffe:caffe_py") - device.execute( - "cp -f bazel-genfiles/third_party/caffe/caffe_pb2.py %s" % cwd) + device.execute("bazel version") except: # noqa MaceLogger.warning("No bazel, use cmake.") +else: + try: + device.execute("bazel build //mace/proto:mace_py") + device.execute("cp -f bazel-genfiles/mace/proto/mace_pb2.py %s" % cwd) + + device.execute("bazel build //third_party/caffe:caffe_py") + device.execute( + "cp -f bazel-genfiles/third_party/caffe/caffe_pb2.py %s" % cwd) + except: # noqa + MaceLogger.error("Failed in proto files' building") diff --git a/tools/python/run_model.py b/tools/python/run_model.py index 52e081fa..345b725b 100644 --- a/tools/python/run_model.py +++ b/tools/python/run_model.py @@ -73,7 +73,7 @@ def run_models(flags, args): MaceLogger.info("Run on devices: %s" % run_devices) for device_id in run_devices: - dev = device.crete_device(flags.target_abi, device_id) + dev = device.create_device(flags.target_abi, device_id) run_models_for_device(flags, args, dev) diff --git a/tools/python/run_target.py b/tools/python/run_target.py index 370b2423..b30dd192 100644 --- a/tools/python/run_target.py +++ b/tools/python/run_target.py @@ -44,7 +44,7 @@ def run_target(target_abi, install_dir, target_obj, device_ids="all"): for device_id in run_devices: # initiate device - dev = device.crete_device(target_abi, device_id) + dev = device.create_device(target_abi, device_id) # reinstall target print("Install target from %s to %s" % (target_obj.path, install_dir)) diff --git a/tools/python/utils/device.py b/tools/python/utils/device.py index 579d70ff..908a0dba 100644 --- a/tools/python/utils/device.py +++ b/tools/python/utils/device.py @@ -94,7 +94,10 @@ class HostDevice(Device): if install_dir.strip() and install_dir != os.path.dirname(target.path): execute("mkdir -p %s" % install_dir) - execute("cp %s %s" % (target.path, install_dir)) + if os.path.isdir(target.path): + execute("cp %s/* %s" % (target.path, install_dir)) + else: + execute("cp %s %s" % (target.path, install_dir)) for lib in target.libs: execute("cp %s %s" % (lib, install_dir)) @@ -285,7 +288,7 @@ def device_class(target_abi): return globals()[device_dispatch[target_abi]] -def crete_device(target_abi, device_id=None): +def create_device(target_abi, device_id=None): return device_class(target_abi)(device_id, target_abi) -- GitLab