当前位置:网站首页>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 :
边栏推荐
- ES6 use of dynamic attributes
- PHP wechat special merchant incoming V3 packaging interface
- Browser render passes
- JS format file unit display
- JS to get the date in the next seven days of the current date
- WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]
- Cesium displays a pop-up box at the specified position and moves with the map
- turf. JS usage
- DIY UAV (anonymous controller p2+f330 rack)
- Redis分布式集群搭建
猜你喜欢
![WARNING:tornado. access:404 GET /favicon. ICO (172.16.8.1) 1.84ms [with static file settings]](/img/6d/6eef1f0ebcab45e9a209a3b6c62b03.png)
WARNING:tornado. access:404 GET /favicon. ICO (172.16.8.1) 1.84ms [with static file settings]

5. Attribute selector

On the use of regular expressions (bracket problem)

4、 Js-es5-i / O

【安全】零基礎如何從0到1逆襲成為安全工程師

Docker installing MySQL local remote connection docker container MySQL

4. Relationship selector (parent-child relationship, ancestor offspring relationship, brother relationship)

2021-04-16

Print an array clockwise

2020-12-28
随机推荐
Is it safe to open an account online? Can a novice open an account?
15. copy constructor
JS array using the reduce() method
Namespace in TS (2)
Vs installation of vassistx plug-in causes Chinese input of wpf-xaml file to be garbled. Solution
Cesium common events, including click events, mouse events, and camera movement events
1.初步认识express
ES6 module import / export summary
VBA format word (page, paragraph, table, picture)
Object in ES6 Use of entries()
What is the difference between getfullyear() and getyear()
Sky background map, navigation page lovefanfan top
Basic use of cesium, including loading images, terrain, models, vector data, etc
JD commodity detail interface, JD detail page interface, baby detail page interface, commodity attribute interface, commodity information query, commodity detail interface, H5 details, JD app details,
How to save the video of wechat video number locally?
Map 23 summary
Redis distributed cluster setup
Svg text stroke effect
Undefined and null in JS
WARNING:tornado.access:404 GET /favicon.ico (172.16.8.1) 1.84ms [附静态文件设置]