From 97f2acccef892836b61821cf87d926dd4208f425 Mon Sep 17 00:00:00 2001 From: jiangjiajun Date: Thu, 29 Aug 2019 19:39:42 +0800 Subject: [PATCH] add tools for PaddleLite op check --- tools/check_for_lite.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tools/check_for_lite.py diff --git a/tools/check_for_lite.py b/tools/check_for_lite.py new file mode 100644 index 0000000..94581b2 --- /dev/null +++ b/tools/check_for_lite.py @@ -0,0 +1,35 @@ +import urllib +import sys +from paddle.fluid.framework import Program + +ops_h = "https://raw.githubusercontent.com/PaddlePaddle/Paddle-Lite/develop/lite/api/_paddle_use_ops.h" +try: + fetch = urllib.urlretrieve(ops_h, "./_paddle_use_ops.h") +except: + fetch = urllib.request.urlretrieve(ops_h, "./_paddle_use_ops.h") + +ops = list() +with open("./_paddle_use_ops.h") as f: + for line in f: + if "USE_LITE_OP" in line: + op = line.strip().split('(')[1].split(')')[0] + ops.append(op) + +model_file = sys.argv[1] +with open(model_file, 'rb') as f: + program = Program.parse_from_string(f.read()) + +unsupported_ops = set() +for op in program.blocks[0].ops: + if op.type not in ops: + unsupported_ops.add(op.type) + +nums = len(unsupported_ops) +if len(unsupported_ops) > 0: + print("========= {} OPs are not supported in Paddle-Lite=========".format( + nums)) + for op in unsupported_ops: + print("========= {} ========".format(op)) +else: + print("\n========== Good News! ========") + print("Good! All ops in this model are supported in Paddle-Lite!\n") -- GitLab