当前位置:   article > 正文

Label Studio结合YOLO模型实现数据集自动标注_label studio 标注图片

label studio 标注图片

最近在尝试做图像目标检测相关的模型训练工作,但是如果想要实现一个模型的训练,数据集是至关重要,而目标检测数据集的制作相对于图像分类要复杂一些,因此需要一个简单易用的标注工具,对比了网上的一堆工具之后,最后选择了label studio,主要是以下原因:

  • 数据安全性:期望标注的数据可以只在自己内部使用,不希望暴露在外网
  • 便捷性:可以通过部署一个网页服务来实现标注,这样后面也可以方便其他同学一起标注
  • 自动/半自动标注:可以结合训练的模型来辅助标注实现自动/半自动标注,也可以可视化和验证训练模型的目标检测效果。 最后发现label studio是满足上面几个诉求,因此搭建了Label Studio标注工具,并且结合YOLO模型实现了数据集的自动/半自动标注,现将整个过程记录。

环境搭建

基本环境搭建

css
复制代码
> conda create -n label-studio python=3.10
> conda activate label-studio
  • 1
  • 2
  • 3
  • 4

前端服务

shell
复制代码
> cd /data/code/github/label-studio
# Run database migrations
> python label_studio/manage.py migrate
> python label_studio/manage.py collectstatic
# Start the server in development mode at http://localhost:8080
python label_studio/manage.py runserver
> python label_studio/server.py --host=0.0.0.0 --port=8081
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

数据保存路径如下:

javascript
复制代码
~/.local/share/label-studio/
  • 1
  • 2
  • 3

如下所示

yaml
复制代码
(label-studio) # ls -lrt ~/.local/share/label-studio/
total 1212
drwxr-xr-x 2 xxxx xxxx    4096 Oct 20 10:36 test_data
drwxr-xr-x 4 xxxx xxxx    4096 Oct 20 11:02 media
drwxr-xr-x 2 xxxx xxxx    4096 Oct 20 12:05 export
-rw-r--r-- 1 xxxx xxxx 1228800 Oct 20 15:30 label_studio.sqlite3
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 项目界面 项目界面
  • 新建项目
  • 基本设置

Labeling Interface中可以设置标注的物体类型

  • 后端推理

Machine Learning可以设置后端推理服务来实现自动化标注,可以参考label-studio-ml-backend,如果使用了Yolov8来做检测的话,可以参考label-studio-yolov8-backend;如果结合SAM来做检测的话,可以参考分割一切?手把手教你部署SAM+LabelStudio实现自动标注

Retrieve predictions when loading a task automatically:会自动将导入的图片去调用预测服务

  • 最终效果

下面的数字是对应类型的快捷键

可以清理标注结果

  • Delete Tasks:删除图片和任务
  • Delete Annotations:删除手动标注结果
  • Delete Predictions:删除预测结果,需要接入了后端预测服务,如果对于预测结果不满意,希望重新预测的话,可以删除后,重新生成预测结果。

标注的数据code如下:

json
复制代码

{
  "id": 50,
  "data": {
    "image": "/data/upload/7/437ac54a-csm_eb24002_58f4fb61dd.jpg"
  },
  "annotations": [
    {
      "id": 5,
      "created_username": " xxxx@gmail.com, 2",
      "created_ago": "0 minutes",
      "completed_by": {
        "id": 2,
        "first_name": "",
        "last_name": "",
        "avatar": null,
        "email": "xxxxx@gmail.com",
        "initials": "li"
      },
      "result": [
        {
          "original_width": 1366,
          "original_height": 768,
          "image_rotation": 0,
          "value": {
            "x": 10.10689990281827,
            "y": 27.483448736637506,
            "width": 23.420796890184647,
            "height": 37.68170958859735,
            "rotation": 0,
            "rectanglelabels": [
              "Car"
            ]
          },
          "id": "8oMV4M5avz",
          "from_name": "label",
          "to_name": "image",
          "type": "rectanglelabels",
          "origin": "manual"
        }
      ],
      "was_cancelled": false,
      "ground_truth": false,
      "created_at": "2023-10-22T09:21:27.660411Z",
      "updated_at": "2023-10-22T09:21:27.660435Z",
      "draft_created_at": "2023-10-22T09:19:22.672990Z",
      "lead_time": 114.60199999999999,
      "import_id": null,
      "last_action": null,
      "task": 50,
      "project": 7,
      "updated_by": 2,
      "parent_prediction": null,
      "parent_annotation": null,
      "last_created_by": null
    }
  ],
  "predictions": []
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61

后端预测服务

可以部署后端预测服务来实现自动标注

shell
复制代码
> git clone https://github.com/HumanSignal/label-studio-ml-backend.git
> cd label-studio-ui-element-backend
> pip install -e .
# 环境验证
> label-studio-ml create env_verify
> label-studio-ml start env_verify -p 9091
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 创建正式环境
css
复制代码
> label-studio-ml create ui_element
> label-studio-ml start ui_element -p 9091
> nohup label-studio-ml start ui_element -p 9091 > ./ui_element/label.log 2>&1 &
> nohup label-studio-ml start ui_element_sam -p 9092 > ./ui_element_sam/label.log 2>&1 &
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

导出标注结果

会导出来所有的标注结果,并且可以导出来不同的标注格式,比如用作YOLO训练的话,一般可以使用YOLO格式,当然也还有COCOVOC数据格式

目前还没法只导出来选中图片的标注结果。 比如导出来的YOLO数据格式如下:

  • images:标注的图片

  • labels:标注数据,使用txt后缀保存,每一行代表一条标注数据,包含5列

    • 第1列:标注的类别,和下面的classex.txt中的类别索引保持一致
    • 第2列:标注的矩形框的中心点x坐标(经过了归一化处理:坐标点/图片宽度)
    • 第3列:标注的矩形框的中心点y坐标(经过了归一化处理:坐标点/图片高度)
    • 第4列:标注的矩形框的宽度(经过了归一化处理:宽度/图片宽度)
    • 第5列:标注的矩形框的高度(经过了归一化处理:高度/图片高度)
复制代码
0 0.7914317925591883 0.3476714942329373 0.3066516347237879 0.1781053970456451
0 0.7931228861330326 0.5379758910762293 0.30552423900789166 0.16834619720752755
0 0.7931228861330328 0.7221807880206979 0.30777903043968435 0.1756655970861157
  • 1
  • 2
  • 3
  • 4
  • classes.txt: 保存标注的类型列表

这里给大家分享一份Python全套学习资料,包括学习路线、软件、源码、视频、面试题等等,都是我自己学习时整理的,希望可以对正在学习或者想要学习Python的朋友有帮助!

CSDN大礼包:全网最全《全套Python学习资料》免费分享
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/352205

推荐阅读
相关标签