



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
官网下载源码、模型和测试数据集:源代码:/ultralytics/ultralytics模型:/ultralytics/assets/releases/download/v0.0.0/yolov8m.pt测试数据:/s/1q8t6WUe2r9NavY-4jYOokA?pwd=mf4i安装依赖环境:cdultralyticspipinstall-rrequirements.txt-i/simplepythonsetup.pyinstall修改脚本(ultralytics/nn/tasks.py)defxywh2xyxy(x):
y=x.clone()
y[:,:,0]=x[:,:,0]-x[:,:,2]/2
#topleftx
y[:,:,1]=x[:,:,1]-x[:,:,3]/2
#toplefty
y[:,:,2]=x[:,:,0]+x[:,:,2]/2
#bottomrightx
y[:,:,3]=x[:,:,1]+x[:,:,3]/2
#bottomrighty
returnydefget_box(input_feature_np):
boxes_feat=input_feature_np[:,:,0:4]
boxes_xyxy=xywh2xyxy(boxes_feat)
returnboxes_xyxydefget_score(input_feature_np):
#confidence_feat=input_feature_np[:,:,4:5]
#classes_feat=input_feature_np[:,:,5:]
#score=confidence_feat*classes_feat
score=input_feature_np[:,:,4:]
returnscore
def_predict_once(self,x,profile=False,visualize=False):
"""
Performaforwardpassthroughthenetwork.
Args:
x(torch.Tensor):Theinputtensortothemodel.
profile(bool):
PrintthecomputationtimeofeachlayerifTrue,defaultstoFalse.
visualize(bool):SavethefeaturemapsofthemodelifTrue,defaultstoFalse
Returns:
(torch.Tensor):Thelastoutputofthemodel.
"""
y,dt=[],[]
#outputs
forminself.model:
ifm.f!=-1:
#ifnotfrompreviouslayer
x=y[m.f]ifisinstance(m.f,int)else[xifj==-1elsey[j]forjinm.f]
#fromearlierlayers
ifprofile:
self._profile_one_layer(m,x,dt)
x=m(x)
#run
y.append(xifm.iinself.saveelseNone)
#saveoutput
ifvisualize:
feature_visualization(x,m.type,m.i,save_dir=visualize)
xt=x.transpose(1,2)
bboxes=get_box(xt)
scores=get_score(xt)
returnbboxes,scores
returnx修改输出(ultralytics/engine/exporter.py)name添加导出onnx脚本importonnxfromonnximportGraphProto,TensorProtofromonnx.helperimportmake_tensor_value_info,make_attribute,make_node,make_modelfromultralyticsimportYOLOdefappend_nms(graph,unused_node=[]):
ngraph=GraphProto()
=
ngraph.input.extend([iforiingraph.inputifnotinunused_node])
ngraph.initializer.extend([iforiingraph.initializerifnotinunused_node])
ngraph.value_info.extend([iforiingraph.value_infoifnotinunused_node])
ngraph.node.extend([iforiingraph.nodeifnotinunused_node])
output_info=[iforiingraph.output]
ngraph.value_info.extend(output_info)
print(graph.output)
nms=make_node(
'DLNonMaxSuppression',
inputs=['bboxes','scores'],
outputs=['num_detections','nmsed_boxes','nmsed_scores','nmsed_classes']
)
nms.attribute.append(make_attribute('backgroundLabelId',-1))
nms.attribute.append(make_attribute('iouThreshold',0.45))
nms.attribute.append(make_attribute('isNormalized',False))
nms.attribute.append(make_attribute('keepTopK',200))
nms.attribute.append(make_attribute('numClasses',80))#
nms.attribute.append(make_attribute('shareLocation',True))
nms.attribute.append(make_attribute('scoreThreshold',0.25))
nms.attribute.append(make_attribute('topK',1000))
ngraph.node.append(nms)
num_detection=make_tensor_value_info('num_detections',TensorProto.INT32,[1,1])
nmsed_box=make_tensor_value_info('nmsed_boxes',TensorProto.FLOAT,[1,200,4])
nmsed_score=make_tensor_value_info('nmsed_scores',TensorProto.FLOAT,[1,200,1])
nmsed_class=make_tensor_value_info('nmsed_classes',TensorProto.FLOAT,[1,200,1])
ngraph.output.extend([num_detection,nmsed_box,nmsed_score,nmsed_class])
returnngraphdefexport_onnx():
#Loadamodel
model=YOLO("yolov8m.pt")
#loadapretrainedmodel(recommendedfortraining)
f=model.export(format="onnx")
#exportthemodeltoONNXformat
print('model.exportsuccess')
#Checks
model_onnx=onnx.load(f)
#loadonnxmodel
onnx.checker.check_model(model_onnx)
#checkonnxmodel
#Simplify
try:
importonnxsim
model_onnx,check=onnxsim.simplify(model_onnx)
assertcheck,'assertcheckfailed'
onnx.save(model_onnx,f)
exceptExceptionase:
print(f'simplifierfailure:{e}')
returnmodel_onnxmodel=export_onnx()model_attrs=dict(
ir_version=
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 人教版小学四年级语文下册课外阅读题练习及答案
- 2024年福建事业单位考试的学习方法研究试题及答案
- 健康管理师考试的各大主题归纳试题及答案
- 信息系统项目管理师考试全真模拟试题及答案
- 2025年育婴师考试多维度学习方法试题及答案
- 2025年生命支持体系知识试题及答案
- 北京市第四中学网校高中化学 第一、第二章 激活化学潜能 第8讲 离子反应(下)教学设计(PDF版)新人教版必修1
- 2025年税务师考试备考步骤试题及答案
- 健康管理师考试对创新思维能力的重视与实施探讨试题及答案
- 八年级道德与法治上册 第三单元 明辨善恶是非 第9课 拒绝犯罪 第1框《犯罪与刑罚》教学设计 北师大版
- 山东省国控设计集团有限公司招聘笔试真题2024
- 2024年山东省济南市中考数学模拟试卷(三)(含答案)
- (正式版)SHT 3046-2024 石油化工立式圆筒形钢制焊接储罐设计规范
- 志愿服务证明(多模板)
- 近视眼的防控课件
- 抖音直播运营团队薪酬绩效考核管理方案(直播带货团队薪酬绩效提成方案)
- 压电陶瓷精品课件
- 教学课件·植物组织培养
- 部编版语文一年级下册识字8-人之初市级优质课课件
- 基于仿真的轴承动力学分析设计毕业设计说明书
- 丽声北极星分级绘本第二级下Eek,Spider 教学设计
评论
0/150
提交评论