Files
zjsh_yolov11/yolo11_point/trains.py
2025-09-01 14:14:18 +08:00

21 lines
625 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
labels_dir = "/media/hx/04e879fa-d697-4b02-ac7e-a4148876ebb0/dataset/seg/dataset2/labels"
for txt_file in os.listdir(labels_dir):
if not txt_file.endswith(".txt"):
continue
path = os.path.join(labels_dir, txt_file)
lines = open(path, "r").readlines()
new_lines = []
for line in lines:
parts = line.strip().split()
if not parts:
continue
# 修改类别 ID1 -> 0
if parts[0] == "1":
parts[0] = "0"
new_lines.append(" ".join(parts))
open(path, "w").write("\n".join(new_lines))
print(f"✅ 已处理: {txt_file}")