1. 关于labelimg 闪退的问题
闪退一般问题的原因是出在
classes.txt 文件中
- 要不是因为你对应的txt文件夹中没有classes.txt文件夹
- 或者是你的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)