Showing
6 changed files
with
287 additions
and
0 deletions
code/annotation_xml_parser.py
0 → 100644
1 | +import xml.etree.ElementTree as elemTree | ||
2 | +import os | ||
3 | + | ||
4 | +CLASSES = ['dog'] | ||
5 | + | ||
6 | +def parseFile(path): | ||
7 | + result = "" | ||
8 | + annotation = elemTree.parse(path) | ||
9 | + | ||
10 | + filename = annotation.find('filename') | ||
11 | + size = annotation.find('size') | ||
12 | + width = size.find('width') | ||
13 | + height = size.find('height') | ||
14 | + | ||
15 | + result += filename.text + ' ' + width.text + ' ' + height.text | ||
16 | + for obj in annotation.findall('./object'): | ||
17 | + name = obj.find('name') | ||
18 | + box = obj.find('bndbox') | ||
19 | + | ||
20 | + label_index = CLASSES.index(name.text) | ||
21 | + xmin = box.find('xmin') | ||
22 | + ymin = box.find('ymin') | ||
23 | + xmax = box.find('xmax') | ||
24 | + ymax = box.find('ymax') | ||
25 | + | ||
26 | + result += ' ' + str(label_index) + ' ' + xmin.text + ' ' + ymin.text + ' ' + xmax.text + ' ' + ymax.text | ||
27 | + | ||
28 | + return result | ||
29 | + | ||
30 | + | ||
31 | +def parseDir(path): | ||
32 | + result = "" | ||
33 | + for file in os.listdir(path): | ||
34 | + if file.split('.')[-1] != 'xml': | ||
35 | + continue | ||
36 | + | ||
37 | + result += parseFile(path+'/'+file) + '\n' | ||
38 | + return result | ||
39 | + | ||
40 | + | ||
41 | +directory = input('Input directory, or 0 to exit: ') | ||
42 | + | ||
43 | +if directory != '0': | ||
44 | + result = parseDir(directory) | ||
45 | + file = open(directory+'/'+'annotation.txt','w') | ||
46 | + file.write(result) | ||
47 | + file.close() | ||
48 | + print("Complete!") |
code/dataset_splitter.py
0 → 100644
1 | +import os | ||
2 | +import tensorflow as tf | ||
3 | + | ||
4 | +all_path = '../data/annotation.txt' | ||
5 | +train_path = '../data/train.txt' | ||
6 | +val_path = '../data/val.txt' | ||
7 | +test_path = '../data/test.txt' | ||
8 | + | ||
9 | +allFile = open(all_path, 'r') | ||
10 | +allFile_lines = allFile.readlines() | ||
11 | +allFile.close() | ||
12 | + | ||
13 | +dataset_size = len(allFile_lines) | ||
14 | + | ||
15 | +train_size = int(0.7 * dataset_size) | ||
16 | +val_size = int(0.15 * dataset_size) | ||
17 | +test_size = int(0.15 * dataset_size) | ||
18 | + | ||
19 | +full_dataset = tf.data.TextLineDataset(all_path) | ||
20 | +full_dataset = full_dataset.shuffle(dataset_size) | ||
21 | +train_dataset = full_dataset.take(train_size) | ||
22 | +test_dataset = full_dataset.skip(train_size) | ||
23 | +val_dataset = test_dataset.skip(test_size) | ||
24 | +test_dataset = test_dataset.take(test_size) | ||
25 | + | ||
26 | +train_dataset = list(train_dataset) | ||
27 | +val_dataset = list(val_dataset) | ||
28 | +test_dataset = list(test_dataset) | ||
29 | + | ||
30 | +writer = open(train_path, 'w') | ||
31 | +for data in train_dataset: | ||
32 | + writer.write(data.numpy().decode('ascii') + '\n') | ||
33 | +writer.close() | ||
34 | + | ||
35 | +writer = open(val_path, 'w') | ||
36 | +for data in val_dataset: | ||
37 | + writer.write(data.numpy().decode('ascii') + '\n') | ||
38 | +writer.close() | ||
39 | + | ||
40 | +writer = open(test_path, 'w') | ||
41 | +for data in test_dataset: | ||
42 | + writer.write(data.numpy().decode('ascii') + '\n') | ||
43 | +writer.close() | ||
44 | + | ||
45 | +print('train dataset counts:', len(train_dataset)) | ||
46 | +print('validation dataset counts:', len(val_dataset)) | ||
47 | +print('test dataset counts:', len(test_dataset)) | ||
48 | + | ||
49 | +reader = open(train_path, 'r') | ||
50 | +train_file = reader.readlines() | ||
51 | +reader.close() | ||
52 | +train_file.sort() | ||
53 | + | ||
54 | +writer = open(train_path, 'w') | ||
55 | +for i in range(len(train_file)): | ||
56 | + writer.write(str(i) + ' ' + train_file[i]) | ||
57 | +writer.close() | ||
58 | + | ||
59 | +reader = open(val_path, 'r') | ||
60 | +val_file = reader.readlines() | ||
61 | +reader.close() | ||
62 | +val_file.sort() | ||
63 | + | ||
64 | +writer = open(val_path, 'w') | ||
65 | +for i in range(len(val_file)): | ||
66 | + writer.write(str(i) + ' ' + val_file[i]) | ||
67 | +writer.close() | ||
68 | + | ||
69 | +reader = open(test_path, 'r') | ||
70 | +test_file = reader.readlines() | ||
71 | +reader.close() | ||
72 | +test_file.sort() | ||
73 | + | ||
74 | +writer = open(test_path, 'w') | ||
75 | +for i in range(len(test_file)): | ||
76 | + writer.write(str(i) + ' ' + test_file[i]) | ||
77 | +writer.close() | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
data/annotation.txt
0 → 100644
This diff is collapsed. Click to expand it.
data/test.txt
0 → 100644
1 | +0 1618c8524c67549e809f54f7a0637834ee731d8c5b7818ddd3c5042b325557f3_06960.jpg 1920 1080 0 554 446 1339 1080 0 371 99 637 538 0 582 143 921 521 | ||
2 | +1 190711_155.jpg 1080 1080 0 97 28 1046 981 | ||
3 | +2 190711_207.jpg 587 626 0 98 8 506 623 | ||
4 | +3 190711_24.jpg 888 959 0 15 17 881 959 | ||
5 | +4 190711_280.jpg 910 1216 0 217 21 748 1216 | ||
6 | +5 190711_330.jpg 786 831 0 140 5 688 806 | ||
7 | +6 190711_348.jpg 781 652 0 41 87 773 569 | ||
8 | +7 190711_375.jpg 811 876 0 187 54 655 849 | ||
9 | +8 190711_64.jpg 1080 1080 0 5 164 819 1075 | ||
10 | +9 190711_67.jpg 551 626 0 1 49 512 613 | ||
11 | +10 190711_706.jpg 225 225 0 26 37 196 225 | ||
12 | +11 190711_736.jpg 183 169 0 8 5 175 161 | ||
13 | +12 190711_742.jpg 225 225 0 9 5 219 210 | ||
14 | +13 190711_8.jpg 635 617 0 47 61 561 585 | ||
15 | +14 190711_874.jpg 389 355 0 40 6 354 339 | ||
16 | +15 190723_10.jpg 250 188 0 47 4 184 171 | ||
17 | +16 190723_120.jpg 275 183 0 36 29 203 160 | ||
18 | +17 190723_164.jpg 232 217 0 26 17 212 217 | ||
19 | +18 190723_241.jpg 300 168 0 1 1 170 167 | ||
20 | +19 190723_279.jpg 220 147 0 66 13 182 141 | ||
21 | +20 190723_330.jpg 225 225 0 1 93 46 178 0 21 87 124 212 0 110 56 214 131 0 128 30 223 80 | ||
22 | +21 190723_354.jpg 275 183 0 47 40 234 172 | ||
23 | +22 190723_431.jpg 253 199 0 54 21 201 188 | ||
24 | +23 190723_495.jpg 225 225 0 85 79 212 180 | ||
25 | +24 190723_607.jpg 300 168 0 1 1 235 168 | ||
26 | +25 190723_612.jpg 275 183 0 94 22 211 178 | ||
27 | +26 190723_742.jpg 259 194 0 28 1 215 165 | ||
28 | +27 190723_758.jpg 299 168 0 80 7 229 146 | ||
29 | +28 190814_37.jpg 244 206 0 29 2 225 203 | ||
30 | +29 190814_434.jpg 275 183 0 135 60 264 121 | ||
31 | +30 190814_458.jpg 263 191 0 80 27 218 169 0 208 1 261 59 | ||
32 | +31 190814_482.jpg 198 255 0 1 56 149 214 | ||
33 | +32 190814_606.jpg 275 183 0 35 24 158 181 | ||
34 | +33 190814_654.jpg 206 245 0 40 61 128 228 | ||
35 | +34 190814_680.jpg 311 162 0 175 23 281 155 | ||
36 | +35 190814_690.jpg 275 183 0 4 35 273 159 | ||
37 | +36 190814_736.jpg 275 183 0 109 13 251 180 | ||
38 | +37 190814_779.jpg 184 274 0 10 17 161 261 | ||
39 | +38 190814_786.jpg 300 168 0 30 36 111 167 | ||
40 | +39 190814_798.jpg 225 225 0 3 7 153 225 | ||
41 | +40 190902_148.jpg 298 169 0 8 43 291 156 | ||
42 | +41 190902_175.jpg 260 194 0 27 57 235 127 | ||
43 | +42 190902_198.jpg 303 166 0 1 17 281 155 | ||
44 | +43 190902_210.jpg 300 168 0 63 20 292 153 | ||
45 | +44 190902_260.jpg 711 400 0 44 72 668 334 | ||
46 | +45 190925_171.jpg 3120 3120 0 666 980 2103 2271 | ||
47 | +46 190927_1048.jpg 1080 810 0 219 4 767 804 | ||
48 | +47 190927_1135.jpg 1080 1079 0 4 311 262 859 0 212 295 510 528 0 202 451 480 703 0 526 379 990 653 | ||
49 | +48 190927_1234.jpg 1080 1080 0 304 393 785 865 | ||
50 | +49 190927_1242.jpg 679 679 0 10 96 648 572 | ||
51 | +50 190927_1331.jpg 1080 1080 0 282 378 838 821 | ||
52 | +51 190927_1366.jpg 1080 1350 0 292 117 725 501 0 64 711 856 1344 | ||
53 | +52 190927_1377.jpg 1080 1080 0 62 361 846 1059 0 296 7 835 306 | ||
54 | +53 190927_1403.jpg 1080 1080 0 20 173 1051 1034 | ||
55 | +54 190927_1478.jpg 1080 1080 0 41 293 727 1040 | ||
56 | +55 190927_284.jpg 1080 1350 0 190 566 454 813 | ||
57 | +56 190927_322.jpg 1080 1080 0 168 37 812 987 | ||
58 | +57 190927_325.jpg 1080 1350 0 160 7 851 1350 | ||
59 | +58 190927_370.jpg 1080 1350 0 256 236 933 1058 | ||
60 | +59 190927_536.jpg 1080 1080 0 10 229 904 953 | ||
61 | +60 190927_63.jpg 1080 1081 0 262 66 901 819 | ||
62 | +61 190927_690.jpg 1080 1080 0 48 89 1029 1059 | ||
63 | +62 190927_842.jpg 540 540 0 255 130 508 377 | ||
64 | +63 190927_868.jpg 1080 1080 0 312 82 655 1000 | ||
65 | +64 190927_869.jpg 1080 1080 0 18 300 940 907 | ||
66 | +65 24830bc00964f17f9829b0c088856a233c9997f1d919a449709543228d0f4de2_05175.jpg 1920 1080 0 501 279 1234 832 | ||
67 | +66 2ca29ac644be58d8a23946e575425386d651f9f0612ffa3b7dec11d655336418_09900.jpg 1920 1080 0 696 474 834 643 | ||
68 | +67 401c9777cb1edad6fddb28ec3daca84abcf99928f22c6ad5b6ada4b03683cc4f_01920.jpg 1920 1080 0 390 185 926 721 0 1584 7 1920 1034 | ||
69 | +68 401c9777cb1edad6fddb28ec3daca84abcf99928f22c6ad5b6ada4b03683cc4f_02490.jpg 1920 1080 0 482 343 918 960 0 912 290 1920 1077 | ||
70 | +69 440028124bb2f30c7f1e025010f2a89c1e575061d2d0e5c826cc37ef9806f37a_02460.jpg 1280 720 0 1028 396 1191 514 | ||
71 | +70 5efc213b50083c042da0aee7e374f83052d8b83d781cd468473e35f5908237f2_05460.jpg 1280 720 0 460 1 1017 720 | ||
72 | +71 68912cf632d7bc73a845968d54e6e5ada41cd1691297921f9658a4b85d5293ee_06120.jpg 1920 1080 0 32 7 1468 907 | ||
73 | +72 6b9b420b60cdd5f411a0bd3a73749960db54c57138602c32db57aa5132d57e66_29415.jpg 1920 1080 0 765 268 1540 679 | ||
74 | +73 6fe6e07ac0f90bb9fce241083dca8671ff2ae18752471f2eec3572059d3c8de0_11400.jpg 1920 1080 0 565 107 971 879 | ||
75 | +74 6fe6e07ac0f90bb9fce241083dca8671ff2ae18752471f2eec3572059d3c8de0_12135.jpg 1920 1080 0 576 7 1653 1080 | ||
76 | +75 bfb7f11afc2aa2329aa5b1608ebf0b73064800b0b67a850057364cbae205c4a2_18855.jpg 1920 1080 0 808 258 1373 897 | ||
77 | +76 c2bafb4bde21aba787f447d1f39365db4949c8bdfd04906d58293c703b9832d7_13920.jpg 1920 1080 0 946 313 1388 849 | ||
78 | +77 c929ea1f6b228579298782cb55a55471cd398d3d00d0c4bc1022e62b7536278e_00960.jpg 1920 1080 0 8 289 918 974 0 633 581 1093 966 0 908 406 1766 945 | ||
79 | +78 dee867499ad03c3a009cbf782d2130a21941f00f8b69166ae2ac2c194e9f808f_04725.jpg 1920 1080 0 693 287 1035 941 | ||
80 | +79 fb7accfff8c6f8ea9b03c91ee5576d0d08080e9ba35918d801aaeb6020dbc88c_04740.jpg 1280 720 0 417 114 758 720 |
data/train.txt
0 → 100644
This diff is collapsed. Click to expand it.
data/val.txt
0 → 100644
1 | +0 047b783c16b8b43d7a8034afb6feaaa5ff995a6ffd5b91d63cf24242c3353704_05730.jpg 1920 1080 0 804 246 1271 732 | ||
2 | +1 184053a95825defe28e5a60f4d62f82841944cb5ffa11b8e1b07402a297fbe43_05670.jpg 1920 1080 0 1207 313 1873 760 0 318 210 1121 907 | ||
3 | +2 190711_115.jpg 426 458 0 29 18 414 452 | ||
4 | +3 190711_195.jpg 856 982 0 254 42 645 934 | ||
5 | +4 190711_276.jpg 772 798 0 101 38 714 778 | ||
6 | +5 190711_292.jpg 1080 1080 0 335 231 738 1003 | ||
7 | +6 190711_380.jpg 1080 1349 0 83 397 842 1349 | ||
8 | +7 190711_75.jpg 1036 901 0 46 89 992 901 | ||
9 | +8 190711_798.jpg 267 400 0 77 113 260 385 | ||
10 | +9 190711_806.jpg 600 400 0 185 91 398 366 | ||
11 | +10 190711_822.jpg 183 175 0 33 24 144 152 | ||
12 | +11 190711_858.jpg 598 400 0 90 2 398 400 | ||
13 | +12 190711_884.jpg 351 400 0 37 73 319 354 | ||
14 | +13 190711_894.jpg 600 400 0 207 14 528 400 | ||
15 | +14 190723_103.jpg 198 254 0 13 14 191 251 | ||
16 | +15 190723_126.jpg 284 177 0 6 71 63 160 0 50 44 114 155 0 108 50 172 164 0 155 55 222 160 0 215 82 279 162 | ||
17 | +16 190723_127.jpg 225 225 0 24 15 212 218 | ||
18 | +17 190723_151.jpg 251 201 0 68 25 205 175 | ||
19 | +18 190723_204.jpg 264 191 0 81 10 221 128 | ||
20 | +19 190723_254.jpg 275 183 0 135 6 245 97 | ||
21 | +20 190723_28.jpg 225 225 0 18 18 201 178 | ||
22 | +21 190723_280.jpg 259 194 0 41 93 116 194 | ||
23 | +22 190723_320.jpg 211 239 0 1 9 211 234 | ||
24 | +23 190723_367.jpg 284 177 0 151 3 263 177 | ||
25 | +24 190723_402.jpg 225 225 0 19 4 197 225 | ||
26 | +25 190723_44.jpg 275 183 0 78 33 214 162 | ||
27 | +26 190723_473.jpg 300 168 0 94 42 196 136 | ||
28 | +27 190723_484.jpg 275 183 0 1 1 201 176 | ||
29 | +28 190814_119.jpg 200 252 0 98 149 122 182 | ||
30 | +29 190814_184.jpg 272 185 0 59 59 177 119 | ||
31 | +30 190814_235.jpg 266 189 0 9 1 242 189 | ||
32 | +31 190814_308.jpg 300 168 0 85 2 267 168 | ||
33 | +32 190814_32.jpg 183 275 0 5 6 166 275 | ||
34 | +33 190814_327.jpg 275 183 0 67 10 241 177 | ||
35 | +34 190814_364.jpg 259 194 0 26 45 213 170 | ||
36 | +35 190814_411.jpg 258 195 0 9 36 245 184 | ||
37 | +36 190814_459.jpg 275 183 0 21 55 229 147 | ||
38 | +37 190814_475.jpg 275 183 0 26 6 234 163 | ||
39 | +38 190814_525.jpg 275 183 0 87 94 275 183 | ||
40 | +39 190814_61.jpg 266 189 0 40 55 141 136 | ||
41 | +40 190814_7.jpg 275 183 0 1 10 272 138 | ||
42 | +41 190814_809.jpg 225 225 0 7 56 153 184 | ||
43 | +42 190814_840.jpg 225 224 0 88 95 221 218 | ||
44 | +43 190902_103.jpg 279 180 0 3 6 264 159 | ||
45 | +44 190902_136.jpg 220 230 0 68 93 159 154 | ||
46 | +45 190902_142.jpg 262 193 0 1 25 226 158 | ||
47 | +46 190902_188.jpg 269 188 0 49 23 263 186 | ||
48 | +47 190902_220.jpg 308 164 0 32 8 83 93 0 38 68 137 128 0 39 113 132 164 0 222 5 282 107 | ||
49 | +48 190902_240.jpg 762 400 0 64 150 613 308 | ||
50 | +49 190902_355.jpg 316 160 0 10 1 147 157 0 161 20 314 150 | ||
51 | +50 190902_677.jpg 238 212 0 12 32 226 200 | ||
52 | +51 190902_75.jpg 259 194 0 16 24 131 184 0 104 30 224 186 | ||
53 | +52 190927_1035.jpg 1080 1080 0 209 387 648 818 | ||
54 | +53 190927_1110.jpg 1080 1080 0 196 401 515 811 | ||
55 | +54 190927_114.jpg 1080 810 0 72 3 884 756 | ||
56 | +55 190927_1206.jpg 1080 1079 0 88 182 823 714 | ||
57 | +56 190927_1333.jpg 1080 1080 0 162 103 770 778 | ||
58 | +57 190927_1441.jpg 1080 809 0 6 45 1046 788 | ||
59 | +58 190927_1457.jpg 1080 1303 0 182 133 947 1146 | ||
60 | +59 190927_1462.jpg 1079 1080 0 348 42 670 595 | ||
61 | +60 190927_298.jpg 1080 1080 0 134 115 1080 958 | ||
62 | +61 190927_344.jpg 1080 1080 0 101 236 884 800 | ||
63 | +62 190927_466.jpg 1080 1080 0 195 129 1051 1025 | ||
64 | +63 190927_616.jpg 1080 1080 0 7 161 1080 999 | ||
65 | +64 190927_660.jpg 1080 1080 0 57 186 916 934 | ||
66 | +65 190927_708.jpg 1080 1080 0 295 495 855 1029 | ||
67 | +66 190927_850.jpg 723 903 0 4 273 723 898 | ||
68 | +67 190927_880.jpg 1080 810 0 283 91 882 761 | ||
69 | +68 327e75afa16d748aa464f9011ca2bfe7003015ea25e7e43d98ce55661b9daaed_02115.jpg 1920 1080 0 851 196 1223 777 | ||
70 | +69 55225c5ddb1c54677d4140e9d24d2d1fd228e93c63dd1380c033315635c66412_00180.jpg 1920 1080 0 487 410 1318 926 | ||
71 | +70 55225c5ddb1c54677d4140e9d24d2d1fd228e93c63dd1380c033315635c66412_00915.jpg 1920 1080 0 1018 307 1368 846 | ||
72 | +71 5efc213b50083c042da0aee7e374f83052d8b83d781cd468473e35f5908237f2_10980.jpg 1280 720 0 645 447 1280 715 0 686 1 1212 328 | ||
73 | +72 5efc213b50083c042da0aee7e374f83052d8b83d781cd468473e35f5908237f2_16680.jpg 1280 720 0 274 195 406 327 0 643 166 723 246 0 474 125 540 191 | ||
74 | +73 5f1bc79f79605a6fc79df4634ea8d4a185f55f57b939109ecb8d52cea069a80a_08760.jpg 1920 1080 0 693 1 1071 285 0 76 49 587 513 0 574 243 1121 627 0 79 665 537 1080 0 532 574 934 993 0 990 435 1290 860 0 709 693 1157 1052 0 1059 882 1832 1080 0 1287 424 1621 1049 0 1582 407 1920 972 | ||
75 | +74 6b9b420b60cdd5f411a0bd3a73749960db54c57138602c32db57aa5132d57e66_25905.jpg 1920 1080 0 682 43 1168 768 | ||
76 | +75 6b9b420b60cdd5f411a0bd3a73749960db54c57138602c32db57aa5132d57e66_28815.jpg 1920 1080 0 137 40 1448 746 | ||
77 | +76 6fe6e07ac0f90bb9fce241083dca8671ff2ae18752471f2eec3572059d3c8de0_14130.jpg 1920 1080 0 687 188 1032 893 | ||
78 | +77 aae127339c7e733ae5fb9c22cb33ae018d8d03f784df88d5a231924d8c2f7469_02910.jpg 1920 1080 0 721 118 1158 674 | ||
79 | +78 c2bafb4bde21aba787f447d1f39365db4949c8bdfd04906d58293c703b9832d7_09120.jpg 1920 1080 0 154 120 1126 1080 0 343 160 616 547 0 1173 133 1356 672 | ||
80 | +79 e4d6ed9893f49041f0cbd21567ab425ef1e4dff1366bc04597d1dc0d45acda17_08535.jpg 1280 720 0 268 66 390 245 0 350 93 438 243 0 476 47 616 214 | ||
81 | +80 ed5c59e9609087510c5336cede23fbc0e54b3e1787f49024db8cd1a94fb1faa4_26280.jpg 1920 1080 0 602 181 1233 1076 0 989 231 1318 891 | ||
82 | +81 fb7accfff8c6f8ea9b03c91ee5576d0d08080e9ba35918d801aaeb6020dbc88c_03225.jpg 1920 1080 0 487 328 1056 847 0 1029 97 1275 343 |
-
Please register or login to post a comment