From 9589dd9c157db1d6a08b5c38a405fd5b82421423 Mon Sep 17 00:00:00 2001 From: daquexian Date: Mon, 18 Dec 2023 18:04:40 +0800 Subject: [PATCH] compatible with custom ops without a custom domain Signed-off-by: daquexian --- onnxsim/onnxsim.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/onnxsim/onnxsim.cpp b/onnxsim/onnxsim.cpp index 6cbbf08..6d4638e 100644 --- a/onnxsim/onnxsim.cpp +++ b/onnxsim/onnxsim.cpp @@ -417,7 +417,13 @@ onnx::ModelProto _FoldConstant(const onnx::ModelProto& model) { model.CopyFrom(tmp); const auto [const_nodes, non_const_nodes] = GetConstantNodes(model); for (const auto& x : const_nodes) { - RunOpAndAddInitializer(model, x); + try { + RunOpAndAddInitializer(model, x); + } catch (const std::exception& e) { + std::cerr << "WARNING: failed to run \"" << node.op_type() << + "\" op (name is \"" << node.name << "\"), skip..." << std::endl; + non_const_nodes.push_back(x); + } } model.mutable_graph()->clear_node(); for (const auto& x : non_const_nodes) {