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

尝试茶叶数据集

image

使用的是yolo11 + tea 跑的尝试的代码,感觉效果不是很好。

现在我使用我之前加的那些模块,看看他的效果怎么样。

 使用自己的电脑测试数据集:

image

 显示已有的训练环境:

image

 启动label-studio:

image

 需要

setx LOCAL_FILES_DOCUMENT_ROOT "F:\master\dataset\tea_bud\images\train"

才能正确出现图片

 

 

 

set LABEL_STUDIO_LOCAL_FILES_SERVING_ENABLED=true
set LABEL_STUDIO_LOCAL_FILES_DOCUMENT_ROOT=F:\master\dataset\tea_bud

 

 

 

使用脚本来生成JSON文件:

import os
import json
from PIL import Image
import urllib.parsedef yolo_to_label_studio_correct_path(image_dir, labels_dir, class_list, output_json="tea_diseases_labels.json"):"""将 YOLO 格式转换为 Label Studio JSON 格式使用正确的图片路径格式"""tasks = []# 获取所有图片文件image_files = [f for f in os.listdir(image_dir) if f.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp'))]print(f"找到 {len(image_files)} 个图片文件")processed_count = 0error_count = 0for image_file in image_files:image_path = os.path.join(image_dir, image_file)label_file = os.path.join(labels_dir, os.path.splitext(image_file)[0] + '.txt')# 创建正确的图片路径格式# 使用 URL 编码的路径,保持 images\filename.jpg 格式encoded_image_path = f"images%5C{image_file}"  # %5C 是反斜杠的 URL 编码image_url = f"/data/local-files/?d={encoded_image_path}"# 创建任务基础结构task = {"data": {"image": image_url},"annotations": [],"predictions": []}# 如果标签文件存在,读取并转换if os.path.exists(label_file):try:# 获取图片尺寸with Image.open(image_path) as img:img_width, img_height = img.sizewith open(label_file, 'r', encoding='utf-8') as f:lines = f.readlines()predictions = []for i, line in enumerate(lines):parts = line.strip().split()if len(parts) == 5:  # YOLO格式: class x_center y_center width heightclass_id, x_center, y_center, width, height = map(float, parts)# 转换 YOLO 格式到像素坐标x_center_px = x_center * img_widthy_center_px = y_center * img_heightwidth_px = width * img_widthheight_px = height * img_height# 计算边界框坐标x_min = x_center_px - width_px / 2y_min = y_center_px - height_px / 2# 转换为百分比坐标(Label Studio 格式)x_percent = (x_min / img_width) * 100y_percent = (y_min / img_height) * 100width_percent = (width_px / img_width) * 100height_percent = (height_px / img_height) * 100# 确保坐标在合理范围内x_percent = max(0, min(x_percent, 100))y_percent = max(0, min(y_percent, 100))width_percent = max(0, min(width_percent, 100 - x_percent))height_percent = max(0, min(height_percent, 100 - y_percent))prediction = {"id": f"result_{i}","type": "rectanglelabels","from_name": "label","to_name": "image","value": {"rectanglelabels": [class_list[int(class_id)]],"x": x_percent,"y": y_percent,"width": width_percent,"height": height_percent}}predictions.append(prediction)# 如果有预测标注,添加到任务中if predictions:task["predictions"] = [{"model_version": "yolo_model","score": 0.95,"result": predictions}]tasks.append(task)processed_count += 1print(f"处理完成: {image_file} - 找到 {len(predictions)} 个标注")except Exception as e:error_count += 1print(f"处理失败: {image_file} - 错误: {str(e)}")# 即使处理失败,也添加没有标注的任务tasks.append(task)else:# 没有标签文件,只添加图片tasks.append(task)print(f"无标签文件: {image_file}")# 保存为 JSON 文件with open(output_json, 'w', encoding='utf-8') as f:json.dump(tasks, f, indent=2, ensure_ascii=False)print(f"\n转换完成!")print(f"成功处理: {processed_count} 个文件")print(f"处理失败: {error_count} 个文件")print(f"总任务数: {len(tasks)}")print(f"输出文件: {output_json}")return output_json# 测试单个任务生成
def test_single_task():"""测试单个任务的格式"""test_task = {"data": {"image": "/data/local-files/?d=images%5Ctest_image.jpg"},"annotations": [],"predictions": [{"model_version": "yolo_model","score": 0.95,"result": [{"id": "result1","type": "rectanglelabels","from_name": "label","to_name": "image","value": {"rectanglelabels": ["tea_blight"],"x": 10.5,"y": 20.3,"width": 15.2,"height": 12.8}}]}]}print("测试任务格式:")print(json.dumps(test_task, indent=2))return test_task# 你的具体配置
if __name__ == "__main__":# 先测试格式test_single_task()# 你的路径配置image_dir = r"F:\master\dataset\new_dataset\teaDiseases\train\images"labels_dir = r"F:\master\dataset\new_dataset\teaDiseases\train\labels"# 你的类别列表 - 请根据实际情况修改!# 这里的类别顺序必须与你的 YOLO 类别 ID 对应class_list = ["algal leaf spot", "brown blight", "grey blight"]  # 修改为你的实际类别# 检查目录是否存在if not os.path.exists(image_dir):print(f"错误: 图片目录不存在: {image_dir}")elif not os.path.exists(labels_dir):print(f"错误: 标签目录不存在: {labels_dir}")else:# 运行转换json_file = yolo_to_label_studio_correct_path(image_dir=image_dir,labels_dir=labels_dir,class_list=class_list,output_json="tea_diseases_labels.json")# 显示前几个任务作为示例with open(json_file, 'r', encoding='utf-8') as f:tasks = json.load(f)print("\n前3个任务示例:")for i in range(min(3, len(tasks))):print(f"\n任务 {i+1}:")print(json.dumps(tasks[i], indent=2))

 

http://www.hskmm.com/?act=detail&tid=28898

相关文章:

  • 2025氧化镁供应厂家推荐:松辽镁业高纯度优质选择!
  • 2025硅藻土订制厂家口碑推荐:品质卓越与专业服务的双重保障
  • 20251011
  • 2025数控滚齿机源头厂家推荐榜:高精度与高效能的首选!
  • (第四次)回归与决策树
  • 2025数控滚齿机订做厂家推荐:吉莱特智能装备,精准高效品质
  • 2025机械加工实力厂家推荐:鑫铭机械专业制造,品质卓越首选
  • 高考语文做法
  • 2025机械加工优质厂家推荐榜:技术精湛与高效服务的行业先锋
  • P10960 SUBSTRACT 个人题解
  • 牛客网刷题
  • 2025新型千斤顶厂家推荐:柳州市联桥科技,品质卓越服务到位
  • 2025深圳网站建设推荐:华企网络专业定制,助力企业线上腾飞
  • 2025石头纸设备批发厂家推荐鼎浩包装,环保高效生产首选!
  • 2025液压阀块供货厂家最新推荐榜:品质卓越与高效服务的行业
  • 2025年PP鱼池优质厂家推荐:超众渔业机械,环保耐用首选!
  • centos安装atop工具,检测服务器情况
  • 完整教程:MongoDB Ops Manager部署
  • 2025医疗器械微弧氧化优质厂家推荐,华源漆业技术领先服务到
  • 2025气柱袋优质厂家推荐:戈尔德包装,防护包装解决方案专家
  • 【网络协议】SSL与TLS的关系 - 教程
  • 2025深圳网站建设公司最新推荐榜:创意设计与专业服务引领者
  • 2025年安全光栅厂家最新推荐榜:精准防护与高效性能的工业首
  • 2025七水硫酸锌实力厂家推荐:安通环保科技,品质卓越信赖之
  • 20232306刘博2025-2026-1《网络与系统攻防技术》实验一实验报告
  • 软件工程学习日志2025.10.10
  • 2025智能照明系统直销厂家推荐:八渡科技,智慧生活首选!
  • 2025磁力泵厂家最新推荐榜:高效稳定与优质服务的首选指南
  • 最小乘积模型与快速凸包构造学习笔记
  • 记录---图文并茂讲解nginx中http升级https(部署SSL证书)知识点总结