This repository has been archived by the owner on Feb 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.py
109 lines (73 loc) · 2.71 KB
/
pipeline.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import sys
import xml.etree.ElementTree as et
import json
if sys.argv[0] == "pipeline.py":
print("DONT RUN ME FROM THE TERMINAL")
exit()
WORKING_DIR = os.getcwd()
CONFIG = None
with open("./config.json", "r") as config_file:
CONFIG = json.load(config_file)
config_file.close()
print("Current Config: " + str(CONFIG))
DATASET_DIR = CONFIG["dataset-dir"] or "dataset"
TRAINING_DIRECTORY = WORKING_DIR + "\\"+DATASET_DIR+"\\train"
TESTING_DIRECTORY = WORKING_DIR + "\\"+DATASET_DIR+"\\test"
IMAGES_DIRECTORY = WORKING_DIR + "\\"+DATASET_DIR+"\\" + CONFIG["image-dir"]
ANNOTATIONS_DIRECTORY = WORKING_DIR + "\\" + \
DATASET_DIR+"\\" + CONFIG["annotation-dir"]
DO_IMAGES_EXIST = os.path.exists(IMAGES_DIRECTORY)
DO_ANNOTATIONS_EXIST = os.path.exists(ANNOTATIONS_DIRECTORY)
if DO_IMAGES_EXIST == False:
os.mkdir(IMAGES_DIRECTORY)
if DO_ANNOTATIONS_EXIST == False:
os.mkdir(ANNOTATIONS_DIRECTORY)
# list of labels in dataset
LABEL_MAP = {}
# populate the label map dict with data from the config file
for label in CONFIG["label_map"]:
LABEL_MAP.update({1: label})
DIRS_INCLUDE_IMG = CONFIG["images"]
DIRS_INCLUDE_DATA = CONFIG["annotations"]
MODEL_TYPE = CONFIG["model-type"] or "efficientdet_lite0"
EXPORT_PATH = CONFIG["export-path"] or "model.tflite"
IMAGES = {}
ANNOTATION = {}
ANNOTATIONS_MISSING: list[str] = []
DIRS_INCLUDE_IMG_PATHS = []
for i, path in enumerate(DIRS_INCLUDE_IMG):
DIRS_INCLUDE_IMG_PATHS.append("./" + DATASET_DIR + "/" + path)
def isFileMissing(ann_dir: str):
ann_name = ann_dir.split("/")[3]
exists = os.path.exists(ann_dir)
if exists:
print("[ \u001b[32m✓\u001b[0m ] " + ann_name)
x = et.parse(ann_dir)
root = x.getroot()
name = str(root[1].text)
path = str(root[2].text)
exists = os.path.exists(path)
if exists:
print("[ \u001b[32m✓\u001b[0m ] " + name)
else:
ANNOTATIONS_MISSING.append(name)
print("[ \u001b[31m✖\u001b[0m ] " + name)
else:
ANNOTATIONS_MISSING.append(ann_name)
print("[ \u001b[31m✖\u001b[0m ] " + ann_name)
def verifyIntegerty() -> bool:
for _img in DIRS_INCLUDE_IMG:
files = os.listdir("./" + DATASET_DIR + "/" + _img)
IMAGES[_img] = files
for _img in DIRS_INCLUDE_DATA:
files = os.listdir("./" + DATASET_DIR + "/" + _img)
ANNOTATION[_img] = files
print(ANNOTATION.keys())
keys = ANNOTATION.keys()
missingFiles = len(ANNOTATIONS_MISSING) > 0
# make this run for all the folders in the ANNOTATION object
for _key in keys:
for _ann in ANNOTATION[_key]:
isFileMissing("./" + DATASET_DIR + "/" + _key + "/" + _ann)
return missingFiles