国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Opencv C++實現(xiàn)yolov5部署onnx模型完成目標(biāo)檢測

這篇具有很好參考價值的文章主要介紹了Opencv C++實現(xiàn)yolov5部署onnx模型完成目標(biāo)檢測。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

代碼分析:

頭文件
#include <fstream>  //文件
#include <sstream>  //流
#include <iostream>
#include <opencv2/dnn.hpp>        //深度學(xué)習(xí)模塊-僅提供推理功能
#include <opencv2/imgproc.hpp>    //圖像處理模塊
#include <opencv2/highgui.hpp>    //媒體的輸入輸出/視頻捕捉/圖像和視頻的編碼解碼/圖形界面的接口
命名空間
using namespace cv;
using namespace dnn;
using namespace std;
結(jié)構(gòu)體 Net_config
struct Net_config{
	float confThreshold; // 置信度閾值
	float nmsThreshold;  // 非最大抑制閾值
	float objThreshold;  // 對象置信度閾值
	string modelpath;
};

里面存了三個閾值和模型地址,其中置信度,顧名思義,看檢測出來的物體的精準(zhǔn)度。以測量值為中心,在一定范圍內(nèi),真值出現(xiàn)在該范圍內(nèi)的幾率。

endsWith()函數(shù) 判斷sub是不是s的子串
int endsWith(string s, string sub) {
	return s.rfind(sub) == (s.length() - sub.length()) ? 1 : 0;
}
anchors_640圖像接收數(shù)組
const float anchors_640[3][6] = { {10.0,  13.0, 16.0,  30.0,  33.0,  23.0},
				  {30.0,  61.0, 62.0,  45.0,  59.0,  119.0},
				  {116.0, 90.0, 156.0, 198.0, 373.0, 326.0} };

根據(jù)圖像大小,選擇相應(yīng)長度的二維數(shù)組。深度為3,每層6個位置。文章來源地址http://www.zghlxwxcb.cn/news/detail-635404.html

YOLO類
class YOLO{
public:
	YOLO(Net_config config); //構(gòu)造函數(shù)
	void detect(Mat& frame); //通過圖像參數(shù),進(jìn)行目標(biāo)檢測
private:
	float* anchors;
	int num_stride;
	int inpWidth;
	int inpHeight;
	vector<string> class_names;
	int num_class;
	float confThreshold;
	float nmsThreshold;
	float objThreshold;
	const bool keep_ratio = true;
	Net net;
	void drawPred(float conf, int left, int top, int right, int bottom, Mat& frame, int classid);
	Mat resize_image(Mat srcimg, int* newh, int* neww, int* top, int* left);
};
YOLO類構(gòu)造函數(shù)的重載
YOLO::YOLO(Net_config config){
	this->confThreshold = config.confThreshold;
	this->nmsThreshold = config.nmsThreshold;
	this->objThreshold = config.objThreshold;
	this->net = readNet(config.modelpath);
	ifstream ifs("class.names"); //class.name中寫入標(biāo)簽內(nèi)容,當(dāng)前只有'person',位置與當(dāng)前.cpp文件同級
	string line;
	while (getline(ifs, line)) this->class_names.push_back(line);
	this->num_class = class_names.size();
	if (endsWith(config.modelpath, "6.onnx")){ //根據(jù)onnx的輸入圖像格式 選擇分辨率 當(dāng)前為1280x1280 可靈活調(diào)整
		anchors = (float*)anchors_1280;
		this->num_stride = 4;      //深度
		this->inpHeight = 1280;    //高
		this->inpWidth = 1280;     //寬
	}
	else{                                       //當(dāng)前為640x640 可以resize滿足onnx需求 也可以調(diào)整數(shù)組或if中的onnx判斷
		anchors = (float*)anchors_640;
		this->num_stride = 3;
		this->inpHeight = 640;
		this->inpWidth = 640;
	}
}
重新規(guī)定圖像大小函數(shù) resize_image()
Mat YOLO::resize_image(Mat srcimg, int* newh, int* neww, int* top, int* left){//傳入圖像以及需要改變的參數(shù)
	int srch = srcimg.rows, srcw = srcimg.cols;
	*newh = this->inpHeight;
	*neww = this->inpWidth;
	Mat dstimg;
	if (this->keep_ratio && srch != srcw) {
		float hw_scale = (float)srch / srcw;
		if (hw_scale > 1) {
			*newh = this->inpHeight;
			*neww = int(this->inpWidth / hw_scale);
			resize(srcimg, dstimg, Size(*neww, *newh), INTER_AREA);
			*left = int((this->inpWidth - *neww) * 0.5);
			copyMakeBorder(dstimg, dstimg, 0, 0, *left, this->inpWidth - *neww - *left, BORDER_CONSTANT, 114);
		}else {
			*newh = (int)this->inpHeight * hw_scale;
			*neww = this->inpWidth;
			resize(srcimg, dstimg, Size(*neww, *newh), INTER_AREA);
			*top = (int)(this->inpHeight - *newh) * 0.5;
			copyMakeBorder(dstimg, dstimg, *top, this->inpHeight - *newh - *top, 0, 0, BORDER_CONSTANT, 114);
		}
	}else {
		resize(srcimg, dstimg, Size(*neww, *newh), INTER_AREA);
	}
	return dstimg;
}
繪制預(yù)測的邊界框函數(shù) drawPred()
void YOLO::drawPred(float conf, int left, int top, int right, int bottom, Mat& frame, int classid){
	//繪制一個顯示邊界框的矩形
	rectangle(frame, Point(left, top), Point(right, bottom), Scalar(0, 0, 255), 2);

	//獲取類名的標(biāo)簽及其置信度
	string label = format("%.2f", conf);
	label = this->class_names[classid] + ":" + label;

	//在邊界框頂部顯示標(biāo)簽
	int baseLine;
	Size labelSize = 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);
}
【核心代碼】檢測函數(shù) detect()
void YOLO::detect(Mat& frame){
	int newh = 0, neww = 0, padh = 0, padw = 0;
	Mat dstimg = this->resize_image(frame, &newh, &neww, &padh, &padw);
	Mat blob = blobFromImage(dstimg, 1 / 255.0, Size(this->inpWidth, this->inpHeight), Scalar(0, 0, 0), true, false);
	this->net.setInput(blob);
	vector<Mat> outs;
	this->net.forward(outs, this->net.getUnconnectedOutLayersNames());
	int num_proposal = outs[0].size[1];
	int nout = outs[0].size[2];
	if (outs[0].dims > 2){
		outs[0] = outs[0].reshape(0, num_proposal);
	}
	
	vector<float> confidences;
	vector<Rect> boxes;
	vector<int> classIds;
	float ratioh = (float)frame.rows / newh, ratiow = (float)frame.cols / neww;
	int n = 0, q = 0, i = 0, j = 0, row_ind = 0;  //xmin,ymin,xamx,ymax,box_score,class_score
	float* pdata = (float*)outs[0].data;
	for (n = 0; n < this->num_stride; n++){ //特征圖尺度
		const float stride = pow(2, n + 3);
		int num_grid_x = (int)ceil((this->inpWidth / stride));
		int num_grid_y = (int)ceil((this->inpHeight / stride));
		for (q = 0; q < 3; q++){
			const float anchor_w = this->anchors[n * 6 + q * 2];
			const float anchor_h = this->anchors[n * 6 + q * 2 + 1];
			for (i = 0; i < num_grid_y; i++){
				for (j = 0; j < num_grid_x; j++){
					float box_score = pdata[4];
					if (box_score > this->objThreshold){
						Mat scores = outs[0].row(row_ind).colRange(5, nout);
						Point classIdPoint;
						double max_class_socre;
						//獲取最高分的值和位置
						minMaxLoc(scores, 0, &max_class_socre, 0, &classIdPoint);
						max_class_socre *= box_score;
						if (max_class_socre > this->confThreshold){
							const int class_idx = classIdPoint.x;
							float cx = pdata[0];  //cx
							float cy = pdata[1];  //cy
							float w = pdata[2];   //w
							float h = pdata[3];   //h
							int left = int((cx - padw - 0.5 * w) * ratiow);
							int top = int((cy - padh - 0.5 * h) * ratioh);
							confidences.push_back((float)max_class_socre);
							boxes.push_back(Rect(left, top, (int)(w * ratiow), (int)(h * ratioh)));
							classIds.push_back(class_idx);
						}
					}
					row_ind++;
					pdata += nout;
				}
			}
		}
	}
	// 執(zhí)行非最大抑制以消除冗余重疊框
	// 置信度較低
	vector<int> indices;
	dnn::NMSBoxes(boxes, confidences, this->confThreshold, this->nmsThreshold, indices);
	for (size_t i = 0; i < indices.size(); ++i){
		int idx = indices[i];
		Rect box = boxes[idx];
		this->drawPred(confidences[idx], box.x, box.y,box.x + box.width, box.y + box.height, frame, classIds[idx]);
	}
}

主函數(shù)

int main(){
        //加載onnx模型
	Net_config yolo_nets = { 0.3, 0.5, 0.3, "yolov5n_person_320.onnx" };
	YOLO yolo_model(yolo_nets);
        //加載單張圖片
	string imgpath = "112.png";
	Mat srcimg = imread(imgpath);
	//開始檢測
        yolo_model.detect(srcimg);
	static const string kWinName = "Deep learning object detection in OpenCV";
	namedWindow(kWinName, WINDOW_NORMAL);
	imshow(kWinName, srcimg); //顯示圖片
	waitKey(0);               //保持停留
	destroyAllWindows();      //關(guān)閉窗口并取消分配任何相關(guān)的內(nèi)存使用
}

完整代碼

#include <fstream>
#include <sstream>
#include <iostream>
#include <opencv2/dnn.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>

using namespace cv;
using namespace dnn;
using namespace std;

struct Net_config
{
	float confThreshold; // Confidence threshold
	float nmsThreshold;  // Non-maximum suppression threshold
	float objThreshold;  //Object Confidence threshold
	string modelpath;
};

int endsWith(string s, string sub) {
	return s.rfind(sub) == (s.length() - sub.length()) ? 1 : 0;
}

const float anchors_640[3][6] = { {10.0,  13.0, 16.0,  30.0,  33.0,  23.0},
				  {30.0,  61.0, 62.0,  45.0,  59.0,  119.0},
				  {116.0, 90.0, 156.0, 198.0, 373.0, 326.0} };

const float anchors_1280[4][6] = { {19, 27, 44, 40, 38, 94},
                                   {96, 68, 86, 152, 180, 137},
                                   {140, 301, 303, 264, 238, 542},
				   {436, 615, 739, 380, 925, 792} };

class YOLO
{
public:
	YOLO(Net_config config);
	void detect(Mat& frame);
private:
	float* anchors;
	int num_stride;
	int inpWidth;
	int inpHeight;
	vector<string> class_names;
	int num_class;

	float confThreshold;
	float nmsThreshold;
	float objThreshold;
	const bool keep_ratio = true;
	Net net;
	void drawPred(float conf, int left, int top, int right, int bottom, Mat& frame, int classid);
	Mat resize_image(Mat srcimg, int* newh, int* neww, int* top, int* left);
};

YOLO::YOLO(Net_config config)
{
	this->confThreshold = config.confThreshold;
	this->nmsThreshold = config.nmsThreshold;
	this->objThreshold = config.objThreshold;

	this->net = readNet(config.modelpath);
	ifstream ifs("class.names");
	string line;
	while (getline(ifs, line)) this->class_names.push_back(line);
	this->num_class = class_names.size();

	if (endsWith(config.modelpath, "6.onnx"))
	{
		anchors = (float*)anchors_1280;
		this->num_stride = 4;
		this->inpHeight = 1280;
		this->inpWidth = 1280;
	}
	else
	{
		anchors = (float*)anchors_640;
		this->num_stride = 3;
		this->inpHeight = 640;
		this->inpWidth = 640;
	}
}

Mat YOLO::resize_image(Mat srcimg, int* newh, int* neww, int* top, int* left)
{
	int srch = srcimg.rows, srcw = srcimg.cols;
	*newh = this->inpHeight;
	*neww = this->inpWidth;
	Mat dstimg;
	if (this->keep_ratio && srch != srcw) {
		float hw_scale = (float)srch / srcw;
		if (hw_scale > 1) {
			*newh = this->inpHeight;
			*neww = int(this->inpWidth / hw_scale);
			resize(srcimg, dstimg, Size(*neww, *newh), INTER_AREA);
			*left = int((this->inpWidth - *neww) * 0.5);
			copyMakeBorder(dstimg, dstimg, 0, 0, *left, this->inpWidth - *neww - *left, BORDER_CONSTANT, 114);
		}
		else {
			*newh = (int)this->inpHeight * hw_scale;
			*neww = this->inpWidth;
			resize(srcimg, dstimg, Size(*neww, *newh), INTER_AREA);
			*top = (int)(this->inpHeight - *newh) * 0.5;
			copyMakeBorder(dstimg, dstimg, *top, this->inpHeight - *newh - *top, 0, 0, BORDER_CONSTANT, 114);
		}
	}
	else {
		resize(srcimg, dstimg, Size(*neww, *newh), INTER_AREA);
	}
	return dstimg;
}

void YOLO::drawPred(float conf, int left, int top, int right, int bottom, Mat& frame, int classid)   // Draw the predicted bounding box
{
	//Draw a rectangle displaying the bounding box
	rectangle(frame, Point(left, top), Point(right, bottom), Scalar(0, 0, 255), 2);

	//Get the label for the class name and its confidence
	string label = format("%.2f", conf);
	label = this->class_names[classid] + ":" + label;

	//Display the label at the top of the bounding box
	int baseLine;
	Size labelSize = 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);
}

void YOLO::detect(Mat& frame)
{
	int newh = 0, neww = 0, padh = 0, padw = 0;
	Mat dstimg = this->resize_image(frame, &newh, &neww, &padh, &padw);
	Mat blob = blobFromImage(dstimg, 1 / 255.0, Size(this->inpWidth, this->inpHeight), Scalar(0, 0, 0), true, false);
	this->net.setInput(blob);
	vector<Mat> outs;
	this->net.forward(outs, this->net.getUnconnectedOutLayersNames());

	int num_proposal = outs[0].size[1];
	int nout = outs[0].size[2];
	if (outs[0].dims > 2)
	{
		outs[0] = outs[0].reshape(0, num_proposal);
	}
	/generate proposals
	vector<float> confidences;
	vector<Rect> boxes;
	vector<int> classIds;
	float ratioh = (float)frame.rows / newh, ratiow = (float)frame.cols / neww;
	int n = 0, q = 0, i = 0, j = 0, row_ind = 0; ///xmin,ymin,xamx,ymax,box_score,class_score
	float* pdata = (float*)outs[0].data;
	for (n = 0; n < this->num_stride; n++)   ///特征圖尺度
	{
		const float stride = pow(2, n + 3);
		int num_grid_x = (int)ceil((this->inpWidth / stride));
		int num_grid_y = (int)ceil((this->inpHeight / stride));
		for (q = 0; q < 3; q++)    ///anchor
		{
			const float anchor_w = this->anchors[n * 6 + q * 2];
			const float anchor_h = this->anchors[n * 6 + q * 2 + 1];
			for (i = 0; i < num_grid_y; i++)
			{
				for (j = 0; j < num_grid_x; j++)
				{
					float box_score = pdata[4];
					if (box_score > this->objThreshold)
					{
						Mat scores = outs[0].row(row_ind).colRange(5, nout);
						Point classIdPoint;
						double max_class_socre;
						// Get the value and location of the maximum score
						minMaxLoc(scores, 0, &max_class_socre, 0, &classIdPoint);
						max_class_socre *= box_score;
						if (max_class_socre > this->confThreshold)
						{
							const int class_idx = classIdPoint.x;
							//float cx = (pdata[0] * 2.f - 0.5f + j) * stride;  ///cx
							//float cy = (pdata[1] * 2.f - 0.5f + i) * stride;   ///cy
							//float w = powf(pdata[2] * 2.f, 2.f) * anchor_w;   ///w
							//float h = powf(pdata[3] * 2.f, 2.f) * anchor_h;  ///h

							float cx = pdata[0];  ///cx
							float cy = pdata[1];   ///cy
							float w = pdata[2];   ///w
							float h = pdata[3];  ///h

							int left = int((cx - padw - 0.5 * w) * ratiow);
							int top = int((cy - padh - 0.5 * h) * ratioh);

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

	// Perform non maximum suppression to eliminate redundant overlapping boxes with
	// lower confidences
	vector<int> indices;
	dnn::NMSBoxes(boxes, confidences, this->confThreshold, this->nmsThreshold, indices);
	for (size_t i = 0; i < indices.size(); ++i)
	{
		int idx = indices[i];
		Rect box = boxes[idx];
		this->drawPred(confidences[idx], box.x, box.y,
			box.x + box.width, box.y + box.height, frame, classIds[idx]);
	}
}

int main()
{
	Net_config yolo_nets = { 0.3, 0.5, 0.3, "yolov5n_person_320.onnx" };
	YOLO yolo_model(yolo_nets);

	//string imgpath = "112.png";
	//Mat srcimg = imread(imgpath);
	//yolo_model.detect(srcimg);
        
        int n = 588;
	for (int i = 1; i <= n; i++) {
		string s = to_string(i) + ".png";
		string imgpath = "F://test//p1//yanfa2//bh//cc//" + s;
		cout << imgpath << endl;

		Mat srcimg = imread(imgpath);
		yolo_model.detect(srcimg);
		imwrite("F://test//p2//yanfa2//bh//cc//" + s, srcimg);
	}

	//static const string kWinName = "Deep learning object detection in OpenCV";
	//namedWindow(kWinName, WINDOW_NORMAL);
	//imshow(kWinName, srcimg);
	//waitKey(0);
	//destroyAllWindows();
}

到了這里,關(guān)于Opencv C++實現(xiàn)yolov5部署onnx模型完成目標(biāo)檢測的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進(jìn)行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • C++調(diào)用yolov5 onnx模型的初步探索

    yolov5-dnn-cpp-python https://github.com/hpc203/yolov5-dnn-cpp-python 轉(zhuǎn)onnx: 用opencv的dnn模塊做yolov5目標(biāo)檢測的程序,包含兩個步驟:(1).把pytorch的訓(xùn)練模型.pth文件轉(zhuǎn)換到.onnx文件。(2).opencv的dnn模塊讀取.onnx文件做前向計算。 SiLU其實就是swish激活函數(shù),而在onnx模型里是不直接支持swish算子的

    2024年02月12日
    瀏覽(24)
  • [C++]使用yolov8的onnx模型僅用opencv和bytetrack實現(xiàn)目標(biāo)追蹤

    [C++]使用yolov8的onnx模型僅用opencv和bytetrack實現(xiàn)目標(biāo)追蹤

    【官方框架地址】 yolov8: https://github.com/ultralytics/ultralytics bytetrack: https://github.com/ifzhang/ByteTrack 【算法介紹】 隨著人工智能技術(shù)的不斷發(fā)展,目標(biāo)追蹤已成為計算機(jī)視覺領(lǐng)域的重要研究方向。Yolov8和ByTetrack作為當(dāng)前先進(jìn)的算法,當(dāng)它們結(jié)合使用時,能夠顯著提升目標(biāo)追蹤的準(zhǔn)

    2024年01月24日
    瀏覽(26)
  • 詳細(xì)介紹 Yolov5 轉(zhuǎn) ONNX模型 + 使用ONNX Runtime 的 Python 部署(包含官方文檔的介紹)

    詳細(xì)介紹 Yolov5 轉(zhuǎn) ONNX模型 + 使用ONNX Runtime 的 Python 部署(包含官方文檔的介紹)

    對ONNX的介紹強(qiáng)烈建議看,本文做了很多參考:模型部署入門教程(一):模型部署簡介 模型部署入門教程(三):PyTorch 轉(zhuǎn) ONNX 詳解 以及Pytorch的官方介紹:(OPTIONAL) EXPORTING A MODEL FROM PYTORCH TO ONNX AND RUNNING IT USING ONNX RUNTIME C++的部署:詳細(xì)介紹 Yolov5 轉(zhuǎn) ONNX模型 + 使用 ONNX Runti

    2024年02月01日
    瀏覽(26)
  • 使用OpenCV DNN推理YOLOv5-CLS轉(zhuǎn)換后的ONNX分類模型

    YOLOv5是一種先進(jìn)的目標(biāo)檢測算法,而YOLOv5-CLS則是YOLOv5的一個變種,專門用于圖像分類任務(wù)。為了在實際應(yīng)用中使用YOLOv5-CLS模型,我們需要將其轉(zhuǎn)換為Open Neural Network Exchange (ONNX) 格式,并使用OpenCV DNN庫來進(jìn)行推理。 步驟1: 安裝OpenCV和ONNX 首先,你需要確保已經(jīng)安裝了OpenCV和

    2024年02月16日
    瀏覽(102)
  • 36、RK3399Pro 環(huán)境搭建和Yolov5 c++調(diào)用opencv進(jìn)行RKNN模型部署和使用

    36、RK3399Pro 環(huán)境搭建和Yolov5 c++調(diào)用opencv進(jìn)行RKNN模型部署和使用

    基本思想:記錄rk3399 pro配置環(huán)境和c++ npu開發(fā)記錄,主要想搞一份c++代碼和其它圖像算法結(jié)合一下,好進(jìn)行部署,淘寶鏈接見附錄 ?需要的python3.7對應(yīng)的aarch64的whl包:包含opencv-whl 、h5py-whl包: 鏈接: https://pan.baidu.com/s/1cvCAmHBa_4KgEjrcFIYnig 提取碼: 5ui4 鏈接: https://pan.baidu.com/s/1hrc

    2024年02月07日
    瀏覽(28)
  • yolov5 opencv dnn部署自己的模型

    yolov5 opencv dnn部署自己的模型

    github開源代碼地址 yolov5官網(wǎng)還提供的dnn、tensorrt推理鏈接 本人使用的opencv c++ github代碼,代碼作者非本人,也是上面作者推薦的鏈接之一 如果想要嘗試直接運(yùn)行源碼中的yolo.cpp文件和yolov5s.pt推理sample.mp4,請參考這個鏈接的介紹 使用github源碼結(jié)合自己導(dǎo)出的onnx模型推理自己的

    2024年01月23日
    瀏覽(48)
  • 用C++部署yolov5模型

    要在C語言中部署YoloV5模型,可以使用以下步驟: 安裝C語言的深度學(xué)習(xí)庫,例如Darknet或者ncnn。 下載訓(xùn)練好的YoloV5模型權(quán)重文件(.pt文件)和模型配置文件(.yaml文件)。 將下載的權(quán)重文件和配置文件移動到C語言深度學(xué)習(xí)庫中指定的目錄下。 在C語言中編寫代碼,使用深度學(xué)習(xí)庫加

    2024年02月15日
    瀏覽(23)
  • yolov5 pt 模型 導(dǎo)出 onnx

    yolov5 pt 模型 導(dǎo)出 onnx

    在訓(xùn)練好的yolov5 pt 模型 可以 通過 export.py 進(jìn)行導(dǎo)出 onnx 導(dǎo)出流程 在 export.py 設(shè)置模型和數(shù)據(jù)源的yaml 在官方的文檔中 說明了可以導(dǎo)出的具體的類型。 在 --include 添加導(dǎo)出的類型, 不同的 類型的 環(huán)境要求不一樣,建議虛擬環(huán)境,比如onnx 和 openvino 的numpy 版本要求不一只,一

    2024年02月11日
    瀏覽(23)
  • YOLOv5 實例分割 用 OPenCV DNN C++ 部署

    YOLOv5 實例分割 用 OPenCV DNN C++ 部署

    如果之前從沒接觸過實例分割,建議先了解一下實例分割的輸出是什么。 實例分割兩個關(guān)鍵輸出是:mask系數(shù)、mask原型 本文參考自該項目(這么優(yōu)秀的代碼當(dāng)然要給star!):GitHub - UNeedCryDear/yolov5-seg-opencv-onnxruntime-cpp: yolov5 segmentation with onnxruntime and opencv 目錄 Pre: 一、代碼總結(jié)

    2024年02月12日
    瀏覽(26)
  • Yolov5 ONNX Runtime 的 Python 部署

    這里使用的yolov5 6.2,使用export.py很方便地得到onnx格式的模型。然后用onnxruntime推理框架在Python上進(jìn)行部署。主要是為了測試模型的準(zhǔn)確,模型部署的最終是用 C++ 部署,從而部署在嵌入式設(shè)備等。 整個代碼分為四個部分:1、對輸入進(jìn)行預(yù)處理; 2、onnxruntime推理得到輸出;

    2024年02月13日
    瀏覽(18)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包