下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
官網(wǎng)下載源碼、模型和測(cè)試數(shù)據(jù)集:源代碼:/ultralytics/ultralytics模型:/ultralytics/assets/releases/download/v0.0.0/yolov8m.pt測(cè)試數(shù)據(jù):/s/1q8t6WUe2r9NavY-4jYOokA?pwd=mf4i安裝依賴(lài)環(huán)境: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添加導(dǎo)出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. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 二手轎車(chē)買(mǎi)賣(mài)合同示范文本
- 個(gè)人車(chē)位贈(zèng)與合同范本
- 臨時(shí)工勞動(dòng)合同范本參考
- 2025年平安保險(xiǎn)公司特定疾病終身保險(xiǎn)賠付合同
- 業(yè)務(wù)合作合同格式樣本
- 不銹鋼采購(gòu)與銷(xiāo)售合同
- 個(gè)人借款質(zhì)押合同書(shū)樣本
- 專(zhuān)用線鐵路物流服務(wù)合同細(xì)則
- 個(gè)人與企業(yè)租賃合同范本大全
- 采購(gòu)標(biāo)準(zhǔn)合同書(shū)
- 游戲綜合YY頻道設(shè)計(jì)模板
- arcgis軟件操作解析課件
- 中興ZCTP 5GC高級(jí)工程師認(rèn)證考試題庫(kù)匯總(含答案)
- 大學(xué)生創(chuàng)新創(chuàng)業(yè)教程PPT全套完整教學(xué)課件
- 小學(xué)科學(xué)項(xiàng)目化作業(yè)的設(shè)計(jì)與實(shí)施研究
- 2023年考研考博-考博英語(yǔ)-西安建筑科技大學(xué)考試歷年真題摘選含答案解析
- 2020年中考生物試卷及答案
- MCNP-5A程序使用說(shuō)明書(shū)
- java基礎(chǔ)知識(shí)大全
- SMM英國(guó)建筑工程標(biāo)準(zhǔn)計(jì)量規(guī)則中文 全套
- GB 18030-2022信息技術(shù)中文編碼字符集
評(píng)論
0/150
提交評(píng)論