33 lines
817 B
Python
33 lines
817 B
Python
import os
|
|
|
|
labels_dir = "../datasets/corners/Outer Chess Corners.v1i.yolov11/valid/labels"
|
|
label_to_be_removed = 1
|
|
|
|
for filename in os.listdir(labels_dir):
|
|
if not filename.endswith(".txt"):
|
|
continue
|
|
|
|
txt_path = os.path.join(labels_dir, filename)
|
|
new_lines = []
|
|
|
|
with open(txt_path, "r") as f:
|
|
lines = f.readlines()
|
|
|
|
for line in lines:
|
|
parts = line.strip().split()
|
|
|
|
if len(parts) < 5:
|
|
continue
|
|
|
|
cls = int(parts[0])
|
|
if cls == label_to_be_removed:
|
|
print(f"{parts} found in {filename}")
|
|
continue
|
|
|
|
new_lines.append(" ".join([str(cls)] + parts[1:]))
|
|
|
|
# Overwrite file with updated indices
|
|
with open(txt_path, "w") as f:
|
|
f.write("\n".join(new_lines))
|
|
|
|
print("All label files have been adjusted!") |