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

yolov8 label_studio 半自动化标注

yolov8 label_studio 半自动化标注

    • 一.参考链接
    • 二.操作步骤
      • 1.创建容器
      • 2.安装依赖
      • 3.测试yolo的推理
      • 4.测试yolo的训练
      • 5.启动label-studio
      • 6.打开浏览器:`http://IP:8081`
      • 7.将标注样本用于训练

本文演示label_studio如何用于yolo模型的半自动标注

演示视频

yolov8 label_studio 半自动化标注

一.参考链接

  • Ultralytics YOLO11 任务
  • Label Studio Quick start

二.操作步骤

1.创建容器

  • A.删除旧的容器
docker stop yolov8_label_studio
docker rm yolov8_label_studio
  • B.创建启动容器的脚本
cat> run_yolov8_label_studio_docker.sh <<-'EOF'

container_name="yolov8_label_studio"
if [ $(docker ps -a -q -f name=^/${container_name}$) ]; then
    echo "容器 '$container_name' 已经存在。"
else
    echo "容器 '$container_name' 不存在。正在创建..."
    docker run --gpus all --shm-size=32g -id -e NVIDIA_VISIBLE_DEVICES=all \
        --privileged  --net=host -v $PWD:/home -w /home \
        --name $container_name --hostname=$container_name \
        nvcr.io/nvidia/pytorch:23.07-py3 /bin/bash
fi
docker start $container_name
docker exec -ti $container_name bash
EOF
  • C.启动容器
bash run_yolov8_label_studio_docker.sh

2.安装依赖

apt update
apt install -y tmux
pip install ultralytics==8.3.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python==4.7.0.72 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-contrib-python==4.7.0.72 -i https://pypi.tuna.tsinghua.edu.cn/simple
# 下载测试模型及图片
cd /home
wget -O best.pt https://github.com/ultralytics/assets/releases/download/v8.3.0/yolo11x.pt
wget -O bus.jpg https://ultralytics.com/images/bus.jpg
pip install label-studio -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install git+https://github.com/HumanSignal/label-studio-ml-backend.git
pip install git+https://github.com/HumanSignal/label-studio-sdk.git
pip install gunicorn==22.0.0 -i https://pypi.tuna.tsinghua.edu.cn/simple

cd /home
git clone https://github.com/seblful/label-studio-yolov8-backend.git

3.测试yolo的推理

cd /home
yolo predict model=yolo11x.pt source='/home/bus.jpg'

4.测试yolo的训练

cd /home
rm -rf coco8*
wget -O /home/coco8.zip https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8.zip
wget -O coco8.yaml https://raw.githubusercontent.com/ultralytics/ultralytics/refs/heads/main/ultralytics/cfg/datasets/coco8.yaml
unzip coco8.zip
sed -i "s/path:.*/path: \/home\/coco8/g" coco8.yaml
yolo detect train data=coco8.yaml model=yolo11n.yaml epochs=16 imgsz=640

5.启动label-studio

  • A.打开tmux,创建二个视口
tmux new -s lm
  • B.视口一:启动ml-backend
cd /home/label-studio-yolov8-backend
export TASK_TYPE="detection"
export MODEL_DIR="/home"
gunicorn --bind :${PORT:-9090} --workers ${WORKERS:-1} --threads ${THREADS:-4} --timeout 0 _wsgi:app
  • C.视口二:启动label-studio
label-studio

6.打开浏览器:http://IP:8081

  • 创建登录帐号
  • 创建项目
  • 导入图片集
  • 设置任务类型:目标分割
  • 配置ML-Backend:http://127.0.0.1:9090
  • 开始标注
  • 导出YOLO格式的标注,输出为一个zip包,里面是图片及label

7.将标注样本用于训练

  • A.创建数据预处理脚本
cat> process_yolo_datasets.py <<-'EOF'
import yaml
import os
import glob
import sys
import shutil
import random

def Mkdir(path):
    if not os.path.exists(path):
        os.mkdir(path)

if len(sys.argv)!=3:
    print(f"{sys.argv[0]} data_root data_yaml_path")
    os._exit(0)
    
data_root=sys.argv[1]
data_yaml_path=sys.argv[2]

all_images=[os.path.basename(x.strip()).split(".")[0] for x in glob.glob(os.path.join(data_root,"images/*.jpg"))]

random.shuffle(all_images)
total_count=len(all_images)
train_count=max(1,int(total_count*0.95)) #分割比例

train_list=all_images[:train_count]
val_list=all_images[train_count:]

Mkdir(os.path.join(data_root,"images/train"))
Mkdir(os.path.join(data_root,"images/val"))

Mkdir(os.path.join(data_root,"labels/train"))
Mkdir(os.path.join(data_root,"labels/val"))

for i in train_list:
    shutil.move(os.path.join(data_root,f"images/{i}.jpg"),os.path.join(data_root,f"images/train/{i}.jpg"))
    shutil.move(os.path.join(data_root,f"labels/{i}.txt"),os.path.join(data_root,f"labels/train/{i}.txt"))

for i in val_list:
    shutil.move(os.path.join(data_root,f"images/{i}.jpg"),os.path.join(data_root,f"images/val/{i}.jpg"))
    shutil.move(os.path.join(data_root,f"labels/{i}.txt"),os.path.join(data_root,f"labels/val/{i}.txt"))    

dataset_yaml={}
dataset_yaml['path']=data_root
dataset_yaml['train']="images/train"
dataset_yaml['val']="images/val"

dataset_yaml['names']={}
with open(os.path.join(data_root,"classes.txt"),"r") as f:
    for i,v in enumerate([x.strip() for x in f.readlines()]):
        dataset_yaml['names'][i]=v

with open(data_yaml_path, 'w', encoding='utf-8') as file:
    yaml.dump(dataset_yaml, file, allow_unicode=True)
EOF
  • B.处理导出的样本
rm -rf demo_dataset
unzip project-1-at-2024-12-26-11-13-a196fb0e.zip -d demo_dataset 
python process_yolo_datasets.py $PWD/demo_dataset data.yaml
  • C.开始训练
yolo detect train data=data.yaml model=yolo11n.yaml epochs=16 imgsz=640

http://www.kler.cn/a/453276.html

相关文章:

  • SQL创建和操纵表
  • CSS(二):美化网页元素
  • 对gPTP上PTP安全控制的评估
  • 【杂谈】-现代汽车有哪些传感器
  • 洛谷 P1014:Cantor 表
  • 简述Git中如何将一个新增文件添加到本地仓库?
  • 裴蜀定理和扩展欧几里得定理
  • 工业金融政务数据分类分级体系建设解读
  • WEB 漏洞 - 文件包含漏洞深度解析
  • Python+OpenCV系列:【打卡系统-工具模块设计】工具模块深度揭秘,考勤智能化的核心秘籍!
  • 无影云电脑的高性能与便捷性
  • 评估大语言模型在药物基因组学问答任务中的表现:PGxQA
  • 菜鸟带新鸟——基于EPlan2022的部件库制作(3D)
  • ubuntu 网络管理--NetworkManager
  • 硬件设计:LVDS电平标准
  • 抖音小程序登录(前端通过tt.login获取code换取openId)
  • 生成10级子目录,每个子目录下有100个不同大小的文件
  • 将现有环境192.168.1.100中的svn迁移至新服务器192.168.1.4;
  • 项目管理咨询公司专注于为各类项目提供全方位的管理咨询服务
  • K8S--“ Failed to create pod sandbox: nameserver list is empty“
  • Jmeter下载安装配置教程(多版本)
  • 【目标跟踪+人流计数+人流热图(Web界面)】基于YOLOV11+Vue+SpringBoot+Flask+MySQL
  • Java 23和JDK 23详细安装方法,常用命令使用等
  • 安卓端侧大模型MLC-LLM部署全攻略:以InternLM2.5-1.8B为例
  • 任务8 数据库服务配置与管理
  • 力扣面试题 39 - 三步问题 C语言解法