forked from lucasjinreal/yolov7_d2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
label.py
46 lines (32 loc) · 1.09 KB
/
label.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
this script is used to extrct YOLO conforming style labels
<object-class-id> <x> <y> <width> <height>
Command:
python3 label.py <Training.csv>
In reference to BOSSTraining.csv and BOSSValidation.csv under Polar/Training
"""
INPUT_CSV_PATH = "../../Downloads/boss_validation.csv"
OUTPUT_CSV_PATH = "../../Downloads/boss_validation_output.csv"
import os
import argparse
import pandas as pd
def label(lines):
df = pd.DataFrame(columns=['file_name','obj_class_id', 'x', 'y', 'width', 'height'])
for row in lines:
full_name = row.split(",")[6]
df = df.append(
{'file_name': row.split(",")[0].split(".")[0],
'obj_class_id': full_name.split("_")[1],
'x': row.split(",")[2],
'y': row.split(",")[3],
'width':int(row.split(",")[4])-int(row.split(",")[2]),
'height':int(row.split(",")[5])-int(row.split(",")[3])},
ignore_index = True
)
res = df.to_csv(OUTPUT_CSV_PATH)
return res
if __name__ == "__main__":
# Extract class id, x-coor, y-coor, width and height from train file csv
with open(INPUT_CSV_PATH) as file:
train_csv_lines = file.readlines()
label(train_csv_lines)