当前位置: 首页 > 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.gsyq.cn/news/19071.html

相关文章:

  • 20251011
  • (第四次)回归与决策树
  • 2025机械加工实力厂家推荐:鑫铭机械专业制造,品质卓越首选
  • 高考语文做法
  • 2025石头纸设备批发厂家推荐鼎浩包装,环保高效生产首选!
  • 2025液压阀块供货厂家最新推荐榜:品质卓越与高效服务的行业
  • centos安装atop工具,检测服务器情况
  • 2025深圳网站建设公司最新推荐榜:创意设计与专业服务引领者
  • 2025智能照明系统直销厂家推荐:八渡科技,智慧生活首选!
  • 最小乘积模型与快速凸包构造学习笔记
  • 2025网络营销推广TOP5榜单:精准引流与高效转化的营销专
  • 基于 Scala 的英文数字验证码识别系统设计与实现
  • commitlint Lint 提交消息格式控制
  • 实用指南:【Android View】窗口机制
  • 2025整平机厂家最新推荐榜:高效精准与耐用品质的行业首选!
  • 2025复合钢丝网优质厂家推荐,昆山佳冠光电科技实力见证!
  • k8s报错
  • 2025保洁公司权威推荐:上海恒旺保洁服务,口碑与实力兼备!
  • 初识pytorch:深度学习中关于数据加载的Dataset和DataLoader
  • 2025卧式CNC高压清洗机厂家推荐榜:高效清洁与卓越性能首
  • 2025年中医确有专长培训TOP5榜单:权威认证与实战经验结
  • .NET 记录Amazon上传S3异常问题
  • Linux中tar、zip、gz、rar文件 解压缩归类
  • 小九源码-springboot051-智能推荐旅游平台 - 实践
  • 2025年OPP涂布机源头厂家最新推荐榜:技术领先与市场口碑
  • 花纹铝板口碑推荐/铝板厂家推荐/铝板知名品牌
  • 2025粉末涂料厂家推荐:财诺名荣,环保高效品质之选!
  • 颠覆传统RAG!Agentic RAG登场,AI代理如何“自我进化”解决复杂 query?
  • 在 Windows 下集成 Conda 与 VS Code 打造高效开发环境
  • 洛谷题单指南-进阶数论-P2421 [NOI2002] 荒岛野人