import os
# 标签文件存放目录
from tqdm import tqdm
labels_dir = r"D:/labels"
# 指定要删除的类别编号列表
target_classes = [2, 23]
# 遍历标签文件
for label_file in tqdm(os.listdir(labels_dir)):
file_path = os.path.join(labels_dir, label_file)
# 读取文件内容
with open(file_path, 'r') as file:
lines = file.readlines()
# 过滤掉指定类别的行
new_lines = [line for line in lines if int(line.split()[0]) not in target_classes]
# 将过滤后的内容写回文件
with open(file_path, 'w') as file:
file.writelines(new_lines)
print("已删除指定类别的框!")
YOLO数据处理:yolo标签删除某些类
最新推荐文章于 2025-04-08 20:48:56 发布