├── .gitignore ├── LICENSE ├── README.md ├── classes.txt ├── images ├── classes.png ├── rectangle.png └── visualizer_example.gif ├── main.py ├── modules ├── bounding_boxes.py ├── csv_downloader.py ├── downloader.py ├── image_level.py ├── parser.py ├── show.py └── utils.py ├── oid_to_pascal_voc_xml.py ├── requirements.txt └── voc_to_YOLOv3.py /.gitignore: -------------------------------------------------------------------------------- 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 | gitignore/Python.gitignore at master · github/gitignore 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 | 110 | 111 | 112 | 113 |
114 | Skip to content 115 |
116 | 117 | 118 | 119 | 120 | 121 | 122 | 613 | 614 | 615 | 616 |
617 | 618 |
619 | 620 | 621 |
622 | 623 |
624 | 625 | 626 | 627 |
628 |
629 |
630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 |
643 |
644 | 645 |
    646 | 647 | 648 | 649 | 650 |
  • 651 | 652 |
    653 | 654 |
    655 | 656 | 657 | Watch 658 | 659 | 662 |
    663 | Notifications 664 |
    665 |
    666 | 677 | 678 | 689 | 690 | 701 | 702 | 713 |
    714 |
    715 |
    716 | 721 |
    722 |
  • 723 | 724 |
  • 725 |
    726 |
    727 | 728 | 734 |
    735 |
    736 | 737 | 743 |
    744 | 745 |
  • 746 | 747 |
  • 748 |
    749 |
    752 | 756 |
  • 757 |
758 | 759 |

760 | 761 | /gitignore 764 | 765 | 766 |

767 | 768 |
769 | 770 | 810 | 811 |
812 | 851 |
852 | 853 | 854 |
855 |
856 |
857 | 858 | 859 | 860 | 861 | 862 | 863 | Permalink 864 | 865 | 866 | 867 | 868 |
869 | 870 | 871 |
872 | 876 | Branch: 877 | master 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 |
886 | 887 |
888 | 892 | Find file 893 | 894 | 895 | Copy path 896 | 897 |
898 |
899 | 902 | 903 |
904 | 908 | Find file 909 | 910 | 911 | Copy path 912 | 913 |
914 |
915 | 916 | 917 | 918 | 919 |
920 |
921 | 922 | @captainpete 923 | captainpete 924 | 925 | Add db.sqlite3-journal to Python.gitignore (#3063) 940 | 941 | 942 | 943 | c1faae4 944 | May 25, 2019 945 | 946 |
947 | 948 | 1026 |
1027 | 1028 | 1029 | 1030 | 1031 | 1032 |
1033 | 1034 |
1035 | 1036 |
1037 | 125 lines (101 sloc) 1038 | 1039 | 1.67 KB 1040 |
1041 | 1042 |
1043 | 1044 |
1045 | Raw 1046 | Blame 1047 | History 1048 |
1049 | 1050 | 1051 |
1052 | 1053 |
1054 | 1058 |
1059 |
1060 | 1064 |
1065 |
1066 |
1067 | 1068 | 1069 | 1070 | 1071 | 1072 | 1073 |
1074 | 1075 | 1076 | 1077 | 1078 | 1079 | 1080 | 1081 | 1082 | 1083 | 1084 | 1085 | 1086 | 1087 | 1088 | 1089 | 1090 | 1091 | 1092 | 1093 | 1094 | 1096 | 1097 | 1098 | 1099 | 1100 | 1101 | 1102 | 1103 | 1104 | 1105 | 1106 | 1107 | 1109 | 1110 | 1111 | 1112 | 1113 | 1114 | 1115 | 1116 | 1117 | 1118 | 1119 | 1120 | 1121 | 1122 | 1123 | 1124 | 1125 | 1126 | 1127 | 1128 | 1129 | 1130 | 1131 | 1132 | 1133 | 1134 | 1135 | 1136 | 1137 | 1138 | 1139 | 1140 | 1141 | 1142 | 1143 | 1144 | 1145 | 1146 | 1147 | 1148 | 1149 | 1150 | 1151 | 1152 | 1153 | 1154 | 1155 | 1156 | 1157 | 1158 | 1159 | 1160 | 1161 | 1162 | 1163 | 1164 | 1165 | 1166 | 1167 | 1168 | 1169 | 1170 | 1171 | 1172 | 1173 | 1174 | 1175 | 1176 | 1177 | 1178 | 1179 | 1180 | 1181 | 1182 | 1183 | 1184 | 1185 | 1186 | 1187 | 1188 | 1189 | 1190 | 1191 | 1192 | 1194 | 1195 | 1196 | 1197 | 1198 | 1199 | 1200 | 1201 | 1202 | 1203 | 1204 | 1205 | 1206 | 1207 | 1208 | 1209 | 1210 | 1211 | 1212 | 1213 | 1214 | 1215 | 1216 | 1217 | 1219 | 1220 | 1221 | 1222 | 1223 | 1224 | 1225 | 1226 | 1227 | 1228 | 1229 | 1230 | 1231 | 1232 | 1233 | 1234 | 1236 | 1237 | 1238 | 1239 | 1240 | 1241 | 1242 | 1243 | 1244 | 1245 | 1246 | 1247 | 1248 | 1249 | 1250 | 1251 | 1252 | 1253 | 1254 | 1255 | 1256 | 1257 | 1258 | 1259 | 1260 | 1261 | 1262 | 1263 | 1264 | 1265 | 1266 | 1267 | 1268 | 1269 | 1270 | 1271 | 1272 | 1273 | 1274 | 1275 | 1276 | 1277 | 1278 | 1279 | 1280 | 1281 | 1282 | 1283 | 1284 | 1285 | 1286 | 1287 | 1289 | 1290 | 1291 | 1292 | 1293 | 1294 | 1295 | 1296 | 1297 | 1298 | 1299 | 1300 | 1301 | 1302 | 1303 | 1304 | 1306 | 1307 | 1308 | 1309 | 1310 | 1311 | 1312 | 1313 | 1314 | 1315 | 1316 | 1317 | 1318 | 1319 | 1320 | 1321 | 1322 | 1323 | 1324 | 1325 | 1326 | 1327 | 1328 | 1329 | 1331 | 1332 | 1333 | 1334 | 1335 | 1336 | 1337 | 1338 | 1339 | 1340 | 1341 | 1342 | 1343 | 1344 | 1345 | 1346 | 1348 | 1349 | 1350 | 1351 | 1352 | 1353 | 1354 | 1355 | 1356 | 1357 | 1358 | 1359 | 1361 | 1362 | 1363 | 1364 | 1365 | 1366 | 1367 | 1368 | 1369 | 1370 | 1371 | 1372 | 1374 | 1375 | 1376 | 1377 | 1378 | 1379 | 1380 | 1381 | 1382 | 1383 | 1384 | 1385 | 1387 | 1388 | 1389 | 1390 | 1391 | 1392 | 1393 | 1394 | 1395 | 1396 | 1397 | 1398 | 1400 | 1401 | 1402 | 1403 | 1404 | 1405 | 1406 | 1407 | 1408 | 1409 | 1410 | 1411 | 1412 | 1413 | 1414 | 1415 | 1417 | 1418 | 1419 | 1420 | 1421 | 1422 | 1423 | 1424 | 1425 | 1426 | 1427 | 1428 | 1430 | 1431 | 1432 | 1433 | 1434 | 1435 | 1436 | 1437 | 1438 | 1439 | 1440 | 1441 | 1442 | 1443 | 1444 | 1445 | 1446 | 1447 | 1448 | 1449 | 1450 | 1451 | 1452 | 1453 | 1454 | 1455 | 1456 | 1457 | 1459 | 1460 | 1461 | 1462 | 1463 | 1464 | 1465 | 1466 | 1467 | 1468 | 1469 | 1470 | 1472 | 1473 | 1474 | 1475 | 1476 | 1477 | 1478 | 1479 | 1480 | 1481 | 1482 | 1483 | 1485 | 1486 | 1487 | 1488 | 1489 | 1490 | 1491 | 1492 | 1493 | 1494 | 1495 | 1496 | 1497 | 1498 | 1499 | 1500 | 1501 | 1502 | 1503 | 1504 | 1505 | 1506 | 1507 | 1508 | 1509 | 1510 | 1511 | 1512 | 1513 | 1514 | 1515 | 1516 | 1517 | 1518 | 1519 | 1520 | 1522 | 1523 | 1524 | 1525 | 1526 | 1527 | 1528 | 1529 | 1530 | 1531 | 1532 | 1533 | 1534 | 1535 | 1536 | 1537 | 1539 | 1540 | 1541 | 1542 | 1543 | 1544 | 1545 | 1546 | 1547 | 1548 | 1549 | 1550 | 1552 | 1553 | 1554 | 1555 | 1556 | 1557 | 1558 | 1559 | 1560 | 1561 | 1562 | 1563 | 1565 | 1566 | 1567 | 1568 | 1569 | 1570 | 1571 | 1572 | 1573 | 1574 | 1575 | 1576 | 1577 | 1578 | 1579 | 1580 | 1581 | 1582 | 1583 | 1584 | 1586 | 1587 | 1588 | 1589 | 1590 | 1591 | 1592 | 1593 | 1594 | 1595 |
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
1095 |
# C extensions
*.so
1108 |
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
1193 |
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
1218 |
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
1235 |
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
1288 |
# Translations
*.mo
*.pot
1305 |
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
1330 |
# Flask stuff:
instance/
.webassets-cache
1347 |
# Scrapy stuff:
.scrapy
1360 |
# Sphinx documentation
docs/_build/
1373 |
# PyBuilder
target/
1386 |
# Jupyter Notebook
.ipynb_checkpoints
1399 |
# IPython
profile_default/
ipython_config.py
1416 |
# pyenv
.python-version
1429 |
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
1458 |
# celery beat schedule file
celerybeat-schedule
1471 |
# SageMath parsed files
*.sage.py
1484 |
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
1521 |
# Spyder project settings
.spyderproject
.spyproject
1538 |
# Rope project settings
.ropeproject
1551 |
# mkdocs documentation
/site
1564 |
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
1585 |
# Pyre type checker
.pyre/
1596 | 1597 | 1609 | 1610 |
1611 | 1612 |
1613 | 1614 | 1615 | 1616 |
1617 | 1618 | 1619 |
1620 | 1621 | 1622 |
1623 |
1624 | 1625 | 1626 | 1627 |
1628 | 1629 |
1630 | 1631 |
1632 |
1633 | 1634 | 1635 |
1636 | 1637 | 1638 | 1666 | 1667 | 1668 | 1669 |
1670 | 1671 | 1674 | You can’t perform that action at this time. 1675 |
1676 | 1677 | 1678 | 1679 | 1680 | 1681 | 1682 | 1683 | 1684 | 1685 | 1691 | 1702 | 1703 | 1707 | 1708 |
1709 | 1710 | 1711 | 1712 | 1713 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

Forked this repository from official creators and added 2 python scripts:

2 | oid_to_pascal_voc_xml.py
3 | voc_to_YOLOv3.py

4 | 5 | instructions to create custom YOLO v3 dataset:
6 | [pylessons.com](https://pylessons.com/YOLOv3-custom-data/) 7 | 8 | 9 |

~ OIDv4 ToolKit ~

10 | 11 | Do you want to build your personal object detector but you don't have enough images to train your model? Do you want to train your personal image classifier, but you are tired of the deadly slowness of ImageNet? Have you already discovered [Open Images Dataset v4](https://storage.googleapis.com/openimages/web/index.html) that has [600](https://storage.googleapis.com/openimages/2018_04/bbox_labels_600_hierarchy_visualizer/circle.html) classes and more than 1,700,000 images with related bounding boxes ready to use? Do you want to exploit it for your projects but you don't want to download gigabytes and gigabytes of data!? 12 | 13 | With this repository we can help you to get the best of this dataset with less effort as possible. 14 | In particular, with this practical ToolKit written in Python3 we give you, for both object detection and image classification tasks, the following options: 15 | 16 | **(2.0) Object Detection** 17 | 18 | * download any of the [600](https://storage.googleapis.com/openimages/2018_04/bbox_labels_600_hierarchy_visualizer/circle.html) classes of the dataset individually, taking care of creating the related bounding boxes for each downloaded image 19 | * download multiple classes at the same time creating separated folder and bounding boxes for each of them 20 | * download multiple classes and creating a common folder for all of them with a unique annotation file of each image 21 | * download a single class or multiple classes with the desired [attributes](https://storage.googleapis.com/openimages/web/download.html) 22 | * use the practical visualizer to inspect the donwloaded classes 23 | 24 | **(3.0) Image Classification** 25 | 26 | * download any of the [19,794](https://storage.googleapis.com/openimages/web/download.html#attributes) classes in a common labeled folder 27 | * exploit tens of possible commands to select only the desired images (ex. like only test images) 28 | 29 | The code is quite documented and designed to be easy to extend and improve. 30 | Me and [Angelo](https://github.com/keldrom) are pleased if our little bit of code can help you with your project and research. Enjoy ;) 31 | 32 | ![Snippet of the OIDv4 available classes](images/classes.png) 33 | 34 | # Open Image Dataset v4 35 | All the information related to this huge dataset can be found [here](https://storage.googleapis.com/openimages/web/index.html). 36 | In these few lines are simply summarized some statistics and important tips. 37 | 38 | **Object Detection** 39 | 40 | 41 | 42 | 43 | 44 |
TrainValidationTest#Classes
Images1,743,04241,620 125,436-
Boxes14,610,229204,621625,282600
45 | 46 | **Image Classification** 47 | 48 | 49 | 50 | 51 | 52 | 53 |
TrainValidationTest#Classes
Images9,011,21941,620125,436-
Machine-Generated Labels78,977,695512,0931,545,8357,870
Human-Verified Labels27,894,289551,3901,667,39919,794
54 | 55 | As it's possible to observe from the previous table we can have access to images from free different groups: train, validation and test. 56 | The ToolKit provides a way to select only a specific group where to search. 57 | Regarding object detection, it's important to underline that some annotations has been done as a group. It means that a single bounding box groups more than one istance. As mentioned by the creator of the dataset: 58 | - **IsGroupOf**: Indicates that the box spans a group of objects (e.g., a bed of flowers or a crowd of people). We asked annotators to use this tag for cases with more than 5 instances which are heavily occluding each other and are physically touching. 59 | That's again an option of the ToolKit that can be used to only grasp the desired images. 60 | 61 | Finally, it's interesting to notice that not all annotations has been produced by humans, but the creator also exploited an enhanced version of the method shown here reported [1](#reference) 62 | 63 | # 1.0 Getting Started 64 | 65 | ## 1.1 Installation 66 | 67 | Python3 is required. 68 | 69 | 1. Clone this repository 70 | ```bash 71 | git clone https://github.com/EscVM/OIDv4_ToolKit.git 72 | ``` 73 | 2. Install the required packages 74 | ```bash 75 | pip3 install -r requirements.txt 76 | ``` 77 | Peek inside the requirements file if you have everything already installed. Most of the dependencies are common libraries. 78 | 79 | ## 1.2 Launch the ToolKit to check the available options 80 | First of all, if you simply want a quick reminder of al the possible options given by the script, you can simply launch, from your console of choice, the [main.py](main.py). Remember to point always at the main directory of the project 81 | ```bash 82 | python3 main.py 83 | ``` 84 | or in the following way to get more information 85 | ```bash 86 | python3 main.py -h 87 | ``` 88 | 89 | # 2.0 Use the ToolKit to download images for Object Detection 90 | The ToolKit permit the download of your dataset in the folder you want (`Dataset`as default). The folder can be imposed with the argument 91 | `--Dataset` so you can make different dataset with different options inside. 92 | 93 | As previously mentioned, there are different available options that can be exploited. Let's see some of them. 94 | 95 | ## 2.1 Download different classes in separated folders 96 | Firstly, the ToolKit can be used to download classes in separated folders. The argument `--classes` accepts a list of classes or 97 | the path to the file.txt (`--classes path/to/file.txt`) that contains the list of all classes one for each lines (classes.txt uploaded as example). 98 | 99 | **Note**: for classes that are composed by different 100 | words please use the `_` character instead of the space (only for the inline use of the argument `--classes`). 101 | Example: `Polar_bear`. 102 | 103 | Let's for example download Apples and Oranges from the validation set. In this case we have to use the following command. 104 | ```bash 105 | python3 main.py downloader --classes Apple Orange --type_csv validation 106 | ``` 107 | The algorith will take care to download all the necessary files and build the directory structure like this: 108 | 109 | ``` 110 | main_folder 111 | │ main.py 112 | │ 113 | └───OID 114 | │ file011.txt 115 | │ file012.txt 116 | │ 117 | └───csv_folder 118 | | │ class-descriptions-boxable.csv 119 | | │ validation-annotations-bbox.csv 120 | | 121 | └───Dataset 122 | | 123 | └─── test 124 | | 125 | └─── train 126 | | 127 | └─── validation 128 | | 129 | └───Apple 130 | | | 131 | | |0fdea8a716155a8e.jpg 132 | | |2fe4f21e409f0a56.jpg 133 | | |... 134 | | └───Labels 135 | | | 136 | | |0fdea8a716155a8e.txt 137 | | |2fe4f21e409f0a56.txt 138 | | |... 139 | | 140 | └───Orange 141 | | 142 | |0b6f22bf3b586889.jpg 143 | |0baea327f06f8afb.jpg 144 | |... 145 | └───Labels 146 | | 147 | |0b6f22bf3b586889.txt 148 | |0baea327f06f8afb.txt 149 | |... 150 | ``` 151 | If you have already downloaded the different csv files you can simply put them in the `csv_folder`. The script takes automatically care of the download of these files, but if you want to manually download them for whatever reason [here](https://storage.googleapis.com/openimages/web/download.html) you can find them. 152 | 153 | If you interupt the downloading script `ctrl+d` you can always restart it from the last image downloaded. 154 | 155 | ## 2.2 Download multiple classes in a common folder 156 | This option allows to download more classes, but in a common folder. Also the related notations are mixed together with 157 | the already explained format (the first element is always the name of the single class). In this way, with a simple 158 | dictionary it's easy to parse the generated label to get the desired format. 159 | 160 | Again if we want to download Apple and Oranges, but in a common folder 161 | ```bash 162 | python3 main.py downloader --classes Apple Orange --type_csv validation --multiclasses 1 163 | ``` 164 | 165 | ### Annotations 166 | 167 | 168 | 169 | In the __original__ dataset the coordinates of the bounding boxes are made in the following way: 170 | 171 | **XMin**, **XMax**, **YMin**, **YMax**: coordinates of the box, in normalized image coordinates. XMin is in [0,1], where 0 is the leftmost pixel, and 1 is the rightmost pixel in the image. Y coordinates go from the top pixel (0) to the bottom pixel (1). 172 | 173 | However, in order to accomodate a more intuitive representation and give the maximum flexibility, every `.txt` annotation is made like: 174 | 175 | `name_of_the_class left top right bottom` 176 | 177 | where each coordinate is denormalized. So, the four different values correspond to the actual number of pixels of the related image. 178 | 179 | If you don't need the labels creation use `--noLabels`. 180 | 181 | ### Optional Arguments 182 | The annotations of the dataset has been marked with a bunch of boolean values. This attributes are reported below: 183 | - **IsOccluded**: Indicates that the object is occluded by another object in the image. 184 | - **IsTruncated**: Indicates that the object extends beyond the boundary of the image. 185 | - **IsGroupOf**: Indicates that the box spans a group of objects (e.g., a bed of flowers or a crowd of people). We asked annotators to use this tag for cases with more than 5 instances which are heavily occluding each other and are physically touching. 186 | - **IsDepiction**: Indicates that the object is a depiction (e.g., a cartoon or drawing of the object, not a real physical instance). 187 | - **IsInside**: Indicates a picture taken from the inside of the object (e.g., a car interior or inside of a building). 188 | - **n_threads**: Select how many threads you want to use. The ToolKit will take care for you to download multiple images in parallel, considerably speeding up the downloading process. 189 | - **limit**: Limit the number of images being downloaded. Useful if you want to restrict the size of your dataset. 190 | - **y**: Answer yes when have to download missing csv files. 191 | 192 | Naturally, the ToolKit provides the same options as paramenters in order to filter the downloaded images. 193 | For example, with: 194 | ```bash 195 | python3 main.py downloader -y --classes Apple Orange --type_csv validation --image_IsGroupOf 0 196 | ``` 197 | only images without group annotations are downloaded. 198 | 199 | # 3.0 Download images from Image-Level Labels Dataset for Image Classifiction 200 | The Toolkit is now able to acess also to the huge dataset without bounding boxes. This dataset is formed by 19,995 classes and it's already divided into train, validation and test. The command used for the download from this dataset is ```downloader_ill``` (Downloader of Image-Level Labels) and requires the argument ```--sub```. This argument selects the sub-dataset between human-verified labels ```h``` (5,655,108 images) and machine-generated labels ```m``` (8,853,429 images). An example of command is: 201 | ```bash 202 | python3 main.py downloader_ill --sub m --classes Orange --type_csv train --limit 30 203 | ``` 204 | The previously explained commands ```Dataset```, ```multiclasses```, ```n_threads``` and ```limit``` are available. 205 | The Toolkit automatically will put the dataset and the csv folder in specific folders that are renamed with a `_nl` at the end. 206 | # Commands sum-up 207 | 208 | | | downloader | visualizer | downloader_ill | | 209 | |-------------------:|:----------:|:----------:|:--------------:|--------------------------------------------------| 210 | | Dataset | O | O | O | Dataset folder name | 211 | | classes | R | | R | Considered classes | 212 | | type_csv | R | | R | Train, test or validation dataset | 213 | | y | O | | O | Answer yes when downloading missing csv files | 214 | | multiclasses | O | | O | Download classes toghether | 215 | | noLabels | O | | | Don't create labels | 216 | | Image_IsOccluded | O | | | Consider or not this filter | 217 | | Image_IsTruncated | O | | | Consider or not this filter | 218 | | Image_IsGroupOf | O | | | Consider or not this filter | 219 | | Image_IsDepiction | O | | | Consider or not this filter | 220 | | Image_IsInside | O | | | Consider or not this filter | 221 | | n_threads | O | | O | Indicates the maximum threads number | 222 | | limit | O | | O | Max number of images to download | 223 | | sub | | | R | Human-verified or Machine-generated images (h/m) | 224 | 225 | R = required, O = optional 226 | 227 | # 4.0 Use the ToolKit to visualize the labeled images 228 | The ToolKit is useful also for visualize the downloaded images with the respective labels. 229 | ```bash 230 | python3 main.py visualizer 231 | ``` 232 | In this way the default `Dataset` folder will be pointed to search the images and labels automatically. To point 233 | another folder it's possible to use `--Dataset` optional argument. 234 | ```bash 235 | python3 main.py visualizer --Dataset desired_folder 236 | ``` 237 | Then the system will ask you which folder to visualize (train, validation or test) and the desired class. 238 | Hence with `d` (next), `a` (previous) and `q` (exit) you will be able to explore all the images. Follow the menu for all the other options. 239 | 240 |

241 | 242 |

243 | 244 | # 5.0 Community Contributions 245 | - [Denis Zuenko](https://github.com/zuenko) has added multithreading to the ToolKit and is currently working on the generalization and speeding up process of the labels creation 246 | - [Skylion007](https://github.com/Skylion007) has improved labels creation reducing the runtime from O(nm) to O(n). That massively speeds up label generation 247 | - [Alex March](https://github.com/hosaka) has added the limit option to the ToolKit in order to download only a maximum number of images of a certain class 248 | - [Michael Baroody](https://github.com/mbaroody) has fixed the toolkit's visualizer for multiword classes 249 | 250 | # Citation 251 | Use this bibtex if you want to cite this repository: 252 | ``` 253 | @misc{OIDv4_ToolKit, 254 | title={Toolkit to download and visualize single or multiple classes from the huge Open Images v4 dataset}, 255 | author={Vittorio, Angelo}, 256 | year={2018}, 257 | publisher={Github}, 258 | journal={GitHub repository}, 259 | howpublished={\url{https://github.com/EscVM/OIDv4_ToolKit}}, 260 | } 261 | ``` 262 | 263 | # Reference 264 | "[We don't need no bounding-boxes: Training object class detectors using only human verification](https://arxiv.org/abs/1602.08405)"Papadopolous et al., CVPR 2016. 265 | -------------------------------------------------------------------------------- /classes.txt: -------------------------------------------------------------------------------- 1 | Apple 2 | Orange 3 | Light switch 4 | -------------------------------------------------------------------------------- /images/classes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pythonlessons/OIDv4_ToolKit/2e838bb41dfd074ee0d50dc311ee44f4baecbeec/images/classes.png -------------------------------------------------------------------------------- /images/rectangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pythonlessons/OIDv4_ToolKit/2e838bb41dfd074ee0d50dc311ee44f4baecbeec/images/rectangle.png -------------------------------------------------------------------------------- /images/visualizer_example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pythonlessons/OIDv4_ToolKit/2e838bb41dfd074ee0d50dc311ee44f4baecbeec/images/visualizer_example.gif -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # --------------- 2 | # Date: 7/19/2018 3 | # Place: Biella/Torino 4 | # Author: EscVM & TArt 5 | # Project: OID v4 6 | # --------------- 7 | 8 | """ 9 | OID v4 Downloader 10 | Download specific classes of the huge online dataset Open Image Dataset. 11 | Licensed under the MIT License (see LICENSE for details) 12 | ------------------------------------------------------------ 13 | Usage: 14 | refer to README.md file 15 | """ 16 | from sys import exit 17 | from textwrap import dedent 18 | from modules.parser import * 19 | from modules.utils import * 20 | from modules.downloader import * 21 | from modules.show import * 22 | from modules.csv_downloader import * 23 | from modules.bounding_boxes import * 24 | from modules.image_level import * 25 | 26 | 27 | ROOT_DIR = '' 28 | DEFAULT_OID_DIR = os.path.join(ROOT_DIR, 'OID') 29 | 30 | if __name__ == '__main__': 31 | 32 | args = parser_arguments() 33 | 34 | if args.command == 'downloader_ill': 35 | image_level(args, DEFAULT_OID_DIR) 36 | else: 37 | bounding_boxes_images(args, DEFAULT_OID_DIR) 38 | -------------------------------------------------------------------------------- /modules/bounding_boxes.py: -------------------------------------------------------------------------------- 1 | import os 2 | from modules.utils import * 3 | from modules.downloader import * 4 | from modules.show import * 5 | from modules.csv_downloader import * 6 | 7 | from modules.utils import bcolors as bc 8 | 9 | def bounding_boxes_images(args, DEFAULT_OID_DIR): 10 | 11 | if not args.Dataset: 12 | dataset_dir = os.path.join(DEFAULT_OID_DIR, 'Dataset') 13 | csv_dir = os.path.join(DEFAULT_OID_DIR, 'csv_folder') 14 | else: 15 | dataset_dir = os.path.join(DEFAULT_OID_DIR, args.Dataset) 16 | csv_dir = os.path.join(DEFAULT_OID_DIR, 'csv_folder') 17 | 18 | name_file_class = 'class-descriptions-boxable.csv' 19 | CLASSES_CSV = os.path.join(csv_dir, name_file_class) 20 | 21 | if args.command == 'downloader': 22 | 23 | logo(args.command) 24 | 25 | if args.type_csv is None: 26 | print(bc.FAIL + 'Missing type_csv argument.' + bc.ENDC) 27 | exit(1) 28 | if args.classes is None: 29 | print(bc.FAIL + 'Missing classes argument.' + bc.ENDC) 30 | exit(1) 31 | if args.multiclasses is None: 32 | args.multiclasses = 0 33 | 34 | folder = ['train', 'validation', 'test'] 35 | file_list = ['train-annotations-bbox.csv', 'validation-annotations-bbox.csv', 'test-annotations-bbox.csv'] 36 | 37 | if args.classes[0].endswith('.txt'): 38 | with open(args.classes[0]) as f: 39 | args.classes = f.readlines() 40 | args.classes = [x.strip() for x in args.classes] 41 | else: 42 | args.classes = [arg.replace('_', ' ') for arg in args.classes] 43 | 44 | if args.multiclasses == '0': 45 | 46 | mkdirs(dataset_dir, csv_dir, args.classes, args.type_csv) 47 | 48 | for classes in args.classes: 49 | 50 | print(bc.INFO + 'Downloading {}.'.format(classes) + bc.ENDC) 51 | class_name = classes 52 | 53 | error_csv(name_file_class, csv_dir, args.yes) 54 | df_classes = pd.read_csv(CLASSES_CSV, header=None) 55 | 56 | class_code = df_classes.loc[df_classes[1] == class_name].values[0][0] 57 | 58 | if args.type_csv == 'train': 59 | name_file = file_list[0] 60 | df_val = TTV(csv_dir, name_file, args.yes) 61 | if not args.n_threads: 62 | download(args, df_val, folder[0], dataset_dir, class_name, class_code) 63 | else: 64 | download(args, df_val, folder[0], dataset_dir, class_name, class_code, threads = int(args.n_threads)) 65 | 66 | elif args.type_csv == 'validation': 67 | name_file = file_list[1] 68 | df_val = TTV(csv_dir, name_file, args.yes) 69 | if not args.n_threads: 70 | download(args, df_val, folder[1], dataset_dir, class_name, class_code) 71 | else: 72 | download(args, df_val, folder[1], dataset_dir, class_name, class_code, threads = int(args.n_threads)) 73 | 74 | elif args.type_csv == 'test': 75 | name_file = file_list[2] 76 | df_val = TTV(csv_dir, name_file, args.yes) 77 | if not args.n_threads: 78 | download(args, df_val, folder[2], dataset_dir, class_name, class_code) 79 | else: 80 | download(args, df_val, folder[2], dataset_dir, class_name, class_code, threads = int(args.n_threads)) 81 | 82 | elif args.type_csv == 'all': 83 | for i in range(3): 84 | name_file = file_list[i] 85 | df_val = TTV(csv_dir, name_file, args.yes) 86 | if not args.n_threads: 87 | download(args, df_val, folder[i], dataset_dir, class_name, class_code) 88 | else: 89 | download(args, df_val, folder[i], dataset_dir, class_name, class_code, threads = int(args.n_threads)) 90 | else: 91 | print(bc.ERROR + 'csv file not specified' + bc.ENDC) 92 | exit(1) 93 | 94 | elif args.multiclasses == '1': 95 | 96 | class_list = args.classes 97 | print(bc.INFO + 'Downloading {} together.'.format(class_list) + bc.ENDC) 98 | multiclass_name = ['_'.join(class_list)] 99 | mkdirs(dataset_dir, csv_dir, multiclass_name, args.type_csv) 100 | 101 | error_csv(name_file_class, csv_dir, args.yes) 102 | df_classes = pd.read_csv(CLASSES_CSV, header=None) 103 | 104 | class_dict = {} 105 | for class_name in class_list: 106 | class_dict[class_name] = df_classes.loc[df_classes[1] == class_name].values[0][0] 107 | 108 | for class_name in class_list: 109 | 110 | if args.type_csv == 'train': 111 | name_file = file_list[0] 112 | df_val = TTV(csv_dir, name_file, args.yes) 113 | if not args.n_threads: 114 | download(args, df_val, folder[0], dataset_dir, class_name, class_dict[class_name], class_list) 115 | else: 116 | download(args, df_val, folder[0], dataset_dir, class_name, class_dict[class_name], class_list, int(args.n_threads)) 117 | 118 | elif args.type_csv == 'validation': 119 | name_file = file_list[1] 120 | df_val = TTV(csv_dir, name_file, args.yes) 121 | if not args.n_threads: 122 | download(args, df_val, folder[1], dataset_dir, class_name, class_dict[class_name], class_list) 123 | else: 124 | download(args, df_val, folder[1], dataset_dir, class_name, class_dict[class_name], class_list, int(args.n_threads)) 125 | 126 | elif args.type_csv == 'test': 127 | name_file = file_list[2] 128 | df_val = TTV(csv_dir, name_file, args.yes) 129 | if not args.n_threads: 130 | download(args, df_val, folder[2], dataset_dir, class_name, class_dict[class_name], class_list) 131 | else: 132 | download(args, df_val, folder[2], dataset_dir, class_name, class_dict[class_name], class_list, int(args.n_threads)) 133 | 134 | elif args.type_csv == 'all': 135 | for i in range(3): 136 | name_file = file_list[i] 137 | df_val = TTV(csv_dir, name_file, args.yes) 138 | if not args.n_threads: 139 | download(args, df_val, folder[i], dataset_dir, class_name, class_dict[class_name], class_list) 140 | else: 141 | download(args, df_val, folder[i], dataset_dir, class_name, class_dict[class_name], class_list, int(args.n_threads)) 142 | 143 | 144 | elif args.command == 'visualizer': 145 | 146 | logo(args.command) 147 | 148 | flag = 0 149 | 150 | while (True): 151 | if flag == 0: 152 | print("Which folder do you want to visualize (train, test, validation)? ") 153 | image_dir = input("> ") 154 | flag = 1 155 | 156 | if image_dir == 'exit': 157 | exit(1) 158 | 159 | class_image_dir = os.path.join(dataset_dir, image_dir) 160 | 161 | print("Which class? ") 162 | show_classes(os.listdir(class_image_dir)) 163 | 164 | class_name = input("> ") 165 | if class_name == 'exit': 166 | exit(1) 167 | 168 | download_dir = os.path.join(dataset_dir, image_dir, class_name) 169 | label_dir = os.path.join(dataset_dir, image_dir, class_name, 'Label') 170 | 171 | if not os.path.isdir(download_dir): 172 | print("[ERROR] Images folder not found") 173 | exit(1) 174 | if not os.path.isdir(label_dir): 175 | print("[ERROR] Labels folder not found") 176 | exit(1) 177 | 178 | index = 0 179 | 180 | print(dedent(""" 181 | -------------------------------------------------------- 182 | INFO: 183 | - Press 'd' to select next image 184 | - Press 'a' to select previous image 185 | - Press 'e' to select a new class 186 | - Press 'w' to select a new folder 187 | - Press 'q' to exit 188 | You can resize the window if it's not optimal 189 | -------------------------------------------------------- 190 | """)) 191 | 192 | show(class_name, download_dir, label_dir,len(os.listdir(download_dir))-1, index) 193 | 194 | while True: 195 | 196 | progression_bar(len(os.listdir(download_dir))-1, index+1) 197 | 198 | k = cv2.waitKey(0) & 0xFF 199 | 200 | if k == ord('d'): 201 | cv2.destroyAllWindows() 202 | if index < (len(os.listdir(download_dir)) - 2): 203 | index += 1 204 | show(class_name, download_dir, label_dir,len(os.listdir(download_dir))-1, index) 205 | elif k == ord('a'): 206 | cv2.destroyAllWindows() 207 | if index > 0: 208 | index -= 1 209 | show(class_name, download_dir, label_dir,len(os.listdir(download_dir))-1, index) 210 | elif k == ord('e'): 211 | cv2.destroyAllWindows() 212 | break 213 | elif k == ord('w'): 214 | flag = 0 215 | cv2.destroyAllWindows() 216 | break 217 | elif k == ord('q'): 218 | cv2.destroyAllWindows() 219 | exit(1) 220 | break 221 | -------------------------------------------------------------------------------- /modules/csv_downloader.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import time 4 | import urllib.request 5 | import pandas as pd 6 | 7 | from modules.utils import bcolors as bc 8 | 9 | OID_URL = 'https://storage.googleapis.com/openimages/2018_04/' 10 | 11 | def TTV(csv_dir, name_file, args_y): 12 | ''' 13 | Manage error_csv and read the correct .csv file. 14 | 15 | :param csv_dir: folder of the .csv files 16 | :param name_file: name of the correct .csv file 17 | :return: None 18 | ''' 19 | CSV = os.path.join(csv_dir, name_file) 20 | error_csv(name_file, csv_dir, args_y) 21 | df_val = pd.read_csv(CSV) 22 | return df_val 23 | 24 | def error_csv(file, csv_dir, args_y): 25 | ''' 26 | Check the presence of the required .csv files. 27 | 28 | :param file: .csv file missing 29 | :param csv_dir: folder of the .csv files 30 | :return: None 31 | ''' 32 | if not os.path.isfile(os.path.join(csv_dir, file)): 33 | print(bc.FAIL + "Missing the {} file.".format(os.path.basename(file)) + bc.ENDC) 34 | if args_y: 35 | ans = 'y' 36 | print(bc.OKBLUE + "Automatic download." + bc.ENDC) 37 | else: 38 | ans = input(bc.OKBLUE + "Do you want to download the missing file? [Y/n] " + bc.ENDC) 39 | 40 | if ans.lower() == 'y': 41 | folder = str(os.path.basename(file)).split('-')[0] 42 | if folder != 'class': 43 | FILE_URL = str(OID_URL + folder + '/' + file) 44 | else: 45 | FILE_URL = str(OID_URL + file) 46 | 47 | FILE_PATH = os.path.join(csv_dir, file) 48 | save(FILE_URL, FILE_PATH) 49 | print('\n' + bc.OKBLUE + "File {} downloaded into {}.".format(file, FILE_PATH) + bc.ENDC) 50 | 51 | else: 52 | exit(1) 53 | 54 | def save(url, filename): 55 | ''' 56 | Download the .csv file. 57 | 58 | :param url: Google url for download .csv files 59 | :param filename: .csv file name 60 | :return: None 61 | ''' 62 | urllib.request.urlretrieve(url, filename, reporthook) 63 | 64 | def reporthook(count, block_size, total_size): 65 | ''' 66 | Print the progression bar for the .csv file download. 67 | 68 | :param count: 69 | :param block_size: 70 | :param total_size: 71 | :return: 72 | ''' 73 | global start_time 74 | if count == 0: 75 | start_time = time.time() 76 | return 77 | duration = time.time() - start_time 78 | progress_size = int(count * block_size) 79 | speed = int(progress_size / ((1024 * duration) + 1e-5)) 80 | percent = int(count * block_size * 100 / (total_size + 1e-5)) 81 | sys.stdout.write("\r...%d%%, %d MB, %d KB/s, %d seconds passed" % 82 | (percent, progress_size / (1024 * 1024), speed, duration)) 83 | sys.stdout.flush() 84 | -------------------------------------------------------------------------------- /modules/downloader.py: -------------------------------------------------------------------------------- 1 | import os 2 | import cv2 3 | from tqdm import tqdm 4 | from modules.utils import images_options 5 | from modules.utils import bcolors as bc 6 | from multiprocessing.dummy import Pool as ThreadPool 7 | 8 | def download(args, df_val, folder, dataset_dir, class_name, class_code, class_list=None, threads = 20): 9 | ''' 10 | Manage the download of the images and the label maker. 11 | :param args: argument parser. 12 | :param df_val: DataFrame Values 13 | :param folder: train, validation or test 14 | :param dataset_dir: self explanatory 15 | :param class_name: self explanatory 16 | :param class_code: self explanatory 17 | :param class_list: list of the class if multiclasses is activated 18 | :param threads: number of threads 19 | :return: None 20 | ''' 21 | if os.name == 'posix': 22 | rows, columns = os.popen('stty size', 'r').read().split() 23 | elif os.name == 'nt': 24 | try: 25 | columns, rows = os.get_terminal_size(0) 26 | except OSError: 27 | columns, rows = os.get_terminal_size(1) 28 | else: 29 | columns = 50 30 | l = int((int(columns) - len(class_name))/2) 31 | 32 | print ('\n' + bc.HEADER + '-'*l + class_name + '-'*l + bc.ENDC) 33 | print(bc.INFO + 'Downloading {} images.'.format(args.type_csv) + bc.ENDC) 34 | df_val_images = images_options(df_val, args) 35 | 36 | images_list = df_val_images['ImageID'][df_val_images.LabelName == class_code].values 37 | images_list = set(images_list) 38 | print(bc.INFO + '[INFO] Found {} online images for {}.'.format(len(images_list), folder) + bc.ENDC) 39 | 40 | if args.limit is not None: 41 | import itertools 42 | print(bc.INFO + 'Limiting to {} images.'.format(args.limit) + bc.ENDC) 43 | images_list = set(itertools.islice(images_list, args.limit)) 44 | 45 | if class_list is not None: 46 | class_name_list = '_'.join(class_list) 47 | else: 48 | class_name_list = class_name 49 | 50 | download_img(folder, dataset_dir, class_name_list, images_list, threads) 51 | if not args.sub: 52 | get_label(folder, dataset_dir, class_name, class_code, df_val, class_name_list, args) 53 | 54 | 55 | def download_img(folder, dataset_dir, class_name, images_list, threads): 56 | ''' 57 | Download the images. 58 | :param folder: train, validation or test 59 | :param dataset_dir: self explanatory 60 | :param class_name: self explanatory 61 | :param images_list: list of the images to download 62 | :param threads: number of threads 63 | :return: None 64 | ''' 65 | image_dir = folder 66 | download_dir = os.path.join(dataset_dir, image_dir, class_name) 67 | downloaded_images_list = [f.split('.')[0] for f in os.listdir(download_dir)] 68 | images_list = list(set(images_list) - set(downloaded_images_list)) 69 | 70 | pool = ThreadPool(threads) 71 | 72 | if len(images_list) > 0: 73 | print(bc.INFO + 'Download of {} images in {}.'.format(len(images_list), folder) + bc.ENDC) 74 | commands = [] 75 | for image in images_list: 76 | path = image_dir + '/' + str(image) + '.jpg ' + '"' + download_dir + '"' 77 | command = 'aws s3 --no-sign-request --only-show-errors cp s3://open-images-dataset/' + path 78 | commands.append(command) 79 | 80 | list(tqdm(pool.imap(os.system, commands), total = len(commands) )) 81 | 82 | print(bc.INFO + 'Done!' + bc.ENDC) 83 | pool.close() 84 | pool.join() 85 | else: 86 | print(bc.INFO + 'All images already downloaded.' +bc.ENDC) 87 | 88 | 89 | def get_label(folder, dataset_dir, class_name, class_code, df_val, class_list, args): 90 | ''' 91 | Make the label.txt files 92 | :param folder: trai, validation or test 93 | :param dataset_dir: self explanatory 94 | :param class_name: self explanatory 95 | :param class_code: self explanatory 96 | :param df_val: DataFrame values 97 | :param class_list: list of the class if multiclasses is activated 98 | :return: None 99 | ''' 100 | if not args.noLabels: 101 | print(bc.INFO + 'Creating labels for {} of {}.'.format(class_name, folder) + bc.ENDC) 102 | 103 | image_dir = folder 104 | if class_list is not None: 105 | download_dir = os.path.join(dataset_dir, image_dir, class_list) 106 | label_dir = os.path.join(dataset_dir, folder, class_list, 'Label') 107 | else: 108 | download_dir = os.path.join(dataset_dir, image_dir, class_name) 109 | label_dir = os.path.join(dataset_dir, folder, class_name, 'Label') 110 | 111 | downloaded_images_list = [f.split('.')[0] for f in os.listdir(download_dir) if f.endswith('.jpg')] 112 | images_label_list = list(set(downloaded_images_list)) 113 | 114 | groups = df_val[(df_val.LabelName == class_code)].groupby(df_val.ImageID) 115 | for image in images_label_list: 116 | try: 117 | current_image_path = os.path.join(download_dir, image + '.jpg') 118 | dataset_image = cv2.imread(current_image_path) 119 | boxes = groups.get_group(image.split('.')[0])[['XMin', 'XMax', 'YMin', 'YMax']].values.tolist() 120 | file_name = str(image.split('.')[0]) + '.txt' 121 | file_path = os.path.join(label_dir, file_name) 122 | if os.path.isfile(file_path): 123 | f = open(file_path, 'a') 124 | else: 125 | f = open(file_path, 'w') 126 | 127 | for box in boxes: 128 | box[0] *= int(dataset_image.shape[1]) 129 | box[1] *= int(dataset_image.shape[1]) 130 | box[2] *= int(dataset_image.shape[0]) 131 | box[3] *= int(dataset_image.shape[0]) 132 | 133 | # each row in a file is name of the class_name, XMin, YMix, XMax, YMax (left top right bottom) 134 | print(class_name, box[0], box[2], box[1], box[3], file=f) 135 | 136 | except Exception as e: 137 | pass 138 | 139 | print(bc.INFO + 'Labels creation completed.' + bc.ENDC) 140 | -------------------------------------------------------------------------------- /modules/image_level.py: -------------------------------------------------------------------------------- 1 | import os 2 | from modules.utils import * 3 | from modules.downloader import * 4 | from modules.show import * 5 | from modules.csv_downloader import * 6 | 7 | from modules.utils import bcolors as bc 8 | 9 | def image_level(args, DEFAULT_OID_DIR): 10 | 11 | if not args.Dataset: 12 | dataset_dir = os.path.join(DEFAULT_OID_DIR, 'Dataset_nl') 13 | csv_dir = os.path.join(DEFAULT_OID_DIR, 'csv_folder_nl') 14 | else: 15 | dataset_dir = os.path.join(DEFAULT_OID_DIR, args.Dataset) 16 | csv_dir = os.path.join(DEFAULT_OID_DIR, 'csv_folder_nl') 17 | 18 | name_file_class = 'class-descriptions.csv' 19 | CLASSES_CSV = os.path.join(csv_dir, name_file_class) 20 | 21 | if args.sub is None: 22 | print(bc.FAIL + 'Missing subset argument.' + bc.ENDC) 23 | exit(1) 24 | 25 | if args.sub == 'h': 26 | 27 | file_list = ['train-annotations-human-imagelabels.csv', \ 28 | 'validation-annotations-human-imagelabels.csv', \ 29 | 'test-annotations-human-imagelabels.csv'] 30 | 31 | if args.sub == 'm': 32 | 33 | file_list = ['train-annotations-machine-imagelabels.csv', \ 34 | 'validation-annotations-machine-imagelabels.csv', \ 35 | 'test-annotations-machine-imagelabels.csv'] 36 | 37 | if args.sub == 'h' or args.sub == 'm': 38 | 39 | logo(args.command) 40 | 41 | if args.type_csv is None: 42 | print(bc.FAIL + 'Missing type_csv argument.' + bc.ENDC) 43 | exit(1) 44 | if args.classes is None: 45 | print(bc.FAIL + 'Missing classes argument.' + bc.ENDC) 46 | exit(1) 47 | if args.multiclasses is None: 48 | args.multiclasses = 0 49 | 50 | folder = ['train', 'validation', 'test'] 51 | 52 | if args.classes[0].endswith('.txt'): 53 | with open(args.classes[0]) as f: 54 | args.classes = f.readlines() 55 | args.classes = [x.strip() for x in args.classes] 56 | else: 57 | args.classes = [arg.replace('_', ' ') for arg in args.classes] 58 | 59 | if args.multiclasses == '0': 60 | 61 | mkdirs(dataset_dir, csv_dir, args.classes, args.type_csv) 62 | 63 | for classes in args.classes: 64 | 65 | class_name = classes 66 | 67 | error_csv(name_file_class, csv_dir, args.yes) 68 | df_classes = pd.read_csv(CLASSES_CSV, header=None) 69 | 70 | class_code = df_classes.loc[df_classes[1] == class_name].values[0][0] 71 | 72 | if args.type_csv == 'train': 73 | name_file = file_list[0] 74 | df_val = TTV(csv_dir, name_file, args.yes) 75 | if not args.n_threads: 76 | download(args, df_val, folder[0], dataset_dir, class_name, class_code) 77 | else: 78 | download(args, df_val, folder[0], dataset_dir, class_name, class_code, threads = int(args.n_threads)) 79 | 80 | elif args.type_csv == 'validation': 81 | name_file = file_list[1] 82 | df_val = TTV(csv_dir, name_file, args.yes) 83 | if not args.n_threads: 84 | download(args, df_val, folder[1], dataset_dir, class_name, class_code) 85 | else: 86 | download(args, df_val, folder[1], dataset_dir, class_name, class_code, threads = int(args.n_threads)) 87 | 88 | elif args.type_csv == 'test': 89 | name_file = file_list[2] 90 | df_val = TTV(csv_dir, name_file, args.yes) 91 | if not args.n_threads: 92 | download(args, df_val, folder[2], dataset_dir, class_name, class_code) 93 | else: 94 | download(args, df_val, folder[2], dataset_dir, class_name, class_code, threads = int(args.n_threads)) 95 | 96 | elif args.type_csv == 'all': 97 | for i in range(3): 98 | name_file = file_list[i] 99 | df_val = TTV(csv_dir, name_file, args.yes) 100 | if not args.n_threads: 101 | download(args, df_val, folder[i], dataset_dir, class_name, class_code) 102 | else: 103 | download(args, df_val, folder[i], dataset_dir, class_name, class_code, threads = int(args.n_threads)) 104 | else: 105 | print(bc.FAIL + 'csv file not specified' + bc.ENDC) 106 | exit(1) 107 | 108 | elif args.multiclasses == '1': 109 | 110 | class_list = args.classes 111 | print(bc.INFO + "Downloading {} together.".format(class_list) + bc.ENDC) 112 | multiclass_name = ['_'.join(class_list)] 113 | mkdirs(dataset_dir, csv_dir, multiclass_name, args.type_csv) 114 | 115 | error_csv(name_file_class, csv_dir, args.yes) 116 | df_classes = pd.read_csv(CLASSES_CSV, header=None) 117 | 118 | class_dict = {} 119 | for class_name in class_list: 120 | class_dict[class_name] = df_classes.loc[df_classes[1] == class_name].values[0][0] 121 | 122 | for class_name in class_list: 123 | 124 | if args.type_csv == 'train': 125 | name_file = file_list[0] 126 | df_val = TTV(csv_dir, name_file, args.yes) 127 | if not args.n_threads: 128 | download(args, df_val, folder[0], dataset_dir, class_name, class_dict[class_name], class_list) 129 | else: 130 | download(args, df_val, folder[0], dataset_dir, class_name, class_dict[class_name], class_list, int(args.n_threads)) 131 | 132 | elif args.type_csv == 'validation': 133 | name_file = file_list[1] 134 | df_val = TTV(csv_dir, name_file, args.yes) 135 | if not args.n_threads: 136 | download(args, df_val, folder[1], dataset_dir, class_name, class_dict[class_name], class_list) 137 | else: 138 | download(args, df_val, folder[1], dataset_dir, class_name, class_dict[class_name], class_list, int(args.n_threads)) 139 | 140 | elif args.type_csv == 'test': 141 | name_file = file_list[2] 142 | df_val = TTV(csv_dir, name_file, args.yes) 143 | if not args.n_threads: 144 | download(args, df_val, folder[2], dataset_dir, class_name, class_dict[class_name], class_list) 145 | else: 146 | download(args, df_val, folder[2], dataset_dir, class_name, class_dict[class_name], class_list, int(args.n_threads)) 147 | 148 | elif args.type_csv == 'all': 149 | for i in range(3): 150 | name_file = file_list[i] 151 | df_val = TTV(csv_dir, name_file, args.yes) 152 | if not args.n_threads: 153 | download(args, df_val, folder[i], dataset_dir, class_name, class_dict[class_name], class_list) 154 | else: 155 | download(args, df_val, folder[i], dataset_dir, class_name, class_dict[class_name], class_list, int(args.n_threads)) 156 | -------------------------------------------------------------------------------- /modules/parser.py: -------------------------------------------------------------------------------- 1 | import argparse 2 | 3 | def parser_arguments(): 4 | ''' 5 | Manage the input from the terminal. 6 | :return: parser 7 | ''' 8 | parser = argparse.ArgumentParser(description='Open Image Dataset Downloader') 9 | 10 | parser.add_argument("command", 11 | metavar=" 'downloader', 'visualizer' or 'ill_downloader'.", 12 | help="'downloader', 'visualizer' or 'ill_downloader'.") 13 | parser.add_argument('--Dataset', required=False, 14 | metavar="/path/to/OID/csv/", 15 | help='Directory of the OID dataset folder') 16 | parser.add_argument('-y', '--yes', required=False, action='store_true', 17 | #metavar="Yes to download missing files", 18 | help='ans Yes to possible download of missing files') 19 | parser.add_argument('--classes', required=False, nargs='+', 20 | metavar="list of classes", 21 | help="Sequence of 'strings' of the wanted classes") 22 | parser.add_argument('--type_csv', required=False, choices=['train', 'test', 'validation', 'all'], 23 | metavar="'train' or 'validation' or 'test' or 'all'", 24 | help='From what csv search the images') 25 | 26 | parser.add_argument('--sub', required=False, choices=['h', 'm'], 27 | metavar="Subset of human verified images or machine generated (h or m)", 28 | help='Download from the human verified dataset or from the machine generated one.') 29 | 30 | parser.add_argument('--image_IsOccluded', required=False, choices=['0', '1'], 31 | metavar="1 or 0", 32 | help='Optional characteristic of the images. Indicates that the object is occluded by another object in the image.') 33 | parser.add_argument('--image_IsTruncated', required=False, choices=['0', '1'], 34 | metavar="1 or 0", 35 | help='Optional characteristic of the images. Indicates that the object extends beyond the boundary of the image.') 36 | parser.add_argument('--image_IsGroupOf', required=False, choices=['0', '1'], 37 | metavar="1 or 0", 38 | help='Optional characteristic of the images. Indicates that the box spans a group of objects (min 5).') 39 | parser.add_argument('--image_IsDepiction', required=False, choices=['0', '1'], 40 | metavar="1 or 0", 41 | help='Optional characteristic of the images. Indicates that the object is a depiction.') 42 | parser.add_argument('--image_IsInside', required=False, choices=['0', '1'], 43 | metavar="1 or 0", 44 | help='Optional characteristic of the images. Indicates a picture taken from the inside of the object.') 45 | 46 | parser.add_argument('--multiclasses', required=False, default='0', choices=['0', '1'], 47 | metavar="0 (default) or 1", 48 | help='Download different classes separately (0) or together (1)') 49 | 50 | parser.add_argument('--n_threads', required=False, metavar="[default 20]", 51 | help='Num of the threads to use') 52 | 53 | parser.add_argument('--noLabels', required=False, action='store_true', 54 | help='No labels creations') 55 | 56 | parser.add_argument('--limit', required=False, type=int, default=None, 57 | metavar="integer number", 58 | help='Optional limit on number of images to download') 59 | 60 | return parser.parse_args() 61 | -------------------------------------------------------------------------------- /modules/show.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import os 3 | import re 4 | import numpy as np 5 | 6 | class_list = [] 7 | color_dic = dict() 8 | flag = 0 9 | 10 | def color_gen(): 11 | ''' 12 | Generate a new color. As first color generates (0, 255, 0) 13 | ''' 14 | global flag 15 | 16 | if flag == 0: 17 | color = (0, 255, 0) 18 | flag += 1 19 | else: 20 | np.random.seed() 21 | color = tuple(255 * np.random.rand(3)) 22 | return color 23 | 24 | def show(class_name, download_dir, label_dir,total_images, index): 25 | ''' 26 | Show the images with the labeled boxes. 27 | 28 | :param class_name: self explanatory 29 | :param download_dir: folder that contains the images 30 | :param label_dir: folder that contains the labels 31 | :param index: self explanatory 32 | :return: None 33 | ''' 34 | 35 | global class_list, color_dic 36 | 37 | if not os.listdir(download_dir)[index].endswith('.jpg'): 38 | index += 2 39 | img_file = os.listdir(download_dir)[index] 40 | current_image_path = str(os.path.join(download_dir, img_file)) 41 | img = cv2.imread(current_image_path) 42 | file_name = str(img_file.split('.')[0]) + '.txt' 43 | file_path = os.path.join(label_dir, file_name) 44 | f = open(file_path, 'r') 45 | 46 | window_name = "Visualizer: {}/{}".format(index+1, total_images) 47 | 48 | cv2.namedWindow(window_name, cv2.WINDOW_NORMAL) 49 | width = 500 50 | height = int((img.shape[0] * width) / img.shape[1]) 51 | cv2.resizeWindow(window_name, width, height) 52 | 53 | for line in f: 54 | # each row in a file is class_name, XMin, YMix, XMax, YMax 55 | match_class_name = re.compile('^[a-zA-Z]+(\s+[a-zA-Z]+)*').match(line) 56 | class_name = line[:match_class_name.span()[1]] 57 | ax = line[match_class_name.span()[1]:].lstrip().rstrip().split(' ') 58 | # opencv top left bottom right 59 | 60 | if class_name not in class_list: 61 | class_list.append(class_name) 62 | color = color_gen() 63 | color_dic[class_name] = color 64 | 65 | font = cv2.FONT_HERSHEY_SIMPLEX 66 | r ,g, b = color_dic[class_name] 67 | cv2.putText(img,class_name,(int(float(ax[0]))+5,int(float(ax[1]))-7), font, 0.8,(b, g, r), 2,cv2.LINE_AA) 68 | cv2.rectangle(img, (int(float(ax[-2])), int(float(ax[-1]))), 69 | (int(float(ax[-4])), 70 | int(float(ax[-3]))), (b, g, r), 3) 71 | 72 | cv2.imshow(window_name, img) 73 | -------------------------------------------------------------------------------- /modules/utils.py: -------------------------------------------------------------------------------- 1 | import os 2 | from textwrap import dedent 3 | 4 | def images_options(df_val, args): 5 | ''' 6 | Manage the options for the images downloader. 7 | 8 | :param df_val: DataFrame Value. 9 | :param args: argument parser. 10 | :return: modified df_val 11 | ''' 12 | if args.image_IsOccluded is not None: 13 | rejectedID = df_val.ImageID[df_val.IsOccluded != int(args.image_IsOccluded)].values 14 | df_val = df_val[~df_val.ImageID.isin(rejectedID)] 15 | 16 | if args.image_IsTruncated is not None: 17 | rejectedID = df_val.ImageID[df_val.IsTruncated != int(args.image_IsTruncated)].values 18 | df_val = df_val[~df_val.ImageID.isin(rejectedID)] 19 | 20 | if args.image_IsGroupOf is not None: 21 | rejectedID = df_val.ImageID[df_val.IsGroupOf != int(args.image_IsGroupOf)].values 22 | df_val = df_val[~df_val.ImageID.isin(rejectedID)] 23 | 24 | if args.image_IsDepiction is not None: 25 | rejectedID = df_val.ImageID[df_val.IsDepiction != int(args.image_IsDepiction)].values 26 | df_val = df_val[~df_val.ImageID.isin(rejectedID)] 27 | 28 | if args.image_IsInside is not None: 29 | rejectedID = df_val.ImageID[df_val.IsInside != int(args.image_IsInside)].values 30 | df_val = df_val[~df_val.ImageID.isin(rejectedID)] 31 | 32 | return df_val 33 | 34 | def mkdirs(Dataset_folder, csv_folder, classes, type_csv): 35 | ''' 36 | Make the folder structure for the system. 37 | 38 | :param Dataset_folder: Self explanatory 39 | :param csv_folder: folder path of csv files 40 | :param classes: list of classes to download 41 | :param type_csv: train, validation, test or all 42 | :return: None 43 | ''' 44 | 45 | directory_list = ['train', 'validation', 'test'] 46 | 47 | if not type_csv == 'all': 48 | for class_name in classes: 49 | if not Dataset_folder.endswith('_nl'): 50 | folder = os.path.join(Dataset_folder, type_csv, class_name, 'Label') 51 | else: 52 | folder = os.path.join(Dataset_folder, type_csv, class_name) 53 | if not os.path.exists(folder): 54 | os.makedirs(folder) 55 | filelist = [f for f in os.listdir(folder) if f.endswith(".txt")] 56 | for f in filelist: 57 | os.remove(os.path.join(folder, f)) 58 | 59 | else: 60 | for directory in directory_list: 61 | for class_name in classes: 62 | if not Dataset_folder.endswith('_nl'): 63 | folder = os.path.join(Dataset_folder, directory, class_name, 'Label') 64 | else: 65 | folder = os.path.join(Dataset_folder, directory, class_name, 'Label') 66 | if not os.path.exists(folder): 67 | os.makedirs(folder) 68 | filelist = [f for f in os.listdir(folder) if f.endswith(".txt")] 69 | for f in filelist: 70 | os.remove(os.path.join(folder, f)) 71 | 72 | if not os.path.exists(csv_folder): 73 | os.makedirs(csv_folder) 74 | 75 | def progression_bar(total_images, index): 76 | ''' 77 | Print the progression bar for the download of the images. 78 | 79 | :param total_images: self explanatory 80 | :param index: self explanatory 81 | :return: None 82 | ''' 83 | # for windows os 84 | if os.name == 'nt': 85 | from ctypes import windll, create_string_buffer 86 | 87 | h = windll.kernel32.GetStdHandle(-12) 88 | csbi = create_string_buffer(22) 89 | res = windll.kernel32.GetConsoleScreenBufferInfo(h, csbi) 90 | 91 | if res: 92 | import struct 93 | (bufx, bufy, curx, cury, wattr, 94 | left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw) 95 | columns = right - left + 1 96 | rows = bottom - top + 1 97 | else: 98 | columns, rows = 80, 25 # can't determine actual size - return default values 99 | # for linux/gnu os 100 | else: 101 | rows, columns = os.popen('stty size', 'r').read().split() 102 | toolbar_width = int(columns) - 10 103 | image_index = index 104 | index = int(index / total_images * toolbar_width) 105 | 106 | print(' ' * (toolbar_width), end='\r') 107 | bar = "[{}{}] {}/{}".format('-' * index, ' ' * (toolbar_width - index), image_index, total_images) 108 | print(bar.rjust(int(columns)), end='\r') 109 | 110 | def show_classes(classes): 111 | '''imag 112 | Show the downloaded classes in the selected folder during visualization mode 113 | ''' 114 | for n in classes: 115 | print("- {}".format(n)) 116 | print("\n") 117 | 118 | def logo(command): 119 | ''' 120 | Print the logo for the downloader and the visualizer when selected 121 | ''' 122 | bc = bcolors 123 | 124 | print(bc.OKGREEN + """ 125 | ___ _____ ______ _ _ 126 | .' `.|_ _||_ _ `. | | | | 127 | / .-. \ | | | | `. \ _ __ | |__| |_ 128 | | | | | | | | | | |[ \ [ ]|____ _| 129 | \ `-' /_| |_ _| |_.' / \ \/ / _| |_ 130 | `.___.'|_____||______.' \__/ |_____| 131 | """ + bc.ENDC) 132 | 133 | if command == 'downloader': 134 | print(bc.OKGREEN + ''' 135 | _____ _ _ 136 | (____ \ | | | | 137 | _ \ \ ___ _ _ _ ____ | | ___ ____ _ | | ____ ____ 138 | | | | / _ \| | | | _ \| |/ _ \ / _ |/ || |/ _ )/ ___) 139 | | |__/ / |_| | | | | | | | | |_| ( ( | ( (_| ( (/ /| | 140 | |_____/ \___/ \____|_| |_|_|\___/ \_||_|\____|\____)_| 141 | 142 | ''' + bc.ENDC) 143 | 144 | if command == 'visualizer': 145 | print(bc.OKGREEN + """ 146 | _ _ _ _ _ 147 | | | | (_) | (_) 148 | | | | |_ ___ _ _ ____| |_ _____ ____ ____ 149 | \ \/ /| |/___) | | |/ _ | | (___ ) _ )/ ___) 150 | \ / | |___ | |_| ( ( | | | |/ __( (/ /| | 151 | \/ |_(___/ \____|\_||_|_|_(_____)____)_| 152 | 153 | """ + bc.ENDC) 154 | 155 | if command == 'downloader_ill': 156 | print(bc.OKGREEN + ''' 157 | 158 | _____ _ _ _____ _ _ 159 | | __ \ | | | | |_ _| | | | 160 | | | | | _____ ___ __ | | ___ __ _ __| | ___ _ __ | | | | | | 161 | | | | |/ _ \ \ /\ / / '_ \| |/ _ \ / _` |/ _` |/ _ \ '__| | | | | | | 162 | | |__| | (_) \ V V /| | | | | (_) | (_| | (_| | __/ | _| |_| |____| |____ 163 | |_____/ \___/ \_/\_/ |_| |_|_|\___/ \__,_|\__,_|\___|_| |_____|______|______| 164 | 165 | 166 | ''' + bc.ENDC) 167 | 168 | class bcolors: 169 | HEADER = '\033[95m' 170 | 171 | INFO = ' [INFO] | ' 172 | OKBLUE = '\033[94m[DOWNLOAD] | ' 173 | WARNING = '\033[93m [WARN] | ' 174 | FAIL = '\033[91m [ERROR] | ' 175 | 176 | OKGREEN = '\033[92m' 177 | ENDC = '\033[0m' -------------------------------------------------------------------------------- /oid_to_pascal_voc_xml.py: -------------------------------------------------------------------------------- 1 | import os 2 | from tqdm import tqdm 3 | from sys import exit 4 | import argparse 5 | import cv2 6 | from textwrap import dedent 7 | from lxml import etree 8 | 9 | XML_DIR = '' 10 | 11 | #os.chdir('Dataset') 12 | os.chdir(os.path.join("OID", "Dataset")) 13 | DIRS = os.listdir(os.getcwd()) 14 | 15 | for DIR in DIRS: 16 | if os.path.isdir(DIR): 17 | os.chdir(DIR) 18 | 19 | print("Currently in Subdirectory:", DIR) 20 | CLASS_DIRS = os.listdir(os.getcwd()) 21 | for CLASS_DIR in CLASS_DIRS: 22 | if " " in CLASS_DIR: 23 | os.rename(CLASS_DIR, CLASS_DIR.replace(" ", "_")) 24 | 25 | CLASS_DIRS = os.listdir(os.getcwd()) 26 | for CLASS_DIR in CLASS_DIRS: 27 | #if " " in CLASS_DIR: 28 | # os.rename(CLASS_DIR, CLASS_DIR.replace(" ", "_")) 29 | if os.path.isdir(CLASS_DIR): 30 | os.chdir(CLASS_DIR) 31 | 32 | print("\n" + "Creating PASCAL VOC XML Files for Class:", CLASS_DIR) 33 | # Create Directory for annotations if it does not exist yet 34 | #if not os.path.exists(XML_DIR): 35 | # os.makedirs(XML_DIR) 36 | 37 | #Read Labels from OIDv4 ToolKit 38 | os.chdir("Label") 39 | 40 | #Create PASCAL XML 41 | for filename in tqdm(os.listdir(os.getcwd())): 42 | if filename.endswith(".txt"): 43 | filename_str = str.split(filename, ".")[0] 44 | 45 | 46 | annotation = etree.Element("annotation") 47 | 48 | os.chdir("..") 49 | folder = etree.Element("folder") 50 | folder.text = os.path.basename(os.getcwd()) 51 | annotation.append(folder) 52 | 53 | filename_xml = etree.Element("filename") 54 | filename_xml.text = filename_str + ".jpg" 55 | annotation.append(filename_xml) 56 | 57 | path = etree.Element("path") 58 | path.text = os.path.join(os.path.dirname(os.path.abspath(filename)), filename_str + ".jpg") 59 | annotation.append(path) 60 | 61 | source = etree.Element("source") 62 | annotation.append(source) 63 | 64 | database = etree.Element("database") 65 | database.text = "Unknown" 66 | source.append(database) 67 | 68 | size = etree.Element("size") 69 | annotation.append(size) 70 | 71 | width = etree.Element("width") 72 | height = etree.Element("height") 73 | depth = etree.Element("depth") 74 | 75 | img = cv2.imread(filename_xml.text) 76 | 77 | try: 78 | width.text = str(img.shape[1]) 79 | except AttributeError: 80 | #os.chdir("..") 81 | os.chdir("Label") 82 | continue 83 | height.text = str(img.shape[0]) 84 | depth.text = str(img.shape[2]) 85 | 86 | size.append(width) 87 | size.append(height) 88 | size.append(depth) 89 | 90 | segmented = etree.Element("segmented") 91 | segmented.text = "0" 92 | annotation.append(segmented) 93 | 94 | os.chdir("Label") 95 | label_original = open(filename, 'r') 96 | 97 | # Labels from OIDv4 Toolkit: name_of_class X_min Y_min X_max Y_max 98 | for line in label_original: 99 | line = line.strip() 100 | l = line.split(' ') 101 | 102 | class_name_len = len(l) - 4 # 4 coordinates 103 | class_name = l[0] 104 | for i in range(1,class_name_len): 105 | class_name = f"{class_name}_{l[i]}" 106 | 107 | addi = class_name_len 108 | 109 | xmin_l = str(int(round(float(l[0+addi])))) 110 | ymin_l = str(int(round(float(l[1+addi])))) 111 | xmax_l = str(int(round(float(l[2+addi])))) 112 | ymax_l = str(int(round(float(l[3+addi])))) 113 | 114 | obj = etree.Element("object") 115 | annotation.append(obj) 116 | 117 | name = etree.Element("name") 118 | name.text = class_name 119 | obj.append(name) 120 | 121 | pose = etree.Element("pose") 122 | pose.text = "Unspecified" 123 | obj.append(pose) 124 | 125 | truncated = etree.Element("truncated") 126 | truncated.text = "0" 127 | obj.append(truncated) 128 | 129 | difficult = etree.Element("difficult") 130 | difficult.text = "0" 131 | obj.append(difficult) 132 | 133 | bndbox = etree.Element("bndbox") 134 | obj.append(bndbox) 135 | 136 | xmin = etree.Element("xmin") 137 | xmin.text = xmin_l 138 | bndbox.append(xmin) 139 | 140 | ymin = etree.Element("ymin") 141 | ymin.text = ymin_l 142 | bndbox.append(ymin) 143 | 144 | xmax = etree.Element("xmax") 145 | xmax.text = xmax_l 146 | bndbox.append(xmax) 147 | 148 | ymax = etree.Element("ymax") 149 | ymax.text = ymax_l 150 | bndbox.append(ymax) 151 | 152 | os.chdir("..") 153 | 154 | #os.chdir(XML_DIR) 155 | 156 | # write xml to file 157 | s = etree.tostring(annotation, pretty_print=True) 158 | with open(filename_str + ".xml", 'wb') as f: 159 | f.write(s) 160 | f.close() 161 | 162 | #os.chdir("..") 163 | os.chdir("Label") 164 | 165 | os.chdir("..") 166 | os.chdir("..") 167 | 168 | os.chdir("..") 169 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pandas 2 | numpy 3 | awscli 4 | 5 | urllib3 6 | 7 | tqdm 8 | 9 | opencv-python -------------------------------------------------------------------------------- /voc_to_YOLOv3.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as ET 2 | from os import getcwd 3 | import os 4 | 5 | 6 | dataset_train = 'OID\\Dataset\\train\\' 7 | dataset_file = '4_CLASS_test.txt' 8 | classes_file = dataset_file[:-4]+'_classes.txt' 9 | 10 | 11 | CLS = os.listdir(dataset_train) 12 | classes =[dataset_train+CLASS for CLASS in CLS] 13 | wd = getcwd() 14 | 15 | 16 | def test(fullname): 17 | bb = "" 18 | in_file = open(fullname) 19 | tree=ET.parse(in_file) 20 | root = tree.getroot() 21 | for i, obj in enumerate(root.iter('object')): 22 | difficult = obj.find('difficult').text 23 | cls = obj.find('name').text 24 | if cls not in CLS or int(difficult)==1: 25 | continue 26 | cls_id = CLS.index(cls) 27 | xmlbox = obj.find('bndbox') 28 | b = (int(xmlbox.find('xmin').text), int(xmlbox.find('ymin').text), int(xmlbox.find('xmax').text), int(xmlbox.find('ymax').text)) 29 | bb += (" " + ",".join([str(a) for a in b]) + ',' + str(cls_id)) 30 | 31 | # we need this because I don't know overlapping or something like that 32 | if cls == 'Traffic_light': 33 | list_file = open(dataset_file, 'a') 34 | file_string = str(fullname)[:-4]+'.jpg'+bb+'\n' 35 | list_file.write(file_string) 36 | list_file.close() 37 | bb = "" 38 | 39 | if bb != "": 40 | list_file = open(dataset_file, 'a') 41 | file_string = str(fullname)[:-4]+'.jpg'+bb+'\n' 42 | list_file.write(file_string) 43 | list_file.close() 44 | 45 | 46 | 47 | for CLASS in classes: 48 | for filename in os.listdir(CLASS): 49 | if not filename.endswith('.xml'): 50 | continue 51 | fullname = os.getcwd()+'\\'+CLASS+'\\'+filename 52 | test(fullname) 53 | 54 | for CLASS in CLS: 55 | list_file = open(classes_file, 'a') 56 | file_string = str(CLASS)+"\n" 57 | list_file.write(file_string) 58 | list_file.close() 59 | --------------------------------------------------------------------------------