-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_format.py
More file actions
25 lines (21 loc) · 801 Bytes
/
Copy pathverify_format.py
File metadata and controls
25 lines (21 loc) · 801 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os, glob, sys
# Verify YOLO format labels
directory = input("Input directory: ")
nvalues = 5 # Number of values of the standard YOLO format
nfound = 0
if not os.path.exists(directory) or not os.path.isdir(directory):
sys.stdout.write("Invalid input directory.\n")
sys.exit()
files = [os.path.normpath(file) for file in glob.glob(os.path.join(directory, "*.txt"))]
for file in files:
filename = os.path.splitext(os.path.basename(file))[0]
if filename == "classes":
continue
with open(file, "r") as txt:
lines = txt.readlines()
for line in lines:
n = len(line.split())
if n != nvalues:
sys.stdout.write(f"{file} has {n} values.\n")
n += 1
sys.stdout.write(f"Found {nfound} invalid files.\n")