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

网站建设 电子政务百度开户公司

网站建设 电子政务,百度开户公司,微信小程序开发工具软件,网站备案空间备案Yolov8目标识别特征检测如需安装运行环境或远程调试&#xff0c;见文章底部个人QQ名片&#xff0c;由专业技术人员远程协助&#xff01;前言这篇博客针对<<Yolov8目标识别特征检测>>编写代码&#xff0c;代码整洁&#xff0c;规则&#xff0c;易读。 学习与应用推荐…

Yolov8目标识别特征检测

如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!

前言

这篇博客针对<<Yolov8目标识别特征检测>>编写代码,代码整洁,规则,易读。 学习与应用推荐首选。

文章目录

一、所需工具软件

二、使用步骤

1. 引入库

2. 识别图像特征

3. 参数设置

4. 运行结果

三、在线协助

一、所需工具软件

1. Pycharm, Python

2. Yolov8, OpenCV

二、使用步骤

1.引入库

代码如下(示例):

import torchfrom ultralytics.yolo.engine.predictor import BasePredictor
from ultralytics.yolo.engine.results import Results
from ultralytics.yolo.utils import DEFAULT_CFG, ROOT, ops
from ultralytics.yolo.utils.plotting import Annotator, colors, save_one_box

2.识别图像特征

代码如下(示例):

class DetectionPredictor(BasePredictor):def get_annotator(self, img):return Annotator(img, line_width=self.args.line_thickness, example=str(self.model.names))def preprocess(self, img):img = torch.from_numpy(img).to(self.model.device)img = img.half() if self.model.fp16 else img.float()  # uint8 to fp16/32img /= 255  # 0 - 255 to 0.0 - 1.0return imgdef postprocess(self, preds, img, orig_img):preds = ops.non_max_suppression(preds,self.args.conf,self.args.iou,agnostic=self.args.agnostic_nms,max_det=self.args.max_det,classes=self.args.classes)results = []for i, pred in enumerate(preds):orig_img = orig_img[i] if isinstance(orig_img, list) else orig_imgshape = orig_img.shapepred[:, :4] = ops.scale_boxes(img.shape[2:], pred[:, :4], shape).round()results.append(Results(boxes=pred, orig_img=orig_img, names=self.model.names))return resultsdef write_results(self, idx, results, batch):p, im, im0 = batchlog_string = ''if len(im.shape) == 3:im = im[None]  # expand for batch dimself.seen += 1imc = im0.copy() if self.args.save_crop else im0if self.source_type.webcam or self.source_type.from_img:  # batch_size >= 1log_string += f'{idx}: 'frame = self.dataset.countelse:frame = getattr(self.dataset, 'frame', 0)self.data_path = pself.txt_path = str(self.save_dir / 'labels' / p.stem) + ('' if self.dataset.mode == 'image' else f'_{frame}')log_string += '%gx%g ' % im.shape[2:]  # print stringself.annotator = self.get_annotator(im0)det = results[idx].boxes  # TODO: make boxes inherit from tensorsif len(det) == 0:return log_stringfor c in det.cls.unique():n = (det.cls == c).sum()  # detections per classlog_string += f"{n} {self.model.names[int(c)]}{'s' * (n > 1)}, "# writefor d in reversed(det):cls, conf = d.cls.squeeze(), d.conf.squeeze()if self.args.save_txt:  # Write to fileline = (cls, *(d.xywhn.view(-1).tolist()), conf) \if self.args.save_conf else (cls, *(d.xywhn.view(-1).tolist()))  # label formatwith open(f'{self.txt_path}.txt', 'a') as f:f.write(('%g ' * len(line)).rstrip() % line + '\n')if self.args.save or self.args.save_crop or self.args.show:  # Add bbox to imagec = int(cls)  # integer classname = f'id:{int(d.id.item())} {self.model.names[c]}' if d.id is not None else self.model.names[c]label = None if self.args.hide_labels else (name if self.args.hide_conf else f'{name} {conf:.2f}')self.annotator.box_label(d.xyxy.squeeze(), label, color=colors(c, True))if self.args.save_crop:save_one_box(d.xyxy,imc,file=self.save_dir / 'crops' / self.model.model.names[c] / f'{self.data_path.stem}.jpg',BGR=True)return log_string

3.参数定义

代码如下(示例):

if __name__ == '__main__':parser = argparse.ArgumentParser()parser.add_argument('--weights', nargs='+', type=str, default='yolov5_best_road_crack_recog.pt', help='model.pt path(s)')parser.add_argument('--img-size', type=int, default=640, help='inference size (pixels)')parser.add_argument('--conf-thres', type=float, default=0.25, help='object confidence threshold')parser.add_argument('--iou-thres', type=float, default=0.45, help='IOU threshold for NMS')parser.add_argument('--view-img', action='store_true', help='display results')parser.add_argument('--save-txt', action='store_true', help='save results to *.txt')parser.add_argument('--classes', nargs='+', type=int, default='0', help='filter by class: --class 0, or --class 0 2 3')parser.add_argument('--agnostic-nms', action='store_true', help='class-agnostic NMS')parser.add_argument('--augment', action='store_true', help='augmented inference')parser.add_argument('--update', action='store_true', help='update all models')parser.add_argument('--project', default='runs/detect', help='save results to project/name')parser.add_argument('--name', default='exp', help='save results to project/name')parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')opt = parser.parse_args()

4.运行结果如下

三、在线协助:

如需安装运行环境或远程调试,见文章底部个人QQ名片,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Qt, C++, Python入门指导
3)界面美化
4)软件制作

博主推荐文章:https://blog.csdn.net/alicema1111/article/details/123851014

个人博客主页:https://blog.csdn.net/alicema1111?type=blog

博主所有文章点这里:https://blog.csdn.net/alicema1111?type=blog

http://www.wooajung.com/news/31335.html

相关文章:

  • 做兼职调查哪个网站好百度怎么做推广和宣传
  • 做防伪查询网站郑州做网站公司排名
  • 嘉兴做微网站的公司汽车软文广告
  • 2015做网站前景百度热榜排行
  • 做百度百科的网站aso排名
  • 公司网站后台怎么上传图片如何免费注册网站平台
  • 做音乐网站是不是侵权最新地址
  • 网站建设必须在服务器app下载推广
  • 怎么用网站做word文件格式国内最新新闻热点事件
  • 单位做好疫情防控工作情况重庆seo搜索引擎优化优与略
  • html做网站在手机上显示网盘网页版登录入口
  • 广州网站推广技巧最好用的搜索神器
  • 什么网站可以兼职做鸭子优化师培训机构
  • 临沂网站推广goldball重庆百度地图
  • 宠物交易网站模板成都网络营销公司
  • 怎么用手机建网站怎么推广网址
  • asia域名网站可靠吗情感网站seo
  • 网站合作建设合同免费的api接口网站
  • 廊坊怎么做网站百度推广登录入口登录
  • 怎样做自己的公司网站国内优秀网站案例
  • 数字藏品平台搭建seo搜索引擎优化是什么意思
  • 中华建设杂志网站记者微信小程序开发详细步骤
  • 餐饮类网站设计站内seo内容优化包括
  • asp绿色网站源码拼多多标题关键词优化方法
  • dede 手机站 怎么获取跳转网站百度搜索引擎营销如何实现
  • bootstrap单页网站深圳全网推互联科技有限公司
  • 网站制作视频教程下载谷歌浏览器 官网下载
  • 北京高端 网站建设品牌公关公司
  • 如何做单位网站门户网站建站系统
  • 抽奖网站插件seo英文怎么读