Skip to content

Commit

Permalink
added json files
Browse files Browse the repository at this point in the history
  • Loading branch information
Cartucho committed Mar 11, 2018
1 parent 77dd910 commit 4784aab
Show file tree
Hide file tree
Showing 85 changed files with 545 additions and 509 deletions.
66 changes: 51 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import argparse
import glob
import json
import os

MINOVERLAP = 0.5 # value defined in the PASCAL VOC2012 challenge

Expand Down Expand Up @@ -48,6 +49,15 @@ def voc_ap(rec, prec):
return ap


def file_lines_to_list(path):
# open txt file lines to a list
with open(path) as f:
content = f.readlines()
# remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
return content


# create the "tmp_files" dir if it doesn't exist already
tmp_files_name = "tmp_files"
if not os.path.exists(tmp_files_name):
Expand All @@ -64,33 +74,59 @@ def voc_ap(rec, prec):
unique_classes = set([])
for txt_file in ground_truth_files_list:
#print(txt_file)
# open txt file lines to a list
with open(txt_file) as f:
content = f.readlines()
## remove whitespace characters like `\n` at the end of each line
content = [x.strip() for x in content]
for line in content:
class_name, _, _, _, _ = line.split()
lines = file_lines_to_list(txt_file)
# create ground-truth dictionary
bounding_boxes = []
for line in lines:
class_name, left, top, right, bottom = line.split()
bbox = left + " " + top + " " + right + " " +bottom
bounding_boxes.append({"class_name":class_name, "bbox":bbox, "used":False})
# since unique_classes is a set() it only adds if not already present
unique_classes.add(class_name)
# dump bounding_boxes into a ".json" file
file_id = txt_file.split(".txt",1)[0]
file_id = file_id.split("/",1)[1]
with open(tmp_files_name + "/" + file_id + "_ground_truth.json", 'wb') as outfile:
json.dump(bounding_boxes, outfile)

# let's sort the classes alphabetically
unique_classes = sorted(unique_classes)
#print(unique_classes)

# get a list with the predicted files
predicted_files_list = glob.glob('predicted/*.txt')
predicted_files_list.sort()

for class_name in unique_classes:
bounding_boxes = []
for txt_file in predicted_files_list:
print txt_file
lines = file_lines_to_list(txt_file)
for line in lines:
line_class_name, confidence, left, top, right, bottom = line.split()
if line_class_name == class_name:
print("match")
file_id = txt_file.split(".txt",1)[0]
file_id = file_id.split("/",1)[1]
bbox = left + " " + top + " " + right + " " +bottom
bounding_boxes.append({"confidence":confidence, "file_id":file_id, "bbox":bbox})
print(bounding_boxes)
# sort predictions by decreasing confidence
bounding_boxes.sort(key=lambda x:x['confidence'], reverse=True)
with open(tmp_files_name + "/" + class_name + "_predictions.json", 'wb') as outfile:
json.dump(bounding_boxes, outfile)


###
import sys
sys.exit()
###

"""
Calculate the AP for each class
"""
for class_name in unique_classes:
print(class_name)
# create temporary file:
# (2) <class_name>_predictions.txt
ground_truth = {}
s = json.dumps(ground_truth)
with open("tmp_class_name_ground_truth.json", "w") as f:
f.write(s)

# sort (2) by decreasing confidence

"""
Assign predictions to ground truth objects
Expand Down
30 changes: 15 additions & 15 deletions predicted/2007_000027.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
tvmonitor;0.471781;0;13;174;244
cup;0.414941;274;226;301;265
book;0.460851;429;219;528;247
bottle;0.287150;336;231;376;305
chair;0.292345;0;199;88;436
book;0.269833;433;260;506;336
book;0.462608;518;314;603;369
book;0.298196;592;310;634;388
book;0.382881;403;384;517;461
book;0.369369;405;429;519;470
pottedplant;0.297364;259;183;304;239
pottedplant;0.510713;279;178;340;248
pictureframe;0.261096;187;206;237;258
book;0.272826;433;272;499;341
book;0.619459;413;390;515;459
tvmonitor 0.471781 0 13 174 244
cup 0.414941 274 226 301 265
book 0.460851 429 219 528 247
bottle 0.287150 336 231 376 305
chair 0.292345 0 199 88 436
book 0.269833 433 260 506 336
book 0.462608 518 314 603 369
book 0.298196 592 310 634 388
book 0.382881 403 384 517 461
book 0.369369 405 429 519 470
pottedplant 0.297364 259 183 304 239
pottedplant 0.510713 279 178 340 248
pictureframe 0.261096 187 206 237 258
book 0.272826 433 272 499 341
book 0.619459 413 390 515 459
26 changes: 13 additions & 13 deletions predicted/2007_000032.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
tvmonitor;0.452213;503;4;639;127
refrigerator;0.283500;14;18;257;240
book;0.325701;508;167;625;246
book;0.473745;501;225;610;259
bottle;0.569329;417;235;452;311
book;0.352939;503;257;552;350
book;0.356840;531;262;584;356
book;0.271981;585;326;639;384
book;0.354973;466;427;585;470
tvmonitor;0.342337;81;27;227;247
pottedplant;0.521316;341;178;391;251
pictureframe;0.260571;247;205;305;260
book;0.354335;481;400;570;460
tvmonitor 0.452213 503 4 639 127
refrigerator 0.283500 14 18 257 240
book 0.325701 508 167 625 246
book 0.473745 501 225 610 259
bottle 0.569329 417 235 452 311
book 0.352939 503 257 552 350
book 0.356840 531 262 584 356
book 0.271981 585 326 639 384
book 0.354973 466 427 585 470
tvmonitor 0.342337 81 27 227 247
pottedplant 0.521316 341 178 391 251
pictureframe 0.260571 247 205 305 260
book 0.354335 481 400 570 460
12 changes: 6 additions & 6 deletions predicted/2007_000033.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pottedplant;0.529134;3;12;78;153
tvmonitor;0.523199;92;37;193;121
refrigerator;0.386569;63;77;560;477
tvmonitor;0.374142;292;6;438;99
windowblind;0.273336;436;0;564;105
pottedplant;0.346044;13;20;124;173
pottedplant 0.529134 3 12 78 153
tvmonitor 0.523199 92 37 193 121
refrigerator 0.386569 63 77 560 477
tvmonitor 0.374142 292 6 438 99
windowblind 0.273336 436 0 564 105
pottedplant 0.346044 13 20 124 173
4 changes: 2 additions & 2 deletions predicted/2007_000039.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
refrigerator;0.537946;482;0;638;275
wastecontainer;0.313999;529;201;593;309
refrigerator 0.537946 482 0 638 275
wastecontainer 0.313999 529 201 593 309
8 changes: 4 additions & 4 deletions predicted/2007_000042.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pottedplant;0.586544;509;1;632;179
tvmonitor;0.338835;555;144;635;204
sofa;0.833625;10;150;209;475
diningtable;0.570301;494;283;638;475
pottedplant 0.586544 509 1 632 179
tvmonitor 0.338835 555 144 635 204
sofa 0.833625 10 150 209 475
diningtable 0.570301 494 283 638 475
10 changes: 5 additions & 5 deletions predicted/2007_000061.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
chair;0.627778;493;111;561;239
diningtable;0.340181;504;102;634;243
chair;0.675353;564;142;639;265
sofa;0.292752;54;82;588;471
remote;0.785086;194;313;312;433
chair 0.627778 493 111 561 239
diningtable 0.340181 504 102 634 243
chair 0.675353 564 142 639 265
sofa 0.292752 54 82 588 471
remote 0.785086 194 313 312 433
14 changes: 7 additions & 7 deletions predicted/2007_000063.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pottedplant;0.819480;14;52;309;425
pottedplant;0.613840;438;209;539;281
vase;0.551992;214;257;251;295
vase;0.264438;458;256;491;283
windowblind;0.339878;247;0;507;112
pictureframe;0.540837;237;204;418;290
pottedplant;0.728262;426;210;528;286
pottedplant 0.819480 14 52 309 425
pottedplant 0.613840 438 209 539 281
vase 0.551992 214 257 251 295
vase 0.264438 458 256 491 283
windowblind 0.339878 247 0 507 112
pictureframe 0.540837 237 204 418 290
pottedplant 0.728262 426 210 528 286
6 changes: 3 additions & 3 deletions predicted/2007_000068.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tvmonitor;0.355530;0;14;125;147
pottedplant;0.726746;475;0;633;447
vase;0.261603;504;240;623;443
tvmonitor 0.355530 0 14 125 147
pottedplant 0.726746 475 0 633 447
vase 0.261603 504 240 623 443
8 changes: 4 additions & 4 deletions predicted/2007_000121.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
chair;0.429933;157;154;290;479
diningtable;0.712185;158;154;502;479
cup;0.285480;100;72;119;93
countertop;0.499608;0;87;178;296
chair 0.429933 157 154 290 479
diningtable 0.712185 158 154 502 479
cup 0.285480 100 72 119 93
countertop 0.499608 0 87 178 296
10 changes: 5 additions & 5 deletions predicted/2007_000123.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
person;0.408621;157;42;193;65
bed;0.363359;1;63;133;215
chair;0.343155;237;121;310;204
bed;0.710099;19;90;143;182
wastecontainer;0.393610;392;228;468;324
person 0.408621 157 42 193 65
bed 0.363359 1 63 133 215
chair 0.343155 237 121 310 204
bed 0.710099 19 90 143 182
wastecontainer 0.393610 392 228 468 324
12 changes: 6 additions & 6 deletions predicted/2007_000129.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
chair;0.459296;267;75;340;135
refrigerator;0.486051;0;12;155;246
chair;0.678557;252;78;352;342
chair;0.616418;396;93;639;335
diningtable;0.485140;260;111;490;369
diningtable;0.537489;244;119;405;355
chair 0.459296 267 75 340 135
refrigerator 0.486051 0 12 155 246
chair 0.678557 252 78 352 342
chair 0.616418 396 93 639 335
diningtable 0.485140 260 111 490 369
diningtable 0.537489 244 119 405 355
16 changes: 8 additions & 8 deletions predicted/2007_000170.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
refrigerator;0.303672;0;27;45;154
bowl;0.503095;12;161;105;198
chair;0.631600;313;60;409;285
diningtable;0.306721;0;125;189;294
diningtable;0.401212;300;90;509;302
chair;0.706046;0;154;188;479
door;0.704533;33;14;181;172
cabinetry;0.253778;289;47;452;225
refrigerator 0.303672 0 27 45 154
bowl 0.503095 12 161 105 198
chair 0.631600 313 60 409 285
diningtable 0.306721 0 125 189 294
diningtable 0.401212 300 90 509 302
chair 0.706046 0 154 188 479
door 0.704533 33 14 181 172
cabinetry 0.253778 289 47 452 225
6 changes: 3 additions & 3 deletions predicted/2007_000175.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sofa;0.841393;345;69;624;479
chair;0.342367;297;86;380;222
pillow;0.282579;423;140;526;260
sofa 0.841393 345 69 624 479
chair 0.342367 297 86 380 222
pillow 0.282579 423 140 526 260
16 changes: 8 additions & 8 deletions predicted/2007_000187.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pottedplant;0.765009;222;4;325;178
pottedplant;0.491541;344;130;369;160
tvmonitor;0.786197;428;42;639;210
sofa;0.791896;3;183;636;460
remote;0.679025;356;311;421;336
pictureframe;0.295145;299;115;349;160
pottedplant;0.312138;352;130;381;181
coffeetable;0.362789;403;166;549;305
pottedplant 0.765009 222 4 325 178
pottedplant 0.491541 344 130 369 160
tvmonitor 0.786197 428 42 639 210
sofa 0.791896 3 183 636 460
remote 0.679025 356 311 421 336
pictureframe 0.295145 299 115 349 160
pottedplant 0.312138 352 130 381 181
coffeetable 0.362789 403 166 549 305
12 changes: 6 additions & 6 deletions predicted/2007_000241.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
bowl;0.252750;190;96;272;138
bowl;0.774696;215;115;322;153
cup;0.459554;315;94;381;137
sink;0.674897;0;133;235;186
tap;0.361740;111;37;227;143
cabinetry;0.321016;497;55;639;337
bowl 0.252750 190 96 272 138
bowl 0.774696 215 115 322 153
cup 0.459554 315 94 381 137
sink 0.674897 0 133 235 186
tap 0.361740 111 37 227 143
cabinetry 0.321016 497 55 639 337
8 changes: 4 additions & 4 deletions predicted/2007_000243.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
refrigerator;0.463334;316;75;441;334
windowblind;0.449150;236;0;380;85
bookcase;0.648869;95;0;219;211
coffeetable;0.472681;6;136;134;274
refrigerator 0.463334 316 75 441 334
windowblind 0.449150 236 0 380 85
bookcase 0.648869 95 0 219 211
coffeetable 0.472681 6 136 134 274
26 changes: 13 additions & 13 deletions predicted/2007_000250.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
bottle;0.506194;322;57;341;120
chair;0.250874;462;72;489;120
cup;0.666443;247;130;291;173
diningtable;0.600672;165;129;489;227
chair;0.384535;478;115;556;229
chair;0.420201;489;91;624;254
chair;0.268141;582;113;631;235
chair;0.861616;168;153;357;420
chair;0.765259;394;152;503;401
cabinetry;0.424704;435;63;575;204
chair;0.402742;461;86;555;232
chair;0.676397;155;127;304;445
chair;0.770853;353;161;495;403
bottle 0.506194 322 57 341 120
chair 0.250874 462 72 489 120
cup 0.666443 247 130 291 173
diningtable 0.600672 165 129 489 227
chair 0.384535 478 115 556 229
chair 0.420201 489 91 624 254
chair 0.268141 582 113 631 235
chair 0.861616 168 153 357 420
chair 0.765259 394 152 503 401
cabinetry 0.424704 435 63 575 204
chair 0.402742 461 86 555 232
chair 0.676397 155 127 304 445
chair 0.770853 353 161 495 403
6 changes: 3 additions & 3 deletions predicted/2007_000256.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
sink;0.553823;397;138;639;222
tap;0.293102;557;34;639;169
wastecontainer;0.314123;205;380;346;479
sink 0.553823 397 138 639 222
tap 0.293102 557 34 639 169
wastecontainer 0.314123 205 380 346 479
2 changes: 1 addition & 1 deletion predicted/2007_000272.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
chair;0.533144;467;249;593;470
chair 0.533144 467 249 593 470
6 changes: 3 additions & 3 deletions predicted/2007_000323.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
bottle;0.280955;458;48;494;134
refrigerator;0.356081;434;16;622;243
refrigerator;0.535987;376;94;439;246
bottle 0.280955 458 48 494 134
refrigerator 0.356081 434 16 622 243
refrigerator 0.535987 376 94 439 246
14 changes: 7 additions & 7 deletions predicted/2007_000333.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pottedplant;0.426336;511;17;608;108
chair;0.256416;337;95;356;158
chair;0.336040;476;99;585;227
sofa;0.573717;564;120;639;280
diningtable;0.633977;3;95;340;454
chair;0.654364;15;149;205;471
chair;0.720733;474;61;579;261
pottedplant 0.426336 511 17 608 108
chair 0.256416 337 95 356 158
chair 0.336040 476 99 585 227
sofa 0.573717 564 120 639 280
diningtable 0.633977 3 95 340 454
chair 0.654364 15 149 205 471
chair 0.720733 474 61 579 261
4 changes: 2 additions & 2 deletions predicted/2007_000346.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
bottle;0.739925;359;15;445;263
refrigerator;0.499644;0;4;279;469
bottle 0.739925 359 15 445 263
refrigerator 0.499644 0 4 279 469
20 changes: 10 additions & 10 deletions predicted/2007_000363.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
pottedplant;0.542316;3;17;56;91
tvmonitor;0.277761;471;3;566;76
tvmonitor;0.275542;172;48;296;129
sofa;0.316454;0;63;80;274
sofa;0.620831;50;115;467;301
chair;0.306937;446;100;591;278
pottedplant;0.319877;0;13;29;99
tvmonitor;0.385547;179;39;291;144
chair;0.841719;474;89;593;266
chair;0.275912;12;98;131;290
pottedplant 0.542316 3 17 56 91
tvmonitor 0.277761 471 3 566 76
tvmonitor 0.275542 172 48 296 129
sofa 0.316454 0 63 80 274
sofa 0.620831 50 115 467 301
chair 0.306937 446 100 591 278
pottedplant 0.319877 0 13 29 99
tvmonitor 0.385547 179 39 291 144
chair 0.841719 474 89 593 266
chair 0.275912 12 98 131 290
Loading

0 comments on commit 4784aab

Please sign in to comment.