Updates
This commit is contained in:
33
rpi/training/utils/remove_labels.py
Normal file
33
rpi/training/utils/remove_labels.py
Normal file
@@ -0,0 +1,33 @@
|
||||
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!")
|
||||
Reference in New Issue
Block a user