欧美性猛交xxxx免费看_牛牛在线视频国产免费_天堂草原电视剧在线观看免费_国产粉嫩高清在线观看_国产欧美日本亚洲精品一5区

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

使用OpenCV+ONNXRuntime部署YOLOV7目標(biāo)檢測(cè)

OpenCV學(xué)堂 ? 來源:OpenCV學(xué)堂 ? 作者:王博 ? 2022-07-23 11:31 ? 次閱讀

簡(jiǎn)單說明

分別使用OpenCV、ONNXRuntime部署YOLOV7目標(biāo)檢測(cè),一共包含12個(gè)onnx模型,依然是包含C++Python兩個(gè)版本的程序。 編寫這套YOLOV7的程序,跟此前編寫的YOLOV6的程序,大部分源碼是相同的,區(qū)別僅僅在于圖片預(yù)處理的過程不一樣。YOLOV7的圖片預(yù)處理是BGR2RGB+不保持高寬比的resize+除以255 由于onnx文件太多,無法直接上傳到倉(cāng)庫(kù)里,需要從百度云盤下載,

下載完成后把models目錄放在主程序文件的目錄內(nèi),編譯運(yùn)行 使用opencv部署的程序,有一個(gè)待優(yōu)化的問題。onnxruntime讀取.onnx文件可以獲得輸入張量的形狀信息, 但是opencv的dnn模塊讀取.onnx文件無法獲得輸入張量的形狀信息,目前是根據(jù).onnx文件的名稱來解析字符串獲得輸入張量的高度和寬度的。

YOLOV7的訓(xùn)練源碼是:

跟YOLOR是同一個(gè)作者的。

OpenCV+YOLOv7

推理過程跟之前的YOLO系列部署代碼可以大部分重用!這里就不在贅述了,詳細(xì)看源碼如下:輸出部分直接解析最后一個(gè)輸出層就好啦!

9c308ff6-0414-11ed-ba43-dac502259ad0.png

詳細(xì)實(shí)現(xiàn)代碼如下:

#include
#include
#include
#include
#include
#include

usingnamespacecv;
usingnamespacednn;
usingnamespacestd;

structNet_config
{
floatconfThreshold;//Confidencethreshold
floatnmsThreshold;//Non-maximumsuppressionthreshold
stringmodelpath;
};

classYOLOV7
{
public:
YOLOV7(Net_configconfig);
voiddetect(Mat&frame);
private:
intinpWidth;
intinpHeight;
vectorclass_names;
intnum_class;

floatconfThreshold;
floatnmsThreshold;
Netnet;
voiddrawPred(floatconf,intleft,inttop,intright,intbottom,Mat&frame,intclassid);
};

YOLOV7::YOLOV7(Net_configconfig)
{
this->confThreshold=config.confThreshold;
this->nmsThreshold=config.nmsThreshold;

this->net=readNet(config.modelpath);
ifstreamifs("coco.names");
stringline;
while(getline(ifs,line))this->class_names.push_back(line);
this->num_class=class_names.size();

size_tpos=config.modelpath.find("_");
intlen=config.modelpath.length()-6-pos;
stringhxw=config.modelpath.substr(pos+1,len);
pos=hxw.find("x");
stringh=hxw.substr(0,pos);
len=hxw.length()-pos;
stringw=hxw.substr(pos+1,len);
this->inpHeight=stoi(h);
this->inpWidth=stoi(w);
}

voidYOLOV7::drawPred(floatconf,intleft,inttop,intright,intbottom,Mat&frame,intclassid)//Drawthepredictedboundingbox
{
//Drawarectangledisplayingtheboundingbox
rectangle(frame,Point(left,top),Point(right,bottom),Scalar(0,0,255),2);

//Getthelabelfortheclassnameanditsconfidence
stringlabel=format("%.2f",conf);
label=this->class_names[classid]+":"+label;

//Displaythelabelatthetopoftheboundingbox
intbaseLine;
SizelabelSize=getTextSize(label,FONT_HERSHEY_SIMPLEX,0.5,1,&baseLine);
top=max(top,labelSize.height);
//rectangle(frame,Point(left,top-int(1.5*labelSize.height)),Point(left+int(1.5*labelSize.width),top+baseLine),Scalar(0,255,0),FILLED);
putText(frame,label,Point(left,top),FONT_HERSHEY_SIMPLEX,0.75,Scalar(0,255,0),1);
}

voidYOLOV7::detect(Mat&frame)
{
Matblob=blobFromImage(frame,1/255.0,Size(this->inpWidth,this->inpHeight),Scalar(0,0,0),true,false);
this->net.setInput(blob);
vectorouts;
this->net.forward(outs,this->net.getUnconnectedOutLayersNames());

intnum_proposal=outs[0].size[0];
intnout=outs[0].size[1];
if(outs[0].dims>2)
{
num_proposal=outs[0].size[1];
nout=outs[0].size[2];
outs[0]=outs[0].reshape(0,num_proposal);
}
/////generateproposals
vectorconfidences;
vectorboxes;
vectorclassIds;
floatratioh=(float)frame.rows/this->inpHeight,ratiow=(float)frame.cols/this->inpWidth;
intn=0,row_ind=0;///cx,cy,w,h,box_score,class_score
float*pdata=(float*)outs[0].data;
for(n=0;nthis->confThreshold)
{
Matscores=outs[0].row(row_ind).colRange(5,nout);
PointclassIdPoint;
doublemax_class_socre;
//Getthevalueandlocationofthemaximumscore
minMaxLoc(scores,0,&max_class_socre,0,&classIdPoint);
max_class_socre*=box_score;
if(max_class_socre>this->confThreshold)
{
constintclass_idx=classIdPoint.x;
floatcx=pdata[0]*ratiow;///cx
floatcy=pdata[1]*ratioh;///cy
floatw=pdata[2]*ratiow;///w
floath=pdata[3]*ratioh;///h

intleft=int(cx-0.5*w);
inttop=int(cy-0.5*h);

confidences.push_back((float)max_class_socre);
boxes.push_back(Rect(left,top,(int)(w),(int)(h)));
classIds.push_back(class_idx);
}
}
row_ind++;
pdata+=nout;
}

//Performnonmaximumsuppressiontoeliminateredundantoverlappingboxeswith
//lowerconfidences
vectorindices;
dnn::NMSBoxes(boxes,confidences,this->confThreshold,this->nmsThreshold,indices);
for(size_ti=0;idrawPred(confidences[idx],box.x,box.y,
box.x+box.width,box.y+box.height,frame,classIds[idx]);
}
}

intmain()
{
Net_configYOLOV7_nets={0.3,0.5,"models/yolov7_736x1280.onnx"};////choices=["models/yolov7_736x1280.onnx","models/yolov7-tiny_384x640.onnx","models/yolov7_480x640.onnx","models/yolov7_384x640.onnx","models/yolov7-tiny_256x480.onnx","models/yolov7-tiny_256x320.onnx","models/yolov7_256x320.onnx","models/yolov7-tiny_256x640.onnx","models/yolov7_256x640.onnx","models/yolov7-tiny_480x640.onnx","models/yolov7-tiny_736x1280.onnx","models/yolov7_256x480.onnx"]
YOLOV7net(YOLOV7_nets);
stringimgpath="images/dog.jpg";
Matsrcimg=imread(imgpath);
net.detect(srcimg);

staticconststringkWinName="DeeplearningobjectdetectioninOpenCV";
namedWindow(kWinName,WINDOW_NORMAL);
imshow(kWinName,srcimg);
waitKey(0);
destroyAllWindows();
}

運(yùn)行測(cè)試如下:

9c3dd738-0414-11ed-ba43-dac502259ad0.png

9c670d92-0414-11ed-ba43-dac502259ad0.png



審核編輯:劉清

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • OpenCV
    +關(guān)注

    關(guān)注

    31

    文章

    635

    瀏覽量

    41594
  • python
    +關(guān)注

    關(guān)注

    56

    文章

    4811

    瀏覽量

    85076

原文標(biāo)題:源碼 | OpenCV DNN + YOLOv7目標(biāo)檢測(cè)

文章出處:【微信號(hào):CVSCHOOL,微信公眾號(hào):OpenCV學(xué)堂】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏

    評(píng)論

    相關(guān)推薦

    YOLOV7網(wǎng)絡(luò)架構(gòu)解讀

    繼美團(tuán)發(fā)布YOLOV6之后,YOLO系列原作者也發(fā)布了YOLOV7
    的頭像 發(fā)表于 11-29 10:00 ?1956次閱讀
    <b class='flag-5'>YOLOV7</b>網(wǎng)絡(luò)架構(gòu)解讀

    在英特爾AI開發(fā)板上用OpenVINO NNCF優(yōu)化YOLOv7

    提高了性能和效率。YOLO算法作為one-stage目標(biāo)檢測(cè)算法最典型的代表,其基于深度神經(jīng)網(wǎng)絡(luò)進(jìn)行對(duì)象的識(shí)別和定位,運(yùn)行速度很快,可以用于實(shí)時(shí)系統(tǒng)。YOLOv7 是 YOLO 模型系列的下一個(gè)演進(jìn)階段,在不增加推理成本的情況下
    的頭像 發(fā)表于 01-05 09:29 ?840次閱讀
    在英特爾AI開發(fā)板上用OpenVINO NNCF優(yōu)化<b class='flag-5'>YOLOv7</b>

    yolov7 onnx模型在NPU上太慢了怎么解決?

    yolov7tiny.onnx。輸入大小為 224x224,但 npu 推理時(shí)間為 127 毫秒。好像太慢了。這個(gè)時(shí)間合理嗎?以下是我的onnx模型轉(zhuǎn)換步驟和我的onnxruntime執(zhí)行代碼: 1. 從 https
    發(fā)表于 04-04 06:13

    無法使用MYRIAD在OpenVINO trade中運(yùn)行YOLOv7自定義模型怎么解決?

    無法確定如何將 YOLOv7 模型的重量(.pt 文件)轉(zhuǎn)換為OpenVINO?中間表示 (IR) 并推斷有 MYRIAD 的 IR。 分辨率 轉(zhuǎn)換使用此 GitHub* 存儲(chǔ)庫(kù)
    發(fā)表于 08-15 08:29

    深度解析YOLOv7的網(wǎng)絡(luò)結(jié)構(gòu)

    最近,Scaled-YOLOv4的作者(也是后來的YOLOR的作者)和YOLOv4的作者AB大佬再次聯(lián)手推出了YOLOv7,目前來看,這一版的YOLOv7是一個(gè)比較正統(tǒng)的YOLO續(xù)作,
    的頭像 發(fā)表于 09-14 11:16 ?7712次閱讀

    YOLOv6在LabVIEW中的推理部署(含源碼)

    YOLOv6 是美團(tuán)視覺智能部研發(fā)的一款目標(biāo)檢測(cè)框架,致力于工業(yè)應(yīng)用。如何使用python進(jìn)行該模型的部署,官網(wǎng)已經(jīng)介紹的很清楚了,但是對(duì)于如何在LabVIEW中實(shí)現(xiàn)該模型的
    的頭像 發(fā)表于 11-06 16:07 ?429次閱讀
    <b class='flag-5'>YOLOv</b>6在LabVIEW中的推理<b class='flag-5'>部署</b>(含源碼)

    YOLOv7訓(xùn)練自己的數(shù)據(jù)集包括哪些

    ? YOLOv7訓(xùn)練自己的數(shù)據(jù)集整個(gè)過程主要包括:環(huán)境安裝—制作數(shù)據(jù)集—模型訓(xùn)練—模型測(cè)試—模型推理 一、準(zhǔn)備深度學(xué)習(xí)環(huán)境 本人的筆記本電腦系統(tǒng)是:Windows10 首先下載YOLOv7的代碼
    的頭像 發(fā)表于 05-29 15:18 ?1148次閱讀
    <b class='flag-5'>YOLOv7</b>訓(xùn)練自己的數(shù)據(jù)集包括哪些

    三種主流模型部署框架YOLOv8推理演示

    部署。這里以YOLOv8為例,演示了YOLOv8對(duì)象檢測(cè)模型在OpenVINO、ONNXRUNTIME、TensorRT三個(gè)主流框架上C++
    的頭像 發(fā)表于 08-06 11:39 ?2825次閱讀

    yolov5和YOLOX正負(fù)樣本分配策略

    整體上在正負(fù)樣本分配中,yolov7的策略算是yolov5和YOLOX的結(jié)合。因此本文先從yolov5和YOLOX正負(fù)樣本分配策略分析入手,后引入到YOLOv7的解析中。
    發(fā)表于 08-14 11:45 ?2375次閱讀
    <b class='flag-5'>yolov</b>5和YOLOX正負(fù)樣本分配策略

    使用OpenVINO優(yōu)化并部署訓(xùn)練好的YOLOv7模型

    在《英特爾銳炫 顯卡+ oneAPI 和 OpenVINO 實(shí)現(xiàn)英特爾 視頻 AI 計(jì)算盒訓(xùn)推一體-上篇》一文中,我們?cè)敿?xì)介紹基于英特爾 獨(dú)立顯卡搭建 YOLOv7 模型的訓(xùn)練環(huán)境,并完成了 YOLOv7 模型訓(xùn)練,獲得了最佳精度的模型權(quán)重。
    的頭像 發(fā)表于 08-25 11:08 ?1619次閱讀
    使用OpenVINO優(yōu)化并<b class='flag-5'>部署</b>訓(xùn)練好的<b class='flag-5'>YOLOv7</b>模型

    OpenCV4.8+YOLOv8對(duì)象檢測(cè)C++推理演示

    自從YOLOv5更新成7.0版本,YOLOv8推出以后,OpenCV4.6以前的版本都無法再加載導(dǎo)出ONNX格式模型了,只有OpenCV4.7以上版本才可以支持最新版本
    的頭像 發(fā)表于 09-27 11:07 ?1647次閱讀
    <b class='flag-5'>OpenCV4.8+YOLOv</b>8對(duì)象<b class='flag-5'>檢測(cè)</b>C++推理演示

    詳細(xì)解讀YOLOV7網(wǎng)絡(luò)架構(gòu)設(shè)計(jì)

    YOLOV7提出了輔助頭的一個(gè)訓(xùn)練方法,主要目的是通過增加訓(xùn)練成本,提升精度,同時(shí)不影響推理的時(shí)間,因?yàn)檩o助頭只會(huì)出現(xiàn)在訓(xùn)練過程中。
    發(fā)表于 11-27 10:45 ?820次閱讀
    詳細(xì)解讀<b class='flag-5'>YOLOV7</b>網(wǎng)絡(luò)架構(gòu)設(shè)計(jì)

    基于OpenCV DNN實(shí)現(xiàn)YOLOv8的模型部署與推理演示

    基于OpenCV DNN實(shí)現(xiàn)YOLOv8推理的好處就是一套代碼就可以部署在Windows10系統(tǒng)、烏班圖系統(tǒng)、Jetson的Jetpack系統(tǒng)
    的頭像 發(fā)表于 03-01 15:52 ?1901次閱讀
    基于<b class='flag-5'>OpenCV</b> DNN實(shí)現(xiàn)<b class='flag-5'>YOLOv</b>8的模型<b class='flag-5'>部署</b>與推理演示

    在樹莓派上部署YOLOv5進(jìn)行動(dòng)物目標(biāo)檢測(cè)的完整流程

    卓越的性能。本文將詳細(xì)介紹如何在性能更強(qiáng)的計(jì)算機(jī)上訓(xùn)練YOLOv5模型,并將訓(xùn)練好的模型部署到樹莓派4B上,通過樹莓派的攝像頭進(jìn)行實(shí)時(shí)動(dòng)物目標(biāo)檢測(cè)。 一、在電腦上訓(xùn)練
    的頭像 發(fā)表于 11-11 10:38 ?1536次閱讀
    在樹莓派上<b class='flag-5'>部署</b><b class='flag-5'>YOLOv</b>5進(jìn)行動(dòng)物<b class='flag-5'>目標(biāo)</b><b class='flag-5'>檢測(cè)</b>的完整流程

    采用華為云 Flexus 云服務(wù)器 X 實(shí)例部署 YOLOv3 算法完成目標(biāo)檢測(cè)

    一、前言 1.1 開發(fā)需求 這篇文章講解:?采用華為云最新推出的 Flexus 云服務(wù)器 X 實(shí)例部署 YOLOv3 算法,完成圖像分析、目標(biāo)檢測(cè)。 隨著計(jì)算機(jī)視覺技術(shù)的飛速發(fā)展,深度
    的頭像 發(fā)表于 01-02 12:00 ?145次閱讀
    采用華為云 Flexus 云服務(wù)器 X 實(shí)例<b class='flag-5'>部署</b> <b class='flag-5'>YOLOv</b>3 算法完成<b class='flag-5'>目標(biāo)</b><b class='flag-5'>檢測(cè)</b>