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

凡科能上传自己做的网站企业网站的建立方法

凡科能上传自己做的网站,企业网站的建立方法,宁夏建设工程造价网,网站系统的软件和硬件接口先前在跑DETR类目标检测算法时,由于其默认使用的是COCO数据集,所以输出结果中包含不同尺度的检测精度,即大、中、小目标。 而现在博主在使用ultralytics时,发现其并没有这个指标效果,但在先前的实验中,博主…

先前在跑DETR类目标检测算法时,由于其默认使用的是COCO数据集,所以输出结果中包含不同尺度的检测精度,即大、中、小目标。
而现在博主在使用ultralytics时,发现其并没有这个指标效果,但在先前的实验中,博主发现DETR中计算这些指标使用的是pycocotools这个工具包,那么我们就可以将检测结果和标注数据采用这个工具进行计算。话不多说,我们开整。

YOLO数据集转COCO

首先,我们要做的是将YOLO格式的数据集转换为COCO格式的数据集,代码如下:
这里需要注意的是,COCO的类别是从1开始的,而YOLO的类别则从0开始,那么我们就需要category_id = int(parts[0])+1

import os
import json
from PIL import Imagedef yolo_to_coco(yolo_dir, img_dir, output_file, categories):"""将YOLO格式的标注转换为COCO格式。:param yolo_dir: 包含YOLO标注txt文件的目录路径。:param img_dir: 包含对应图像的目录路径。:param output_file: 输出的COCO格式JSON文件路径。:param categories: 类别列表,如[{"id": 0, "name": "cat"}, {"id": 1, "name": "dog"}]"""images = []annotations = []image_id = 0annotation_id = 0for txt_file in os.listdir(yolo_dir):if not txt_file.endswith('.txt'):continue# 获取对应的图像文件名img_file = os.path.splitext(txt_file)[0] + '.jpg'image_id = os.path.splitext(txt_file)[0]img_path = os.path.join(img_dir, img_file)if not os.path.exists(img_path):print(f"找不到对应的图像文件: {img_file}")continue# 获取图像尺寸with Image.open(img_path) as img:width, height = img.size# 图像信息image_info = {"id": image_id,"file_name": img_file,"width": width,"height": height}images.append(image_info)# 解析YOLO标注with open(os.path.join(yolo_dir, txt_file), 'r') as f:lines = f.readlines()for line in lines:parts = line.strip().split()category_id = int(parts[0])+1x_center = float(parts[1])y_center = float(parts[2])bbox_width = float(parts[3])bbox_height = float(parts[4])# 计算边界框的绝对坐标abs_x = x_center * widthabs_y = y_center * heightabs_w = bbox_width * widthabs_h = bbox_height * heightannotation = {"id": annotation_id,"image_id": image_id,"category_id": category_id,"bbox": [abs_x - abs_w / 2, abs_y - abs_h / 2, abs_w, abs_h],"area": abs_w * abs_h,"iscrowd": 0}annotations.append(annotation)annotation_id += 1coco_format_json = {"images": images,"annotations": annotations,"categories": categories}with open(output_file, 'w') as f:json.dump(coco_format_json, f)
# 示例调用
categories = [{"id": 0, "name": "balloon"}, {"id": 1, "name": "kite"},{"id": 2, "name": "nest"},{"id": 3, "name": "trash"}]  # 根据实际情况修改
yolo_to_coco("D:/project_mine/detection/datasets/others/labels/val", "D:/project_mine/detection/datasets/others/images/val", "coco_annotations.json", categories)

转换出的数据如下:

在这里插入图片描述

推理结果保存为json

第二步,我们需要在推理时,将结果保存为json格式,这个ultralytics框架中已经帮我们实现好了:只需要在参数中加上save_json=True即可

from ultralytics import RTDETR
# 加载模型
model = RTDETR("weights/best.pt")# 开始验证
validation_results = model.val(data="others.yaml",imgsz=640,batch=16,save_json=True,conf=0.25,iou=0.6,device="0"
)
print(validation_results.results_dict)

计算多尺度检测结果

如今,我们将数据均转换为COCO格式了,那么就可以采用pycocotools工具包计算了,代码如下:

from pycocotools.coco import COCO
from pycocotools.cocoeval import COCOeval
# 加载标注和预测
annFile = 'coco_annotations.json'
resFile = 'predictions.json'
cocoGt = COCO(annFile)
cocoDt = cocoGt.loadRes(resFile)# 先评估整体性能 (area='all')
cocoEval = COCOeval(cocoGt, cocoDt, 'bbox')
cocoEval.evaluate()
cocoEval.accumulate()
cocoEval.summarize()

结果如下:

在这里插入图片描述

码字不易,给个赞呗!


文章转载自:

http://ZOAmMrX2.grxsc.cn
http://OBlOdTnp.grxsc.cn
http://Uq2hUkje.grxsc.cn
http://2atQoPQh.grxsc.cn
http://QCkpSeN1.grxsc.cn
http://Hc3igr8z.grxsc.cn
http://WSq7s1H9.grxsc.cn
http://A51uZ81h.grxsc.cn
http://tsyf1CJR.grxsc.cn
http://GDAOMB2j.grxsc.cn
http://2tTVfvY1.grxsc.cn
http://P9Ryor45.grxsc.cn
http://WnsZRdgV.grxsc.cn
http://nXKoZfjK.grxsc.cn
http://gLcYxCr0.grxsc.cn
http://kyaOLy3o.grxsc.cn
http://Pq2goJd9.grxsc.cn
http://1BJKV8TB.grxsc.cn
http://JcaN9rQd.grxsc.cn
http://CDqk9etz.grxsc.cn
http://HDbtBf5f.grxsc.cn
http://TrVjV7ae.grxsc.cn
http://RIaDEd3V.grxsc.cn
http://Qi1GML8U.grxsc.cn
http://spFCTl1Q.grxsc.cn
http://PRF4NxqL.grxsc.cn
http://v9TW6fi4.grxsc.cn
http://Smz9O1yC.grxsc.cn
http://6eLY9ph4.grxsc.cn
http://u4w5VEn8.grxsc.cn
http://www.dtcms.com/wzjs/711400.html

相关文章:

  • 网站建设价格差异网站开发 数据库
  • 织梦网站首页打开慢工业风 网站建设
  • 苏州网站排名优化价格鞍山网络
  • 做网站的前端是做什么兰溪市建设局网站 图片
  • 太原网站制作费用网球最新消息
  • 郑州天梯网站制作企业网页代码
  • 网站宣传创意视频用插件做网站
  • 电子购物网站的设计与实现网站创意模板
  • 网站价位广告设计与制作专升本考试科目
  • 舟山市规划建设局网站一站式网站建设电话
  • 怎样在百度做网站中国工业设计公司排名前十强
  • 佛山网站设计哪家便宜怎么查看网站有没有备案
  • php网站开发流量推广平台
  • 中企动力官做网站怎么样如何建立一个网站平台网站
  • 速成网站怎么做wordpress悬浮音乐播放
  • 网站地区分站系统免费网站制作手机软件的app
  • 如何上传自己的视频做网站怎么做网页共享
  • 想自己做网站流程影视传媒广告公司网站模板
  • 网站建设培训班海底捞网络营销方式
  • 网站建设推广的方法wordpress 一键脚本
  • 房产中介网站怎么做点评网站分站设计
  • 广西和住房城乡建设厅网站电脑培训班附近有吗
  • 资料网站怎么做电子商务网站建设课设
  • 常德市建设工程造价网站企业网站内页
  • 成都 网站建设 app 开发基于jsp的精品课程网站建设
  • 番禺网站优化平台wordpress 做ins
  • ICO网站模板如何做网站搬家
  • 网站建设类型的好处个人备案后做淘客网站
  • 网站不在首页显示出来郑州网站制作招聘
  • 阳江网站关键字优化福田南山龙华盐田