MasteredUltraInstinct commited on
Commit
ecea543
·
verified ·
1 Parent(s): bef49c6

Create generate_csv.py

Browse files
Files changed (1) hide show
  1. generate_csv.py +19 -0
generate_csv.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import csv
3
+
4
+ def generate_csv(split):
5
+ csv_path = f"dataset_{split}.csv"
6
+ folder = f"dataset/{split}"
7
+ with open(csv_path, "w", newline="", encoding="utf-8") as f:
8
+ writer = csv.writer(f)
9
+ writer.writerow(["img_path", "latex"])
10
+ for file in sorted(os.listdir(folder)):
11
+ if file.endswith(".txt"):
12
+ img_file = file.replace(".txt", ".png")
13
+ img_path = f"{split}/{img_file}"
14
+ with open(os.path.join(folder, file), "r", encoding="utf-8") as label_file:
15
+ latex = label_file.read().strip()
16
+ writer.writerow([img_path, latex])
17
+
18
+ generate_csv("train")
19
+ generate_csv("val")