当前位置:网站首页>Onnx crop intermediate node
Onnx crop intermediate node
2022-06-13 08:54:00 【Human high quality Algorithm Engineer】
I have recently encountered the need to onnx The middle nodes of the model are cut out ,mxnet Converted caff Model , Preprocessing ( Subtract the mean divided by the variance ) It is written in the model structure , The pretreatment layer shall be taken out separately during quantification , There are two ways to do this , One that can be loaded mxnet Trained models , Remove the pretreatment before saving ; In the other case, it will directly onnx The corresponding two preprocessing nodes in are cut off , Here is the specific implementation of the second method
import onnx_graphsurgeon as gs
import numpy as np
import onnx
# remove preprocessing node
# (x - mean)/std
def remove_preprocessing_node(onnx_path):
onnx_model = onnx.load(onnx_path) # load onnx Model
graph = onnx_model.graph
old_nodes = graph.node
new_nodes = old_nodes[2:] # Get rid of data,sub,mul The first three nodes
del onnx_model.graph.node[:] # Delete the current onnx All of the models node
onnx_model.graph.node.extend(new_nodes) # extend New nodes
conv0_node = onnx_model.graph.node[0]
conv0_node.input[0] = 'data' # Set the input to the convolution node of the first layer data node
# graph = onnx_model.graph
# print(graph.node)
onnx.checker.check_model(onnx_model)
onnx.save(onnx_model, "./janus_mask_occ_nopre.onnx")
def crop_middle_nodes(onnx_path):
if __name__ == "__main__":
onnx_path = "J:/code/mxnet_mask/janus_mask_occ.onnx"
remove_preprocessing_node(onnx_path)
Realization effect :
边栏推荐
- 6、 JS naming rules and specifications
- About RSA encryption and decryption principle
- Map 23 summary
- 2、 Three ways to write JS code
- Calculation method of paging
- 4. Relationship selector (parent-child relationship, ancestor offspring relationship, brother relationship)
- 【QNX Hypervisor 2.2 用户手册】4.5.1 构建QNX Guest
- 1.SolidWorks各模块的学习顺序
- Redis分布式集群搭建
- Mapbox usage, including drawing, loading, modifying, deleting points and faces, displaying pop ups, etc
猜你喜欢
4、 Js-es5-i / O
useRoutes() may be used only in the context of a <Router> component.
Browser render passes
Diversified tables through TL table row consolidation
关于RSA加密解密原理
1. Learning sequence of SolidWorks modules
anaconda下安装pytorch
Sky background map, navigation page lovefanfan top
「解读」华为云桌面说“流畅”的时候,究竟在说什么?
2020-12-28
随机推荐
Cesium common events, including click events, mouse events, and camera movement events
An error CV2 is reported when the picture is converted to grayscale cvtColor(img, cv2.COLOR_BGR2GRAY)
regular expression
ES6 module import / export summary
1.初步认识express
14. class initialization, default constructor, =default
Screenshot of cesium implementation scenario
Problèmes et traitement du disque gbase 8a
Svg text stroke effect
VI editor
Tensorflow1.14 corresponds to numpy version
The 360 mobile assistant on Huawei maimang 7 cannot be uninstalled
1.SolidWorks各模块的学习顺序
How to resolve "the operation cannot be completed successfully because the file contains viruses or potentially junk software
\Difference between N and \r
Object array de encapsulation
Replace jade engine with EJS
2020-12-28
JS obtain geographic location information according to longitude and latitude and mark it on the map
Four kinds of hooks in deep learning