当前位置: 首页 > news >正文

Opencv C++实现yolov5部署onnx模型完成目标检测

代码分析:

头文件

#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;

结构体 Net_config

struct Net_config{float confThreshold; // 置信度阈值float nmsThreshold;  // 非最大抑制阈值float objThreshold;  // 对象置信度阈值string modelpath;
};

里面存了三个阈值和模型地址,其中置信度,顾名思义,看检测出来的物体的精准度。以测量值为中心,在一定范围内,真值出现在该范围内的几率。

endsWith()函数 判断sub是不是s的子串

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

anchors_640图像接收数组

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} };

根据图像大小,选择相应长度的二维数组。深度为3,每层6个位置。

YOLO类

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::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中写入标签内容,当前只有'person',位置与当前.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")){ //根据onnx的输入图像格式 选择分辨率 当前为1280x1280 可灵活调整anchors = (float*)anchors_1280;this->num_stride = 4;      //深度this->inpHeight = 1280;    //高this->inpWidth = 1280;     //宽}else{                                       //当前为640x640 可以resize满足onnx需求 也可以调整数组或if中的onnx判断anchors = (float*)anchors_640;this->num_stride = 3;this->inpHeight = 640;this->inpWidth = 640;}
}

重新规定图像大小函数 resize_image()

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;
}

绘制预测的边界框函数 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);//获取类名的标签及其置信度string label = format("%.2f", conf);label = this->class_names[classid] + ":" + label;//在边界框顶部显示标签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);
}

【核心代码】检测函数 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_scorefloat* 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];  //cxfloat cy = pdata[1];  //cyfloat w = pdata[2];   //wfloat h = pdata[3];   //hint 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;}}}}// 执行非最大抑制以消除冗余重叠框// 置信度较低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(){//加载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();      //关闭窗口并取消分配任何相关的内存使用
}

完整代码

#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 thresholdfloat nmsThreshold;  // Non-maximum suppression thresholdfloat objThreshold;  //Object Confidence thresholdstring 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 boxrectangle(frame, Point(left, top), Point(right, bottom), Scalar(0, 0, 255), 2);//Get the label for the class name and its confidencestring label = format("%.2f", conf);label = this->class_names[classid] + ":" + label;//Display the label at the top of the bounding boxint 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 proposalsvector<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_scorefloat* 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 scoreminMaxLoc(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;  ///hfloat cx = pdata[0];  ///cxfloat cy = pdata[1];   ///cyfloat w = pdata[2];   ///wfloat h = pdata[3];  ///hint 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 confidencesvector<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();
}

相关文章:

Opencv C++实现yolov5部署onnx模型完成目标检测

代码分析&#xff1a; 头文件 #include <fstream> //文件 #include <sstream> //流 #include <iostream> #include <opencv2/dnn.hpp> //深度学习模块-仅提供推理功能 #include <opencv2/imgproc.hpp> //图像处理模块 #include &l…...

django bootstrap html实现左右布局,带折叠按钮,左侧可折叠隐藏

一、实现的效果 在django项目中,需要使用bootstrap 实现一个左右分布的布局,左侧区域可以折叠隐藏起来,使得右侧的显示区域变大。(为了区分区域,左右加了配色,不好看的修改颜色即可) 点击折叠按钮,左侧区域隐藏,右侧区域铺满: 二、实现思路 1、使用col-md属性,让左…...

Mapping温度分布验证选择数据记录仪时需要考虑的13件事

01 什么是温度分布验证&#xff1f; 温度分布验证是通过在规定的研究时间内测量定义区域内的多个点来确定特定温度控制环境或过程&#xff08;如冷冻柜、冰箱、培养箱、稳定室、仓库或高压灭菌器&#xff09;的温度分布的过程。温度分布验证的目标是确定每个测量点之间的差异&…...

【题解】 判断一个链表是否为回文结构

判断一个链表是否为回文结构 题目链接&#xff1a;判断一个链表是否为回文结构 解题思路1&#xff1a;借助数组 遍历链表将值都放在数组中&#xff0c;再遍历数组元素&#xff0c;判断该数组是否为一个回文结构 代码如下&#xff1a; bool isPail(ListNode* head) {ListNod…...

Microsoft Message Queuing Denial-of-Service Vulnerability

近期官方公布了一个MSMQ的拒绝服务漏洞&#xff0c;可能因为网络安全设备的更新&#xff0c;影响业务&#xff0c;值得大家关注。 漏洞具体描述参见如下&#xff1a; Name: Microsoft Message Queuing Denial-of-Service Vulnerability Description: Microsoft Message Queuing…...

软件设计师(五)软件工程基础知识

一、软件工程概述 软件开发和维护过程中所遇到的各种问题称为“软件危机”。 软件工程是指应用计算机科学、数学及管理科学等原理&#xff0c;以工程化的原则和方法来解决软件问题的工程&#xff0c;其目的是提高软件生产率、提高软件质量、降低软件成本。 #mermaid-svg-h3j6K…...

Java中的JUnit单元测试方法的使用

Java中的JUnit单元测试方法 使用步骤如下&#xff1a; 选中当前工程 - 右键选择&#xff1a;build path - add libraries - JUnit 4 - 下一步创建Java类&#xff0c;进行单元测试。 此时的Java类要求&#xff1a;① 此类是public的 ②此类提供公共的无参的构造器此类中声明单…...

一文学透设计模式——抽象工厂模式

创建者模式 抽象工厂模式 概念 抽象工厂模式是围绕一个超级工厂创建其他工厂。该超级工厂又称为其他工厂的工厂。这种类型的设计模式属于创建型模式&#xff0c;它提供了一种创建对象的最佳方式。 这是很多地方对于抽象工厂模式的描述&#xff0c;说实话感觉不是特别好懂。…...

Vue3与Vue2区别和总结(1)

在2020年9月18日&#xff0c;Vue.js发布3.0版本&#xff0c;代号&#xff1a;One Piece&#xff08;海贼王&#xff09; 既然vue2已经存在了六七年之久为什么还要研发vue3呢&#xff1f; 那就不得不提vue3带来的提升了 1.Vue3带来了什么 1.性能的提升 打包大小减少41% 初次…...

【华秋推荐】物联网入门学习模块 ESP8266

随着全球信息技术的不断进步和普及&#xff0c;物联网成为当今备受关注的技术热点之一。通过物理和数字设备之间的连接来实现自动化和互联互通的网络。无线传感器、云计算和大数据分析等技术&#xff0c;物联网使设备能够相互交流和共享信息&#xff0c;实现智能化的自动化操作…...

本科专科毕业论文如何选题-附1000多论文题目-论文选题--【毕业论文】

文章目录 本系列校训毕设的技术铺垫论文选题选题目的和意义&#xff1a;选题举例参考文献 配套资源 本系列校训 互相伤害互相卷&#xff0c;玩命学习要你管&#xff0c;天生我才必有用&#xff0c;我命由我不由天&#xff01; 毕业论文不怕难&#xff0c;毕业设计来铺垫&#…...

pip安装jupyter notebook

之前电脑安装了anaconda&#xff0c;里面安装了jupyter notebook&#xff0c;用来做PPT之类的展示总让我觉得有点“炫酷”。 现在换了新电脑。没有anaconda&#xff0c;纯粹只是装了python3.11&#xff0c;然后突然也想手工安装下jupyter notebook&#xff0c;于是只能通过pip方…...

STM32刷Micropython固件参考指南

STM32刷Micropython固件指南 其实刷固件和普通的程序下载烧录无多大的差异&#xff0c;主要是其他因数的影响导致刷固件或刷完固件无法运行的情况和相关问题。 &#x1f4d1;刷固件教程 固件下载。目前所支持的stm32型号有这些&#xff1a; stm32f0, stm32f4, stm32f7, stm32g…...

学生信息管理系统自动化测试

项目地址&#xff1a; http://82.156.151.156:8080/login.html 一、系统测试用例 二、测试实现过程 先是根据自己的项目设计了一个 UI 自动化测试用例, 然后根据这个测试用例使用了 selenium4自动化测试工具和 JUnit5单元测试框架结合实现的 web 自动化测试.。 测试模块划分…...

Java面向对象之toString()方法

toString()方法 toString()方法在Object类中定义&#xff0c;其返回值是String类型&#xff0c;返回类名和它的引用地址。在进行String与其它类型数据的连接操作时&#xff0c;自动调用toString()方法。 Date nownew Date(); System.out.println(“now”now); 相当于 System.…...

MySQL(一)

mysql简介 1、什么是数据库 &#xff1f; 数据库&#xff08;Database&#xff09;是按照数据结构来组织、存储和管理数据的仓库&#xff0c;它产生于距今六十多年前&#xff0c;随着信息技术和市场的发展&#xff0c;特别是二十世纪九十年代以后&#xff0c;数据管理不再仅仅…...

使用docker部署node和react应用

使用docker部署node和react应用 Docker 使开发人员能够将所有应用程序打包到容器中。这些容器可以在任何安装了 Docker 的机器上运行&#xff0c;并且应用程序将是相同的。这是在多个系统上运行代码库克隆的好方法&#xff0c;并且我们可以确保它们都是相同的。 在本文中&…...

对List集合、数组去重

前言&#xff1a; 还记得在2021我发布的第一篇博客就是关于数组的去重&#xff0c;从那一刻开始&#xff0c;命运的齿轮开始转动…… 扯远了哈哈哈&#xff0c;我重新写这篇文章只是想让去重方式更加严谨(ps&#xff1a;我才不会说是因为技术成长了&#xff0c;看不上之前写的…...

AI相机“妙鸭相机”原理分析和手动实现方案

妙鸭相机 一个通过上传大约20张照片&#xff0c;生成专属自拍。在2023年7月末爆火&#xff0c;根据36Kr报道&#xff0c;妙鸭相机系阿里系产品&#xff0c;挂靠在阿里大文娱体系下&#xff0c;并非独立公司。 使用方法是上传20张自拍照片&#xff0c;之后可以选择模板生成自己…...

关于计算机大学生秋招面试的那点事?(Golang篇)

前言&#xff1b; Go语言&#xff08;简称Golang&#xff09;越来越受到开发者的关注和欢迎。它由Google公司于2009年推出&#xff0c;旨在提供更好的性能和并发性能。眼下&#xff0c;越来越多的公司在使用它&#xff0c;比如著名的云计算服务商AWS&#xff0c;以及知名电商京…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

FFmpeg 低延迟同屏方案

引言 在实时互动需求激增的当下&#xff0c;无论是在线教育中的师生同屏演示、远程办公的屏幕共享协作&#xff0c;还是游戏直播的画面实时传输&#xff0c;低延迟同屏已成为保障用户体验的核心指标。FFmpeg 作为一款功能强大的多媒体框架&#xff0c;凭借其灵活的编解码、数据…...

系统设计 --- MongoDB亿级数据查询优化策略

系统设计 --- MongoDB亿级数据查询分表策略 背景Solution --- 分表 背景 使用audit log实现Audi Trail功能 Audit Trail范围: 六个月数据量: 每秒5-7条audi log&#xff0c;共计7千万 – 1亿条数据需要实现全文检索按照时间倒序因为license问题&#xff0c;不能使用ELK只能使用…...

质量体系的重要

质量体系是为确保产品、服务或过程质量满足规定要求&#xff0c;由相互关联的要素构成的有机整体。其核心内容可归纳为以下五个方面&#xff1a; &#x1f3db;️ 一、组织架构与职责 质量体系明确组织内各部门、岗位的职责与权限&#xff0c;形成层级清晰的管理网络&#xf…...

生成 Git SSH 证书

&#x1f511; 1. ​​生成 SSH 密钥对​​ 在终端&#xff08;Windows 使用 Git Bash&#xff0c;Mac/Linux 使用 Terminal&#xff09;执行命令&#xff1a; ssh-keygen -t rsa -b 4096 -C "your_emailexample.com" ​​参数说明​​&#xff1a; -t rsa&#x…...

12.找到字符串中所有字母异位词

&#x1f9e0; 题目解析 题目描述&#xff1a; 给定两个字符串 s 和 p&#xff0c;找出 s 中所有 p 的字母异位词的起始索引。 返回的答案以数组形式表示。 字母异位词定义&#xff1a; 若两个字符串包含的字符种类和出现次数完全相同&#xff0c;顺序无所谓&#xff0c;则互为…...

微信小程序云开发平台MySQL的连接方式

注&#xff1a;微信小程序云开发平台指的是腾讯云开发 先给结论&#xff1a;微信小程序云开发平台的MySQL&#xff0c;无法通过获取数据库连接信息的方式进行连接&#xff0c;连接只能通过云开发的SDK连接&#xff0c;具体要参考官方文档&#xff1a; 为什么&#xff1f; 因为…...

Map相关知识

数据结构 二叉树 二叉树&#xff0c;顾名思义&#xff0c;每个节点最多有两个“叉”&#xff0c;也就是两个子节点&#xff0c;分别是左子 节点和右子节点。不过&#xff0c;二叉树并不要求每个节点都有两个子节点&#xff0c;有的节点只 有左子节点&#xff0c;有的节点只有…...

大语言模型(LLM)中的KV缓存压缩与动态稀疏注意力机制设计

随着大语言模型&#xff08;LLM&#xff09;参数规模的增长&#xff0c;推理阶段的内存占用和计算复杂度成为核心挑战。传统注意力机制的计算复杂度随序列长度呈二次方增长&#xff0c;而KV缓存的内存消耗可能高达数十GB&#xff08;例如Llama2-7B处理100K token时需50GB内存&a…...

以光量子为例,详解量子获取方式

光量子技术获取量子比特可在室温下进行。该方式有望通过与名为硅光子学&#xff08;silicon photonics&#xff09;的光波导&#xff08;optical waveguide&#xff09;芯片制造技术和光纤等光通信技术相结合来实现量子计算机。量子力学中&#xff0c;光既是波又是粒子。光子本…...