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

摄影做网站全国防疫大数据平台

摄影做网站,全国防疫大数据平台,上海网站建设公,懒人图库网站源码windows 使用yolov5训练模型,之后opencv加载模型进行推理。 一,搭建环境 安装 Anaconda 二,创建虚拟环境并安装yolov5 conda create -n yolov5 python3.9 -y conda activate yolov5 git clone https://github.com/ultralytics/yolov5 cd …

windows 使用yolov5训练模型,之后opencv加载模型进行推理。

一,搭建环境

安装 Anaconda

二,创建虚拟环境并安装yolov5

conda create -n yolov5 python=3.9 -y
conda activate yolov5
git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt

三,安装LabelImg 进行标注

四,准备训练配置

1,data.yaml

train: ./images/train
val: ./images/valnc: 1
names: ['erha'] #类别名称,比如二哈

2,确保图像和标签对应

images/train/img001.jpg
labels/train/img001.txt

3,训练

python train.py --img 640 --batch 16 --epochs 50 --data  ./keiler/datasets/data.yaml --weights yolov5s.pt --name erha

输出模型路径:

runs/train/erha4/weights/best.pt

4,将模型 转成 onnx格式,这样才能给到opencv  加载

 五,opencv 推理

#include <iostream>
#include <Thread/semaphore.h>
#include <signal.h>
#include "core/Engine.h"
#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <iostream>
using namespace toolkit;using namespace cv;
using namespace dnn;
using namespace std;int main()
{// 加载模型Net net = readNetFromONNX("best.onnx");net.setPreferableBackend(DNN_BACKEND_OPENCV);net.setPreferableTarget(DNN_TARGET_CPU); // 可改为 DNN_TARGET_CUDAcout << "Net is empty? " << net.empty() << endl;// 读取图像Mat image = imread("test.jpeg");if (image.empty()){cerr << "Image not found!" << endl;return -1;}// YOLOv5 输入大小int input_width = 640;int input_height = 640;int num_classes = 1;// 原图尺寸int original_width = image.cols;int original_height = image.rows;// 预处理Mat blob;resize(image, image, Size(input_width, input_height));blobFromImage(image, blob, 1.0 / 255.0, Size(input_width, input_height), Scalar(), true, false);// 设置输入net.setInput(blob);// 前向推理std::vector<Mat> outputs;net.forward(outputs, net.getUnconnectedOutLayersNames());// 后处理float confThreshold = 0.001;float nmsThreshold = 0.001;vector<int> classIds;vector<float> confidences;vector<Rect> boxes;// 输出维度 [1, N, 85]Mat output = outputs[0];const int num_detections = output.size[1];const int dimensions = output.size[2];float* data = (float*)output.data;float x_factor = (float)original_width / input_width;float y_factor = (float)original_height / input_height;std::cout<<"num_detections "<<num_detections<<std::endl;for (int i = 0; i < num_detections; ++i) {float obj_conf = data[i * dimensions + 4];std::cout<<" obj_conf"<<obj_conf<<std::endl;if (obj_conf < confThreshold) continue;float* class_scores = data + i * dimensions + 5;Mat scores(1, num_classes, CV_32F, class_scores);Point classIdPoint;double max_class_score;minMaxLoc(scores, 0, &max_class_score, 0, &classIdPoint);float confidence = obj_conf * (float)max_class_score;std::cout<<" confidence"<<confidence<<std::endl;if (confidence > confThreshold) {// 解码框坐标float cx = data[i * dimensions + 0];float cy = data[i * dimensions + 1];float w = data[i * dimensions + 2];float h = data[i * dimensions + 3];int left = (int)((cx - w / 2) * x_factor);int top = (int)((cy - h / 2) * y_factor);int width = (int)(w * x_factor);int height = (int)(h * y_factor);boxes.push_back(Rect(left, top, width, height));confidences.push_back(confidence);classIds.push_back(classIdPoint.x);}}// NMS 抑制vector<int> indices;NMSBoxes(boxes, confidences, confThreshold, nmsThreshold, indices);for (int idx : indices) {Rect box = boxes[idx];rectangle(image, box, Scalar(0, 255, 0), 2);putText(image, to_string(classIds[idx]), box.tl(), FONT_HERSHEY_SIMPLEX, 0.6, Scalar(0, 0, 255), 2);}cv::imwrite("result.jpg", image);}

失败了,没有检测出来,稍后再查查。

http://www.dtcms.com/wzjs/100264.html

相关文章:

  • 外贸营销网站建设公司广西关键词优化公司
  • 网站域名的密码站长之家怎么找网址
  • 企业做增资 网站平台网络营销运营方案
  • 顺德定制网站设计淘宝关键词排名是怎么做的
  • 最专业的网站制作公司搜索引擎营销的方式
  • 大型网站怎么加载图片的快速排名软件seo系统
  • 没有网站怎么做链接视频播放器百度指数查询排行榜
  • 创建免费网站需要什么条件西安区seo搜索排名优化
  • 人和动物做的电影网站seo标题优化步骤
  • html手机网站怎么做seo流量增加软件
  • 做网站属于程序员吗短视频培训要多少学费
  • 关键词排名优化咨询苏州seo关键词优化排名
  • 一个人在家做网站建设软件网站关键词优化
  • 寻找在山西运城专业做网站推广的网站关键词优化代理
  • 长沙网上商城开发搜索引擎优化网页
  • 高端网站建设与管理谷歌推广平台
  • 微信公众号微网站怎么做的网络推广怎么收费
  • 网站如何做好内链网站推广100种方法
  • 青海省建设工程在哪个网站发布深圳全网推广
  • 谷歌做网站推广网店运营流程步骤
  • 企业在线查询系统百度手机端排名如何优化
  • 苏州做企业网站公司网页百度网盘
  • 品牌设计网站大全武汉seo优化代理
  • 汽车网站建设流程长沙网站seo分析
  • 山海关网站制作比百度还强大的搜索引擎
  • 木地板企业网站模版全网营销系统1700元真实吗
  • 免费网站封装app北京官网优化公司
  • 做钢材都有什么网站青岛seo博客
  • 中国有名的网站建设公司商城小程序
  • 网站建设地带最新发布的最新