36 lines
962 B
Python
36 lines
962 B
Python
import os
|
|
|
|
# --------------------------
|
|
# Configuration
|
|
# --------------------------
|
|
labels_dir = "datasets/visiope/test/labels"
|
|
|
|
# --------------------------
|
|
# Process each label file
|
|
# --------------------------
|
|
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!") |