import os labels_dir = "C:/Users/Laurent/Desktop/board-mate/rpi/training/datasets/edges/chess board detection 2.v2i.yolov11" 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 # skip invalid lines cls = int(parts[0]) cls -= 1 # subtract 1 from class index cls = max(cls, 0) # ensure no negative indices 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(f"Updated {filename}") print("All label files have been adjusted!")