Delete loading script auxiliary file
Browse files- examples/make_jsonl.py +0 -64
examples/make_jsonl.py
DELETED
|
@@ -1,64 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/python3
|
| 2 |
-
# -*- coding: utf-8 -*-
|
| 3 |
-
from collections import defaultdict
|
| 4 |
-
import json
|
| 5 |
-
import os
|
| 6 |
-
from pathlib import Path
|
| 7 |
-
|
| 8 |
-
from project_settings import project_path
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
def main():
|
| 12 |
-
|
| 13 |
-
for subset in ["train", "test"]:
|
| 14 |
-
filename = project_path / "data/annotations/{}.json".format(subset)
|
| 15 |
-
with open(filename.as_posix(), "r", encoding="utf-8") as f:
|
| 16 |
-
js = json.load(f)
|
| 17 |
-
|
| 18 |
-
images = js["images"]
|
| 19 |
-
type_ = js["type"]
|
| 20 |
-
annotations = js["annotations"]
|
| 21 |
-
categories = js["categories"]
|
| 22 |
-
|
| 23 |
-
index_to_label = dict()
|
| 24 |
-
for category in categories:
|
| 25 |
-
index = category["id"]
|
| 26 |
-
name = category["name"]
|
| 27 |
-
index_to_label[index] = name
|
| 28 |
-
|
| 29 |
-
# print(images)
|
| 30 |
-
image_id_to_annotations = defaultdict(list)
|
| 31 |
-
for annotation in annotations:
|
| 32 |
-
image_id = annotation["image_id"]
|
| 33 |
-
image_id_to_annotations[image_id].append(annotation)
|
| 34 |
-
|
| 35 |
-
to_filename = project_path / "data/annotations/{}.jsonl".format(subset)
|
| 36 |
-
with open(to_filename.as_posix(), "w", encoding="utf-8") as f:
|
| 37 |
-
for image in images:
|
| 38 |
-
image_id = image["id"]
|
| 39 |
-
annotations = image_id_to_annotations[image_id]
|
| 40 |
-
|
| 41 |
-
image_path = Path("data/images") / image["file_name"]
|
| 42 |
-
|
| 43 |
-
row = {
|
| 44 |
-
"image_id": image["id"],
|
| 45 |
-
"image": image_path.as_posix(),
|
| 46 |
-
"width": image["width"],
|
| 47 |
-
"height": image["height"],
|
| 48 |
-
"objects": [
|
| 49 |
-
{
|
| 50 |
-
"id": annotation["id"],
|
| 51 |
-
"area": annotation["area"],
|
| 52 |
-
"bbox": annotation["bbox"],
|
| 53 |
-
"category": index_to_label[annotation["category_id"]],
|
| 54 |
-
} for annotation in annotations
|
| 55 |
-
]
|
| 56 |
-
}
|
| 57 |
-
row = json.dumps(row, ensure_ascii=False)
|
| 58 |
-
f.write("{}\n".format(row))
|
| 59 |
-
|
| 60 |
-
return
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
if __name__ == '__main__':
|
| 64 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|