



下載本文檔
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
官網(wǎng)下載源碼、模型和測試數(shù)據(jù)集:源代碼:/ultralytics/ultralytics模型:/ultralytics/assets/releases/download/v0.0.0/yolov8m.pt測試數(shù)據(jù):/s/1q8t6WUe2r9NavY-4jYOokA?pwd=mf4i安裝依賴環(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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 環(huán)保行業(yè)運營流程優(yōu)化作業(yè)指導(dǎo)書
- 護師及主管護師練習卷含答案
- 奶茶店品牌評估營銷手冊
- 項目開發(fā)進度管理與計劃安排
- 分析法律制定中權(quán)利約束邊界
- 員工培訓(xùn)計劃與實施細則
- 醫(yī)療敷料貼合度提高方法
- 三農(nóng)村環(huán)境治理綜合方案
- 豪客來服務(wù)質(zhì)量調(diào)查
- 游戲美術(shù)行業(yè)的數(shù)字化設(shè)計與制作工具應(yīng)用方案
- 2025年高考作文素材積累之《人民日報》4篇經(jīng)典時評結(jié)構(gòu)賞析
- 衛(wèi)星定位導(dǎo)航原理知到智慧樹章節(jié)測試課后答案2024年秋哈爾濱工業(yè)大學
- 研究生學術(shù)英語寫作 課件 Chapter 7 Abstract;Chapter 8 Citation and Reference
- ISO45001管理體系培訓(xùn)課件
- 心力衰竭患者利尿劑抵抗診斷及管理中國專家共識2024解讀
- 主任臨床查房程序規(guī)范及評分標準
- 《望海潮》《揚州慢》導(dǎo)學案(含答案) 統(tǒng)編版高中語文選擇性必修下冊
- 土壤有機質(zhì)的測定 編制說明
- 蔣詩萌小品《誰殺死了周日》臺詞完整版
- 醫(yī)美機構(gòu)轉(zhuǎn)讓合同模板
- 全國基層退役軍人服務(wù)中心(站)工作人員職業(yè)技能競賽考試題庫-上(單選、多選題)
評論
0/150
提交評論