Skip to content

Commit

Permalink
fix: Avoid repeatedly adding initializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Xyzhao1999 committed Aug 18, 2023
1 parent 69c9f58 commit 685d7c7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion onnxsim/onnxsim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ std::vector<onnx::TensorProto> RunOp(onnx::ModelProto& model,
const onnx::NodeProto& op) {
std::vector<std::string> input_names;
std::vector<onnx::TensorProto> input_tps;
std::set<std::string> initializer_names;

onnx::ModelProto op_model;
op_model.set_ir_version(model.ir_version());
Expand All @@ -260,9 +261,12 @@ std::vector<onnx::TensorProto> RunOp(onnx::ModelProto& model,
if (input.empty()) {
continue;
}

if (initializer_names.find(input) != initializer_names.end()) {
continue;
}
auto in_tp = FindInitializerByName(model, input);
if (in_tp.dims().size() == 1 && in_tp.dims()[0] == 0) {
initializer_names.insert(input);
*op_model.mutable_graph()->add_initializer() = in_tp;
continue;
}
Expand Down

0 comments on commit 685d7c7

Please sign in to comment.