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) {