diff --git a/vehicle-detection/darkflow/.gitignore b/vehicle-detection/darkflow/.gitignore
new file mode 100644
index 0000000..c93215c
--- /dev/null
+++ b/vehicle-detection/darkflow/.gitignore
@@ -0,0 +1,21 @@
+
+# Python bytecode
+*.pyc
+
+# Weight files
+bin/
+
+# Test data
+test/*.jpg
+
+# Annotated test results
+results/
+
+# Intermediate training data
+backup/
+tfnet/yolo/parse-history.txt
+tfnet/yolo/*.parsed
+*.txt
+*.pb
+/profile
+/test.py
diff --git a/vehicle-detection/darkflow/LICENSE b/vehicle-detection/darkflow/LICENSE
new file mode 100644
index 0000000..9cecc1d
--- /dev/null
+++ b/vehicle-detection/darkflow/LICENSE
@@ -0,0 +1,674 @@
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+ Preamble
+
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
+
+ When we speak of free software, we are referring to freedom, not
+price. Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
+
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
+
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
+
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
+
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
+
+ The precise terms and conditions for copying, distribution and
+modification follow.
+
+ TERMS AND CONDITIONS
+
+ 0. Definitions.
+
+ "This License" refers to version 3 of the GNU General Public License.
+
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
+
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
+
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
+
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
+
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
+
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
+
+ 1. Source Code.
+
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
+
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
+
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
+
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
+
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
+
+ The Corresponding Source for a work in source code form is that
+same work.
+
+ 2. Basic Permissions.
+
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
+this License.
+
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
+
+ 13. Use with the GNU Affero General Public License.
+
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
+
+ 14. Revised Versions of this License.
+
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
+
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
+
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
+
+ 15. Disclaimer of Warranty.
+
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
+
+ END OF TERMS AND CONDITIONS
+
+ How to Apply These Terms to Your New Programs
+
+ If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+ To do so, attach the following notices to the program. It is safest
+to attach them to the start of each source file to most effectively
+state the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+ {one line to give the program's name and a brief idea of what it does.}
+ Copyright (C) {year} {name of author}
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
+
+Also add information on how to contact you by electronic and paper mail.
+
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ {project} Copyright (C) {year} {fullname}
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
+
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
diff --git a/vehicle-detection/darkflow/README.md b/vehicle-detection/darkflow/README.md
new file mode 100644
index 0000000..bc00945
--- /dev/null
+++ b/vehicle-detection/darkflow/README.md
@@ -0,0 +1,144 @@
+
+
+This package is originally implmented by @[thtrieu](https://github.com/thtrieu). The original yolo models are trained against the annotated Udacity SDC datasets, and is now capable of detecting cars, pedestrians and traffic lights. The performance is not perfect, but it does run at real-time on a GTX1070. Looking forward to more improvements from the Udacity community.
+
+## Dependencies
+
+Python3, tensorflow 0.12, numpy, opencv 3.
+
+## Update
+
+@[Ryansun](https://github.com/ryansun1900) contributed the **training part of YOLO9000**. The project is now completed :)
+
+Someone's quick and
+**Android demo is available on Tensorflow's official github!** [here](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/TensorFlowYoloDetector.java)
+
+**Demo in webcam is available!**. Use option `--demo camera` :)
+
+YOLOv1 is up and running:
+- v1.0: `yolo-full` 1.1GB, `yolo-small` 376MB, `yolo-tiny` 180MB
+- v1.1: `yolov1` 789MB, `tiny-yolo` 108MB, `tiny-coco` 268MB, `yolo-coco` 937MB
+
+YOLO9000 is up and running:
+- `yolo` 270MB, `tiny-yolo-voc` 63 MB.
+
+### Parsing the annotations
+
+Skip this if you are not training or fine-tuning anything (you simply want to forward flow a trained net)
+
+For example, if you want to work with only 3 classes `tvmonitor`, `person`, `pottedplant`; edit `labels.txt` as follows
+
+```
+tvmonitor
+person
+pottedplant
+```
+
+And that's it. `darkflow` will take care of the rest.
+
+### Design the net
+
+Skip this if you are working with one of the three original configurations since they are already there. Otherwise, see the following example:
+
+```python
+...
+
+[convolutional]
+batch_normalize = 1
+size = 3
+stride = 1
+pad = 1
+activation = leaky
+
+[maxpool]
+
+[connected]
+output = 4096
+activation = linear
+
+...
+```
+
+### Flowing the graph using `flow`
+
+```bash
+# Have a look at its options
+./flow --h
+```
+
+First, let's take a closer look at one of a very useful option `--load`
+
+```bash
+# 1. Load yolo-tiny.weights
+./flow --model cfg/yolo-tiny.cfg --load bin/yolo-tiny.weights
+
+# 2. To completely initialize a model, leave the --load option
+./flow --model cfg/yolo-3c.cfg
+
+# 3. It is useful to reuse the first identical layers of tiny for 3c
+./flow --model cfg/yolo-3c.cfg --load bin/yolo-tiny.weights
+# this will print out which layers are reused, which are initialized
+```
+
+All input images from default folder `test/` are flowed through the net and predictions are put in `test/out/`. We can always specify more parameters for such forward passes, such as detection threshold, batch size, test folder, etc.
+
+```bash
+# Forward all images in test/ using tiny yolo and 100% GPU usage
+./flow --test test/ --model cfg/yolo-tiny.cfg --load bin/yolo-tiny.weights --gpu 1.0
+```
+
+### Training new model
+
+Training is simple as you only have to add option `--train` like below:
+
+```bash
+# Initialize yolo-3c from yolo-tiny, then train the net on 100% GPU:
+./flow --model cfg/yolo-3c.cfg --load bin/yolo-tiny.weights --train --gpu 1.0
+
+# Completely initialize yolo-3c and train it with ADAM optimizer
+./flow --model cfg/yolo-3c.cfg --train --trainer adam
+```
+
+During training, the script will occasionally save intermediate results into Tensorflow checkpoints, stored in `ckpt/`. To resume to any checkpoint before performing training/testing, use `--load [checkpoint_num]` option, if `checkpoint_num < 0`, `darkflow` will load the most recent save by parsing `ckpt/checkpoint`.
+
+```bash
+# Resume the most recent checkpoint for training
+./flow --train --model cfg/yolo-3c.cfg --load -1
+
+# Test with checkpoint at step 1500
+./flow --model cfg/yolo-3c.cfg --load 1500
+
+# Fine tuning yolo-tiny from the original one
+./flow --train --model cfg/yolo-tiny.cfg --load bin/yolo-tiny.weights
+```
+
+### Training against Udacity Self Driving Datasets
+
+Udacity Self Driving Car course have provided an annotated dataset of images that contains bounding boxes for five classes of objects: cars, pedestrians, truck, cyclists and traffic lights.
+
+A model cfg based on v1.1/tiny-yolo is provided for the udacity dataset in cfg/v1.1/tiny-yolov1-5c.cfg, with a TensorFlow checkpoint [here](https://drive.google.com/file/d/0B2K7eATT8qRARVVvcGtQUzRBV1E/view?usp=sharing). A v2 tiny-yolo configuration for the udacity dataset could be found under cfg/tiny-yolo-udacity.cfg, with checkpoint [here](https://drive.google.com/file/d/0B2K7eATT8qRAY0g0aWhjdkw0bEU/view?usp=sharing)
+
+To train tiny-yolov1.weights from for the udacity dataset, the following step was taken: 1. Download udacity dataset [here](http://bit.ly/udacity-annotations-autti) and download the following [annotation file](https://drive.google.com/file/d/0B2K7eATT8qRAZHlsdTVCNWVLVnM/view?usp=sharing).
+
+Create a small dataset with 3-5 images, and train via:
+```
+python3 flow --train --model cfg/v1.1/tiny-yolov1-5c.cfg --load tiny-yolov1.weights --dataset --gpu 1.0
+```
+
+Reduce the learning rate in the cfg file, and continue training.
+```
+python3 flow --train --model cfg/v1.1/tiny-yolov1-5c.cfg --load -1 --dataset --gpu 1.0
+```
+
+In general, above is a guideline to train against other datasets with different classes.
+
+### Migrating the graph to mobile devices (JAVA / C++ / Objective-C++)
+
+```bash
+## Saving the lastest checkpoint to protobuf file
+./flow --model cfg/yolo-3c.cfg --load -1 --savepb
+```
+
+For further usage of this protobuf file, please refer to the official documentation of `Tensorflow` on C++ API [_here_](https://www.tensorflow.org/versions/r0.9/api_docs/cc/index.html). To run it on, say, iOS application, simply add the file to Bundle Resources and update the path to this file inside source code.
+
+That's all.
diff --git a/vehicle-detection/darkflow/cars.jpg b/vehicle-detection/darkflow/cars.jpg
new file mode 100644
index 0000000..e0e080f
Binary files /dev/null and b/vehicle-detection/darkflow/cars.jpg differ
diff --git a/vehicle-detection/darkflow/cfg/__init__.py b/vehicle-detection/darkflow/cfg/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/vehicle-detection/darkflow/cfg/coco.names b/vehicle-detection/darkflow/cfg/coco.names
new file mode 100644
index 0000000..ca76c80
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/coco.names
@@ -0,0 +1,80 @@
+person
+bicycle
+car
+motorbike
+aeroplane
+bus
+train
+truck
+boat
+traffic light
+fire hydrant
+stop sign
+parking meter
+bench
+bird
+cat
+dog
+horse
+sheep
+cow
+elephant
+bear
+zebra
+giraffe
+backpack
+umbrella
+handbag
+tie
+suitcase
+frisbee
+skis
+snowboard
+sports ball
+kite
+baseball bat
+baseball glove
+skateboard
+surfboard
+tennis racket
+bottle
+wine glass
+cup
+fork
+knife
+spoon
+bowl
+banana
+apple
+sandwich
+orange
+broccoli
+carrot
+hot dog
+pizza
+donut
+cake
+chair
+sofa
+pottedplant
+bed
+diningtable
+toilet
+tvmonitor
+laptop
+mouse
+remote
+keyboard
+cell phone
+microwave
+oven
+toaster
+sink
+refrigerator
+book
+clock
+vase
+scissors
+teddy bear
+hair drier
+toothbrush
diff --git a/vehicle-detection/darkflow/cfg/extraction.cfg b/vehicle-detection/darkflow/cfg/extraction.cfg
new file mode 100644
index 0000000..94e1067
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/extraction.cfg
@@ -0,0 +1,206 @@
+[net]
+batch=128
+subdivisions=1
+height=224
+width=224
+max_crop=320
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.1
+policy=poly
+power=4
+max_batches=1600000
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=7
+stride=2
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=192
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1000
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[avgpool]
+
+[softmax]
+groups=1
+
+[cost]
+type=sse
+
diff --git a/vehicle-detection/darkflow/cfg/extraction.conv.cfg b/vehicle-detection/darkflow/cfg/extraction.conv.cfg
new file mode 100644
index 0000000..2a7d09e
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/extraction.conv.cfg
@@ -0,0 +1,179 @@
+[net]
+batch=1
+subdivisions=1
+height=256
+width=256
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.5
+policy=poly
+power=6
+max_batches=500000
+
+[convolutional]
+filters=64
+size=7
+stride=2
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=192
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[avgpool]
+
+[connected]
+output=1000
+activation=leaky
+
+[softmax]
+groups=1
+
diff --git a/vehicle-detection/darkflow/cfg/process.py b/vehicle-detection/darkflow/cfg/process.py
new file mode 100644
index 0000000..d989629
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/process.py
@@ -0,0 +1,318 @@
+"""
+WARNING: spaghetti code.
+"""
+
+import numpy as np
+import pickle
+import os
+
+def parser(model):
+ """
+ Read the .cfg file to extract layers into `layers`
+ as well as model-specific parameters into `meta`
+ """
+ def _parse(l, i = 1):
+ return l.split('=')[i].strip()
+
+ with open(model, 'rb') as f:
+ lines = f.readlines()
+
+ lines = [line.decode() for line in lines]
+
+ meta = dict(); layers = list() # will contains layers' info
+ h, w, c = [int()] * 3; layer = dict()
+ for line in lines:
+ line = line.strip()
+ line = line.split('#')[0]
+ if '[' in line:
+ if layer != dict():
+ if layer['type'] == '[net]':
+ h = layer['height']
+ w = layer['width']
+ c = layer['channels']
+ meta['net'] = layer
+ else:
+ if layer['type'] == '[crop]':
+ h = layer['crop_height']
+ w = layer['crop_width']
+ layers += [layer]
+ layer = {'type': line}
+ else:
+ try:
+ i = float(_parse(line))
+ if i == int(i): i = int(i)
+ layer[line.split('=')[0].strip()] = i
+ except:
+ try:
+ key = _parse(line, 0)
+ val = _parse(line, 1)
+ layer[key] = val
+ except:
+ 'banana ninja yadayada'
+
+ meta.update(layer) # last layer contains meta info
+ if 'anchors' in meta:
+ splits = meta['anchors'].split(',')
+ anchors = [float(x.strip()) for x in splits]
+ meta['anchors'] = anchors
+ meta['model'] = model # path to cfg, not model name
+ meta['inp_size'] = [h, w, c]
+ return layers, meta
+
+def cfg_yielder(model, binary):
+ """
+ yielding each layer information to initialize `layer`
+ """
+ layers, meta = parser(model); yield meta;
+ h, w, c = meta['inp_size']; l = w * h * c
+
+ # Start yielding
+ flat = False # flag for 1st dense layer
+ conv = '.conv.' in model
+ for i, d in enumerate(layers):
+ #-----------------------------------------------------
+ if d['type'] == '[crop]':
+ yield ['crop', i]
+ #-----------------------------------------------------
+ elif d['type'] == '[local]':
+ n = d.get('filters', 1)
+ size = d.get('size', 1)
+ stride = d.get('stride', 1)
+ pad = d.get('pad', 0)
+ activation = d.get('activation', 'logistic')
+ w_ = (w - 1 - (1 - pad) * (size - 1)) // stride + 1
+ h_ = (h - 1 - (1 - pad) * (size - 1)) // stride + 1
+ yield ['local', i, size, c, n, stride,
+ pad, w_, h_, activation]
+ if activation != 'linear': yield [activation, i]
+ w, h, c = w_, h_, n
+ l = w * h * c
+ #-----------------------------------------------------
+ elif d['type'] == '[convolutional]':
+ n = d.get('filters', 1)
+ size = d.get('size', 1)
+ stride = d.get('stride', 1)
+ pad = d.get('pad', 0)
+ padding = d.get('padding', 0)
+ if pad: padding = size // 2
+ activation = d.get('activation', 'logistic')
+ batch_norm = d.get('batch_normalize', 0) or conv
+ yield ['convolutional', i, size, c, n,
+ stride, padding, batch_norm,
+ activation]
+ if activation != 'linear': yield [activation, i]
+ w_ = (w + 2 * padding - size) // stride + 1
+ h_ = (h + 2 * padding - size) // stride + 1
+ w, h, c = w_, h_, n
+ l = w * h * c
+ #-----------------------------------------------------
+ elif d['type'] == '[maxpool]':
+ stride = d.get('stride', 1)
+ size = d.get('size', stride)
+ padding = d.get('padding', (size-1) // 2)
+ yield ['maxpool', i, size, stride, padding]
+ w_ = (w + 2*padding) // d['stride']
+ h_ = (h + 2*padding) // d['stride']
+ w, h = w_, h_
+ l = w * h * c
+ #-----------------------------------------------------
+ elif d['type'] == '[avgpool]':
+ flat = True; l = c
+ yield ['avgpool', i]
+ #-----------------------------------------------------
+ elif d['type'] == '[softmax]':
+ yield ['softmax', i, d['groups']]
+ #-----------------------------------------------------
+ elif d['type'] == '[connected]':
+ if not flat:
+ yield ['flatten', i]
+ flat = True
+ activation = d.get('activation', 'logistic')
+ yield ['connected', i, l, d['output'], activation]
+ if activation != 'linear': yield [activation, i]
+ l = d['output']
+ #-----------------------------------------------------
+ elif d['type'] == '[dropout]':
+ yield ['dropout', i, d['probability']]
+ #-----------------------------------------------------
+ elif d['type'] == '[select]':
+ if not flat:
+ yield ['flatten', i]
+ flat = True
+ inp = d.get('input', None)
+ if type(inp) is str:
+ file = inp.split(',')[0]
+ layer_num = int(inp.split(',')[1])
+ with open(file, 'rb') as f:
+ profiles = pickle.load(f, encoding = 'latin1')[0]
+ layer = profiles[layer_num]
+ else: layer = inp
+ activation = d.get('activation', 'logistic')
+ d['keep'] = d['keep'].split('/')
+ classes = int(d['keep'][-1])
+ keep = [int(c) for c in d['keep'][0].split(',')]
+ keep_n = len(keep)
+ train_from = classes * d['bins']
+ for count in range(d['bins']-1):
+ for num in keep[-keep_n:]:
+ keep += [num + classes]
+ k = 1
+ while layers[i-k]['type'] not in ['[connected]', '[extract]']:
+ k += 1
+ if i-k < 0:
+ break
+ if i-k < 0: l_ = l
+ elif layers[i-k]['type'] == 'connected':
+ l_ = layers[i-k]['output']
+ else:
+ l_ = layers[i-k].get('old',[l])[-1]
+ yield ['select', i, l_, d['old_output'],
+ activation, layer, d['output'],
+ keep, train_from]
+ if activation != 'linear': yield [activation, i]
+ l = d['output']
+ #-----------------------------------------------------
+ elif d['type'] == '[conv-select]':
+ n = d.get('filters', 1)
+ size = d.get('size', 1)
+ stride = d.get('stride', 1)
+ pad = d.get('pad', 0)
+ padding = d.get('padding', 0)
+ if pad: padding = size // 2
+ activation = d.get('activation', 'logistic')
+ batch_norm = d.get('batch_normalize', 0) or conv
+ d['keep'] = d['keep'].split('/')
+ classes = int(d['keep'][-1])
+ keep = [int(x) for x in d['keep'][0].split(',')]
+
+ segment = classes + 5
+ assert n % segment == 0, \
+ 'conv-select: segment failed'
+ bins = n // segment
+ keep_idx = list()
+ for j in range(bins):
+ offset = j * segment
+ for k in range(5):
+ keep_idx += [offset + k]
+ for k in keep:
+ keep_idx += [offset + 5 + k]
+ w_ = (w + 2 * padding - size) // stride + 1
+ h_ = (h + 2 * padding - size) // stride + 1
+ c_ = len(keep_idx)
+ yield ['conv-select', i, size, c, n,
+ stride, padding, batch_norm,
+ activation, keep_idx, c_]
+ w, h, c = w_, h_, c_
+ l = w * h * c
+ #-----------------------------------------------------
+ elif d['type'] == '[conv-extract]':
+ file = d['profile']
+ with open(file, 'rb') as f:
+ profiles = pickle.load(f, encoding = 'latin1')[0]
+ inp_layer = None
+ inp = d['input']
+ out = d['output']
+ inp_layer = None
+ if inp >= 0:
+ inp_layer = profiles[inp]
+ if inp_layer is not None:
+ assert len(inp_layer) == c, \
+ 'Conv-extract does not match input dimension'
+ out_layer = profiles[out]
+
+ n = d.get('filters', 1)
+ size = d.get('size', 1)
+ stride = d.get('stride', 1)
+ pad = d.get('pad', 0)
+ padding = d.get('padding', 0)
+ if pad: padding = size // 2
+ activation = d.get('activation', 'logistic')
+ batch_norm = d.get('batch_normalize', 0) or conv
+
+ k = 1
+ find = ['[convolutional]','[conv-extract]']
+ while layers[i-k]['type'] not in find:
+ k += 1
+ if i-k < 0: break
+ if i-k >= 0:
+ previous_layer = layers[i-k]
+ c_ = previous_layer['filters']
+ else:
+ c_ = c
+
+ yield ['conv-extract', i, size, c_, n,
+ stride, padding, batch_norm,
+ activation, inp_layer, out_layer]
+ if activation != 'linear': yield [activation, i]
+ w_ = (w + 2 * padding - size) // stride + 1
+ h_ = (h + 2 * padding - size) // stride + 1
+ w, h, c = w_, h_, len(out_layer)
+ l = w * h * c
+ #-----------------------------------------------------
+ elif d['type'] == '[extract]':
+ if not flat:
+ yield['flatten', i]
+ flat = True
+ activation = d.get('activation', 'logistic')
+ file = d['profile']
+ with open(file, 'rb') as f:
+ profiles = pickle.load(f, encoding = 'latin1')[0]
+ inp_layer = None
+ inp = d['input']
+ out = d['output']
+ if inp >= 0:
+ inp_layer = profiles[inp]
+ out_layer = profiles[out]
+ old = d['old']
+ old = [int(x) for x in old.split(',')]
+ if inp_layer is not None:
+ if len(old) > 2:
+ h_, w_, c_, n_ = old
+ new_inp = list()
+ for p in range(c_):
+ for q in range(h_):
+ for r in range(w_):
+ if p not in inp_layer:
+ continue
+ new_inp += [r + w*(q + h*p)]
+ inp_layer = new_inp
+ old = [h_ * w_ * c_, n_]
+ assert len(inp_layer) == l, \
+ 'Extract does not match input dimension'
+ d['old'] = old
+ yield ['extract', i] + old + [activation] + [inp_layer, out_layer]
+ if activation != 'linear': yield [activation, i]
+ l = len(out_layer)
+ #-----------------------------------------------------
+ elif d['type'] == '[route]': # add new layer here
+ routes = d['layers']
+ if type(routes) is str:
+ routes = [int(x.strip()) for x in routes.split(',')]
+ else: routes = [routes]
+ routes = [i + x if x < 0 else x for x in routes]
+ for j, x in enumerate(routes):
+ lx = layers[x]; xtype = lx['type']
+ _size = lx['_size'][:3]
+ if not j: w, h, c = _size
+ else:
+ w_, h_, c_ = _size
+ assert w_ == w and h_ == h, \
+ 'Routing incompatible conv sizes'
+ c += c_
+ yield ['route', i, routes]
+ l = w * h * c
+ #-----------------------------------------------------
+ elif d['type'] == '[reorg]':
+ stride = d.get('stride', 1)
+ yield ['reorg', i, stride]
+ w = w // stride; h = h // stride;
+ c = c * (stride ** 2)
+ l = w * h * c
+ #-----------------------------------------------------
+ else:
+ exit('Layer {} not implemented'.format(d['type']))
+
+ d['_size'] = list([h, w, c, l, flat])
+
+ if not flat: meta['out_size'] = [h, w, c]
+ else: meta['out_size'] = l
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/tiny-yolo-4c.cfg b/vehicle-detection/darkflow/cfg/tiny-yolo-4c.cfg
new file mode 100644
index 0000000..37c5ba0
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/tiny-yolo-4c.cfg
@@ -0,0 +1,135 @@
+[net]
+batch=64
+subdivisions=8
+width=416
+height=416
+channels=3
+momentum=0.9
+decay=0.0005
+angle=0
+saturation = 1.5
+exposure = 1.5
+hue=.1
+
+learning_rate=0.001
+max_batches = 40100
+policy=steps
+steps=-1,100,20000,30000
+scales=.1,10,.1,.1
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=1
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+###########
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[conv-select]
+size=1
+stride=1
+pad=1
+filters=125
+keep=8,14,15,19/20
+activation=linear
+
+[region]
+anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52
+bias_match=1
+classes=4
+coords=4
+num=5
+softmax=1
+jitter=.2
+rescore=1
+
+object_scale=5
+noobject_scale=1
+class_scale=1
+coord_scale=1
+
+absolute=1
+thresh=.6
+random=1
diff --git a/vehicle-detection/darkflow/cfg/tiny-yolo-5c.cfg b/vehicle-detection/darkflow/cfg/tiny-yolo-5c.cfg
new file mode 100644
index 0000000..2ba277e
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/tiny-yolo-5c.cfg
@@ -0,0 +1,126 @@
+[net]
+batch=64
+subdivisions=2
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+saturation=.75
+exposure=.75
+hue = .1
+
+learning_rate=0.00005
+policy=steps
+steps=200,400,600,800,20000,30000
+scales=2.5,2,2,2,.1,.1
+max_batches = 40000
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=256
+activation=leaky
+
+[connected]
+output= 735
+activation=linear
+
+[detection]
+classes=5
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
+
diff --git a/vehicle-detection/darkflow/cfg/tiny-yolo-udacity.cfg b/vehicle-detection/darkflow/cfg/tiny-yolo-udacity.cfg
new file mode 100644
index 0000000..2f19803
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/tiny-yolo-udacity.cfg
@@ -0,0 +1,134 @@
+[net]
+batch=64
+subdivisions=8
+width=416
+height=416
+channels=3
+momentum=0.9
+decay=0.0005
+angle=0
+saturation = 1.5
+exposure = 1.5
+hue=.1
+
+learning_rate=0.0005
+max_batches = 40100
+policy=steps
+steps=-1,100,20000,30000
+scales=.1,10,.1,.1
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=1
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+###########
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=1
+stride=1
+pad=1
+filters=50
+activation=linear
+
+[region]
+anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52
+bias_match=1
+classes=5
+coords=4
+num=5
+softmax=1
+jitter=.2
+rescore=1
+
+object_scale=5
+noobject_scale=1
+class_scale=1
+coord_scale=1
+
+absolute=1
+thresh = .5
+random=1
diff --git a/vehicle-detection/darkflow/cfg/tiny-yolo-voc.cfg b/vehicle-detection/darkflow/cfg/tiny-yolo-voc.cfg
new file mode 100644
index 0000000..032b747
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/tiny-yolo-voc.cfg
@@ -0,0 +1,134 @@
+[net]
+batch=64
+subdivisions=8
+width=416
+height=416
+channels=3
+momentum=0.9
+decay=0.0005
+angle=0
+saturation = 1.5
+exposure = 1.5
+hue=.1
+
+learning_rate=0.001
+max_batches = 40100
+policy=steps
+steps=-1,100,20000,30000
+scales=.1,10,.1,.1
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=1
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+###########
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=1
+stride=1
+pad=1
+filters=125
+activation=linear
+
+[region]
+anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52
+bias_match=1
+classes=20
+coords=4
+num=5
+softmax=1
+jitter=.2
+rescore=1
+
+object_scale=5
+noobject_scale=1
+class_scale=1
+coord_scale=1
+
+absolute=1
+thresh = .5
+random=1
diff --git a/vehicle-detection/darkflow/cfg/tiny-yolo.cfg b/vehicle-detection/darkflow/cfg/tiny-yolo.cfg
new file mode 100644
index 0000000..5580098
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/tiny-yolo.cfg
@@ -0,0 +1,134 @@
+[net]
+batch=64
+subdivisions=8
+width=416
+height=416
+channels=3
+momentum=0.9
+decay=0.0005
+angle=0
+saturation = 1.5
+exposure = 1.5
+hue=.1
+
+learning_rate=0.001
+max_batches = 120000
+policy=steps
+steps=-1,100,80000,100000
+scales=.1,10,.1,.1
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=1
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+###########
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=1
+stride=1
+pad=1
+filters=425
+activation=linear
+
+[region]
+anchors = 0.738768,0.874946, 2.42204,2.65704, 4.30971,7.04493, 10.246,4.59428, 12.6868,11.8741
+bias_match=1
+classes=80
+coords=4
+num=5
+softmax=1
+jitter=.2
+rescore=1
+
+object_scale=5
+noobject_scale=1
+class_scale=1
+coord_scale=1
+
+absolute=1
+thresh = .6
+random=1
diff --git a/vehicle-detection/darkflow/cfg/v1.1/person-bottle.cfg b/vehicle-detection/darkflow/cfg/v1.1/person-bottle.cfg
new file mode 100644
index 0000000..e5c0a25
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1.1/person-bottle.cfg
@@ -0,0 +1,128 @@
+[net]
+batch=64
+subdivisions=2
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+saturation=.75
+exposure=.75
+hue = .1
+
+learning_rate=0.0005
+policy=steps
+steps=200,400,600,800,20000,30000
+scales=2.5,2,2,2,.1,.1
+max_batches = 40000
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=256
+activation=leaky
+
+[select]
+old_output=1470
+keep=4,14/20
+bins=49
+output=588
+activation=linear
+
+[detection]
+classes=2
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1.1/tiny-coco.cfg b/vehicle-detection/darkflow/cfg/v1.1/tiny-coco.cfg
new file mode 100644
index 0000000..e58c73a
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1.1/tiny-coco.cfg
@@ -0,0 +1,125 @@
+[net]
+batch=64
+subdivisions=2
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+hue = .1
+saturation=.75
+exposure=.75
+
+learning_rate=0.0005
+policy=steps
+steps=200,400,600,800,100000,150000
+scales=2.5,2,2,2,.1,.1
+max_batches = 200000
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=256
+activation=leaky
+
+[connected]
+output= 4655
+activation=linear
+
+[detection]
+classes=80
+coords=4
+rescore=1
+side=7
+num=3
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
diff --git a/vehicle-detection/darkflow/cfg/v1.1/tiny-yolo-4c.cfg b/vehicle-detection/darkflow/cfg/v1.1/tiny-yolo-4c.cfg
new file mode 100644
index 0000000..22d862e
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1.1/tiny-yolo-4c.cfg
@@ -0,0 +1,128 @@
+[net]
+batch=64
+subdivisions=2
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+saturation=.75
+exposure=.75
+hue = .1
+
+learning_rate=0.0005
+policy=steps
+steps=200,400,600,800,20000,30000
+scales=2.5,2,2,2,.1,.1
+max_batches = 40000
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=256
+activation=leaky
+
+[select]
+old_output=1470
+keep=8,14,15,19/20
+bins=49
+output=686
+activation=linear
+
+[detection]
+classes=4
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1.1/tiny-yolov1-5c.cfg b/vehicle-detection/darkflow/cfg/v1.1/tiny-yolov1-5c.cfg
new file mode 100644
index 0000000..2ba277e
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1.1/tiny-yolov1-5c.cfg
@@ -0,0 +1,126 @@
+[net]
+batch=64
+subdivisions=2
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+saturation=.75
+exposure=.75
+hue = .1
+
+learning_rate=0.00005
+policy=steps
+steps=200,400,600,800,20000,30000
+scales=2.5,2,2,2,.1,.1
+max_batches = 40000
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=256
+activation=leaky
+
+[connected]
+output= 735
+activation=linear
+
+[detection]
+classes=5
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
+
diff --git a/vehicle-detection/darkflow/cfg/v1.1/tiny-yolov1.cfg b/vehicle-detection/darkflow/cfg/v1.1/tiny-yolov1.cfg
new file mode 100644
index 0000000..ac4b346
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1.1/tiny-yolov1.cfg
@@ -0,0 +1,126 @@
+[net]
+batch=64
+subdivisions=2
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+saturation=.75
+exposure=.75
+hue = .1
+
+learning_rate=0.0005
+policy=steps
+steps=200,400,600,800,20000,30000
+scales=2.5,2,2,2,.1,.1
+max_batches = 40000
+
+[convolutional]
+batch_normalize=1
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=256
+activation=leaky
+
+[connected]
+output= 1470
+activation=linear
+
+[detection]
+classes=20
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
+
diff --git a/vehicle-detection/darkflow/cfg/v1.1/yolo-coco.cfg b/vehicle-detection/darkflow/cfg/v1.1/yolo-coco.cfg
new file mode 100644
index 0000000..ed3f2d6
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1.1/yolo-coco.cfg
@@ -0,0 +1,255 @@
+[net]
+batch=64
+subdivisions=4
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+hue = .1
+saturation=.75
+exposure=.75
+
+learning_rate=0.0005
+policy=steps
+steps=200,400,600,800,100000,150000
+scales=2.5,2,2,2,.1,.1
+max_batches = 200000
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=7
+stride=2
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=192
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+#######
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=2
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[local]
+size=3
+stride=1
+pad=1
+filters=256
+activation=leaky
+
+[connected]
+output= 4655
+activation=linear
+
+[detection]
+classes=80
+coords=4
+rescore=1
+side=7
+num=3
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
+
diff --git a/vehicle-detection/darkflow/cfg/v1.1/yolov1.cfg b/vehicle-detection/darkflow/cfg/v1.1/yolov1.cfg
new file mode 100644
index 0000000..c4f415c
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1.1/yolov1.cfg
@@ -0,0 +1,257 @@
+[net]
+batch=1
+subdivisions=1
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+saturation=1.5
+exposure=1.5
+hue=.1
+
+learning_rate=0.0005
+policy=steps
+steps=200,400,600,20000,30000
+scales=2.5,2,2,.1,.1
+max_batches = 40000
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=7
+stride=2
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=192
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+#######
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=2
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[local]
+size=3
+stride=1
+pad=1
+filters=256
+activation=leaky
+
+[dropout]
+probability=.5
+
+[connected]
+output= 1715
+activation=linear
+
+[detection]
+classes=20
+coords=4
+rescore=1
+side=7
+num=3
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
+
diff --git a/vehicle-detection/darkflow/cfg/v1/tiny-old.profile b/vehicle-detection/darkflow/cfg/v1/tiny-old.profile
new file mode 100644
index 0000000..0799061
Binary files /dev/null and b/vehicle-detection/darkflow/cfg/v1/tiny-old.profile differ
diff --git a/vehicle-detection/darkflow/cfg/v1/tiny.profile b/vehicle-detection/darkflow/cfg/v1/tiny.profile
new file mode 100644
index 0000000..e6635ae
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/tiny.profile
@@ -0,0 +1 @@
+€]q]qa.
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1/yolo-2c.cfg b/vehicle-detection/darkflow/cfg/v1/yolo-2c.cfg
new file mode 100644
index 0000000..bde5bce
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/yolo-2c.cfg
@@ -0,0 +1,141 @@
+[net]
+batch=64
+subdivisions=64
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.0001
+policy=steps
+steps=20,40,60,80,20000,30000
+scales=5,5,2,2,.1,.1
+max_batches = 40000
+
+[crop]
+crop_width=448
+crop_height=448
+flip=0
+angle=0
+saturation = 1.5
+exposure = 1.5
+
+[convolutional]
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[connected]
+output=256
+activation=linear
+
+[connected]
+output=4096
+activation=leaky
+
+[dropout]
+probability=.5
+
+[select]
+old_output=1470
+keep=14,19/20
+bins=49
+output=588
+activation=linear
+
+[detection]
+classes=2
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1/yolo-4c.cfg b/vehicle-detection/darkflow/cfg/v1/yolo-4c.cfg
new file mode 100644
index 0000000..ecf46d2
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/yolo-4c.cfg
@@ -0,0 +1,237 @@
+[net]
+batch=64
+subdivisions=64
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.001
+policy=steps
+steps=200,400,600,20000,30000
+scales=2.5,2,2,.1,.1
+max_batches = 40000
+
+[crop]
+crop_width=448
+crop_height=448
+flip=0
+angle=0
+saturation = 1.5
+exposure = 1.5
+
+[convolutional]
+filters=64
+size=7
+stride=2
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=192
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+#######
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=2
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[connected]
+output=4096
+activation=leaky
+
+[dropout]
+probability=.5
+
+[select]
+old_output=1470
+keep=8,14,15,19/20
+bins=49
+output=686
+activation=linear
+
+[detection]
+classes=4
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1/yolo-full.cfg b/vehicle-detection/darkflow/cfg/v1/yolo-full.cfg
new file mode 100644
index 0000000..9eb08d9
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/yolo-full.cfg
@@ -0,0 +1,234 @@
+[net]
+batch=64
+subdivisions=64
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.001
+policy=steps
+steps=200,400,600,20000,30000
+scales=2.5,2,2,.1,.1
+max_batches = 40000
+
+[crop]
+crop_width=448
+crop_height=448
+flip=0
+angle=0
+saturation = 1.5
+exposure = 1.5
+
+[convolutional]
+filters=64
+size=7
+stride=2
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=192
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+#######
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=2
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[connected]
+output=4096
+activation=leaky
+
+[dropout]
+probability=.5
+
+[connected]
+output= 1470
+activation=linear
+
+[detection]
+classes=20
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1/yolo-small.cfg b/vehicle-detection/darkflow/cfg/v1/yolo-small.cfg
new file mode 100644
index 0000000..2a84485
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/yolo-small.cfg
@@ -0,0 +1,239 @@
+[net]
+batch=64
+subdivisions=64
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.001
+policy=steps
+steps=200,400,600,20000,30000
+scales=2.5,2,2,.1,.1
+max_batches = 40000
+
+[crop]
+crop_width=448
+crop_height=448
+flip=0
+angle=0
+saturation = 1.5
+exposure = 1.5
+
+[convolutional]
+filters=64
+size=7
+stride=2
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=192
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+#######
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=2
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[connected]
+output=512
+activation=leaky
+
+[connected]
+output=4096
+activation=leaky
+
+[dropout]
+probability=.5
+
+[connected]
+output= 1470
+activation=linear
+
+[detection]
+classes=20
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
+
diff --git a/vehicle-detection/darkflow/cfg/v1/yolo-tiny-extract.cfg b/vehicle-detection/darkflow/cfg/v1/yolo-tiny-extract.cfg
new file mode 100644
index 0000000..cddf222
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/yolo-tiny-extract.cfg
@@ -0,0 +1,175 @@
+[net]
+batch=64
+subdivisions=64
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.0001
+policy=steps
+steps=20,40,60,80,20000,30000
+scales=5,5,2,2,.1,.1
+max_batches = 40000
+
+[crop]
+crop_width=448
+crop_height=448
+flip=0
+angle=0
+saturation = 1.5
+exposure = 1.5
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=-1
+output=0
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=0
+output=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=1
+output=2
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=2
+output=3
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=3
+output=4
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=4
+output=5
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=5
+output=6
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=6
+output=7
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[conv-extract]
+profile=cfg/v1/tiny.profile
+input=7
+output=8
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[extract]
+profile=cfg/v1/tiny.profile
+input=8
+output=9
+old=7,7,1024,256
+activation=linear
+
+[extract]
+profile=cfg/v1/tiny.profile
+input=9
+output=10
+old=256,4096
+activation=leaky
+
+[dropout]
+probability=1.
+
+[select]
+input=cfg/v1/tiny.profile,10
+old_output=1470
+keep=8,14,15,19/20
+bins=49
+output=686
+activation=linear
+
+[detection]
+classes=4
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1/yolo-tiny-extract_.cfg b/vehicle-detection/darkflow/cfg/v1/yolo-tiny-extract_.cfg
new file mode 100644
index 0000000..21e250e
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/yolo-tiny-extract_.cfg
@@ -0,0 +1,177 @@
+[net]
+batch=64
+subdivisions=64
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.0001
+policy=steps
+steps=20,40,60,80,20000,30000
+scales=5,5,2,2,.1,.1
+max_batches = 40000
+
+[crop]
+crop_width=448
+crop_height=448
+flip=0
+angle=0
+saturation = 1.5
+exposure = 1.5
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=-1
+output=0
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=0
+output=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=1
+output=2
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=2
+output=3
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=3
+output=4
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=4
+output=5
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=5
+output=6
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=6
+output=7
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[conv-extract]
+profile=cfg/v1/tiny-old.profile
+input=7
+output=8
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[extract]
+profile=cfg/v1/tiny-old.profile
+input=8
+output=9
+old=7,7,1024,256
+activation=linear
+
+[extract]
+profile=cfg/v1/tiny-old.profile
+input=9
+output=10
+old=256,4096
+activation=leaky
+
+[dropout]
+probability=1.
+
+[select]
+input=cfg/v1/tiny-old.profile,10
+old_output=1470
+keep=8,14,15,19/20
+bins=49
+output=686
+activation=linear
+
+[detection]
+classes=4
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+object_scale=2.5
+noobject_scale=2
+class_scale=2.5
+coord_scale=5
+
+save=11250
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1/yolo-tiny.cfg b/vehicle-detection/darkflow/cfg/v1/yolo-tiny.cfg
new file mode 100644
index 0000000..8d139e8
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/yolo-tiny.cfg
@@ -0,0 +1,138 @@
+[net]
+batch=64
+subdivisions=64
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.0001
+policy=steps
+steps=20,40,60,80,20000,30000
+scales=5,5,2,2,.1,.1
+max_batches = 40000
+
+[crop]
+crop_width=448
+crop_height=448
+flip=0
+angle=0
+saturation = 1.5
+exposure = 1.5
+
+[convolutional]
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[connected]
+output=256
+activation=linear
+
+[connected]
+output=4096
+activation=leaky
+
+[dropout]
+probability=.5
+
+[connected]
+output= 1470
+activation=linear
+
+[detection]
+classes=20
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/v1/yolo-tiny4c.cfg b/vehicle-detection/darkflow/cfg/v1/yolo-tiny4c.cfg
new file mode 100644
index 0000000..21357ac
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/v1/yolo-tiny4c.cfg
@@ -0,0 +1,141 @@
+[net]
+batch=64
+subdivisions=64
+height=448
+width=448
+channels=3
+momentum=0.9
+decay=0.0005
+
+learning_rate=0.0001
+policy=steps
+steps=20,40,60,80,20000,30000
+scales=5,5,2,2,.1,.1
+max_batches = 40000
+
+[crop]
+crop_width=448
+crop_height=448
+flip=0
+angle=0
+saturation = 1.5
+exposure = 1.5
+
+[convolutional]
+filters=16
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[connected]
+output=256
+activation=linear
+
+[connected]
+output=4096
+activation=leaky
+
+[dropout]
+probability=.5
+
+[select]
+old_output=1470
+keep=8,14,15,19/20
+bins=49
+output=686
+activation=linear
+
+[detection]
+classes=4
+coords=4
+rescore=1
+side=7
+num=2
+softmax=0
+sqrt=1
+jitter=.2
+object_scale=1
+noobject_scale=.5
+class_scale=1
+coord_scale=5
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/cfg/yolo-voc.cfg b/vehicle-detection/darkflow/cfg/yolo-voc.cfg
new file mode 100644
index 0000000..ceb3f2a
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/yolo-voc.cfg
@@ -0,0 +1,244 @@
+[net]
+batch=64
+subdivisions=8
+height=416
+width=416
+channels=3
+momentum=0.9
+decay=0.0005
+angle=0
+saturation = 1.5
+exposure = 1.5
+hue=.1
+
+learning_rate=0.0001
+max_batches = 45000
+policy=steps
+steps=100,25000,35000
+scales=10,.1,.1
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+
+#######
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[route]
+layers=-9
+
+[reorg]
+stride=2
+
+[route]
+layers=-1,-3
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=1
+stride=1
+pad=1
+filters=125
+activation=linear
+
+[region]
+anchors = 1.08,1.19, 3.42,4.41, 6.63,11.38, 9.42,5.11, 16.62,10.52
+bias_match=1
+classes=20
+coords=4
+num=5
+softmax=1
+jitter=.2
+rescore=1
+
+object_scale=5
+noobject_scale=1
+class_scale=1
+coord_scale=1
+
+absolute=1
+thresh = .6
+random=0
diff --git a/vehicle-detection/darkflow/cfg/yolo.cfg b/vehicle-detection/darkflow/cfg/yolo.cfg
new file mode 100644
index 0000000..8376b1a
--- /dev/null
+++ b/vehicle-detection/darkflow/cfg/yolo.cfg
@@ -0,0 +1,244 @@
+[net]
+batch=1
+subdivisions=1
+width=416
+height=416
+channels=3
+momentum=0.9
+decay=0.0005
+angle=0
+saturation = 1.5
+exposure = 1.5
+hue=.1
+
+learning_rate=0.001
+max_batches = 120000
+policy=steps
+steps=-1,100,80000,100000
+scales=.1,10,.1,.1
+
+[convolutional]
+batch_normalize=1
+filters=32
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=64
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=128
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=256
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[maxpool]
+size=2
+stride=2
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=512
+size=1
+stride=1
+pad=1
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+filters=1024
+size=3
+stride=1
+pad=1
+activation=leaky
+
+
+#######
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[route]
+layers=-9
+
+[reorg]
+stride=2
+
+[route]
+layers=-1,-3
+
+[convolutional]
+batch_normalize=1
+size=3
+stride=1
+pad=1
+filters=1024
+activation=leaky
+
+[convolutional]
+size=1
+stride=1
+pad=1
+filters=425
+activation=linear
+
+[region]
+anchors = 0.738768,0.874946, 2.42204,2.65704, 4.30971,7.04493, 10.246,4.59428, 12.6868,11.8741
+bias_match=1
+classes=80
+coords=4
+num=5
+softmax=1
+jitter=.2
+rescore=1
+
+object_scale=5
+noobject_scale=1
+class_scale=1
+coord_scale=1
+
+absolute=1
+thresh=.3
+random=0
diff --git a/vehicle-detection/darkflow/dark/__init__.py b/vehicle-detection/darkflow/dark/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/vehicle-detection/darkflow/dark/connected.py b/vehicle-detection/darkflow/dark/connected.py
new file mode 100644
index 0000000..d1eb37d
--- /dev/null
+++ b/vehicle-detection/darkflow/dark/connected.py
@@ -0,0 +1,111 @@
+from .layer import Layer
+import numpy as np
+
+class extract_layer(Layer):
+ def setup(self, old_inp, old_out,
+ activation, inp, out):
+ if inp is None: inp = range(old_inp)
+ self.activation = activation
+ self.old_inp = old_inp
+ self.old_out = old_out
+ self.inp = inp
+ self.out = out
+ self.wshape = {
+ 'biases': [len(self.out)],
+ 'weights': [len(self.inp), len(self.out)]
+ }
+
+ @property
+ def signature(self):
+ sig = ['connected']
+ sig += self._signature[1:-2]
+ return sig
+
+ def present(self):
+ args = self.signature
+ self.presenter = connected_layer(*args)
+
+ def recollect(self, val):
+ w = val['weights']
+ b = val['biases']
+ if w is None: self.w = val; return
+ w = np.take(w, self.inp, 0)
+ w = np.take(w, self.out, 1)
+ b = np.take(b, self.out)
+ assert1 = w.shape == tuple(self.wshape['weights'])
+ assert2 = b.shape == tuple(self.wshape['biases'])
+ assert assert1 and assert2, \
+ 'Dimension does not match in {} recollect'.format(
+ self._signature)
+
+ self.w['weights'] = w
+ self.w['biases'] = b
+
+
+
+class select_layer(Layer):
+ def setup(self, inp, old,
+ activation, inp_idx,
+ out, keep, train):
+ self.old = old
+ self.keep = keep
+ self.train = train
+ self.inp_idx = inp_idx
+ self.activation = activation
+ inp_dim = inp
+ if inp_idx is not None:
+ inp_dim = len(inp_idx)
+ self.inp = inp_dim
+ self.out = out
+ self.wshape = {
+ 'biases': [out],
+ 'weights': [inp_dim, out]
+ }
+
+ @property
+ def signature(self):
+ sig = ['connected']
+ sig += self._signature[1:-4]
+ return sig
+
+ def present(self):
+ args = self.signature
+ self.presenter = connected_layer(*args)
+
+ def recollect(self, val):
+ w = val['weights']
+ b = val['biases']
+ if w is None: self.w = val; return
+ if self.inp_idx is not None:
+ w = np.take(w, self.inp_idx, 0)
+
+ keep_b = np.take(b, self.keep)
+ keep_w = np.take(w, self.keep, 1)
+ train_b = b[self.train:]
+ train_w = w[:, self.train:]
+ self.w['biases'] = np.concatenate(
+ (keep_b, train_b), axis = 0)
+ self.w['weights'] = np.concatenate(
+ (keep_w, train_w), axis = 1)
+
+
+class connected_layer(Layer):
+ def setup(self, input_size,
+ output_size, activation):
+ self.activation = activation
+ self.inp = input_size
+ self.out = output_size
+ self.wshape = {
+ 'biases': [self.out],
+ 'weights': [self.inp, self.out]
+ }
+
+ def finalize(self, transpose):
+ weights = self.w['weights']
+ if weights is None: return
+ shp = self.wshape['weights']
+ if not transpose:
+ weights = weights.reshape(shp[::-1])
+ weights = weights.transpose([1,0])
+ else: weights = weights.reshape(shp)
+ self.w['weights'] = weights
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/dark/convolution.py b/vehicle-detection/darkflow/dark/convolution.py
new file mode 100644
index 0000000..6c3f410
--- /dev/null
+++ b/vehicle-detection/darkflow/dark/convolution.py
@@ -0,0 +1,156 @@
+from .layer import Layer
+import numpy as np
+
+class local_layer(Layer):
+ def setup(self, ksize, c, n, stride,
+ pad, w_, h_, activation):
+ self.pad = pad * (ksize / 2)
+ self.activation = activation
+ self.stride = stride
+ self.ksize = ksize
+ self.h_out = h_
+ self.w_out = w_
+
+ self.dnshape = [h_ * w_, n, c, ksize, ksize]
+ self.wshape = dict({
+ 'biases': [h_ * w_ * n],
+ 'kernels': [h_ * w_, ksize, ksize, c, n]
+ })
+
+ def finalize(self, _):
+ weights = self.w['kernels']
+ if weights is None: return
+ weights = weights.reshape(self.dnshape)
+ weights = weights.transpose([0,3,4,2,1])
+ self.w['kernels'] = weights
+
+class conv_extract_layer(Layer):
+ def setup(self, ksize, c, n, stride,
+ pad, batch_norm, activation,
+ inp, out):
+ if inp is None: inp = range(c)
+ self.activation = activation
+ self.batch_norm = batch_norm
+ self.stride = stride
+ self.ksize = ksize
+ self.pad = pad
+ self.inp = inp
+ self.out = out
+ self.wshape = dict({
+ 'biases': [len(out)],
+ 'kernel': [ksize, ksize, len(inp), len(out)]
+ })
+
+ @property
+ def signature(self):
+ sig = ['convolutional']
+ sig += self._signature[1:-2]
+ return sig
+
+ def present(self):
+ args = self.signature
+ self.presenter = convolutional_layer(*args)
+
+ def recollect(self, w):
+ if w is None:
+ self.w = w
+ return
+ k = w['kernel']
+ b = w['biases']
+ k = np.take(k, self.inp, 2)
+ k = np.take(k, self.out, 3)
+ b = np.take(b, self.out)
+ assert1 = k.shape == tuple(self.wshape['kernel'])
+ assert2 = b.shape == tuple(self.wshape['biases'])
+ assert assert1 and assert2, \
+ 'Dimension not matching in {} recollect'.format(
+ self._signature)
+ self.w['kernel'] = k
+ self.w['biases'] = b
+
+
+class conv_select_layer(Layer):
+ def setup(self, ksize, c, n, stride,
+ pad, batch_norm, activation,
+ keep_idx, real_n):
+ self.batch_norm = bool(batch_norm)
+ self.activation = activation
+ self.keep_idx = keep_idx
+ self.stride = stride
+ self.ksize = ksize
+ self.pad = pad
+ self.wshape = dict({
+ 'biases': [real_n],
+ 'kernel': [ksize, ksize, c, real_n]
+ })
+ if self.batch_norm:
+ self.wshape.update({
+ 'moving_variance' : [real_n],
+ 'moving_mean': [real_n],
+ 'gamma' : [real_n]
+ })
+ self.h['is_training'] = {
+ 'shape': (),
+ 'feed': True,
+ 'dfault': False
+ }
+
+ @property
+ def signature(self):
+ sig = ['convolutional']
+ sig += self._signature[1:-2]
+ return sig
+
+ def present(self):
+ args = self.signature
+ self.presenter = convolutional_layer(*args)
+
+ def recollect(self, w):
+ if w is None:
+ self.w = w
+ return
+ idx = self.keep_idx
+ k = w['kernel']
+ b = w['biases']
+ self.w['kernel'] = np.take(k, idx, 3)
+ self.w['biases'] = np.take(b, idx)
+ if self.batch_norm:
+ m = w['moving_mean']
+ v = w['moving_variance']
+ g = w['gamma']
+ self.w['moving_mean'] = np.take(m, idx)
+ self.w['moving_variance'] = np.take(v, idx)
+ self.w['gamma'] = np.take(g, idx)
+
+class convolutional_layer(Layer):
+ def setup(self, ksize, c, n, stride,
+ pad, batch_norm, activation):
+ self.batch_norm = bool(batch_norm)
+ self.activation = activation
+ self.stride = stride
+ self.ksize = ksize
+ self.pad = pad
+ self.dnshape = [n, c, ksize, ksize] # darknet shape
+ self.wshape = dict({
+ 'biases': [n],
+ 'kernel': [ksize, ksize, c, n]
+ })
+ if self.batch_norm:
+ self.wshape.update({
+ 'moving_variance' : [n],
+ 'moving_mean': [n],
+ 'gamma' : [n]
+ })
+ self.h['is_training'] = {
+ 'feed': True,
+ 'dfault': False,
+ 'shape': ()
+ }
+
+ def finalize(self, _):
+ """deal with darknet"""
+ kernel = self.w['kernel']
+ if kernel is None: return
+ kernel = kernel.reshape(self.dnshape)
+ kernel = kernel.transpose([2,3,1,0])
+ self.w['kernel'] = kernel
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/dark/darknet.py b/vehicle-detection/darkflow/dark/darknet.py
new file mode 100644
index 0000000..f7843d4
--- /dev/null
+++ b/vehicle-detection/darkflow/dark/darknet.py
@@ -0,0 +1,86 @@
+from cfg.process import cfg_yielder
+from .darkop import create_darkop
+from utils import loader
+import warnings
+import time
+import os
+
+class Darknet(object):
+
+ _EXT = '.weights'
+
+ def __init__(self, FLAGS):
+ self.get_weight_src(FLAGS)
+ self.modify = False
+
+ print('Parsing {}'.format(self.src_cfg))
+ src_parsed = self.parse_cfg(self.src_cfg, FLAGS)
+ self.src_meta, self.src_layers = src_parsed
+
+ if self.src_cfg == FLAGS.model:
+ self.meta, self.layers = src_parsed
+ else:
+ print('Parsing {}'.format(FLAGS.model))
+ des_parsed = self.parse_cfg(FLAGS.model, FLAGS)
+ self.meta, self.layers = des_parsed
+
+ self.load_weights()
+
+ def get_weight_src(self, FLAGS):
+ """
+ analyse FLAGS.load to know where is the
+ source binary and what is its config.
+ can be: None, FLAGS.model, or some other
+ """
+ self.src_bin = FLAGS.model + self._EXT
+ self.src_bin = FLAGS.binary + self.src_bin
+ self.src_bin = os.path.abspath(self.src_bin)
+ exist = os.path.isfile(self.src_bin)
+
+ if FLAGS.load == str(): FLAGS.load = int()
+ if type(FLAGS.load) is int:
+ self.src_cfg = FLAGS.model
+ if FLAGS.load: self.src_bin = None
+ elif not exist: self.src_bin = None
+ else:
+ assert os.path.isfile(FLAGS.load), \
+ '{} not found'.format(FLAGS.load)
+ self.src_bin = FLAGS.load
+ name = loader.model_name(FLAGS.load)
+ cfg_path = FLAGS.config+name+'.cfg'
+ if not os.path.isfile(cfg_path):
+ warnings.warn(
+ '{} not found, use {} instead'.format(
+ cfg_path, FLAGS.model))
+ cfg_path = FLAGS.model
+ self.src_cfg = cfg_path
+ FLAGS.load = int()
+
+
+ def parse_cfg(self, model, FLAGS):
+ """
+ return a list of `layers` objects (darkop.py)
+ given path to binaries/ and configs/
+ """
+ args = [model, FLAGS.binary]
+ cfg_layers = cfg_yielder(*args)
+ meta = dict(); layers = list()
+ for i, info in enumerate(cfg_layers):
+ if i == 0: meta = info; continue
+ else: new = create_darkop(*info)
+ layers.append(new)
+ return meta, layers
+
+ def load_weights(self):
+ """
+ Use `layers` and Loader to load .weights file
+ """
+ print('Loading {} ...'.format(self.src_bin))
+ start = time.time()
+
+ args = [self.src_bin, self.src_layers]
+ wgts_loader = loader.create_loader(*args)
+ for layer in self.layers: layer.load(wgts_loader)
+
+ stop = time.time()
+ print('Finished in {}s'.format(stop - start))
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/dark/darkop.py b/vehicle-detection/darkflow/dark/darkop.py
new file mode 100644
index 0000000..bcde00a
--- /dev/null
+++ b/vehicle-detection/darkflow/dark/darkop.py
@@ -0,0 +1,60 @@
+from .layer import Layer
+from .convolution import *
+from .connected import *
+
+class avgpool_layer(Layer):
+ pass
+
+class crop_layer(Layer):
+ pass
+
+class maxpool_layer(Layer):
+ def setup(self, ksize, stride, pad):
+ self.stride = stride
+ self.ksize = ksize
+ self.pad = pad
+
+class softmax_layer(Layer):
+ def setup(self, groups):
+ self.groups = groups
+
+class dropout_layer(Layer):
+ def setup(self, p):
+ self.h['pdrop'] = dict({
+ 'feed': p, # for training
+ 'dfault': 1.0, # for testing
+ 'shape': ()
+ })
+
+class route_layer(Layer):
+ def setup(self, routes):
+ self.routes = routes
+
+class reorg_layer(Layer):
+ def setup(self, stride):
+ self.stride = stride
+
+"""
+Darkop Factory
+"""
+
+darkops = {
+ 'dropout': dropout_layer,
+ 'connected': connected_layer,
+ 'maxpool': maxpool_layer,
+ 'convolutional': convolutional_layer,
+ 'avgpool': avgpool_layer,
+ 'softmax': softmax_layer,
+ 'crop': crop_layer,
+ 'local': local_layer,
+ 'select': select_layer,
+ 'route': route_layer,
+ 'reorg': reorg_layer,
+ 'conv-select': conv_select_layer,
+ 'conv-extract': conv_extract_layer,
+ 'extract': extract_layer
+}
+
+def create_darkop(ltype, num, *args):
+ op_class = darkops.get(ltype, Layer)
+ return op_class(ltype, num, *args)
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/dark/layer.py b/vehicle-detection/darkflow/dark/layer.py
new file mode 100644
index 0000000..329262f
--- /dev/null
+++ b/vehicle-detection/darkflow/dark/layer.py
@@ -0,0 +1,71 @@
+from utils import loader
+import numpy as np
+
+class Layer(object):
+
+ def __init__(self, *args):
+ self._signature = list(args)
+ self.type = list(args)[0]
+ self.number = list(args)[1]
+
+ self.w = dict() # weights
+ self.h = dict() # placeholders
+ self.wshape = dict() # weight shape
+ self.wsize = dict() # weight size
+ self.setup(*args[2:]) # set attr up
+ self.present()
+ for var in self.wshape:
+ shp = self.wshape[var]
+ size = np.prod(shp)
+ self.wsize[var] = size
+
+ def load(self, src_loader):
+ var_lay = src_loader.VAR_LAYER
+ if self.type not in var_lay: return
+
+ src_type = type(src_loader)
+ if src_type is loader.weights_loader:
+ wdict = self.load_weights(src_loader)
+ else:
+ wdict = self.load_ckpt(src_loader)
+ if wdict is not None:
+ self.recollect(wdict)
+
+ def load_weights(self, src_loader):
+ val = src_loader([self.presenter])
+ if val is None: return None
+ else: return val.w
+
+ def load_ckpt(self, src_loader):
+ result = dict()
+ presenter = self.presenter
+ for var in presenter.wshape:
+ name = presenter.varsig(var)
+ shape = presenter.wshape[var]
+ key = [name, shape]
+ val = src_loader(key)
+ result[var] = val
+ return result
+
+ @property
+ def signature(self):
+ return self._signature
+
+ # For comparing two layers
+ def __eq__(self, other):
+ return self.signature == other.signature
+ def __ne__(self, other):
+ return not self.__eq__(other)
+
+ def varsig(self, var):
+ if var not in self.wshape:
+ return None
+ sig = str(self.number)
+ sig += '-' + self.type
+ sig += '/' + var
+ return sig
+
+ def recollect(self, w): self.w = w
+ def present(self): self.presenter = self
+ def setup(self, *args): pass
+ def finalize(self): pass
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/flow b/vehicle-detection/darkflow/flow
new file mode 100755
index 0000000..ec8bc9e
--- /dev/null
+++ b/vehicle-detection/darkflow/flow
@@ -0,0 +1,60 @@
+#! /usr/bin/env python
+
+from net.build import TFNet
+from tensorflow import flags
+import os
+
+flags.DEFINE_string("test", "./test/", "path to testing directory")
+flags.DEFINE_string("binary", "./bin/", "path to .weights directory")
+flags.DEFINE_string("config", "./cfg/", "path to .cfg directory")
+flags.DEFINE_string("dataset", "../pascal/VOCdevkit/IMG/", "path to dataset directory")
+flags.DEFINE_string("backup", "./ckpt/", "path to backup folder")
+flags.DEFINE_string("annotation", "../pascal/VOCdevkit/ANN/", "path to annotation directory")
+flags.DEFINE_float("threshold", 0.1, "detection threshold")
+flags.DEFINE_string("model", "", "configuration of choice")
+flags.DEFINE_string("trainer", "rmsprop", "training algorithm")
+flags.DEFINE_float("momentum", 0.0, "applicable for rmsprop and momentum optimizers")
+flags.DEFINE_boolean("verbalise", True, "say out loud while building graph")
+flags.DEFINE_boolean("train", False, "train the whole net")
+flags.DEFINE_string("load", "", "how to initialize the net? Either from .weights or a checkpoint, or even from scratch")
+flags.DEFINE_boolean("savepb", False, "save net and weight to a .pb file")
+flags.DEFINE_float("gpu", 0.0, "how much gpu (from 0.0 to 1.0)")
+flags.DEFINE_float("lr", 1e-5, "learning rate")
+flags.DEFINE_integer("keep",20,"Number of most recent training results to save")
+flags.DEFINE_integer("batch", 48, "batch size")
+flags.DEFINE_integer("epoch", 1000, "number of epoch")
+flags.DEFINE_integer("save", 2000, "save checkpoint every ? training examples")
+flags.DEFINE_string("demo", '', "demo on webcam")
+flags.DEFINE_boolean("profile", False, "profile")
+FLAGS = flags.FLAGS
+
+# make sure all necessary dirs exist
+def get_dir(dirs):
+ for d in dirs:
+ this = os.path.abspath(os.path.join(os.path.curdir, d))
+ if not os.path.exists(this): os.makedirs(this)
+get_dir([FLAGS.test, FLAGS.binary, FLAGS.backup, os.path.join(FLAGS.test,'out')])
+
+# fix FLAGS.load to appropriate type
+try: FLAGS.load = int(FLAGS.load)
+except: pass
+
+tfnet = TFNet(FLAGS)
+
+if FLAGS.profile:
+ tfnet.framework.profile(tfnet)
+ exit()
+
+if FLAGS.demo:
+ tfnet.camera(FLAGS.demo)
+ exit()
+
+if FLAGS.train:
+ print('Enter training ...'); tfnet.train()
+ if not FLAGS.savepb: exit('Training finished')
+
+if FLAGS.savepb:
+ print('Rebuild a constant version ...')
+ tfnet.savepb(); exit('Done')
+
+tfnet.predict()
diff --git a/vehicle-detection/darkflow/net/__init__.py b/vehicle-detection/darkflow/net/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/vehicle-detection/darkflow/net/build.py b/vehicle-detection/darkflow/net/build.py
new file mode 100644
index 0000000..dd3d745
--- /dev/null
+++ b/vehicle-detection/darkflow/net/build.py
@@ -0,0 +1,119 @@
+import tensorflow as tf
+import time
+from . import help
+from . import flow
+from .ops import op_create, identity
+from .ops import HEADER, LINE
+from .framework import create_framework
+from dark.darknet import Darknet
+
+class TFNet(object):
+
+ _TRAINER = dict({
+ 'rmsprop': tf.train.RMSPropOptimizer,
+ 'adadelta': tf.train.AdadeltaOptimizer,
+ 'adagrad': tf.train.AdagradOptimizer,
+ 'adagradDA': tf.train.AdagradDAOptimizer,
+ 'momentum': tf.train.MomentumOptimizer,
+ 'adam': tf.train.AdamOptimizer,
+ 'ftrl': tf.train.FtrlOptimizer,
+ })
+
+ # imported methods
+ say = help.say
+ train = flow.train
+ camera = help.camera
+ predict = flow.predict
+ to_darknet = help.to_darknet
+ build_train_op = help.build_train_op
+ load_from_ckpt = help.load_from_ckpt
+
+ def __init__(self, FLAGS, darknet = None):
+ self.ntrain = 0
+ if darknet is None:
+ darknet = Darknet(FLAGS)
+ self.ntrain = len(darknet.layers)
+ #self.ntrain = 1
+
+ self.darknet = darknet
+ args = [darknet.meta, FLAGS]
+ self.num_layer = len(darknet.layers)
+ self.framework = create_framework(*args)
+
+ self.meta = darknet.meta
+ self.FLAGS = FLAGS
+
+ self.say('\nBuilding net ...')
+ start = time.time()
+ self.graph = tf.Graph()
+ with self.graph.as_default() as g:
+ self.build_forward()
+ self.setup_meta_ops()
+ self.say('Finished in {}s\n'.format(
+ time.time() - start))
+
+ def build_forward(self):
+ verbalise = self.FLAGS.verbalise
+
+ # Placeholders
+ inp_size = [None] + self.meta['inp_size']
+ self.inp = tf.placeholder(tf.float32, inp_size, 'input')
+ self.feed = dict() # other placeholders
+
+ # Build the forward pass
+ state = identity(self.inp)
+ roof = self.num_layer - self.ntrain
+ self.say(HEADER, LINE)
+ for i, layer in enumerate(self.darknet.layers):
+ scope = '{}-{}'.format(str(i),layer.type)
+ args = [layer, state, i, roof, self.feed]
+ state = op_create(*args)
+ mess = state.verbalise()
+ self.say(mess)
+ self.say(LINE)
+
+ self.top = state
+ self.out = tf.identity(state.out, name='output')
+
+ def setup_meta_ops(self):
+ cfg = dict({
+ 'allow_soft_placement': False,
+ 'log_device_placement': False
+ })
+
+ utility = min(self.FLAGS.gpu, 1.)
+ if utility > 0.0:
+ self.say('GPU mode with {} usage'.format(utility))
+ cfg['gpu_options'] = tf.GPUOptions(
+ per_process_gpu_memory_fraction = utility)
+ cfg['allow_soft_placement'] = True
+ else:
+ self.say('Running entirely on CPU')
+ cfg['device_count'] = {'GPU': 0}
+
+ if self.FLAGS.train: self.build_train_op()
+ self.sess = tf.Session(config = tf.ConfigProto(**cfg))
+ self.sess.run(tf.global_variables_initializer())
+
+ if not self.ntrain: return
+ self.saver = tf.train.Saver(tf.global_variables(),
+ max_to_keep = self.FLAGS.keep)
+ if self.FLAGS.load != 0: self.load_from_ckpt()
+
+ def savepb(self):
+ """
+ Create a standalone const graph def that
+ C++ can load and run.
+ """
+ darknet_pb = self.to_darknet()
+ flags_pb = self.FLAGS
+ flags_pb.verbalise = False
+
+ # rebuild another tfnet. all const.
+ tfnet_pb = TFNet(flags_pb, darknet_pb)
+ tfnet_pb.sess = tf.Session(graph = tfnet_pb.graph)
+ # tfnet_pb.predict() # uncomment for unit testing
+ name = 'graph-{}.pb'.format(self.meta['name'])
+ self.say('Saving const graph def to {}'.format(name))
+ graph_def = tfnet_pb.sess.graph_def
+ tf.train.write_graph(graph_def,'./',name,False)
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/flow.py b/vehicle-detection/darkflow/net/flow.py
new file mode 100644
index 0000000..baf389a
--- /dev/null
+++ b/vehicle-detection/darkflow/net/flow.py
@@ -0,0 +1,107 @@
+import os
+import time
+import numpy as np
+import tensorflow as tf
+import pickle
+
+train_stats = (
+ 'Training statistics: \n'
+ '\tLearning rate : {}\n'
+ '\tBatch size : {}\n'
+ '\tEpoch number : {}\n'
+ '\tBackup every : {}'
+)
+
+def _save_ckpt(self, step, loss_profile):
+ file = '{}-{}{}'
+ model = self.meta['name']
+
+ profile = file.format(model, step, '.profile')
+ profile = os.path.join(self.FLAGS.backup, profile)
+ with open(profile, 'wb') as profile_ckpt:
+ pickle.dump(loss_profile, profile_ckpt)
+
+ ckpt = file.format(model, step, '')
+ ckpt = os.path.join(self.FLAGS.backup, ckpt)
+ self.say('Checkpoint at step {}'.format(step))
+ self.saver.save(self.sess, ckpt)
+
+
+def train(self):
+ loss_ph = self.framework.placeholders
+ loss_mva = None; profile = list()
+
+ batches = self.framework.shuffle()
+ loss_op = self.framework.loss
+
+ for i, (x_batch, datum) in enumerate(batches):
+ if not i: self.say(train_stats.format(
+ self.FLAGS.lr, self.FLAGS.batch,
+ self.FLAGS.epoch, self.FLAGS.save
+ ))
+
+ feed_dict = {
+ loss_ph[key]: datum[key]
+ for key in loss_ph }
+ feed_dict[self.inp] = x_batch
+ feed_dict.update(self.feed)
+
+ fetches = [self.train_op, loss_op]
+ fetched = self.sess.run(fetches, feed_dict)
+ loss = fetched[1]
+
+ if loss_mva is None: loss_mva = loss
+ loss_mva = .9 * loss_mva + .1 * loss
+ step_now = self.FLAGS.load + i + 1
+
+ form = 'step {} - loss {} - moving ave loss {}'
+ self.say(form.format(step_now, loss, loss_mva))
+ profile += [(loss, loss_mva)]
+
+ ckpt = (i+1) % (self.FLAGS.save // self.FLAGS.batch)
+ args = [step_now, profile]
+ if not ckpt: _save_ckpt(self, *args)
+
+ if ckpt: _save_ckpt(self, *args)
+
+
+def predict(self):
+ inp_path = self.FLAGS.test
+ all_inp_ = os.listdir(inp_path)
+ all_inp_ = [i for i in all_inp_ if self.framework.is_inp(i)]
+ if not all_inp_:
+ msg = 'Failed to find any test files in {} .'
+ exit('Error: {}'.format(msg.format(inp_path)))
+
+ batch = min(self.FLAGS.batch, len(all_inp_))
+
+ for j in range(len(all_inp_) // batch):
+ inp_feed = list(); new_all = list()
+ all_inp = all_inp_[j*batch: (j*batch+batch)]
+ for inp in all_inp:
+ new_all += [inp]
+ this_inp = os.path.join(inp_path, inp)
+ this_inp = self.framework.preprocess(this_inp)
+ expanded = np.expand_dims(this_inp, 0)
+ inp_feed.append(expanded)
+ all_inp = new_all
+
+ feed_dict = {self.inp : np.concatenate(inp_feed, 0)}
+
+ self.say('Forwarding {} inputs ...'.format(len(inp_feed)))
+ start = time.time()
+ out = self.sess.run(self.out, feed_dict)
+ stop = time.time(); last = stop - start
+
+ self.say('Total time = {}s / {} inps = {} ips'.format(
+ last, len(inp_feed), len(inp_feed) / last))
+
+ self.say('Post processing {} inputs ...'.format(len(inp_feed)))
+ start = time.time()
+ for i, prediction in enumerate(out):
+ self.framework.postprocess(prediction,
+ os.path.join(inp_path, all_inp[i]))
+ stop = time.time(); last = stop - start
+
+ self.say('Total time = {}s / {} inps = {} ips'.format(
+ last, len(inp_feed), len(inp_feed) / last))
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/framework.py b/vehicle-detection/darkflow/net/framework.py
new file mode 100644
index 0000000..2ffdeaa
--- /dev/null
+++ b/vehicle-detection/darkflow/net/framework.py
@@ -0,0 +1,52 @@
+from . import yolo
+from . import yolov2
+from . import vanilla
+
+class framework(object):
+ constructor = vanilla.constructor
+ loss = vanilla.train.loss
+
+ def __init__(self, meta, FLAGS):
+ model = meta['model'].split('/')[-1]
+ model = '.'.join(model.split('.')[:-1])
+ meta['name'] = model
+
+ self.constructor(meta, FLAGS)
+
+ def is_inp(self):
+ return True
+
+class YOLO(framework):
+ constructor = yolo.constructor
+ parse = yolo.data.parse
+ shuffle = yolo.data.shuffle
+ preprocess = yolo.test.preprocess
+ postprocess = yolo.test.postprocess
+ loss = yolo.train.loss
+ is_inp = yolo.misc.is_inp
+ profile = yolo.misc.profile
+ _batch = yolo.data._batch
+
+class YOLOv2(framework):
+ constructor = yolo.constructor
+ parse = yolo.data.parse
+ shuffle = yolov2.data.shuffle
+ preprocess = yolo.test.preprocess
+ loss = yolov2.train.loss
+ is_inp = yolo.misc.is_inp
+ postprocess = yolov2.test.postprocess
+ _batch = yolov2.data._batch
+
+"""
+framework factory
+"""
+
+types = {
+ '[detection]': YOLO,
+ '[region]': YOLOv2
+}
+
+def create_framework(meta, FLAGS):
+ net_type = meta['type']
+ this = types.get(net_type, framework)
+ return this(meta, FLAGS)
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/help.py b/vehicle-detection/darkflow/net/help.py
new file mode 100644
index 0000000..6907986
--- /dev/null
+++ b/vehicle-detection/darkflow/net/help.py
@@ -0,0 +1,103 @@
+"""
+tfnet secondary (helper) methods
+"""
+from utils.loader import create_loader
+from time import time as timer
+import tensorflow as tf
+import numpy as np
+import sys
+import cv2
+import os
+
+old_graph_msg = 'Resolving old graph def {} (no guarantee)'
+
+def build_train_op(self):
+ self.framework.loss(self.out)
+ self.say('Building {} train op'.format(self.meta['model']))
+ optimizer = self._TRAINER[self.FLAGS.trainer](self.FLAGS.lr)
+ gradients = optimizer.compute_gradients(self.framework.loss)
+ self.train_op = optimizer.apply_gradients(gradients)
+
+def load_from_ckpt(self):
+ if self.FLAGS.load < 0: # load lastest ckpt
+ with open(self.FLAGS.backup + 'checkpoint', 'r') as f:
+ last = f.readlines()[-1].strip()
+ load_point = last.split(' ')[1]
+ load_point = load_point.split('"')[1]
+ load_point = load_point.split('-')[-1]
+ self.FLAGS.load = int(load_point)
+
+ load_point = os.path.join(self.FLAGS.backup, self.meta['name'])
+ load_point = '{}-{}'.format(load_point, self.FLAGS.load)
+ self.say('Loading from {}'.format(load_point))
+ try: self.saver.restore(self.sess, load_point)
+ except: load_old_graph(self, load_point)
+
+def say(self, *msgs):
+ if not self.FLAGS.verbalise:
+ return
+ msgs = list(msgs)
+ for msg in msgs:
+ if msg is None: continue
+ print(msg)
+
+def load_old_graph(self, ckpt):
+ ckpt_loader = create_loader(ckpt)
+ self.say(old_graph_msg.format(ckpt))
+
+ for var in tf.global_variables():
+ name = var.name.split(':')[0]
+ args = [name, var.get_shape()]
+ val = ckpt_loader(args)
+ assert val is not None, \
+ 'Cannot find and load {}'.format(var.name)
+ shp = val.shape
+ plh = tf.placeholder(tf.float32, shp)
+ op = tf.assign(var, plh)
+ self.sess.run(op, {plh: val})
+
+def camera(self, file):
+ camera = cv2.VideoCapture(0)
+ self.say('Press [ESC] to quit demo')
+ assert camera.isOpened(), \
+ 'Cannot capture source'
+
+ elapsed = int()
+ start = timer()
+ while camera.isOpened():
+ _, frame = camera.read()
+ preprocessed = self.framework.preprocess(frame)
+ feed_dict = {self.inp: [preprocessed]}
+ net_out = self.sess.run(self.out,feed_dict)[0]
+ processed = self.framework.postprocess(net_out, frame, False)
+ cv2.imshow('', processed)
+ elapsed += 1
+ if elapsed % 5 == 0:
+ sys.stdout.write('\r')
+ sys.stdout.write('{0:3.3f} FPS'.format(
+ elapsed / (timer() - start)))
+ sys.stdout.flush()
+ choice = cv2.waitKey(1)
+ if choice == 27: break
+
+ sys.stdout.write('\n')
+ camera.release()
+ cv2.destroyAllWindows()
+
+def to_darknet(self):
+ darknet_ckpt = self.darknet
+ with self.graph.as_default() as g:
+ for var in tf.global_variables():
+ name = var.name.split(':')[0]
+ var_name = name.split('-')
+ l_idx = int(var_name[0])
+ w_sig = var_name[1].split('/')[-1]
+ l = darknet_ckpt.layers[l_idx]
+ l.w[w_sig] = var.eval(self.sess)
+
+ for layer in darknet_ckpt.layers:
+ for ph in layer.h:
+ # Use default
+ layer.h[ph] = None
+
+ return darknet_ckpt
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/mnist/run.py b/vehicle-detection/darkflow/net/mnist/run.py
new file mode 100644
index 0000000..e69de29
diff --git a/vehicle-detection/darkflow/net/ops/__init__.py b/vehicle-detection/darkflow/net/ops/__init__.py
new file mode 100644
index 0000000..d687cb3
--- /dev/null
+++ b/vehicle-detection/darkflow/net/ops/__init__.py
@@ -0,0 +1,27 @@
+from .simple import *
+from .convolution import *
+from .baseop import HEADER, LINE
+
+op_types = {
+ 'convolutional': convolutional,
+ 'conv-select': conv_select,
+ 'connected': connected,
+ 'maxpool': maxpool,
+ 'leaky': leaky,
+ 'dropout': dropout,
+ 'flatten': flatten,
+ 'avgpool': avgpool,
+ 'softmax': softmax,
+ 'identity': identity,
+ 'crop': crop,
+ 'local': local,
+ 'select': select,
+ 'route': route,
+ 'reorg': reorg,
+ 'conv-extract': conv_extract,
+ 'extract': extract
+}
+
+def op_create(*args):
+ layer_type = list(args)[0].type
+ return op_types[layer_type](*args)
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/ops/baseop.py b/vehicle-detection/darkflow/net/ops/baseop.py
new file mode 100644
index 0000000..4b95ec3
--- /dev/null
+++ b/vehicle-detection/darkflow/net/ops/baseop.py
@@ -0,0 +1,101 @@
+import tensorflow as tf
+import numpy as np
+
+FORM = '{:>6} | {:>6} | {:<32} | {}'
+FORM_ = '{}+{}+{}+{}'
+LINE = FORM_.format('-'*7, '-'*8, '-'*34, '-'*15)
+HEADER = FORM.format(
+ 'Source', 'Train?','Layer description', 'Output size')
+
+def _shape(tensor): # work for both tf.Tensor & np.ndarray
+ if type(tensor) in [tf.Variable, tf.Tensor]:
+ return tensor.get_shape()
+ else: return tensor.shape
+
+def _name(tensor):
+ return tensor.name.split(':')[0]
+
+class BaseOp(object):
+ """
+ BaseOp objects initialise with a darknet's `layer` object
+ and input tensor of that layer `inp`, it calculates the
+ output of this layer and place the result in self.out
+ """
+
+ # let slim take care of the following vars
+ _SLIM = ['gamma', 'moving_mean', 'moving_variance']
+
+ def __init__(self, layer, inp, num, roof, feed):
+ self.inp = inp # BaseOp
+ self.num = num # int
+ self.out = None # tf.Tensor
+ self.lay = layer
+
+ self.scope = '{}-{}'.format(
+ str(self.num), self.lay.type)
+ self.gap = roof - self.num
+ self.var = not self.gap > 0
+ self.act = 'Load '
+ self.convert(feed)
+ if self.var: self.train_msg = 'Yep! '
+ else: self.train_msg = 'Nope '
+ self.forward()
+
+ def convert(self, feed):
+ """convert self.lay to variables & placeholders"""
+ for var in self.lay.wshape:
+ self.wrap_variable(var)
+ for ph in self.lay.h:
+ self.wrap_pholder(ph, feed)
+
+ def wrap_variable(self, var):
+ """wrap layer.w into variables"""
+ val = self.lay.w.get(var, None)
+ if val is None:
+ shape = self.lay.wshape[var]
+ args = [0., 1e-2, shape]
+ if 'moving_mean' in var:
+ val = np.zeros(shape)
+ elif 'moving_variance' in var:
+ val = np.ones(shape)
+ else:
+ val = np.random.normal(*args)
+ self.lay.w[var] = val.astype(np.float32)
+ self.act = 'Init '
+ if not self.var: return
+
+ val = self.lay.w[var]
+ self.lay.w[var] = tf.constant_initializer(val)
+ if var in self._SLIM: return
+ with tf.variable_scope(self.scope):
+ self.lay.w[var] = tf.get_variable(var,
+ shape = self.lay.wshape[var],
+ dtype = tf.float32,
+ initializer = self.lay.w[var])
+
+ def wrap_pholder(self, ph, feed):
+ """wrap layer.h into placeholders"""
+ phtype = type(self.lay.h[ph])
+ if phtype is not dict: return
+ sig = '{}/{}'.format(self.scope, ph)
+ val = self.lay.h[ph]
+ shp = val['shape']
+ dft = val['dfault']
+
+ self.lay.h[ph] = tf.placeholder_with_default(
+ val['dfault'], val['shape'], name = sig)
+ feed[self.lay.h[ph]] = val['feed']
+
+ def verbalise(self): # console speaker
+ msg = str()
+ inp = _name(self.inp.out)
+ if inp == 'input': \
+ msg = FORM.format(
+ '', '', 'input',
+ _shape(self.inp.out)) + '\n'
+ if not self.act: return msg
+ return msg + FORM.format(
+ self.act, self.train_msg,
+ self.speak(), _shape(self.out))
+
+ def speak(self): pass
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/ops/convolution.py b/vehicle-detection/darkflow/net/ops/convolution.py
new file mode 100644
index 0000000..09eac6b
--- /dev/null
+++ b/vehicle-detection/darkflow/net/ops/convolution.py
@@ -0,0 +1,118 @@
+import tensorflow.contrib.slim as slim
+from .baseop import BaseOp
+import tensorflow as tf
+import numpy as np
+
+class reorg(BaseOp):
+ def _forward(self):
+ inp = self.inp.out
+ shape = inp.get_shape().as_list()
+ _, h, w, c = shape
+ s = self.lay.stride
+ out = list()
+ for i in range(h/s):
+ row_i = list()
+ for j in range(w/s):
+ si, sj = s * i, s * j
+ boxij = inp[:, si: si+s, sj: sj+s,:]
+ flatij = tf.reshape(boxij, [-1,1,1,c*s*s])
+ row_i += [flatij]
+ out += [tf.concat(2, row_i)]
+ self.out = tf.concat(1, out)
+
+ def forward(self):
+ inp = self.inp.out
+ s = self.lay.stride
+ self.out = tf.extract_image_patches(
+ inp, [1,s,s,1], [1,s,s,1], [1,1,1,1], 'VALID')
+
+ def speak(self):
+ args = [self.lay.stride] * 2
+ msg = 'local flatten {}x{}'
+ return msg.format(*args)
+
+
+class local(BaseOp):
+ def forward(self):
+ pad = [[self.lay.pad, self.lay.pad]] * 2;
+ temp = tf.pad(self.inp.out, [[0, 0]] + pad + [[0, 0]])
+
+ k = self.lay.w['kernels']
+ ksz = self.lay.ksize
+ half = ksz/2
+ out = list()
+ for i in range(self.lay.h_out):
+ row_i = list()
+ for j in range(self.lay.w_out):
+ kij = k[i * self.lay.w_out + j]
+ i_, j_ = i + 1 - half, j + 1 - half
+ tij = temp[:, i_ : i_ + ksz, j_ : j_ + ksz,:]
+ row_i.append(
+ tf.nn.conv2d(tij, kij,
+ padding = 'VALID',
+ strides = [1] * 4))
+ out += [tf.concat(2, row_i)]
+
+ self.out = tf.concat(1, out)
+
+ def speak(self):
+ l = self.lay
+ args = [l.ksize] * 2 + [l.pad] + [l.stride]
+ args += [l.activation]
+ msg = 'loca {}x{}p{}_{} {}'.format(*args)
+ return msg
+
+class convolutional(BaseOp):
+ def forward(self):
+ pad = [[self.lay.pad, self.lay.pad]] * 2;
+ temp = tf.pad(self.inp.out, [[0, 0]] + pad + [[0, 0]])
+ temp = tf.nn.conv2d(temp, self.lay.w['kernel'], padding = 'VALID',
+ name = self.scope, strides = [1] + [self.lay.stride] * 2 + [1])
+ if self.lay.batch_norm:
+ temp = self.batchnorm(self.lay, temp)
+ self.out = tf.nn.bias_add(temp, self.lay.w['biases'])
+
+ def batchnorm(self, layer, inp):
+ if not self.var:
+ temp = (inp - layer.w['moving_mean'])
+ temp /= (np.sqrt(layer.w['moving_variance']) + 1e-5)
+ temp *= layer.w['gamma']
+ return temp
+ else:
+ args = dict({
+ 'center' : False, 'scale' : True,
+ 'epsilon': 1e-5, 'scope' : self.scope,
+ 'updates_collections' : None,
+ 'is_training': layer.h['is_training']
+ })
+ v = tf.__version__.split('.')[1]
+ if int(v) < 12: key = 'initializers'
+ else: key = 'param_initializers'
+ args.update({key : layer.w})
+ return slim.batch_norm(inp, **args)
+
+ def speak(self):
+ l = self.lay
+ args = [l.ksize] * 2 + [l.pad] + [l.stride]
+ args += [l.batch_norm * '+bnorm']
+ args += [l.activation]
+ msg = 'conv {}x{}p{}_{} {} {}'.format(*args)
+ return msg
+
+class conv_select(convolutional):
+ def speak(self):
+ l = self.lay
+ args = [l.ksize] * 2 + [l.pad] + [l.stride]
+ args += [l.batch_norm * '+bnorm']
+ args += [l.activation]
+ msg = 'sele {}x{}p{}_{} {} {}'.format(*args)
+ return msg
+
+class conv_extract(convolutional):
+ def speak(self):
+ l = self.lay
+ args = [l.ksize] * 2 + [l.pad] + [l.stride]
+ args += [l.batch_norm * '+bnorm']
+ args += [l.activation]
+ msg = 'extr {}x{}p{}_{} {} {}'.format(*args)
+ return msg
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/ops/simple.py b/vehicle-detection/darkflow/net/ops/simple.py
new file mode 100644
index 0000000..ea41228
--- /dev/null
+++ b/vehicle-detection/darkflow/net/ops/simple.py
@@ -0,0 +1,130 @@
+import tensorflow.contrib.slim as slim
+from .baseop import BaseOp
+import tensorflow as tf
+
+class route(BaseOp):
+ def forward(self):
+ routes = self.lay.routes
+ routes_out = list()
+ for r in routes:
+ this = self.inp
+ while this.lay.number != r:
+ this = this.inp
+ assert this is not None, \
+ 'Routing to non-existence {}'.format(r)
+ routes_out += [this.out]
+ self.out = tf.concat(3, routes_out)
+
+ def speak(self):
+ msg = 'concat {}'
+ return msg.format(self.lay.routes)
+
+class connected(BaseOp):
+ def forward(self):
+ self.out = tf.nn.xw_plus_b(
+ self.inp.out,
+ self.lay.w['weights'],
+ self.lay.w['biases'],
+ name = self.scope)
+
+ def speak(self):
+ layer = self.lay
+ args = [layer.inp, layer.out]
+ args += [layer.activation]
+ msg = 'full {} x {} {}'
+ return msg.format(*args)
+
+class select(connected):
+ """a weird connected layer"""
+ def speak(self):
+ layer = self.lay
+ args = [layer.inp, layer.out]
+ args += [layer.activation]
+ msg = 'sele {} x {} {}'
+ return msg.format(*args)
+
+class extract(connected):
+ """a weird connected layer"""
+ def speak(self):
+ layer = self.lay
+ args = [len(layer.inp), len(layer.out)]
+ args += [layer.activation]
+ msg = 'extr {} x {} {}'
+ return msg.format(*args)
+
+class flatten(BaseOp):
+ def forward(self):
+ temp = tf.transpose(
+ self.inp.out, [0,3,1,2])
+ self.out = slim.flatten(
+ temp, scope = self.scope)
+
+ def speak(self): return 'flat'
+
+
+class softmax(BaseOp):
+ def forward(self):
+ self.out = tf.nn.softmax(self.inp.out)
+
+ def speak(self): return 'softmax()'
+
+
+class avgpool(BaseOp):
+ def forward(self):
+ self.out = tf.reduce_mean(
+ self.inp.out, [1, 2],
+ name = self.scope
+ )
+
+ def speak(self): return 'avgpool()'
+
+
+class dropout(BaseOp):
+ def forward(self):
+ self.out = tf.nn.dropout(
+ self.inp.out,
+ self.lay.h['pdrop'],
+ name = self.scope
+ )
+
+ def speak(self): return 'drop'
+
+
+class crop(BaseOp):
+ def forward(self):
+ self.out = self.inp.out * 2. - 1.
+
+ def speak(self):
+ return 'scale to (-1, 1)'
+
+
+class maxpool(BaseOp):
+ def forward(self):
+ self.out = tf.nn.max_pool(
+ self.inp.out, padding = 'SAME',
+ ksize = [1] + [self.lay.ksize]*2 + [1],
+ strides = [1] + [self.lay.stride]*2 + [1],
+ name = self.scope
+ )
+
+ def speak(self):
+ l = self.lay
+ return 'maxp {}x{}p{}_{}'.format(
+ l.ksize, l.ksize, l.pad, l.stride)
+
+
+class leaky(BaseOp):
+ def forward(self):
+ self.out = tf.maximum(
+ .1 * self.inp.out,
+ self.inp.out,
+ name = self.scope
+ )
+
+ def verbalise(self): pass
+
+
+class identity(BaseOp):
+ def __init__(self, inp):
+ self.inp = None
+ self.out = inp
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/vanilla/__init__.py b/vehicle-detection/darkflow/net/vanilla/__init__.py
new file mode 100644
index 0000000..b189372
--- /dev/null
+++ b/vehicle-detection/darkflow/net/vanilla/__init__.py
@@ -0,0 +1,4 @@
+from . import train
+
+def constructor(self, meta, FLAGS):
+ self.meta, self.FLAGS = meta, FLAGS
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/vanilla/train.py b/vehicle-detection/darkflow/net/vanilla/train.py
new file mode 100644
index 0000000..1864a65
--- /dev/null
+++ b/vehicle-detection/darkflow/net/vanilla/train.py
@@ -0,0 +1,42 @@
+_LOSS_TYPE = ['sse','l2', 'smooth',
+ 'sparse', 'l1', 'softmax',
+ 'svm', 'fisher']
+
+def loss(self, net_out):
+ m = self.meta
+ loss_type = self.meta['type']
+ assert loss_type in _LOSS_TYPE, \
+ 'Loss type {} not implemented'.format(loss_type)
+
+ out = net_out
+ out_shape = out.get_shape()
+ out_dtype = out.dtype.base_dtype
+ _truth = tf.placeholders(out_dtype, out_shape)
+
+ self.placeholders = dict({
+ 'truth': _truth
+ })
+
+ diff = _truth - out
+ if loss_type in ['sse','12']:
+ loss = tf.nn.l2_loss(diff)
+
+ elif loss_type == ['smooth']:
+ small = tf.cast(diff < 1, tf.float32)
+ large = 1. - small
+ l1_loss = tf.nn.l1_loss(tf.mul(diff, large))
+ l2_loss = tf.nn.l2_loss(tf.mul(diff, small))
+ loss = l1_loss + l2_loss
+
+ elif loss_type in ['sparse', 'l1']:
+ loss = l1_loss(diff)
+
+ elif loss_type == 'softmax':
+ loss = tf.nn.softmax_cross_entropy_with_logits(logits, y)
+ loss = tf.reduce_mean(loss)
+
+ elif loss_type == 'svm':
+ assert 'train_size' in m, \
+ 'Must specify'
+ size = m['train_size']
+ self.nu = tf.Variable(tf.ones([train_size, num_classes]))
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/yolo/__init__.py b/vehicle-detection/darkflow/net/yolo/__init__.py
new file mode 100644
index 0000000..82db3ff
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolo/__init__.py
@@ -0,0 +1,31 @@
+from . import train
+from . import test
+from . import data
+from . import misc
+import numpy as np
+
+
+""" YOLO framework __init__ equivalent"""
+
+def constructor(self, meta, FLAGS):
+
+ def _to_color(indx, base):
+ """ return (b, r, g) tuple"""
+ base2 = base * base
+ b = 2 - indx / base2
+ r = 2 - (indx % base2) / base
+ g = 2 - (indx % base2) % base
+ return (b * 127, r * 127, g * 127)
+
+ misc.labels(meta)
+ assert len(meta['labels']) == meta['classes'], (
+ 'labels.txt and {} indicate' + ' '
+ 'inconsistent class numbers'
+ ).format(meta['model'])
+ colors = list()
+ base = int(np.ceil(pow(meta['classes'], 1./3)))
+ for x in range(len(meta['labels'])):
+ colors += [_to_color(x, base)]
+ meta['colors'] = colors
+ self.fetch = list()
+ self.meta, self.FLAGS = meta, FLAGS
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/net/yolo/data.py b/vehicle-detection/darkflow/net/yolo/data.py
new file mode 100644
index 0000000..39047f1
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolo/data.py
@@ -0,0 +1,166 @@
+from utils.pascal_voc_clean_xml import pascal_voc_clean_xml
+from utils.udacity_voc_csv import udacity_voc_csv
+from numpy.random import permutation as perm
+from .test import preprocess
+# from .misc import show
+from copy import deepcopy
+import pickle
+import numpy as np
+import os
+
+def parse(self, exclusive = False):
+ """
+ Decide whether to parse the annotation or not,
+ If the parsed file is not already there, parse.
+ """
+ meta = self.meta
+ ext = '.parsed'
+ history = os.path.join('net', 'yolo', 'parse-history.txt');
+ if not os.path.isfile(history):
+ file = open(history, 'w')
+ file.close()
+ with open(history, 'r') as f:
+ lines = f.readlines()
+ for line in lines:
+ line = line.strip().split(' ')
+ labels = line[1:]
+ if labels == meta['labels']:
+ if os.path.isfile(line[0]):
+ with open(line[0], 'rb') as f:
+ return pickle.load(f, encoding = 'latin1')[0]
+ #return pickle.load(f)[0]
+
+ # actual parsing
+ ann = self.FLAGS.annotation
+ if not os.path.isdir(ann):
+ msg = 'Annotation directory not found {} .'
+ exit('Error: {}'.format(msg.format(ann)))
+ print('\n{} parsing {}'.format(meta['model'], ann))
+ #dumps = pascal_voc_clean_xml(ann, meta['labels'], exclusive)
+ dumps = udacity_voc_csv(ann, meta['labels'], exclusive)
+
+ save_to = os.path.join('net', 'yolo', meta['name'])
+ while True:
+ if not os.path.isfile(save_to + ext): break
+ save_to = save_to + '_'
+ save_to += ext
+
+ with open(save_to, 'wb') as f:
+ pickle.dump([dumps], f, protocol = -1)
+ with open(history, 'a') as f:
+ f.write('{} '.format(save_to))
+ f.write(' '.join(meta['labels']))
+ f.write('\n')
+ print('Result saved to {}'.format(save_to))
+ return dumps
+
+
+def _batch(self, chunk):
+ """
+ Takes a chunk of parsed annotations
+ returns value for placeholders of net's
+ input & loss layer correspond to this chunk
+ """
+ meta = self.meta
+ S, B = meta['side'], meta['num']
+ C, labels = meta['classes'], meta['labels']
+
+ # preprocess
+ jpg = chunk[0]; w, h, allobj_ = chunk[1]
+ allobj = deepcopy(allobj_)
+ path = os.path.join(self.FLAGS.dataset, jpg)
+ img = self.preprocess(path, allobj)
+
+ # Calculate regression target
+ cellx = 1. * w / S
+ celly = 1. * h / S
+ for obj in allobj:
+ centerx = .5*(obj[1]+obj[3]) #xmin, xmax
+ centery = .5*(obj[2]+obj[4]) #ymin, ymax
+ cx = centerx / cellx
+ cy = centery / celly
+ if cx >= S or cy >= S: return None, None
+ obj[3] = float(obj[3]-obj[1]) / w
+ obj[4] = float(obj[4]-obj[2]) / h
+ obj[3] = np.sqrt(obj[3])
+ obj[4] = np.sqrt(obj[4])
+ obj[1] = cx - np.floor(cx) # centerx
+ obj[2] = cy - np.floor(cy) # centery
+ obj += [int(np.floor(cy) * S + np.floor(cx))]
+
+ # show(img, allobj, S, 448, 448, 448./S, 448./S) # unit test
+
+ # Calculate placeholders' values
+ probs = np.zeros([S*S,C])
+ confs = np.zeros([S*S,B])
+ coord = np.zeros([S*S,B,4])
+ proid = np.zeros([S*S,C])
+ prear = np.zeros([S*S,4])
+ for obj in allobj:
+ probs[obj[5], :] = [0.] * C
+ probs[obj[5], labels.index(obj[0])] = 1.
+ proid[obj[5], :] = [1] * C
+ coord[obj[5], :, :] = [obj[1:5]] * B
+ prear[obj[5],0] = obj[1] - obj[3]**2 * .5 * S # xleft
+ prear[obj[5],1] = obj[2] - obj[4]**2 * .5 * S # yup
+ prear[obj[5],2] = obj[1] + obj[3]**2 * .5 * S # xright
+ prear[obj[5],3] = obj[2] + obj[4]**2 * .5 * S # ybot
+ confs[obj[5], :] = [1.] * B
+
+ # Finalise the placeholders' values
+ upleft = np.expand_dims(prear[:,0:2], 1)
+ botright = np.expand_dims(prear[:,2:4], 1)
+ wh = botright - upleft;
+ area = wh[:,:,0] * wh[:,:,1]
+ upleft = np.concatenate([upleft] * B, 1)
+ botright = np.concatenate([botright] * B, 1)
+ areas = np.concatenate([area] * B, 1)
+
+ # value for placeholder at input layer
+ inp_feed_val = img
+ # value for placeholder at loss layer
+ loss_feed_val = {
+ 'probs': probs, 'confs': confs,
+ 'coord': coord, 'proid': proid,
+ 'areas': areas, 'upleft': upleft,
+ 'botright': botright
+ }
+
+ return inp_feed_val, loss_feed_val
+
+def shuffle(self):
+ batch = self.FLAGS.batch
+ data = self.parse()
+ size = len(data)
+
+ print('Dataset of {} instance(s)'.format(size))
+ if batch > size: self.FLAGS.batch = batch = size
+ batch_per_epoch = int(size / batch)
+
+ for i in range(self.FLAGS.epoch):
+ shuffle_idx = perm(np.arange(size))
+ for b in range(batch_per_epoch):
+ # yield these
+ x_batch = list()
+ feed_batch = dict()
+
+ for j in range(b*batch, b*batch+batch):
+ train_instance = data[shuffle_idx[j]]
+ inp, new_feed = self._batch(train_instance)
+
+ if inp is None: continue
+ x_batch += [np.expand_dims(inp, 0)]
+
+ for key in new_feed:
+ new = new_feed[key]
+ old_feed = feed_batch.get(key,
+ np.zeros((0,) + new.shape))
+ feed_batch[key] = np.concatenate([
+ old_feed, [new]
+ ])
+
+ x_batch = np.concatenate(x_batch, 0)
+ yield x_batch, feed_batch
+
+ print('Finish {} epoch(es)'.format(i + 1))
+
diff --git a/vehicle-detection/darkflow/net/yolo/misc.py b/vehicle-detection/darkflow/net/yolo/misc.py
new file mode 100644
index 0000000..e4ad6c1
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolo/misc.py
@@ -0,0 +1,124 @@
+import pickle
+import numpy as np
+import cv2
+import os
+
+labels20 = ["aeroplane", "bicycle", "bird", "boat", "bottle",
+ "bus", "car", "cat", "chair", "cow", "diningtable", "dog",
+ "horse", "motorbike", "person", "pottedplant", "sheep", "sofa",
+ "train", "tvmonitor"]
+
+# 8, 14, 15, 19
+
+voc_models = ['yolo-full', 'yolo-tiny', 'yolo-small', # <- v1
+ 'yolov1', 'tiny-yolov1', # <- v1.1
+ 'tiny-yolo-voc', 'yolo-voc'] # <- v2
+
+coco_models = ['tiny-coco', 'yolo-coco', # <- v1.1
+ 'yolo', 'tiny-yolo'] # <- v2
+
+coco_names = 'coco.names'
+
+def labels(meta):
+ model = meta['name']
+ if model in voc_models:
+ meta['labels'] = labels20
+ else:
+ file = 'labels.txt'
+ if model in coco_models:
+ file = os.path.join('cfg',coco_names)
+ with open(file, 'r') as f:
+ meta['labels'] = list()
+ labs = [l.strip() for l in f.readlines()]
+ for lab in labs:
+ if lab == '----': break
+ meta['labels'] += [lab]
+ if len(meta['labels']) == 0:
+ meta['labels'] = labels20
+
+def is_inp(self, name):
+ return name[-4:] in ['.jpg','.JPG', '.jpeg', '.JPEG']
+
+def show(im, allobj, S, w, h, cellx, celly):
+ for obj in allobj:
+ a = obj[5] % S
+ b = obj[5] // S
+ cx = a + obj[1]
+ cy = b + obj[2]
+ centerx = cx * cellx
+ centery = cy * celly
+ ww = obj[3]**2 * w
+ hh = obj[4]**2 * h
+ cv2.rectangle(im,
+ (int(centerx - ww/2), int(centery - hh/2)),
+ (int(centerx + ww/2), int(centery + hh/2)),
+ (0,0,255), 2)
+ cv2.imshow("result", im)
+ cv2.waitKey()
+ cv2.destroyAllWindows()
+
+def show2(im, allobj):
+ for obj in allobj:
+ cv2.rectangle(im,
+ (obj[1], obj[2]),
+ (obj[3], obj[4]),
+ (0,0,255),2)
+ cv2.imshow('result', im)
+ cv2.waitKey()
+ cv2.destroyAllWindows()
+
+
+_MVA = .05
+
+def profile(self, net):
+ pass
+# data = self.parse(exclusive = True)
+# size = len(data); batch = self.FLAGS.batch
+# all_inp_ = [x[0] for x in data]
+# net.say('Will cycle through {} examples {} times'.format(
+# len(all_inp_), net.FLAGS.epoch))
+
+# fetch = list(); mvave = list(); names = list();
+# this = net.top
+# conv_lay = ['convolutional', 'connected', 'local', 'conv-select']
+# while this.inp is not None:
+# if this.lay.type in conv_lay:
+# fetch = [this.out] + fetch
+# names = [this.lay.signature] + names
+# mvave = [None] + mvave
+# this = this.inp
+# print(names)
+
+# total = int(); allofthem = len(all_inp_) * net.FLAGS.epoch
+# batch = min(net.FLAGS.batch, len(all_inp_))
+# for count in range(net.FLAGS.epoch):
+# net.say('EPOCH {}'.format(count))
+# for j in range(len(all_inp_)/batch):
+# inp_feed = list(); new_all = list()
+# all_inp = all_inp_[j*batch: (j*batch+batch)]
+# for inp in all_inp:
+# new_all += [inp]
+# this_inp = os.path.join(net.FLAGS.dataset, inp)
+# this_inp = net.framework.preprocess(this_inp)
+# expanded = np.expand_dims(this_inp, 0)
+# inp_feed.append(expanded)
+# all_inp = new_all
+# feed_dict = {net.inp : np.concatenate(inp_feed, 0)}
+# out = net.sess.run(fetch, feed_dict)
+
+# for i, o in enumerate(out):
+# oi = out[i];
+# dim = len(oi.shape) - 1
+# ai = mvave[i];
+# mi = np.mean(oi, tuple(range(dim)))
+# vi = np.var(oi, tuple(range(dim)))
+# if ai is None: mvave[i] = [mi, vi]
+# elif 'banana ninja yada yada':
+# ai[0] = (1 - _MVA) * ai[0] + _MVA * mi
+# ai[1] = (1 - _MVA) * ai[1] + _MVA * vi
+# total += len(inp_feed)
+# net.say('{} / {} = {}%'.format(
+# total, allofthem, 100. * total / allofthem))
+
+# with open('profile', 'wb') as f:
+# pickle.dump([mvave], f, protocol = -1)
diff --git a/vehicle-detection/darkflow/net/yolo/test.py b/vehicle-detection/darkflow/net/yolo/test.py
new file mode 100644
index 0000000..100164b
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolo/test.py
@@ -0,0 +1,128 @@
+from utils.im_transform import imcv2_recolor, imcv2_affine_trans
+from utils.box import BoundBox, box_iou, prob_compare
+import numpy as np
+import cv2
+import os
+
+def _fix(obj, dims, scale, offs):
+ for i in range(1, 5):
+ dim = dims[(i + 1) % 2]
+ off = offs[(i + 1) % 2]
+ obj[i] = int(obj[i] * scale - off)
+ obj[i] = max(min(obj[i], dim), 0)
+
+def preprocess(self, im, allobj = None):
+ """
+ Takes an image, return it as a numpy tensor that is readily
+ to be fed into tfnet. If there is an accompanied annotation (allobj),
+ meaning this preprocessing is serving the train process, then this
+ image will be transformed with random noise to augment training data,
+ using scale, translation, flipping and recolor. The accompanied
+ parsed annotation (allobj) will also be modified accordingly.
+ """
+ if type(im) is not np.ndarray:
+ im = cv2.imread(im)
+
+ if allobj is not None: # in training mode
+ result = imcv2_affine_trans(im)
+ im, dims, trans_param = result
+ scale, offs, flip = trans_param
+ for obj in allobj:
+ _fix(obj, dims, scale, offs)
+ if not flip: continue
+ obj_1_ = obj[1]
+ obj[1] = dims[0] - obj[3]
+ obj[3] = dims[0] - obj_1_
+ im = imcv2_recolor(im)
+
+ h, w, c = self.meta['inp_size']
+ imsz = cv2.resize(im, (h, w))
+ imsz = imsz / 255.
+ imsz = imsz[:,:,::-1]
+ if allobj is None: return imsz
+ return imsz#, np.array(im) # for unit testing
+
+_thresh = dict({
+ 'person': .2,
+ 'pottedplant': .1,
+ 'chair': .12,
+ 'tvmonitor': .13
+})
+
+def postprocess(self, net_out, im, save = True):
+ """
+ Takes net output, draw predictions, save to disk
+ """
+ meta, FLAGS = self.meta, self.FLAGS
+ threshold, sqrt = FLAGS.threshold, meta['sqrt'] + 1
+ C, B, S = meta['classes'], meta['num'], meta['side']
+ colors, labels = meta['colors'], meta['labels']
+
+ boxes = []
+ SS = S * S # number of grid cells
+ prob_size = SS * C # class probabilities
+ conf_size = SS * B # confidences for each grid cell
+ #net_out = net_out[0]
+ probs = net_out[0 : prob_size]
+ confs = net_out[prob_size : (prob_size + conf_size)]
+ cords = net_out[(prob_size + conf_size) : ]
+ probs = probs.reshape([SS, C])
+ confs = confs.reshape([SS, B])
+ cords = cords.reshape([SS, B, 4])
+
+ for grid in range(SS):
+ for b in range(B):
+ bx = BoundBox(C)
+ bx.c = confs[grid, b]
+ bx.x = (cords[grid, b, 0] + grid % S) / S
+ bx.y = (cords[grid, b, 1] + grid // S) / S
+ bx.w = cords[grid, b, 2] ** sqrt
+ bx.h = cords[grid, b, 3] ** sqrt
+ p = probs[grid, :] * bx.c
+ p *= (p > threshold)
+ bx.probs = p
+ boxes.append(bx)
+
+ # non max suppress boxes
+ for c in range(C):
+ for i in range(len(boxes)): boxes[i].class_num = c
+ boxes = sorted(boxes, key = prob_compare)
+ for i in range(len(boxes)):
+ boxi = boxes[i]
+ if boxi.probs[c] == 0: continue
+ for j in range(i + 1, len(boxes)):
+ boxj = boxes[j]
+ if box_iou(boxi, boxj) >= .4:
+ boxes[j].probs[c] = 0.
+
+ if type(im) is not np.ndarray:
+ imgcv = cv2.imread(im)
+ else: imgcv = im
+ h, w, _ = imgcv.shape
+ for b in boxes:
+ max_indx = np.argmax(b.probs)
+ max_prob = b.probs[max_indx]
+ label = self.meta['labels'][max_indx]
+ if max_prob > _thresh.get(label,threshold):
+ left = int ((b.x - b.w/2.) * w)
+ right = int ((b.x + b.w/2.) * w)
+ top = int ((b.y - b.h/2.) * h)
+ bot = int ((b.y + b.h/2.) * h)
+ if left < 0 : left = 0
+ if right > w - 1: right = w - 1
+ if top < 0 : top = 0
+ if bot > h - 1: bot = h - 1
+ thick = int((h + w) // 150)
+ cv2.rectangle(imgcv,
+ (left, top), (right, bot),
+ self.meta['colors'][max_indx], thick)
+ mess = '{}'.format(label)
+ cv2.putText(
+ imgcv, mess, (left, top - 12),
+ 0, 1e-3 * h, self.meta['colors'][max_indx],
+ thick // 3)
+
+ if not save: return imgcv
+ outfolder = os.path.join(FLAGS.test, 'out')
+ img_name = os.path.join(outfolder, im.split('/')[-1])
+ cv2.imwrite(img_name, imgcv)
diff --git a/vehicle-detection/darkflow/net/yolo/train.py b/vehicle-detection/darkflow/net/yolo/train.py
new file mode 100644
index 0000000..539ac5d
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolo/train.py
@@ -0,0 +1,92 @@
+import tensorflow.contrib.slim as slim
+import pickle
+import tensorflow as tf
+from .misc import show
+import numpy as np
+import os
+
+def loss(self, net_out):
+ """
+ Takes net.out and placeholders value
+ returned in batch() func above,
+ to build train_op and loss
+ """
+ # meta
+ m = self.meta
+ sprob = float(m['class_scale'])
+ sconf = float(m['object_scale'])
+ snoob = float(m['noobject_scale'])
+ scoor = float(m['coord_scale'])
+ S, B, C = m['side'], m['num'], m['classes']
+ SS = S * S # number of grid cells
+
+ print('{} loss hyper-parameters:'.format(m['model']))
+ print('\tside = {}'.format(m['side']))
+ print('\tbox = {}'.format(m['num']))
+ print('\tclasses = {}'.format(m['classes']))
+ print('\tscales = {}'.format([sprob, sconf, snoob, scoor]))
+
+ size1 = [None, SS, C]
+ size2 = [None, SS, B]
+
+ # return the below placeholders
+ _probs = tf.placeholder(tf.float32, size1)
+ _confs = tf.placeholder(tf.float32, size2)
+ _coord = tf.placeholder(tf.float32, size2 + [4])
+ # weights term for L2 loss
+ _proid = tf.placeholder(tf.float32, size1)
+ # material calculating IOU
+ _areas = tf.placeholder(tf.float32, size2)
+ _upleft = tf.placeholder(tf.float32, size2 + [2])
+ _botright = tf.placeholder(tf.float32, size2 + [2])
+
+ self.placeholders = {
+ 'probs':_probs, 'confs':_confs, 'coord':_coord, 'proid':_proid,
+ 'areas':_areas, 'upleft':_upleft, 'botright':_botright
+ }
+
+ # Extract the coordinate prediction from net.out
+ coords = net_out[:, SS * (C + B):]
+ coords = tf.reshape(coords, [-1, SS, B, 4])
+ wh = tf.pow(coords[:,:,:,2:4], 2) * S # unit: grid cell
+ area_pred = wh[:,:,:,0] * wh[:,:,:,1] # unit: grid cell^2
+ centers = coords[:,:,:,0:2] # [batch, SS, B, 2]
+ floor = centers - (wh * .5) # [batch, SS, B, 2]
+ ceil = centers + (wh * .5) # [batch, SS, B, 2]
+
+ # calculate the intersection areas
+ intersect_upleft = tf.maximum(floor, _upleft)
+ intersect_botright = tf.minimum(ceil , _botright)
+ intersect_wh = intersect_botright - intersect_upleft
+ intersect_wh = tf.maximum(intersect_wh, 0.0)
+ intersect = tf.mul(intersect_wh[:,:,:,0], intersect_wh[:,:,:,1])
+
+ # calculate the best IOU, set 0.0 confidence for worse boxes
+ iou = tf.truediv(intersect, _areas + area_pred - intersect)
+ best_box = tf.equal(iou, tf.reduce_max(iou, [2], True))
+ best_box = tf.to_float(best_box)
+ confs = tf.mul(best_box, _confs)
+
+ # take care of the weight terms
+ conid = snoob * (1. - confs) + sconf * confs
+ weight_coo = tf.concat(3, 4 * [tf.expand_dims(confs, -1)])
+ cooid = scoor * weight_coo
+ proid = sprob * _proid
+
+ # flatten 'em all
+ probs = slim.flatten(_probs)
+ proid = slim.flatten(proid)
+ confs = slim.flatten(confs)
+ conid = slim.flatten(conid)
+ coord = slim.flatten(_coord)
+ cooid = slim.flatten(cooid)
+
+ self.fetch += [probs, confs, conid, cooid, proid]
+ true = tf.concat(1, [probs, confs, coord])
+ wght = tf.concat(1, [proid, conid, cooid])
+
+ print('Building {} loss'.format(m['model']))
+ loss = tf.pow(net_out - true, 2)
+ loss = tf.mul(loss, wght)
+ loss = tf.reduce_sum(loss, 1)
+ self.loss = .5 * tf.reduce_mean(loss)
diff --git a/vehicle-detection/darkflow/net/yolov2/__init__.py b/vehicle-detection/darkflow/net/yolov2/__init__.py
new file mode 100644
index 0000000..9b1c58b
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolov2/__init__.py
@@ -0,0 +1,5 @@
+from . import train
+from . import test
+from . import data
+from ..yolo import misc
+import numpy as np
diff --git a/vehicle-detection/darkflow/net/yolov2/data.py b/vehicle-detection/darkflow/net/yolov2/data.py
new file mode 100644
index 0000000..1cfc390
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolov2/data.py
@@ -0,0 +1,85 @@
+from utils.pascal_voc_clean_xml import pascal_voc_clean_xml
+from numpy.random import permutation as perm
+from ..yolo.test import preprocess
+from ..yolo.data import shuffle
+from copy import deepcopy
+import pickle
+import numpy as np
+import os
+
+def _batch(self, chunk):
+ """
+ Takes a chunk of parsed annotations
+ returns value for placeholders of net's
+ input & loss layer correspond to this chunk
+ """
+ meta = self.meta
+ labels = meta['labels']
+
+ H, W, _ = meta['out_size']
+ C, B = meta['classes'], meta['num']
+ anchors = meta['anchors']
+
+ # preprocess
+ jpg = chunk[0]; w, h, allobj_ = chunk[1]
+ allobj = deepcopy(allobj_)
+ path = os.path.join(self.FLAGS.dataset, jpg)
+ img = self.preprocess(path, allobj)
+
+ # Calculate regression target
+ cellx = 1. * w / W
+ celly = 1. * h / H
+ for obj in allobj:
+ centerx = .5*(obj[1]+obj[3]) #xmin, xmax
+ centery = .5*(obj[2]+obj[4]) #ymin, ymax
+ cx = centerx / cellx
+ cy = centery / celly
+ if cx >= W or cy >= H: return None, None
+ obj[3] = float(obj[3]-obj[1]) / w
+ obj[4] = float(obj[4]-obj[2]) / h
+ obj[3] = np.sqrt(obj[3])
+ obj[4] = np.sqrt(obj[4])
+ obj[1] = cx - np.floor(cx) # centerx
+ obj[2] = cy - np.floor(cy) # centery
+ obj += [int(np.floor(cy) * W + np.floor(cx))]
+
+ #show(im, allobj, S, w, h, cellx, celly) # unit test
+
+ # Calculate placeholders' values
+ probs = np.zeros([H*W,B,C])
+ confs = np.zeros([H*W,B])
+ coord = np.zeros([H*W,B,4])
+ proid = np.zeros([H*W,B,C])
+ prear = np.zeros([H*W,4])
+ for obj in allobj:
+ probs[obj[5], :, :] = [[0.]*C] * B
+ probs[obj[5], :, labels.index(obj[0])] = 1.
+ proid[obj[5], :, :] = [[1.]*C] * B
+ coord[obj[5], :, :] = [obj[1:5]] * B
+ prear[obj[5],0] = obj[1] - obj[3]**2 * .5 * W # xleft
+ prear[obj[5],1] = obj[2] - obj[4]**2 * .5 * H # yup
+ prear[obj[5],2] = obj[1] + obj[3]**2 * .5 * W # xright
+ prear[obj[5],3] = obj[2] + obj[4]**2 * .5 * H # ybot
+ confs[obj[5], :] = [1.] * B
+
+ # Finalise the placeholders' values
+ upleft = np.expand_dims(prear[:,0:2], 1)
+ botright = np.expand_dims(prear[:,2:4], 1)
+ wh = botright - upleft;
+ area = wh[:,:,0] * wh[:,:,1]
+ upleft = np.concatenate([upleft] * B, 1)
+ botright = np.concatenate([botright] * B, 1)
+ areas = np.concatenate([area] * B, 1)
+
+ # value for placeholder at input layer
+ inp_feed_val = img
+ # value for placeholder at loss layer
+ loss_feed_val = {
+ 'probs': probs, 'confs': confs,
+ 'coord': coord, 'proid': proid,
+ 'areas': areas, 'upleft': upleft,
+ 'botright': botright
+ }
+
+ return inp_feed_val, loss_feed_val
+
diff --git a/vehicle-detection/darkflow/net/yolov2/test.py b/vehicle-detection/darkflow/net/yolov2/test.py
new file mode 100644
index 0000000..4664d3c
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolov2/test.py
@@ -0,0 +1,97 @@
+import numpy as np
+import math
+import cv2
+import os
+#from scipy.special import expit
+from utils.box import BoundBox, box_iou, prob_compare
+from utils.box import prob_compare2, box_intersection
+
+_thresh = dict({
+ 'person': .2,
+ 'pottedplant': .1,
+ 'chair': .12,
+ 'tvmonitor': .13
+})
+
+def expit(x):
+ return 1. / (1. + np.exp(-x))
+
+def _softmax(x):
+ e_x = np.exp(x - np.max(x))
+ out = e_x / e_x.sum()
+ return out
+
+def postprocess(self, net_out, im, save = True):
+ """
+ Takes net output, draw net_out, save to disk
+ """
+ # meta
+ meta = self.meta
+ H, W, _ = meta['out_size']
+ threshold = meta['thresh']
+ C, B = meta['classes'], meta['num']
+ anchors = meta['anchors']
+ net_out = net_out.reshape([H, W, B, -1])
+
+ boxes = list()
+ for row in range(H):
+ for col in range(W):
+ for b in range(B):
+ bx = BoundBox(C)
+ bx.x, bx.y, bx.w, bx.h, bx.c = net_out[row, col, b, :5]
+ bx.c = expit(bx.c)
+ bx.x = (col + expit(bx.x)) / W
+ bx.y = (row + expit(bx.y)) / H
+ bx.w = math.exp(bx.w) * anchors[2 * b + 0] / W
+ bx.h = math.exp(bx.h) * anchors[2 * b + 1] / H
+ classes = net_out[row, col, b, 5:]
+ bx.probs = _softmax(classes) * bx.c
+ bx.probs *= bx.probs > threshold
+ boxes.append(bx)
+
+ # non max suppress boxes
+ for c in range(C):
+ for i in range(len(boxes)):
+ boxes[i].class_num = c
+ boxes = sorted(boxes, key = prob_compare)
+ for i in range(len(boxes)):
+ boxi = boxes[i]
+ if boxi.probs[c] == 0: continue
+ for j in range(i + 1, len(boxes)):
+ boxj = boxes[j]
+ if box_iou(boxi, boxj) >= .4:
+ boxes[j].probs[c] = 0.
+
+
+ colors = meta['colors']
+ labels = meta['labels']
+ if type(im) is not np.ndarray:
+ imgcv = cv2.imread(im)
+ else: imgcv = im
+ h, w, _ = imgcv.shape
+ for b in boxes:
+ max_indx = np.argmax(b.probs)
+ max_prob = b.probs[max_indx]
+ label = 'object' * int(C < 2)
+ label += labels[max_indx] * int(C>1)
+ if max_prob > threshold:
+ left = int ((b.x - b.w/2.) * w)
+ right = int ((b.x + b.w/2.) * w)
+ top = int ((b.y - b.h/2.) * h)
+ bot = int ((b.y + b.h/2.) * h)
+ if left < 0 : left = 0
+ if right > w - 1: right = w - 1
+ if top < 0 : top = 0
+ if bot > h - 1: bot = h - 1
+ thick = int((h+w)/300)
+ cv2.rectangle(imgcv,
+ (left, top), (right, bot),
+ colors[max_indx], thick)
+ mess = '{}'.format(label)
+ cv2.putText(imgcv, mess, (left, top - 12),
+ 0, 1e-3 * h, colors[max_indx],thick//3)
+
+ if not save: return imgcv
+ outfolder = os.path.join(self.FLAGS.test, 'out')
+ img_name = os.path.join(outfolder, im.split('/')[-1])
+ cv2.imwrite(img_name, imgcv)
diff --git a/vehicle-detection/darkflow/net/yolov2/train.py b/vehicle-detection/darkflow/net/yolov2/train.py
new file mode 100644
index 0000000..7262db1
--- /dev/null
+++ b/vehicle-detection/darkflow/net/yolov2/train.py
@@ -0,0 +1,108 @@
+import tensorflow.contrib.slim as slim
+import pickle
+import tensorflow as tf
+from ..yolo.misc import show
+import numpy as np
+import os
+import math
+
+def expit_tensor(x):
+ return 1. / (1. + tf.exp(-x))
+
+def loss(self, net_out):
+ """
+ Takes net.out and placeholders value
+ returned in batch() func above,
+ to build train_op and loss
+ """
+ # meta
+ m = self.meta
+ sprob = float(m['class_scale'])
+ sconf = float(m['object_scale'])
+ snoob = float(m['noobject_scale'])
+ scoor = float(m['coord_scale'])
+ H, W, _ = m['out_size']
+ B, C = m['num'], m['classes']
+ HW = H * W # number of grid cells
+ anchors = m['anchors']
+
+ print('{} loss hyper-parameters:'.format(m['model']))
+ print('\tH = {}'.format(H))
+ print('\tW = {}'.format(W))
+ print('\tbox = {}'.format(m['num']))
+ print('\tclasses = {}'.format(m['classes']))
+ print('\tscales = {}'.format([sprob, sconf, snoob, scoor]))
+
+ size1 = [None, HW, B, C]
+ size2 = [None, HW, B]
+
+ # return the below placeholders
+ _probs = tf.placeholder(tf.float32, size1)
+ _confs = tf.placeholder(tf.float32, size2)
+ _coord = tf.placeholder(tf.float32, size2 + [4])
+ # weights term for L2 loss
+ _proid = tf.placeholder(tf.float32, size1)
+ # material calculating IOU
+ _areas = tf.placeholder(tf.float32, size2)
+ _upleft = tf.placeholder(tf.float32, size2 + [2])
+ _botright = tf.placeholder(tf.float32, size2 + [2])
+
+ self.placeholders = {
+ 'probs':_probs, 'confs':_confs, 'coord':_coord, 'proid':_proid,
+ 'areas':_areas, 'upleft':_upleft, 'botright':_botright
+ }
+
+ # Extract the coordinate prediction from net.out
+ net_out_reshape = tf.reshape(net_out, [-1, H, W, B, (4 + 1 + C)])
+ coords = net_out_reshape[:, :, :, :, :4]
+ coords = tf.reshape(coords, [-1, H*W, B, 4])
+ adjusted_coords_xy = expit_tensor(coords[:,:,:,0:2])
+ adjusted_coords_wh = tf.sqrt(tf.exp(coords[:,:,:,2:4]) * np.reshape(anchors, [1, 1, B, 2]) / np.reshape([W, H], [1, 1, 1, 2]))
+ coords = tf.concat(3, [adjusted_coords_xy, adjusted_coords_wh])
+
+ adjusted_c = expit_tensor(net_out_reshape[:, :, :, :, 4])
+ adjusted_c = tf.reshape(adjusted_c, [-1, H*W, B, 1])
+
+ adjusted_prob = tf.nn.softmax(net_out_reshape[:, :, :, :, 5:])
+ adjusted_prob = tf.reshape(adjusted_prob, [-1, H*W, B, C])
+
+ adjusted_net_out = tf.concat(3, [adjusted_coords_xy, adjusted_coords_wh, adjusted_c, adjusted_prob])
+
+ wh = tf.pow(coords[:,:,:,2:4], 2) * np.reshape([W, H], [1, 1, 1, 2])
+ area_pred = wh[:,:,:,0] * wh[:,:,:,1]
+ centers = coords[:,:,:,0:2]
+ floor = centers - (wh * .5)
+ ceil = centers + (wh * .5)
+
+ # calculate the intersection areas
+ intersect_upleft = tf.maximum(floor, _upleft)
+ intersect_botright = tf.minimum(ceil , _botright)
+ intersect_wh = intersect_botright - intersect_upleft
+ intersect_wh = tf.maximum(intersect_wh, 0.0)
+ intersect = tf.mul(intersect_wh[:,:,:,0], intersect_wh[:,:,:,1])
+
+ # calculate the best IOU, set 0.0 confidence for worse boxes
+ iou = tf.truediv(intersect, _areas + area_pred - intersect)
+ best_box = tf.equal(iou, tf.reduce_max(iou, [2], True))
+ best_box = tf.to_float(best_box)
+ confs = tf.mul(best_box, _confs)
+
+ # take care of the weight terms
+ conid = snoob * (1. - confs) + sconf * confs
+ weight_coo = tf.concat(3, 4 * [tf.expand_dims(confs, -1)])
+ cooid = scoor * weight_coo
+ weight_pro = tf.concat(3, C * [tf.expand_dims(confs, -1)])
+ proid = sprob * weight_pro
+
+ self.fetch += [_probs, confs, conid, cooid, proid]
+ true = tf.concat(3, [_coord, tf.expand_dims(confs, 3), _probs ])
+ wght = tf.concat(3, [cooid, tf.expand_dims(conid, 3), proid ])
+
+ print('Building {} loss'.format(m['model']))
+ loss = tf.pow(adjusted_net_out - true, 2)
+ loss = tf.mul(loss, wght)
+ loss = tf.reshape(loss, [-1, H*W*B*(4 + 1 + C)])
+ loss = tf.reduce_sum(loss, 1)
+ self.loss = .5 * tf.reduce_mean(loss)
+
+
diff --git a/vehicle-detection/darkflow/utils/__init__.py b/vehicle-detection/darkflow/utils/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/vehicle-detection/darkflow/utils/box.py b/vehicle-detection/darkflow/utils/box.py
new file mode 100644
index 0000000..5136647
--- /dev/null
+++ b/vehicle-detection/darkflow/utils/box.py
@@ -0,0 +1,44 @@
+import numpy as np
+
+class BoundBox:
+ def __init__(self, classes):
+ self.x, self.y = float(), float()
+ self.w, self.h = float(), float()
+ self.c = float()
+ self.class_num = classes
+ self.probs = np.zeros((classes,))
+
+def overlap(x1,w1,x2,w2):
+ l1 = x1 - w1 / 2.;
+ l2 = x2 - w2 / 2.;
+ left = max(l1, l2)
+ r1 = x1 + w1 / 2.;
+ r2 = x2 + w2 / 2.;
+ right = min(r1, r2)
+ return right - left;
+
+def box_intersection(a, b):
+ w = overlap(a.x, a.w, b.x, b.w);
+ h = overlap(a.y, a.h, b.y, b.h);
+ if w < 0 or h < 0: return 0;
+ area = w * h;
+ return area;
+
+def box_union(a, b):
+ i = box_intersection(a, b);
+ u = a.w * a.h + b.w * b.h - i;
+ return u;
+
+def box_iou(a, b):
+ return box_intersection(a, b) / box_union(a, b);
+
+def prob_compare(box):
+ return box.probs[box.class_num]
+
+def prob_compare2(boxa, boxb):
+ if (boxa.pi < boxb.pi):
+ return 1
+ elif(boxa.pi == boxb.pi):
+ return 0
+ else:
+ return -1
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/utils/im_transform.py b/vehicle-detection/darkflow/utils/im_transform.py
new file mode 100644
index 0000000..82b9461
--- /dev/null
+++ b/vehicle-detection/darkflow/utils/im_transform.py
@@ -0,0 +1,30 @@
+import numpy as np
+import cv2
+
+def imcv2_recolor(im, a = .1):
+ t = [np.random.uniform()]
+ t += [np.random.uniform()]
+ t += [np.random.uniform()]
+ t = np.array(t) * 2. - 1.
+
+ # random amplify each channel
+ im = im * (1 + t * a)
+ mx = 255. * (1 + a)
+ up = np.random.uniform() * 2 - 1
+ im = np.power(im/mx, 1. + up * .5)
+ return np.array(im * 255., np.uint8)
+
+def imcv2_affine_trans(im):
+ # Scale and translate
+ h, w, c = im.shape
+ scale = np.random.uniform() / 10. + 1.
+ max_offx = (scale-1.) * w
+ max_offy = (scale-1.) * h
+ offx = int(np.random.uniform() * max_offx)
+ offy = int(np.random.uniform() * max_offy)
+
+ im = cv2.resize(im, (0,0), fx = scale, fy = scale)
+ im = im[offy : (offy + h), offx : (offx + w)]
+ flip = np.random.binomial(1, .5)
+ if flip: im = cv2.flip(im, 1)
+ return im, [w, h, c], [scale, [offx, offy], flip]
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/utils/images_to_mp4.py b/vehicle-detection/darkflow/utils/images_to_mp4.py
new file mode 100644
index 0000000..dff1613
--- /dev/null
+++ b/vehicle-detection/darkflow/utils/images_to_mp4.py
@@ -0,0 +1,27 @@
+import cv2
+import argparse
+import numpy as np
+import glob, os
+
+
+def main(args):
+ fourcc = cv2.VideoWriter_fourcc('M','J','P','G')
+ writer = cv2.VideoWriter('/tmp/outpu.avi', fourcc, 10, (1920, 1200))
+ os.chdir(args.image_folder)
+ file_list = glob.glob("*.jpg")
+ sorted_files = sorted(file_list, key=lambda x: int(x.split('.')[0]))
+ for file in sorted_files:
+ print(file)
+ img = cv2.imread(file)
+ writer.write(img)
+
+ writer.release()
+
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description='Converts images in a directory to a mp4 for visualization')
+ parser.add_argument('-i', '--image_folder', help='Input image folder')
+ parser.add_argument('-d', '--decompress', default=False, type=bool, help='Decompress the images')
+ parser.add_argument('-o', '--output', default='out', help='Output mp4 file name without extension')
+ args = parser.parse_args()
+ main(args)
+
diff --git a/vehicle-detection/darkflow/utils/loader.py b/vehicle-detection/darkflow/utils/loader.py
new file mode 100644
index 0000000..899d429
--- /dev/null
+++ b/vehicle-detection/darkflow/utils/loader.py
@@ -0,0 +1,151 @@
+import tensorflow as tf
+import os
+import dark
+import numpy as np
+
+class loader(object):
+ """
+ interface to work with both .weights and .ckpt files
+ in loading / recollecting / resolving mode
+ """
+ VAR_LAYER = ['convolutional', 'connected', 'local',
+ 'select', 'conv-select',
+ 'extract', 'conv-extract']
+
+ def __init__(self, *args):
+ self.src_key = list()
+ self.vals = list()
+ self.load(*args)
+
+ def __call__(self, key):
+ for idx in range(len(key)):
+ val = self.find(key, idx)
+ if val is not None: return val
+ return None
+
+ def find(self, key, idx):
+ up_to = min(len(self.src_key), 4)
+ for i in range(up_to):
+ key_b = self.src_key[i]
+ if key_b[idx:] == key[idx:]:
+ return self.yields(i)
+ return None
+
+ def yields(self, idx):
+ del self.src_key[idx]
+ temp = self.vals[idx]
+ del self.vals[idx]
+ return temp
+
+class weights_loader(loader):
+ """one who understands .weights files"""
+
+ _W_ORDER = dict({ # order of param flattened into .weights file
+ 'convolutional': [
+ 'biases','gamma','moving_mean','moving_variance','kernel'
+ ],
+ 'connected': ['biases', 'weights'],
+ 'local': ['biases', 'kernels']
+ })
+
+ def load(self, path, src_layers):
+ self.src_layers = src_layers
+ walker = weights_walker(path)
+
+ for i, layer in enumerate(src_layers):
+ if layer.type not in self.VAR_LAYER: continue
+ self.src_key.append([layer])
+
+ if walker.eof: new = None
+ else:
+ args = layer.signature
+ new = dark.darknet.create_darkop(*args)
+ self.vals.append(new)
+
+ if new is None: continue
+ order = self._W_ORDER[new.type]
+ for par in order:
+ if par not in new.wshape: continue
+ val = walker.walk(new.wsize[par])
+ new.w[par] = val
+ new.finalize(walker.transpose)
+
+ if walker.path is not None:
+ #assert walker.offset == walker.size, \
+ #'expect {} bytes, found {}'.format(
+ # walker.offset, walker.size)
+ print('Successfully identified {} bytes'.format(
+ walker.offset))
+
+class checkpoint_loader(loader):
+ """
+ one who understands .ckpt files, very much
+ """
+ def load(self, ckpt, ignore):
+ meta = ckpt + '.meta'
+ with tf.Graph().as_default() as graph:
+ with tf.Session().as_default() as sess:
+ saver = tf.train.import_meta_graph(meta)
+ saver.restore(sess, ckpt)
+ for var in tf.global_variables():
+ name = var.name.split(':')[0]
+ packet = [name, var.get_shape().as_list()]
+ self.src_key += [packet]
+ self.vals += [var.eval(sess)]
+
+def create_loader(path, cfg = None):
+ if path is None:
+ load_type = weights_loader
+ elif '.weights' in path:
+ load_type = weights_loader
+ else:
+ load_type = checkpoint_loader
+
+ return load_type(path, cfg)
+
+class weights_walker(object):
+ """incremental reader of float32 binary files"""
+ def __init__(self, path):
+ self.eof = False # end of file
+ self.path = path # current pos
+ if path is None:
+ self.eof = True
+ return
+ else:
+ self.size = os.path.getsize(path)# save the path
+ major, minor, revision, seen = np.memmap(path,
+ shape = (), mode = 'r', offset = 0,
+ dtype = '({})i4,'.format(4))
+ self.transpose = major > 1000 or minor > 1000
+ self.offset = 16
+
+ def walk(self, size):
+ if self.eof: return None
+ end_point = self.offset + 4 * size
+ assert end_point <= self.size, \
+ 'Over-read {}'.format(self.path)
+
+ float32_1D_array = np.memmap(
+ self.path, shape = (), mode = 'r',
+ offset = self.offset,
+ dtype='({})float32,'.format(size)
+ )
+
+ self.offset = end_point
+ if end_point == self.size:
+ self.eof = True
+ return float32_1D_array
+
+def model_name(file_path):
+ file_name = file_path.split('/')[-1]
+ ext = str()
+ if '.' in file_name: # exclude extension
+ file_name = file_name.split('.')
+ ext = file_name[-1]
+ file_name = '.'.join(file_name[:-1])
+ if ext == str() or ext == 'meta': # ckpt file
+ file_name = file_name.split('-')
+ num = int(file_name[-1])
+ return '-'.join(file_name[:-1])
+ if ext == 'weights':
+ return file_name
diff --git a/vehicle-detection/darkflow/utils/pascal_voc_clean_xml.py b/vehicle-detection/darkflow/utils/pascal_voc_clean_xml.py
new file mode 100644
index 0000000..f044a1f
--- /dev/null
+++ b/vehicle-detection/darkflow/utils/pascal_voc_clean_xml.py
@@ -0,0 +1,114 @@
+"""
+parse PASCAL VOC xml annotations
+"""
+
+import os
+import sys
+
+def pascal_voc_clean_xml(ANN, pick, exclusive = False):
+ print(sys.version)
+ print('Parsing for {} {}'.format(
+ pick, 'exclusively' * int(exclusive)))
+ def pp(l): # pretty printing
+ for i in l: print('{}: {}'.format(i,l[i]))
+
+ def parse(line): # exclude the xml tag
+ x = line.split('>')[1].split('<')[0]
+ try: r = int(x)
+ except: r = x
+ return r
+
+ def _int(literal): # for literals supposed to be int
+ return int(float(literal))
+
+ dumps = list()
+ cur_dir = os.getcwd()
+ os.chdir(ANN)
+ annotations = os.listdir('.')
+ annotations = [file for file in annotations if '.xml' in file]
+ size = len(os.listdir('.'))
+
+ for i, file in enumerate(annotations):
+
+ # progress bar
+ sys.stdout.write('\r')
+ percentage = 1. * (i+1) / size
+ progress = int(percentage * 20)
+ bar_arg = [progress*'=', ' '*(19-progress), percentage*100]
+ bar_arg += [file]
+ sys.stdout.write('[{}>{}]{:.0f}% {}'.format(*bar_arg))
+ sys.stdout.flush()
+
+ # actual parsing
+ with open(file, 'r') as f:
+ lines = f.readlines()
+ w = h = int()
+ all = current = list()
+ name = str()
+ obj = False
+ flag = False
+ for i in range(len(lines)):
+ line = lines[i]
+ if '' in line:
+ jpg = str(parse(line))
+ if '' in line:
+ w = _int(parse(line))
+ if '' in line:
+ h = _int(parse(line))
+ if '' in line:
+ obj = False
+ if '' in line:
+ obj = False
+ if '' in line:
+ obj = True
+ if not obj: continue
+ if '' in line:
+ if current != list():
+ if current[0] in pick:
+ all += [current]
+ elif exclusive:
+ flag = True
+ break
+ current = list()
+ name = str(parse(line))
+ if name not in pick:
+ obj = False
+ continue
+ current = [name,None,None,None,None]
+ if len(current) != 5: continue
+ xn = '' in line
+ xx = '' in line
+ yn = '' in line
+ yx = '' in line
+ if xn: current[1] = _int(parse(line))
+ if xx: current[3] = _int(parse(line))
+ if yn: current[2] = _int(parse(line))
+ if yx: current[4] = _int(parse(line))
+
+ if flag: continue
+ if current != list() and current[0] in pick:
+ all += [current]
+
+ add = [[jpg, [w, h, all]]]
+ dumps += add
+
+ # gather all stats
+ stat = dict()
+ for dump in dumps:
+ all = dump[1][2]
+ for current in all:
+ if current[0] in pick:
+ if current[0] in stat:
+ stat[current[0]]+=1
+ else:
+ stat[current[0]] =1
+
+ print()
+ print('Statistics:')
+ pp(stat)
+ print('Dataset size: {}'.format(len(dumps)))
+
+ os.chdir(cur_dir)
+ return dumps
\ No newline at end of file
diff --git a/vehicle-detection/darkflow/utils/udacity_voc_csv.py b/vehicle-detection/darkflow/utils/udacity_voc_csv.py
new file mode 100644
index 0000000..c37d3f5
--- /dev/null
+++ b/vehicle-detection/darkflow/utils/udacity_voc_csv.py
@@ -0,0 +1,67 @@
+"""
+parse PASCAL VOC xml annotations
+"""
+
+import os
+import sys
+import csv
+import cv2
+
+def udacity_voc_csv(ANN, pick, exclusive = False):
+
+ print('Parsing for {} {}'.format(
+ pick, 'exclusively' * int(exclusive)))
+ def pp(l): # pretty printing
+ for i in l: print('{}: {}'.format(i,l[i]))
+
+ def parse(line): # exclude the xml tag
+ x = line.decode().split('>')[1].decode().split('<')[0]
+ try: r = int(x)
+ except: r = x
+ return r
+
+ def _int(literal): # for literals supposed to be int
+ return int(float(literal))
+
+ dumps = list()
+
+ csv_fname = os.path.join('/home/yan/data/udacity_data/udacity.csv')
+ with open(csv_fname, 'r') as csvfile:
+ spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|', )
+ for row in spamreader:
+ img_name = row[0]
+ w = 1920
+ h = 1200
+
+ labels = row[1:]
+ all = list()
+ for i in range(0, len(labels), 5):
+ xmin = int(labels[i])
+ ymin = int(labels[i + 1])
+ xmax = int(labels[i + 2])
+ ymax = int(labels[i + 3])
+ class_idx = int(labels[i + 4])
+ class_name = pick[class_idx]
+ all += [[class_name, xmin, ymin, xmax, ymax]]
+
+ add = [[img_name, [w, h, all]]]
+ dumps += add
+
+
+ # gather all stats
+ stat = dict()
+ for dump in dumps:
+ all = dump[1][2]
+ for current in all:
+ if current[0] in pick:
+ if current[0] in stat:
+ stat[current[0]]+=1
+ else:
+ stat[current[0]] =1
+
+ print()
+ print('Statistics:')
+ pp(stat)
+ print('Dataset size: {}'.format(len(dumps)))
+
+ return dumps