Last active
May 18, 2022 13:00
-
-
Save antoinebrl/e0be20545d2d1c8e5020fffe25f65d20 to your computer and use it in GitHub Desktop.
ONNX Surgery example - Replacing `GlobalAveragePool` with `AveragePool`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import onnx | |
model = onnx.load("model.onnx") | |
graph = model.graph | |
# Identify relevant node | |
idx = -1 | |
for i, n in enumerate(model.graph.node): | |
if n.name == "GlobalAveragePool": | |
idx = i | |
node = model.graph.node[idx] | |
print(node) | |
new_node = onnx.helper.make_node("AveragePool", node.input, node.output, kernel_shape=[12,4], pads=[0,0,0,0], strides=[12,4]) | |
graph.node.remove(node) | |
graph.node.insert(idx, new_node) | |
onnx.checker.check_model(model) | |
onnx.save(model, "model-surgery.onnx") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment