当前位置: 首页 > news >正文

网站建设接私活平台房价查询网

网站建设接私活平台,房价查询网,建立网站得多少钱,网站应用系统设计方案某些模型最后卷积层之后的算子不适合在推理引擎里面跑,切割掉conv后面的算子,在cpu上实现有比较好的性能. 包含: 1.获取onnx中间节点的shape的示例 2.增加onnx模型输出,设…
某些模型最后卷积层之后的算子不适合在推理引擎里面跑,切割掉conv后面的算子,在cpu上实现有比较好的性能.
包含:
1.获取onnx中间节点的shape的示例
2.增加onnx模型输出,设置名称,type, shape. 示例
3.编辑onnx模型示例切割掉绿色部分示例
import onnx
import sys
import json
from onnx import shape_inference, TensorProtoif len(sys.argv) < 2:print('Usage: ' + sys.argv[0] + '<onnx_filename>')exit(-1)onnx_file = sys.argv[1]# 加载ONNX模型
model = onnx.load(onnx_file)graph = model.graphoutputs = model.graph.output 
if(len(outputs)!=3):print("This isn't ScoreBoxKpt model!")quit()output_list=["output0","output1","output2"]for output in outputs:if output.name in score_box_kpt :print(f"output name: {output.name}")else:print("This isn't a fit model!")quit()def getConvList(endName):stack=[]stack.append(endName)convList=[]while(len(stack)):name=stack.pop()for node in graph.node:if name in node.output :if node.op_type=="Conv":if node.name not in convList :convList.append(node.name)else: for input in node.input:if input not in stack:stack.insert(0, input)return convListConv0=getConvList(output_list[0])
Conv1=getConvList(output_list[1])
Conv2=getConvList(output_list[2])def save2json(save_dict, name):if len(save_dict) == 0:print("this is nothing to save json")return Nonewith open(name, 'w') as fp:#{'a': 'Runoob', 'b': 7}json.dump(save_dict, fp, sort_keys=False, indent=4, separators=(',', ': ')) #default=strsave_dict = {output_list[0]:scoreConv,output_list[1]:boxConv,output_list[2]:kptConv}conv_list=Conv0+Conv1+Conv2#获取onnx中间节点的shape.
output_dim_dic={}
inferred_onnx_model = shape_inference.infer_shapes(model)
inferred_graph = inferred_onnx_model.graph
inferred_value_info = inferred_graph.value_info
for node in graph.node:if node.name in conv_list:for value_info in inferred_value_info:if value_info.name==node.output[0]:output_dim_dic[node.name]=value_info.type.tensor_type;#删除conv 后面的onnx节点
# Find target node index
for name in conv_list:target_node = Nonefor node in graph.node:if node.name == name:target_node=nodebreakoutput_names = []for output in target_node.output:output_names.append(output)set1=set(output_names)del_node = []have_new_del_node = Falsewhile True:have_new_del_node = Falsefor node in graph.node:if node.name in del_node:continueset2=set(node.input)if set1.intersection(set2): output_names+=node.output         set1=set(output_names)del_node.append(node.name)have_new_del_node = Trueif have_new_del_node == False:breakfor node in graph.node:if node.name in del_node:print(f"1remove node {node.name}")model.graph.node.remove(node)have_new_del_node = False
while True:have_new_del_node = Falsefor node1 in graph.node:if node1.name in conv_list :continueset1=set(node1.output)to_delete =Truefor node2 in graph.node:set2=set(node2.input)if set1.intersection(set2): to_delete = Falsebreakif to_delete == True:print(f"2remove node {node1.name}")model.graph.node.remove(node1)have_new_del_node=Trueif have_new_del_node == False :breaksave_output_name=[]
for node in graph.node:if node.name in conv_list:#增加输出层output_info = onnx.helper.ValueInfoProto()node.output[0]=node.nameoutput_info.name = node.output[0]for dim_value in output_dim_dic[node.name].shape.dim:output_info.type.tensor_type.shape.dim.extend([dim_value])output_info.type.tensor_type.elem_type = TensorProto.FLOATprint(output_info)graph.output.extend([output_info])save_output_name.append(node.output[0])outputs = model.graph.output 
# 打印输出节点名称
for output in outputs:if output.name  in save_output_name :continuemodel.graph.output.remove(output)
outputs = model.graph.output 
# 打印输出节点名称
for output in outputs:if output.name  in save_output_name :continuemodel.graph.output.remove(output)
# Save modified ONNX model
onnx.checker.check_model(model)
onnx.save(model, "backbone.onnx")
save2json(save_dict, 'conv_param.json'
http://www.yayakq.cn/news/373929/

相关文章:

  • 网站架构企业收费标准百度推广费用一年多少钱
  • wordpress 公司网站 模板 下载wordpress 柚子皮下载
  • 在线注册网站wordpress注册邮件发送设置
  • 莱芜招聘网seo外包服务专家
  • 成华区建设局质检站网站快速搭建网站服务器
  • 衡水哪家制作网站好装饰公司哪家口碑好
  • 科技公司的网站网站推广小助手
  • 关键词你们懂的seo资讯推推蛙
  • 临西网站建设iis wordpress 500
  • 网站后台管理界面htmlwordpress绿色中文主题
  • 新余做网站的青浦网站招营业员做一休一
  • 一站式网站建设老薛主机怎么安装wordpress
  • 工信部网站备案平台在哪里推广网站
  • 网站建设金手指稳定定制品牌
  • 连州住房建设局网站德阳市做网站
  • 小米路由 做网站郑州网站建设易云巢
  • 建设银行网银网站特色网站建设调查内容有哪些
  • 网站建设人员配置大连网站搜索排名提升
  • 海南网络电视台重庆seo全网营销
  • 一个网站里有两个网页怎么做建筑设计网课
  • 网站建设 好牛做棋牌网站违法嘛
  • 东台市住房和城乡建设局网站搜索大全搜索引擎
  • 爱站工具网酒店网站可以怎么做
  • 郑州一站式网站搭建thinkphp5做网站
  • 企业网站策划文案wordpress 什么值得买 主题
  • 温州市建设工程管理网站wordpress竖版图片
  • 网站制作建设飞沐带dede后台的整套网站源码 怎么进入dede后台
  • 网站公司上海网页设计案例下载
  • 建三江建设局网站百度下载安装官方下载
  • 网站开发客户挖掘wordpress电影分享主题