关于yolo数据集labelimg闪退、更改标签名的解决方法

1. 关于labelimg 闪退的问题

闪退一般问题的原因是出在
classes.txt 文件中

  1. 要不是因为你对应的txt文件夹中没有classes.txt文件夹
  2. 或者是你的classes.txt 里面的标签名,没有跟你标的标签数量相对应。

2. 关于标签名不能对应的问题

在这里插入图片描述

前面的0 对应的是classes.txt 中第一个标签相对应的。
可以先更改前面的第一数字
然后在classes.txt中更改相对应的标签名
在这里插入图片描述

遇到多个txt文件需要更改的解决方案

用下面代码就行自动更换标签名

import os
import re
# 路径
path = './1/'
# 文件列表
files = []
for file in os.listdir(path):
    if file.endswith(".txt"):
        files.append(path+file)
# 逐文件读取-修改-重写
for file in files:
    with open(file, 'r') as f:
    # '^0', '2'    意思是用2 提换掉0
        new_data = re.sub('^0', '2', f.read(), flags=re.MULTILINE)  # 将列中的0替换为car
    with open(file, 'w') as f:
        f.write(new_data)
    with open(file, 'r') as f:
        new_data = re.sub('^1', '2', f.read(), flags=re.MULTILINE)  # 将列中的1替换为horse
    with open(file, 'w') as f:
        f.write(new_data)
    with open(file, 'r') as f:
        new_data = re.sub('^2', 'chair', f.read(), flags=re.MULTILINE)  # 将列中的2替换为chair
    with open(file, 'w') as f:
        f.write(new_data)
    with open(file, 'r') as f:
        new_data = re.sub('^3', 'bicycle', f.read(), flags=re.MULTILINE)  # 将列中的3替换为bicycle
    with open(file, 'w') as f:
        f.write(new_data)
  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值