Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能不能减少标注的工作量实现自动标注 #12858

Closed
2375963934a opened this issue Mar 28, 2024 · 10 comments
Closed

能不能减少标注的工作量实现自动标注 #12858

2375963934a opened this issue Mar 28, 2024 · 10 comments
Labels

Comments

@2375963934a
Copy link

能不能用训练好的模型检测图像时生成一个对应标签的json文件然后将检测的图像和对应生成的json文件去进行调整然后重新训练提高模型的精度

Copy link
Contributor

👋 Hello @2375963934a, thank you for your interest in YOLOv5 🚀! Please visit our ⭐️ Tutorials to get started, where you can find quickstart guides for simple tasks like Custom Data Training all the way to advanced concepts like Hyperparameter Evolution.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Requirements

Python>=3.8.0 with all requirements.txt installed including PyTorch>=1.8. To get started:

git clone https://github.com/ultralytics/yolov5  # clone
cd yolov5
pip install -r requirements.txt  # install

Environments

YOLOv5 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

YOLOv5 CI

If this badge is green, all YOLOv5 GitHub Actions Continuous Integration (CI) tests are currently passing. CI tests verify correct operation of YOLOv5 training, validation, inference, export and benchmarks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Introducing YOLOv8 🚀

We're excited to announce the launch of our latest state-of-the-art (SOTA) object detection model for 2023 - YOLOv8 🚀!

Designed to be fast, accurate, and easy to use, YOLOv8 is an ideal choice for a wide range of object detection, image segmentation and image classification tasks. With YOLOv8, you'll be able to quickly and accurately detect objects in real-time, streamline your workflows, and achieve new levels of accuracy in your projects.

Check out our YOLOv8 Docs for details and get started with:

pip install ultralytics

@glenn-jocher
Copy link
Member

@2375963934a 当然可以!使用已训练好的模型来自动生成标签是一种增强模型精度的有效方法。简单来说,你可以这么做:

  1. 使用你的模型对一批未标注的图像进行推理(预测)。
  2. 导出这些预测结果到JSON文件。
  3. 人工检查和调整这些自动生成的标签,确保它们的准确性。
  4. 使用调整后的数据重新训练你的模型以提升其性能。

在YOLOv5中,你可以通过detect.py脚本来进行图片的推理。导出到JSON的功能可能需要你自己写一些简单的代码来实现,具体取决于预测结果的格式和你的需求。😊

记得,持续改进数据标注的质量是提升模型性能的关键!🚀

@2375963934a
Copy link
Author

我是想先少量标注训练出一个模型,在用模型去推理图像让他生成json文件继续训练,我用的是yolov5m-seg来进行训练的,但是不知道怎么生成json文件

@glenn-jocher
Copy link
Member

@2375963934a 您好!使用您描述的方法来迭代提高模型精度非常有效。对于生成JSON文件部分,您可以考虑使用YOLOv5的推理输出,然后编写简单的脚本将这些输出转换为您需要的JSON格式。

以YOLOv5的标准输出为例,您可以通过如下步骤进行:

  1. 运行模型进行推理,并确保推理结果以您需要的格式保存(例如,保存为txt或直接在屏幕上打印输出)。
  2. 编写一个Python脚本,读取这些输出并将其转换为JSON格式。这个脚本可能包含读取输出文件、解析检测结果、并把这些解析的数据保存为JSON对象的逻辑。
  3. 最后,使用Python的json库将这些JSON对象写入到文件中。

以下是一个简单的代码示例,展示如何将假设的检测输出转换为JSON格式:

import json

# 假设的检测结果
detections = [
    {"class": 0, "confidence": 0.98, "box": [0.1, 0.2, 0.3, 0.4]},
    {"class": 1, "confidence": 0.75, "box": [0.4, 0.3, 0.2, 0.1]}
]

# 将检测结果写入JSON文件
with open("detections.json", "w") as f:
    json.dump(detections, f)

请根据您的具体输出结果和需求调整此脚本。希望这能帮助您实现目标!😄

@2375963934a
Copy link
Author

我想要的是推理结果直接输出json文件,就像我在labelme中标注过的图片一样,可以对应推理图片在labelme中打开出现多边形框,实现像我标注过这种推理图片一样

@2375963934a
Copy link
Author

image
生成这种格式的json文件该怎么做到
0001.json

@glenn-jocher
Copy link
Member

@2375963934a,您好!👋

要直接从YOLOv5推理结果生成Labelme风格的JSON文件,您需要自己编写一段脚本来转换格式。基本步骤是将每个检测的边界框或多边形框转换成Labelme的JSON格式。这通常包括类别名称、点坐标、形状类型等。

以下是一个简化的Python代码示例,演示了如何将假设的YOLO检测结果转换为Labelme支持的JSON格式:

import json

# 假设的YOLO检测结果
detections = [
    {"class": "person", "confidence": 0.98, "box": [0.1, 0.2, 0.3, 0.4]},
    {"class": "car", "confidence": 0.75, "box": [0.4, 0.3, 0.2, 0.1]}
]

# 转换为Labelme格式
labelme_shapes = []
for det in detections:
    x1, y1, x2, y2 = det["box"]
    points = [[x1, y1], [x2, y1], [x2, y2], [x1, y2]]
    shape = {
        "label": det["class"],
        "points": points,
        "group_id": None,
        "shape_type": "rectangle",
        "flags": {}
    }
    labelme_shapes.append(shape)

labelme_format = {
    "version": "4.5.6",
    "flags": {},
    "shapes": labelme_shapes,
    "imagePath": "path/to/your/image.jpg",
    "imageData": None,
    "imageHeight": 1080,
    "imageWidth": 1920
}

# 写入到文件
with open("result.json", "w") as f:
    json.dump(labelme_format, f, ensure_ascii=False, indent=2)

请注意,您需要根据您的具体需求调整代码,比如处理不同的形状类型或者从实际的YOLO输出中抽取数据。希望这个示例能帮到您!😊

@wuqrcn
Copy link

wuqrcn commented Apr 9, 2024

你的意思是想左脚踩右脚直接上天?

@glenn-jocher
Copy link
Member

哈哈, 看起来您是在寻找一个挑战性的解决方案!😄 如果有什么具体问题或需求,请随时详细告诉我们,我们很乐意帮助你找到解决方案。

Copy link
Contributor

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐

@github-actions github-actions bot added the Stale label May 10, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants