Feat: Update code can handle map 2 map (hdr, exterior), add readme for metadata.json format
#4
by
presencesw
- opened
README.md
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
The metadata.json have struct as:
|
2 |
+
|
3 |
+
|
4 |
+
```json
|
5 |
+
{
|
6 |
+
"data": [
|
7 |
+
[{"input_image": [], "groundtruth": []}],
|
8 |
+
[{"input_image": [], "groundtruth": []}],
|
9 |
+
...
|
10 |
+
],
|
11 |
+
"confuse": [], # list of image path not have rigth format
|
12 |
+
"false": [], # list of folder path not have right format ex: data_temp\14\1303 Doylin Dr, Cary, NC\ex 22
|
13 |
+
}
|
14 |
+
```
|
run_v2.py
ADDED
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import re
|
3 |
+
import shutil
|
4 |
+
import json
|
5 |
+
# from type import List
|
6 |
+
|
7 |
+
def get_list_train_test_exterior(camera_setting):
|
8 |
+
# print(camera_setting)
|
9 |
+
list_numbers = []
|
10 |
+
data = []
|
11 |
+
confuse = []
|
12 |
+
for images_name in os.listdir(os.path.join(camera_setting)):
|
13 |
+
images_name = os.path.join(camera_setting, images_name)
|
14 |
+
if os.path.isdir(images_name):
|
15 |
+
return False
|
16 |
+
images_id = images_name.split(".")[0].split("\\")[-1]
|
17 |
+
numbers = images_id[-4:]
|
18 |
+
if not numbers.isdigit():
|
19 |
+
numbers = images_id.split("_")[-2]
|
20 |
+
if not numbers.isdigit():
|
21 |
+
print(images_id)
|
22 |
+
list_numbers.append(numbers)
|
23 |
+
set_numbers = set()
|
24 |
+
for number in list_numbers:
|
25 |
+
set_numbers.add(number)
|
26 |
+
# print(set_numbers)
|
27 |
+
|
28 |
+
for image_number in set_numbers:
|
29 |
+
temp_list_train = []
|
30 |
+
temp_list_test = []
|
31 |
+
for images_name in os.listdir(os.path.join(camera_setting)):
|
32 |
+
if image_number in images_name:
|
33 |
+
# print(image_number)
|
34 |
+
# print(images_name)
|
35 |
+
if images_name.endswith(".jpg"):
|
36 |
+
temp_list_test.append(images_name)
|
37 |
+
else:
|
38 |
+
temp_list_train.append(images_name)
|
39 |
+
if len(temp_list_train) == 0:
|
40 |
+
confuse.append([os.path.join(camera_setting, i) for i in temp_list_test])
|
41 |
+
elif len(temp_list_test) == 0:
|
42 |
+
confuse.append([os.path.join(camera_setting, i) for i in temp_list_train])
|
43 |
+
else:
|
44 |
+
temp_dict = {}
|
45 |
+
temp_dict['input_image'] = [os.path.join(camera_setting, i) for i in temp_list_train]
|
46 |
+
temp_dict['groundtruth'] = [os.path.join(camera_setting, i) for i in temp_list_test]
|
47 |
+
data.append(temp_dict)
|
48 |
+
return {"data": data, "confuse": confuse}
|
49 |
+
|
50 |
+
def get_list_train_test_hdr(camera_setting):
|
51 |
+
data = []
|
52 |
+
confuse = []
|
53 |
+
dict_numbers = {}
|
54 |
+
for images_name in os.listdir(os.path.join(camera_setting)):
|
55 |
+
# images_name = os.path.join(camera_setting, images_name)
|
56 |
+
if os.path.isdir(os.path.join(camera_setting, images_name)):
|
57 |
+
return False
|
58 |
+
images_id = images_name.split(".")[0].split("\\")[-1]
|
59 |
+
numbers = images_id[-4:]
|
60 |
+
if not numbers.isdigit():
|
61 |
+
numbers = images_id.split("_")[-2]
|
62 |
+
if not numbers.isdigit():
|
63 |
+
print(images_id)
|
64 |
+
dict_numbers[int(numbers)] = images_name
|
65 |
+
# print(numbers)
|
66 |
+
# print(images_id, "\n")
|
67 |
+
dict_numbers = dict(sorted(dict_numbers.items()))
|
68 |
+
temp_list_input_image = []
|
69 |
+
temp_list_groundtruth = []
|
70 |
+
is_groundtruth = False
|
71 |
+
for number in dict_numbers:
|
72 |
+
image = os.path.join(camera_setting, dict_numbers[number])
|
73 |
+
if not image.endswith(".jpg"):
|
74 |
+
temp_list_input_image.append(image)
|
75 |
+
is_groundtruth = False
|
76 |
+
elif image.endswith(".jpg") and is_groundtruth == False:
|
77 |
+
temp_list_groundtruth.append(image)
|
78 |
+
data.append(
|
79 |
+
{
|
80 |
+
"input_image": temp_list_input_image,
|
81 |
+
"groundtruth": temp_list_groundtruth
|
82 |
+
}
|
83 |
+
)
|
84 |
+
temp_list_input_image = []
|
85 |
+
temp_list_groundtruth = []
|
86 |
+
is_groundtruth = True
|
87 |
+
elif image.endswith(".jpg") and is_groundtruth == True:
|
88 |
+
confuse.append(image)
|
89 |
+
return {"data": data, "confuse": confuse}
|
90 |
+
|
91 |
+
|
92 |
+
# def extract_numbers(string):
|
93 |
+
# numbers = re.findall(r'\d+', string)
|
94 |
+
# return ''.join(numbers)
|
95 |
+
|
96 |
+
def check_folder(camera_setting):
|
97 |
+
list_folder = []
|
98 |
+
for item in os.listdir(camera_setting):
|
99 |
+
if os.path.isdir(os.path.join(camera_setting, item)):
|
100 |
+
list_folder.append(os.path.join(camera_setting, item))
|
101 |
+
for folder in list_folder:
|
102 |
+
files = os.listdir(folder)
|
103 |
+
for fname in files:
|
104 |
+
# copying the files to the
|
105 |
+
# destination directory
|
106 |
+
shutil.copy2(os.path.join(folder,fname), os.path.join(folder,".."))
|
107 |
+
return list_folder
|
108 |
+
|
109 |
+
def main(data_path):
|
110 |
+
map_image = dict()
|
111 |
+
map_image['data'] = []
|
112 |
+
map_image['confuse'] = []
|
113 |
+
map_image['false'] = []
|
114 |
+
for fold_number in os.listdir(data_path):
|
115 |
+
if "." in fold_number:
|
116 |
+
continue
|
117 |
+
# print(fold_number)
|
118 |
+
for address in os.listdir(os.path.join(data_path, fold_number)):
|
119 |
+
address = os.path.join(data_path, fold_number, address)
|
120 |
+
for camera_setting in os.listdir(address):
|
121 |
+
# print(os.path.join(address, camera_setting))
|
122 |
+
if "exterior" in camera_setting.lower():
|
123 |
+
camera_setting = os.path.join(address, camera_setting)
|
124 |
+
temp_output = get_list_train_test_exterior(camera_setting=camera_setting)
|
125 |
+
elif "hdr" in camera_setting.lower():
|
126 |
+
camera_setting = os.path.join(address, camera_setting)
|
127 |
+
temp_output = get_list_train_test_hdr(camera_setting=camera_setting)
|
128 |
+
if temp_output == False:
|
129 |
+
map_image['false'].append(camera_setting)
|
130 |
+
else:
|
131 |
+
map_image['data'] += temp_output['data']
|
132 |
+
map_image['confuse'] += temp_output['confuse']
|
133 |
+
with open(f"metadata.json", 'w') as fout:
|
134 |
+
json_dumps_str = json.dumps(map_image, indent=4)
|
135 |
+
print(json_dumps_str, file=fout)
|
136 |
+
if __name__ == "__main__":
|
137 |
+
data_path = "data_temp"
|
138 |
+
main(data_path)
|