collect + pruned
Browse files- collect-dataset.py +6 -3
- prune-dataset.py +29 -0
collect-dataset.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import json
|
2 |
import os
|
|
|
3 |
import shutil
|
4 |
from typing import Dict, List
|
5 |
from io import BytesIO
|
@@ -81,7 +82,8 @@ if __name__ == "__main__":
|
|
81 |
shutil.rmtree("./data/", ignore_errors=True)
|
82 |
os.mkdir("./data/")
|
83 |
counter = 0
|
84 |
-
|
|
|
85 |
print(f"Processing page {i}...")
|
86 |
orgs = get_orgs(i*1000)
|
87 |
for org in orgs:
|
@@ -95,8 +97,9 @@ if __name__ == "__main__":
|
|
95 |
raise ValueError("Image is not square")
|
96 |
image = image.resize((512, 512), resample=Image.LANCZOS)
|
97 |
image_text = pytesseract.image_to_string(image)
|
98 |
-
if (len(image_text)
|
99 |
-
|
|
|
100 |
except Exception as ex:
|
101 |
print(
|
102 |
f"Error downloading image for {org.get('uuid')}: {ex}")
|
|
|
1 |
import json
|
2 |
import os
|
3 |
+
import sys
|
4 |
import shutil
|
5 |
from typing import Dict, List
|
6 |
from io import BytesIO
|
|
|
82 |
shutil.rmtree("./data/", ignore_errors=True)
|
83 |
os.mkdir("./data/")
|
84 |
counter = 0
|
85 |
+
start_page = int(sys.argv[1])
|
86 |
+
for i in range(start_page, 3000):
|
87 |
print(f"Processing page {i}...")
|
88 |
orgs = get_orgs(i*1000)
|
89 |
for org in orgs:
|
|
|
97 |
raise ValueError("Image is not square")
|
98 |
image = image.resize((512, 512), resample=Image.LANCZOS)
|
99 |
image_text = pytesseract.image_to_string(image)
|
100 |
+
if (len(image_text) >= 3):
|
101 |
+
continue;
|
102 |
+
image.save(f"./data/{org.get('uuid')}.png", format="PNG")
|
103 |
except Exception as ex:
|
104 |
print(
|
105 |
f"Error downloading image for {org.get('uuid')}: {ex}")
|
prune-dataset.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import os
|
3 |
+
|
4 |
+
def file_exists(file_path):
|
5 |
+
return os.path.isfile(file_path)
|
6 |
+
|
7 |
+
def read_jsonl(file_path):
|
8 |
+
data = []
|
9 |
+
with open(file_path, 'r') as f:
|
10 |
+
for line in f:
|
11 |
+
data.append(json.loads(line))
|
12 |
+
return data
|
13 |
+
|
14 |
+
if __name__ == "__main__":
|
15 |
+
count = 0
|
16 |
+
data = read_jsonl("./data/metadata.jsonl")
|
17 |
+
print(len(data))
|
18 |
+
for d in data:
|
19 |
+
# check if file exist
|
20 |
+
if not file_exists("./data/" + d.get("file_name")):
|
21 |
+
print("File not found: " + d.get("file_name"))
|
22 |
+
continue
|
23 |
+
# write to new JSONL file
|
24 |
+
with open("./data/metadata-pruned.jsonl", "a") as f:
|
25 |
+
f.write(json.dumps(d) + "\n")
|
26 |
+
count +=1
|
27 |
+
# print(d.get("file_name"))
|
28 |
+
print(len(data))
|
29 |
+
print(count)
|