-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathannotations_original_preprocessing.py
More file actions
40 lines (28 loc) · 1.08 KB
/
Copy pathannotations_original_preprocessing.py
File metadata and controls
40 lines (28 loc) · 1.08 KB
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
#!/usr/bin/env python
# coding: utf-8
# # Annotation files preprocessing
import os
import json
from pathlib import Path
ROOT = Path(os.getcwd())
DATE = "settembre_2020"
images_path = ROOT / "images_original" / DATE
annotations_path = ROOT / "annotations_original" / DATE
for json_ann in os.listdir(annotations_path):
if json_ann.endswith("json"):
print(json_ann)
with open(os.path.join(annotations_path, json_ann), "r") as f:
s = f.read()
s = s.replace("\t", "")
s = s.replace("\n", "")
s = s.replace(",}", "}")
s = s.replace(",]", "]")
data = json.loads(s)
shapes = data["shapes"]
name = os.path.splitext(data["imagePath"].split("\\")[-1])[0]
PROCESSED_PATH = ROOT / "annotations" / DATE
os.makedirs(PROCESSED_PATH, exist_ok=True)
with open(PROCESSED_PATH / f"{name}.json", "w") as outfile:
json.dump(data["shapes"], outfile)
print(f"copied in {PROCESSED_PATH}/{name}.json!")
print("\n")