From cd805fa9a3e336faa42ec85dcf865137f6fb1d61 Mon Sep 17 00:00:00 2001 From: root Date: Fri, 29 Nov 2019 07:57:17 +0000 Subject: [PATCH] check for onnx model --- x2paddle/convert.py | 7 +++---- x2paddle/op_mapper/onnx_op_mapper.py | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/x2paddle/convert.py b/x2paddle/convert.py index 75a5621..711c974 100644 --- a/x2paddle/convert.py +++ b/x2paddle/convert.py @@ -163,13 +163,12 @@ def onnx2paddle(model_path, save_dir, params_merge=False): return print("Now translating model from onnx to paddle.") + from x2paddle.op_mapper.onnx_op_mapper import ONNXOpMapper from x2paddle.decoder.onnx_decoder import ONNXDecoder - model = ONNXDecoder(model_path) + from x2paddle.optimizer.onnx_optimizer import ONNXOptimizer - from x2paddle.op_mapper.onnx_op_mapper import ONNXOpMapper + model = ONNXDecoder(model_path) mapper = ONNXOpMapper(model, save_dir) - - from x2paddle.optimizer.onnx_optimizer import ONNXOptimizer optimizer = ONNXOptimizer(mapper) optimizer.delete_redundance_code() diff --git a/x2paddle/op_mapper/onnx_op_mapper.py b/x2paddle/op_mapper/onnx_op_mapper.py index 89b216d..cbb1a7f 100644 --- a/x2paddle/op_mapper/onnx_op_mapper.py +++ b/x2paddle/op_mapper/onnx_op_mapper.py @@ -141,7 +141,12 @@ class ONNXOpMapper(OpMapper): onnx.save(model, os.path.join(self.tmp_data_dir, 'onnx_model_infer.onnx')) - os.system('onnx_infer --save_dir=' + self.tmp_data_dir) + is_success = os.system('onnx_infer --save_dir=' + self.tmp_data_dir) + if is_success != 0: + raise Exception("onnxruntime inference onnx model failed, Please \ + confirm the correctness of onnx model by onnxruntime, \ + if onnx model is valid, you can submit issue in github." + ) return def get_dynamic_shape(self, layer): -- GitLab