diff --git a/.gitignore b/.gitignore index 85a8b85..b56526f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ build/ *.hdf5 *.pk *.table +demo/COCO_val2017 +demo/BDD100K_val \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e5a2b26..3509d42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,7 @@ if(DEBUG) add_definitions(-DDEBUG) endif() +add_definitions(-DTKDNN_PATH="${CMAKE_CURRENT_SOURCE_DIR}") #------------------------------------------------------------------------------- # CUDA @@ -20,6 +21,8 @@ SET(CUDA_SEPARABLE_COMPILATION ON) set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32) find_package(CUDNN REQUIRED) +include_directories(${CUDNN_INCLUDE_DIR}) + # compile file(GLOB tkdnn_CUSRC "src/kernels/*.cu" "src/sorting.cu") @@ -36,7 +39,8 @@ include_directories(${EIGEN3_INCLUDE_DIR}) find_package(OpenCV REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV") -find_package(yaml-cpp REQUIRED) +# gives problems in cross-compiling, probably malformed cmake config +#find_package(yaml-cpp REQUIRED) #------------------------------------------------------------------------------- # Build Libraries @@ -47,12 +51,13 @@ set(tkdnn_LIBS kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRAR set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} ${NVINFER_INCLUDES}) add_library(tkDNN SHARED ${tkdnn_SRC}) -target_link_libraries(tkDNN ${tkdnn_LIBS} nvinfer_plugin) +target_link_libraries(tkDNN ${tkdnn_LIBS}) #static #add_library(tkDNN_static STATIC ${tkdnn_SRC}) #target_link_libraries(tkDNN_static ${tkdnn_LIBS}) +# SMALL NETS add_executable(test_simple tests/simple/test_simple.cpp) target_link_libraries(test_simple tkDNN) @@ -62,97 +67,49 @@ target_link_libraries(test_mnist tkDNN) add_executable(test_mnistRT tests/mnist/test_mnistRT.cpp) target_link_libraries(test_mnistRT tkDNN) -## YOLO NETS -add_executable(test_yolo tests/yolo/yolo.cpp) -target_link_libraries(test_yolo tkDNN) - -add_executable(test_yolo_voc tests/yolo_voc/yolo_voc.cpp) -target_link_libraries(test_yolo_voc tkDNN) - -add_executable(test_yolo_tiny tests/yolo_tiny/yolo_tiny.cpp) -target_link_libraries(test_yolo_tiny tkDNN) - -add_executable(test_yolo_relu tests/yolo_relu/yolo_relu.cpp) -target_link_libraries(test_yolo_relu tkDNN) - - -add_executable(test_yolo_224 tests/yolo_224/yolo_224.cpp) -target_link_libraries(test_yolo_224 tkDNN) - -add_executable(test_yolo_berkeley tests/yolo_berkeley/yolo_berkeley.cpp) -target_link_libraries(test_yolo_berkeley tkDNN) - -add_executable(test_yolo3_coco4 tests/yolo3_coco4/yolo3_coco4.cpp) -target_link_libraries(test_yolo3_coco4 tkDNN) - -add_executable(test_yolo3 tests/yolo3/yolo3.cpp) -target_link_libraries(test_yolo3 tkDNN) - -add_executable(test_yolo3_512 tests/yolo3_512/yolo3_512.cpp) -target_link_libraries(test_yolo3_512 tkDNN) - -add_executable(test_yolo3_512tp tests/yolo3_512tp/yolo3_512tp.cpp) -target_link_libraries(test_yolo3_512tp tkDNN) - -add_executable(test_yolo3_tiny tests/yolo3_tiny/yolo3_tiny.cpp) -target_link_libraries(test_yolo3_tiny tkDNN) - -add_executable(test_yolo3_tiny512 tests/yolo3_tiny512/yolo3_tiny512.cpp) -target_link_libraries(test_yolo3_tiny512 tkDNN) - -add_executable(test_yolo3_tinyNM512 tests/yolo3_tinyNM512/yolo3_tinyNM512.cpp) -target_link_libraries(test_yolo3_tinyNM512 tkDNN) - -add_executable(test_yolo3_tiny512tp tests/yolo3_tiny512tp/yolo3_tiny512tp.cpp) -target_link_libraries(test_yolo3_tiny512tp tkDNN) - -add_executable(test_yolo3_berkeley tests/yolo3_berkeley/yolo3_berkeley.cpp) -target_link_libraries(test_yolo3_berkeley tkDNN) - -add_executable(test_yolo3_flir tests/yolo3_flir/yolo3_flir.cpp) -target_link_libraries(test_yolo3_flir tkDNN) - -add_executable(test_yolo4 tests/yolo4/yolo4.cpp) -target_link_libraries(test_yolo4 tkDNN) - -add_executable(test_mobilenetv2ssd tests/mobilenetv2ssd/mobilenetv2ssd.cpp) -target_link_libraries(test_mobilenetv2ssd tkDNN) - -add_executable(test_bdd-mobilenetv2ssd tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp) -target_link_libraries(test_bdd-mobilenetv2ssd tkDNN) - -add_executable(test_mobilenetv2ssd512 tests/mobilenetv2ssd512/mobilenetv2ssd512.cpp) -target_link_libraries(test_mobilenetv2ssd512 tkDNN) - -add_executable(test_resnet101 tests/resnet101/resnet101.cpp) -target_link_libraries(test_resnet101 tkDNN) - -add_executable(test_csresnext50-panet-spp tests/csresnext50-panet-spp/csresnext50-panet-spp.cpp) -target_link_libraries(test_csresnext50-panet-spp tkDNN) - -add_executable(test_bdd-csresnext50-panet-spp tests/bdd-csresnext50-panet-spp/bdd-csresnext50-panet-spp.cpp) -target_link_libraries(test_bdd-csresnext50-panet-spp tkDNN) - -add_executable(test_resnet101_cnet tests/resnet101_cnet/resnet101_cnet.cpp) -target_link_libraries(test_resnet101_cnet tkDNN) - -add_executable(test_resnet101_cnet3d tests/resnet101_cnet3d/resnet101_cnet3d.cpp) -target_link_libraries(test_resnet101_cnet3d tkDNN) - -add_executable(test_dla34 tests/dla34/dla34.cpp) -target_link_libraries(test_dla34 tkDNN) - -add_executable(test_dla34_cnet tests/dla34_cnet/dla34_cnet.cpp) -target_link_libraries(test_dla34_cnet tkDNN) - -add_executable(test_dla34_cnet3d tests/dla34_cnet3d/dla34_cnet3d.cpp) -target_link_libraries(test_dla34_cnet3d tkDNN) - add_executable(test_imuodom tests/imuodom/imuodom.cpp) target_link_libraries(test_imuodom tkDNN) -################################################################################ +# DARKNET +file(GLOB darknet_SRC "tests/darknet/*.cpp") +foreach(test_SRC ${darknet_SRC}) + get_filename_component(test_NAME "${test_SRC}" NAME_WE) + set(test_NAME test_${test_NAME}) + add_executable(${test_NAME} ${test_SRC}) + target_link_libraries(${test_NAME} tkDNN) +endforeach() +# MOBILENET +add_executable(test_mobilenetv2ssd tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp) +target_link_libraries(test_mobilenetv2ssd tkDNN) + +add_executable(test_bdd-mobilenetv2ssd tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp) +target_link_libraries(test_bdd-mobilenetv2ssd tkDNN) + +add_executable(test_mobilenetv2ssd512 tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp) +target_link_libraries(test_mobilenetv2ssd512 tkDNN) + +# BACKBONES +add_executable(test_resnet101 tests/backbones/resnet101/resnet101.cpp) +target_link_libraries(test_resnet101 tkDNN) + +add_executable(test_dla34 tests/backbones/dla34/dla34.cpp) +target_link_libraries(test_dla34 tkDNN) + +# CENTERNET +add_executable(test_resnet101_cnet tests/centernet/resnet101_cnet/resnet101_cnet.cpp) +target_link_libraries(test_resnet101_cnet tkDNN) + +add_executable(test_dla34_cnet tests/centernet/dla34_cnet/dla34_cnet.cpp) +target_link_libraries(test_dla34_cnet tkDNN) + +add_executable(test_resnet101_cnet3d tests/centernet/resnet101_cnet3d/resnet101_cnet3d.cpp) +target_link_libraries(test_resnet101_cnet3d tkDNN) + +add_executable(test_dla34_cnet3d tests/centernet/dla34_cnet3d/dla34_cnet3d.cpp) +target_link_libraries(test_dla34_cnet3d tkDNN) + +# DEMOS add_executable(test_rtinference tests/test_rtinference/rtinference.cpp) target_link_libraries(test_rtinference tkDNN) @@ -179,18 +136,3 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" # source directory DESTINATION "share/tkDNN/cmake/" # target directory ) - -#------------------------------------------------------------------------------- -# Prepare for test (not needed anymore) -#------------------------------------------------------------------------------- -#set(TEST_DATA true CACHE BOOL "If true download deps") -#if( ${TEST_DATA} ) -# message("Launching pre-build dependency installer script...") -# -# execute_process (COMMAND bash -c "bash build_models.sh download" -# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests) -# -# set(TEST_DATA false CACHE BOOL "If true download deps" FORCE) -# message("Finished dowloading test weights") -#endif() - diff --git a/LICENSE b/LICENSE index 0a93a39..2a878a9 100644 --- a/LICENSE +++ b/LICENSE @@ -1,21 +1,339 @@ -MIT License + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 -Copyright (c) 2017 Francesco Gatti + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: + Preamble -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + 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 +this service 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 make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. 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. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute 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 and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +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 +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the 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 a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, 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. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE 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. + + 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 +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + tkDNN + Copyright (C) 2017 Francesco Gatti + + 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 2 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, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision 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, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This 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. diff --git a/README.md b/README.md index d700d02..234e66b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,67 @@ # tkDNN -tkDNN is a Deep Neural Network library built with cuDNN and tensorRT primitives, specifically thought to work on NVIDIA Jetson Boards. It has been tested on TK1(branch cudnn2), TX1, TX2, AGX Xavier and several discrete GPU. +tkDNN is a Deep Neural Network library built with cuDNN and tensorRT primitives, specifically thought to work on NVIDIA Jetson Boards. It has been tested on TK1(branch cudnn2), TX1, TX2, AGX Xavier, Nano and several discrete GPUs. The main goal of this project is to exploit NVIDIA boards as much as possible to obtain the best inference performance. It does not allow training. + +If you use tkDNN in your research, please cite the [following paper](https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9212130&casa_token=sQTJXi7tJNoAAAAA:BguH9xCIY48MxbtDS3LXzIXzO-9sWArm7Hd7y7BwaLmqRuM_Gx8bOYizFPNMNtpo5K0kB-P-). For use in commercial solutions, write at gattifrancesco@hotmail.it and micaela.verucchi@unimore.it or refer to https://hipert.unimore.it/ . + +``` +@inproceedings{verucchi2020systematic, + title={A Systematic Assessment of Embedded Neural Networks for Object Detection}, + author={Verucchi, Micaela and Brilli, Gianluca and Sapienza, Davide and Verasani, Mattia and Arena, Marco and Gatti, Francesco and Capotondi, Alessandro and Cavicchioli, Roberto and Bertogna, Marko and Solieri, Marco}, + booktitle={2020 25th IEEE International Conference on Emerging Technologies and Factory Automation (ETFA)}, + volume={1}, + pages={937--944}, + year={2020}, + organization={IEEE} +} +``` + +## FPS Results +Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimension as the input size, on + * RTX 2080Ti (CUDA 10.2, TensorRT 7.0.0, Cudnn 7.6.5); + * Xavier AGX, Jetpack 4.3 (CUDA 10.0, CUDNN 7.6.3, tensorrt 6.0.1 ); + * Xavier NX, Jetpack 4.4 (CUDA 10.2, CUDNN 8.0.0, tensorrt 7.1.0 ). + * Tx2, Jetpack 4.2 (CUDA 10.0, CUDNN 7.3.1, tensorrt 5.0.6 ); + * Jetson Nano, Jetpack 4.4 (CUDA 10.2, CUDNN 8.0.0, tensorrt 7.1.0 ). + +| Platform | Network | FP32, B=1 | FP32, B=4 | FP16, B=1 | FP16, B=4 | INT8, B=1 | INT8, B=4 | +| :------: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | +| RTX 2080Ti | yolo4 320 | 118.59 | 237.31 | 207.81 | 443.32 | 262.37 | 530.93 | +| RTX 2080Ti | yolo4 416 | 104.81 | 162.86 | 169.06 | 293.78 | 206.93 | 353.26 | +| RTX 2080Ti | yolo4 512 | 92.98 | 132.43 | 140.36 | 215.17 | 165.35 | 254.96 | +| RTX 2080Ti | yolo4 608 | 63.77 | 81.53 | 111.39 | 152.89 | 127.79 | 184.72 | +| AGX Xavier | yolo4 320 | 26.78 | 32.05 | 57.14 | 79.05 | 73.15 | 97.56 | +| AGX Xavier | yolo4 416 | 19.96 | 21.52 | 41.01 | 49.00 | 50.81 | 60.61 | +| AGX Xavier | yolo4 512 | 16.58 | 16.98 | 31.12 | 33.84 | 37.82 | 41.28 | +| AGX Xavier | yolo4 608 | 9.45 | 10.13 | 21.92 | 23.36 | 27.05 | 28.93 | +| Xavier NX | yolo4 320 | 14.56 | 16.25 | 30.14 | 41.15 | 42.13 | 53.42 | +| Xavier NX | yolo4 416 | 10.02 | 10.60 | 22.43 | 25.59 | 29.08 | 32.94 | +| Xavier NX | yolo4 512 | 8.10 | 8.32 | 15.78 | 17.13 | 20.51 | 22.46 | +| Xavier NX | yolo4 608 | 5.26 | 5.18 | 11.54 | 12.06 | 15.09 | 15.82 | +| Tx2 | yolo4 320 | 11.18 | 12.07 | 15.32 | 16.31 | - | - | +| Tx2 | yolo4 416 | 7.30 | 7.58 | 9.45 | 9.90 | - | - | +| Tx2 | yolo4 512 | 5.96 | 5.95 | 7.22 | 7.23 | - | - | +| Tx2 | yolo4 608 | 3.63 | 3.65 | 4.67 | 4.70 | - | - | +| Nano | yolo4 320 | 4.23 | 4.55 | 6.14 | 6.53 | - | - | +| Nano | yolo4 416 | 2.88 | 3.00 | 3.90 | 4.04 | - | - | +| Nano | yolo4 512 | 2.32 | 2.34 | 3.02 | 3.04 | - | - | +| Nano | yolo4 608 | 1.40 | 1.41 | 1.92 | 1.93 | - | - | + +## MAP Results +Results for COCO val 2017 (5k images), on RTX 2080Ti, with conf threshold=0.001 + +| | CodaLab | CodaLab | CodaLab | CodaLab | tkDNN map | tkDNN map | +| -------------------- | :-----------: | :-------: | :-----------: | :---------: | :-----------: | :-------: | +| | **tkDNN** | **tkDNN** | **darknet** | **darknet** | **tkDNN** | **tkDNN** | +| | MAP(0.5:0.95) | AP50 | MAP(0.5:0.95) | AP50 | MAP(0.5:0.95) | AP50 | +| Yolov3 (416x416) | 0.381 | 0.675 | 0.380 | 0.675 | 0.372 | 0.663 | +| yolov4 (416x416) | 0.468 | 0.705 | 0.471 | 0.710 | 0.459 | 0.695 | +| yolov3tiny (416x416) | 0.096 | 0.202 | 0.096 | 0.201 | 0.093 | 0.198 | +| yolov4tiny (416x416) | 0.202 | 0.400 | 0.201 | 0.400 | 0.197 | 0.395 | +| Cnet-dla34 (512x512) | 0.366 | 0.543 | \- | \- | 0.361 | 0.535 | +| mv2SSD (512x512) | 0.226 | 0.381 | \- | \- | 0.223 | 0.378 | + ## Index - [tkDNN](#tkdnn) - [Index](#index) @@ -69,10 +129,10 @@ Weights are essential for any network to run inference. For each test a folder o Therefore, once the weights have been exported, the folders layers and debug should be placed in the corresponding test. ### 1)Export weights from darknet -To export weights for NNs that are defined in darknet framework, use [this](https://github.com/ceccocats/darknet) fork of darknet and follow these steps to obtain a correct debug and layers folder, ready for tkDNN. +To export weights for NNs that are defined in darknet framework, use [this](https://git.hipert.unimore.it/fgatti/darknet.git) fork of darknet and follow these steps to obtain a correct debug and layers folder, ready for tkDNN. ``` -git clone https://github.com/ceccocats/darknet +git clone https://git.hipert.unimore.it/fgatti/darknet.git cd darknet make mkdir layers debug @@ -101,7 +161,6 @@ python demo.py --input_res 512 --arch resdcn_101 ctdet --demo /path/to/image/or/ python demo.py --input_res 512 --arch dla_34 ctdet --demo /path/to/image/or/folder/or/video/or/webcam --load_model ../models/ctdet_coco_dla_2x.pth --exp_wo --exp_wo_dim 512 ``` ### 4)Export weights for MobileNetSSD - To get the weights needed to run Mobilenet tests use [this](https://github.com/mive93/pytorch-ssd) fork of a Pytorch implementation of SSD network. ``` @@ -110,25 +169,68 @@ cd pytorch-ssd conda env create -f env_mobv2ssd.yml python run_ssd_live_demo.py mb2-ssd-lite ``` -## Run the demo -To run the an object detection demo follow these steps (example with yolov3): +## Darknet Parser +tkDNN implement and easy parser for darknet cfg files, a network can be converted with *tk::dnn::darknetParser*: ``` -rm yolo3_FP32.rt # be sure to delete(or move) old tensorRT files -./test_yolo3 # run the yolo test (is slow) -./demo yolo3_FP32.rt ../demo/yolo_test.mp4 y +// example of parsing yolo4 +tk::dnn::Network *net = tk::dnn::darknetParser("yolov4.cfg", "yolov4/layers", "coco.names"); +net->print(); ``` -In general the demo program takes 4 parameters: +All models from darknet are now parsed directly from cfg, you still need to export the weights with the described tools in the previous section. +
+ Supported layers + convolutional + maxpool + avgpool + shortcut + upsample + route + reorg + region + yolo +
+
+ Supported activations + relu + leaky + mish +
+ +## Run the demo +This is an example using yolov4. + +To run the an object detection first create the .rt file by running: ``` -./demo +rm yolo4_fp32.rt # be sure to delete(or move) old tensorRT files +./test_yolo4 # run the yolo test (is slow) +``` +If you get problems in the creation, try to check the error activating the debug of TensorRT in this way: +``` +cmake .. -DDEBUG=True +make +``` + +Once you have successfully created your rt file, run the demo: +``` +./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y +``` +In general the demo program takes 7 parameters: +``` +./demo ``` where * `````` is the rt file generated by a test * ```<``` is the path to a video file or a camera input * `````` is the type of network. Thee types are currently supported: ```y``` (YOLO family), ```c``` (CenterNet family) and ```m``` (MobileNet-SSD family) * ``````is the number of classes the network is trained on +* `````` number of batches to use in inference (N.B. you should first export TKDNN_BATCHSIZE to the required n_batches and create again the rt file for the network). +* `````` if set to 0 the demo will not show the visualization but save the video into result.mp4 (if n-batches ==1) +* `````` confidence threshold for the detector. Only bounding boxes with threshold greater than conf-thresh will be displayed. + N.b. By default it is used FP32 inference + ![demo](https://user-images.githubusercontent.com/11562617/72547657-540e7800-388d-11ea-83c6-49dfea2a0607.gif) ### Run the 3D demo @@ -149,36 +251,59 @@ The demo3D program takes the same parameters of the demo program: To run the an object detection demo with FP16 inference follow these steps (example with yolov3): ``` export TKDNN_MODE=FP16 # set the half floating point optimization -rm yolo3_FP16.rt # be sure to delete(or move) old tensorRT files +rm yolo3_fp16.rt # be sure to delete(or move) old tensorRT files ./test_yolo3 # run the yolo test (is slow) -./demo yolo3_FP16.rt ../demo/yolo_test.mp4 y +./demo yolo3_fp16.rt ../demo/yolo_test.mp4 y ``` N.b. Using FP16 inference will lead to some errors in the results (first or second decimal). ### INT8 inference -To run the an object detection demo with INT8 inference follow these steps (example with yolov3): +To run the an object detection demo with INT8 inference three environment variables need to be set: + * ```export TKDNN_MODE=INT8```: set the 8-bit integer optimization + * ```export TKDNN_CALIB_IMG_PATH=/path/to/calibration/image_list.txt``` : image_list.txt has in each line the absolute path to a calibration image + * ```export TKDNN_CALIB_LABEL_PATH=/path/to/calibration/label_list.txt```: label_list.txt has in each line the absolute path to a calibration label + +You should provide image_list.txt and label_list.txt, using training images. However, if you want to quickly test the INT8 inference you can run (from this repo root folder) ``` -export TKDNN_MODE=INT8 # set the 8-bit integer optimization +bash scripts/download_validation.sh COCO +``` +to automatically download COCO2017 validation (inside demo folder) and create those needed file. Use BDD instead of COCO to download BDD validation. -# image_list.txt contains the list of the absolute paths to the calibration images -export TKDNN_CALIB_IMG_PATH=/path/to/calibration/image_list.txt - -# label_list.txt contains the list of the absolute paths to the calibration labels -export TKDNN_CALIB_LABEL_PATH=/path/to/calibration/label_list.txt -rm yolo3_INT8.rt # be sure to delete(or move) old tensorRT files +Then a complete example using yolo3 and COCO dataset would be: +``` +export TKDNN_MODE=INT8 +export TKDNN_CALIB_LABEL_PATH=../demo/COCO_val2017/all_labels.txt +export TKDNN_CALIB_IMG_PATH=../demo/COCO_val2017/all_images.txt +rm yolo3_int8.rt # be sure to delete(or move) old tensorRT files ./test_yolo3 # run the yolo test (is slow) -./demo yolo3_INT8.rt ../demo/yolo_test.mp4 y +./demo yolo3_int8.rt ../demo/yolo_test.mp4 y ``` -N.b. Using INT8 inference will lead to some errors in the results. - -N.b. The test will be slower: this is due to the INT8 calibration, which may take some time to complete. - -N.b. INT8 calibration requires TensorRT version greater than or equal to 6.0 +N.B. + * Using INT8 inference will lead to some errors in the results. + * The test will be slower: this is due to the INT8 calibration, which may take some time to complete. + * INT8 calibration requires TensorRT version greater than or equal to 6.0 + * Only 100 images are used to create the calibration table by default (set in the code). ### BatchSize bigger than 1 ``` export TKDNN_BATCHSIZE=2 +# build tensorRT files +``` +This will create a TensorRT file with the desired **max** batch size. +The test will still run with a batch of 1, but the created tensorRT can manage the desired batch size. + +### Test batch Inference +This will test the network with random input and check if the output of each batch is the same. +``` +./test_rtinference +# should be less or equal to the max batch size of the + +# example +export TKDNN_BATCHSIZE=4 # set max batch size +rm yolo3_fp32.rt # be sure to delete(or move) old tensorRT files +./test_yolo3 # build RT file +./test_rtinference yolo3_fp32.rt 4 # test with a batch size of 4 ``` ## mAP demo @@ -212,6 +337,8 @@ cd build ./map_demo dla34_cnet_FP32.rt c ../demo/COCO_val2017/all_labels.txt ../demo/config.yaml ``` +This demo also creates a json file named ```net_name_COCO_res.json``` containing all the detections computed. The detections are in COCO format, the correct format to submit the results to [CodaLab COCO detection challenge](https://competitions.codalab.org/competitions/20794#participate). + ## Existing tests and supported networks | Test Name | Network | Dataset | N Classes | Input size | Weights | @@ -237,6 +364,9 @@ cd build | resnet101_cnet | Centernet (Resnet101 backend)4 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/5BTjHMWBcJk8g3i/download) | | csresnext50-panet-spp | Cross Stage Partial Network 7 | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/Kcs4xBozwY4wFx8/download) | | yolo4 | Yolov4 8 | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) | +| yolo4_berkeley | Yolov4 8 | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 540x320 | [weights](https://cloud.hipert.unimore.it/s/nkWFa5fgb4NTdnB/download) | +| yolo4tiny | Yolov4 tiny 9 | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download) | +| yolo4x | Yolov4x-mish 9 | [COCO 2017](http://cocodataset.org/) | 80 | 672x672 | [weights](https://cloud.hipert.unimore.it/s/BLPpiAigZJLorQD/download) | ## References @@ -249,3 +379,4 @@ cd build 6. He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016. 7. Wang, Chien-Yao, et al. "CSPNet: A New Backbone that can Enhance Learning Capability of CNN." arXiv preprint arXiv:1911.11929 (2019). 8. Bochkovskiy, Alexey, Chien-Yao Wang, and Hong-Yuan Mark Liao. "YOLOv4: Optimal Speed and Accuracy of Object Detection." arXiv preprint arXiv:2004.10934 (2020). +9. Bochkovskiy, Alexey, "Yolo v4, v3 and v2 for Windows and Linux" (https://github.com/AlexeyAB/darknet) diff --git a/cmake/FindCUDNN.cmake b/cmake/FindCUDNN.cmake index f240fcb..583b4a6 100644 --- a/cmake/FindCUDNN.cmake +++ b/cmake/FindCUDNN.cmake @@ -1,33 +1,66 @@ -# Find the header files +# find the library +if(CUDA_FOUND) + find_cuda_helper_libs(cudnn) + set(CUDNN_LIBRARY ${CUDA_cudnn_LIBRARY} CACHE FILEPATH "location of the cuDNN library") + unset(CUDA_cudnn_LIBRARY CACHE) -find_path(CUDNN_INCLUDE_DIR - ${CMAKE_SYSROOT}/usr/local/include - ${CMAKE_SYSROOT}/usr/include - /usr/local/nvidia/tensorrt/include/ - NO_DEFAULT_PATH -) + find_cuda_helper_libs(nvinfer) + set(NVINFER_LIBRARY ${CUDA_nvinfer_LIBRARY} CACHE FILEPATH "location of the nvinfer library") + unset(CUDA_nvinfer_LIBRARY CACHE) +endif() -set(OLD_ROOT ${CMAKE_FIND_ROOT_PATH}) -list(APPEND CMAKE_FIND_ROOT_PATH /) -list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.7) -list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.5) -find_library(CUDNN_LIB - NAMES cudnn - PATHS - /usr/local/driveworks/targets/${CMAKE_SYSTEM_PROCESSOR}-Linux/lib - /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/ +# find the include +if(CUDNN_LIBRARY) + find_path(CUDNN_INCLUDE_DIR + cudnn.h + PATHS ${CUDA_TOOLKIT_INCLUDE} + DOC "location of cudnn.h" NO_DEFAULT_PATH -) -find_library(CUDNN_NVLIB - NAMES "nvinfer" - PATHS - /usr/local/driveworks/targets/${CMAKE_SYSTEM_PROCESSOR}-Linux/lib - /usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/ - NO_DEFAULT_PATH -) -set(CMAKE_FIND_ROOT_PATH ${OLD_ROOT}) + ) -set(CUDNN_LIBRARIES ${CUDNN_LIB} ${CUDNN_NVLIB}) -message("-- Found CUDNN: " ${CUDNN_LIB}) -message("-- Found NVINFER: " ${CUDNN_NVLIB}) -set(CUDNN_FOUND true) + if(NOT CUDNN_INCLUDE_DIR) + find_path(CUDNN_INCLUDE_DIR + cudnn.h + DOC "location of cudnn.h" + ) + endif() + + message("-- Found CUDNN: " ${CUDNN_LIBRARY}) + message("-- Found CUDNN include: " ${CUDNN_INCLUDE_DIR}) +endif() + +if(NVINFER_LIBRARY) + find_path(NVINFER_INCLUDE_DIR + NvInfer.h + PATHS ${CUDA_TOOLKIT_INCLUDE} + DOC "location of NvInfer.h" + NO_DEFAULT_PATH + ) + + if(NOT NVINFER_INCLUDE_DIR) + find_path(NVINFER_INCLUDE_DIR + NvInfer.h + DOC "location of NvInfer.h" + ) + endif() + + message("-- Found NVINFER: " ${NVINFER_LIBRARY}) + message("-- Found NVINFER include: " ${NVINFER_INCLUDE_DIR}) +endif() + + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(CUDNN + FOUND_VAR CUDNN_FOUND + REQUIRED_VARS + CUDNN_LIBRARY + CUDNN_INCLUDE_DIR + VERSION_VAR CUDNN_VERSION +) + +if(CUDNN_FOUND) + set(CUDNN_LIBRARIES ${CUDNN_LIBRARY} ${NVINFER_LIBRARY}) + set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR} ${NVINFER_INCLUDE_DIR}) +endif() + +set(CUDNN_FOUND true) \ No newline at end of file diff --git a/demo/config.yaml b/demo/config.yaml index e6f91a7..31ac599 100644 --- a/demo/config.yaml +++ b/demo/config.yaml @@ -3,5 +3,5 @@ map_points : 101 #number of recall points (0 for all, 101 for COCO, 11 Pascal map_levels : 10 #number of IoU step for the AP map_step : 0.05 #step of IoU IoU_thresh : 0.5 #starting IoU threshold -conf_thresh : 0.0 #threshold on the condifence of the bbox +conf_thresh : 0.001 #threshold on the condifence of the bbox verbose : false #print on screen information diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 75012b6..9f50d0b 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -34,6 +34,21 @@ int main(int argc, char *argv[]) { int n_classes = 80; if(argc > 4) n_classes = atoi(argv[4]); + int n_batch = 1; + if(argc > 5) + n_batch = atoi(argv[5]); + bool show = true; + if(argc > 6) + show = atoi(argv[6]); + float conf_thresh=0.3; + if(argc > 7) + conf_thresh = atof(argv[7]); + + if(n_batch < 1 || n_batch > 64) + FatalError("Batch dim not supported"); + + if(!show) + SAVE_RESULT = true; tk::dnn::Yolo3Detection yolo; tk::dnn::CenternetDetection cnet; @@ -57,7 +72,7 @@ int main(int argc, char *argv[]) { FatalError("Network type not allowed (3rd parameter)\n"); } - detNN->init(net, n_classes); + detNN->init(net, n_classes, n_batch, conf_thresh); gRun = true; @@ -75,27 +90,40 @@ int main(int argc, char *argv[]) { } cv::Mat frame; - cv::Mat dnn_input; - cv::namedWindow("detection", cv::WINDOW_NORMAL); - - std::vector detected_bbox; + if(show) + cv::namedWindow("detection", cv::WINDOW_NORMAL); + + std::vector batch_frame; + std::vector batch_dnn_input; while(gRun) { - cap >> frame; - if(!frame.data) { - break; - } - - // this will be resized to the net format - dnn_input = frame.clone(); + batch_dnn_input.clear(); + batch_frame.clear(); - //inference - detNN->update(dnn_input); - frame = detNN->draw(frame); + for(int bi=0; bi< n_batch; ++bi){ + cap >> frame; + if(!frame.data) + break; + + batch_frame.push_back(frame); - cv::imshow("detection", frame); - cv::waitKey(1); - if(SAVE_RESULT) + // this will be resized to the net format + batch_dnn_input.push_back(frame.clone()); + } + if(!frame.data) + break; + + //inference + detNN->update(batch_dnn_input, n_batch); + detNN->draw(batch_frame); + + if(show){ + for(int bi=0; bi< n_batch; ++bi){ + cv::imshow("detection", batch_frame[bi]); + cv::waitKey(1); + } + } + if(n_batch == 1 && SAVE_RESULT) resultVideo << frame; } @@ -103,10 +131,10 @@ int main(int argc, char *argv[]) { double mean = 0; std::cout<stats.begin(), detNN->stats.end())<<" ms\n"; - std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())<<" ms\n"; + std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n"; + std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n"; for(int i=0; istats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size(); - std::cout<<"Avg: "< 1) net = argv[1]; if(argc > 2) @@ -52,6 +54,7 @@ int main(int argc, char *argv[]) if(argc > 4) config_filename = argv[4]; + //check if files needed exist if(!fileExist(config_filename)) FatalError("Wrong config file path."); if(!fileExist(net)) @@ -63,26 +66,31 @@ int main(int argc, char *argv[]) tk::dnn::readmAPParams( config_filename, classes, map_points, map_levels, map_step, IoU_thresh, conf_thresh, verbose); - std::ofstream times, memory; + //extract network name from rt path std::string net_name; removePathAndExtension(net, net_name); std::cout<<"Network: "<init(net, n_classes, 1, conf_thresh); - detNN->init(net, n_classes); - + //read images std::ifstream all_labels(labels_path); std::string l_filename; std::vector images; @@ -124,24 +132,28 @@ int main(int argc, char *argv[]) FatalError("Wrong image file path."); cv::Mat frame = cv::imread(f.iFilename.c_str(), cv::IMREAD_COLOR); + std::vector batch_frames; + batch_frames.push_back(frame); int height = frame.rows; int width = frame.cols; - cv::Mat dnn_input; if(!frame.data) break; - dnn_input = frame.clone(); + std::vector batch_dnn_input; + batch_dnn_input.push_back(frame.clone()); //inference - detected_bbox.clear(); - detNN->update(dnn_input, write_res_on_file, ×); - frame = detNN->draw(frame); + detNN->update(batch_dnn_input,1,write_res_on_file, ×, write_coco_json); + detNN->draw(batch_frames); detected_bbox = detNN->detected; - + + if(write_coco_json) + printJsonCOCOFormat(&coco_json, f.iFilename.c_str(), detected_bbox, classes, width, height); + std::ofstream myfile; if(write_dets) - myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("000"))); + myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("labels/") + 7)); // save detections labels for(auto d:detected_bbox){ @@ -157,33 +169,36 @@ int main(int argc, char *argv[]) f.det.push_back(b); if(write_dets) - myfile << d.cl << " "<< d.prob << " "<< d.x << " "<< d.y << " "<< d.w << " "<< d.h <<"\n"; + myfile << d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n"; if(show)// draw rectangle for detection - cv::rectangle(frame, cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2); + cv::rectangle(batch_frames[0], cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2); } if(write_dets) myfile.close(); // read and save groundtruth labels - std::ifstream labels(l_filename); - for(std::string line; std::getline(labels, line); ){ - std::istringstream in(line); - tk::dnn::BoundingBox b; - in >> b.cl >> b.x >> b.y >> b.w >> b.h; - b.prob = 1; - b.truthFlag = 1; - f.gt.push_back(b); + if(fileExist(f.lFilename.c_str())) + { + std::ifstream labels(l_filename); + for(std::string line; std::getline(labels, line); ){ + std::istringstream in(line); + tk::dnn::BoundingBox b; + in >> b.cl >> b.x >> b.y >> b.w >> b.h; + b.prob = 1; + b.truthFlag = 1; + f.gt.push_back(b); - if(show)// draw rectangle for groundtruth - cv::rectangle(frame, cv::Point((b.x-b.w/2)*width, (b.y-b.h/2)*height), cv::Point((b.x+b.w/2)*width,(b.y+b.h/2)*height), cv::Scalar(0, 255, 0), 2); + if(show)// draw rectangle for groundtruth + cv::rectangle(batch_frames[0], cv::Point((b.x-b.w/2)*width, (b.y-b.h/2)*height), cv::Point((b.x+b.w/2)*width,(b.y+b.h/2)*height), cv::Scalar(0, 255, 0), 2); + } } images.push_back(f); if(show){ - cv::imshow("detection", frame); + cv::imshow("detection", batch_frames[0]); cv::waitKey(0); } @@ -193,6 +208,13 @@ int main(int argc, char *argv[]) } + + if(write_coco_json){ + coco_json.seekp (coco_json.tellp() - std::streampos(2)); + coco_json << "\n]\n"; + coco_json.close(); + } + std::cout << "Avg VM[MB]: " << vm_total/images_done/1024.0 << ";Avg RSS[MB]: " << rss_total/images_done/1024.0 << std::endl; //compute mAP diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..3c9fb61 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,7 @@ +FROM ceccocats/tkdnn:latest +LABEL maintainer "Francesco Gatti" + +RUN cd && git clone https://github.com/ceccocats/tkDNN.git && cd tkDNN && mkdir build && cd build \ + && cmake .. && make -j12 + + diff --git a/docker/Dockerfile.base b/docker/Dockerfile.base new file mode 100644 index 0000000..e61b0d3 --- /dev/null +++ b/docker/Dockerfile.base @@ -0,0 +1,57 @@ +FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04 +LABEL maintainer "Francesco Gatti" + +ADD nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb /tmp/trt.deb +RUN apt-get update && dpkg -i /tmp/trt.deb && rm /tmp/trt.deb && apt-get update +RUN apt install -y libnvinfer7=7.0.0-1+cuda10.2 libnvinfer-dev=7.0.0-1+cuda10.2 +RUN DEBIAN_FRONTEND=noninteractive apt install -y git wget libeigen3-dev libyaml-cpp-dev +RUN cd /tmp && \ + wget https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-x86_64.sh && \ + chmod +x cmake-3.17.3-Linux-x86_64.sh && \ + ./cmake-3.17.3-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir --skip-license && \ + rm ./cmake-3.17.3-Linux-x86_64.sh + +RUN echo "INSTALL OPENCV" +RUN apt-get install -y build-essential \ + unzip \ + pkg-config \ + libjpeg-dev \ + libpng-dev \ + libtiff-dev \ + libavcodec-dev \ + libavformat-dev \ + libswscale-dev \ + libv4l-dev \ + libxvidcore-dev \ + libx264-dev \ + libgtk-3-dev \ + libatlas-base-dev \ + gfortran \ + libgstreamer1.0-dev \ + libgstreamer-plugins-base1.0-dev \ + libdc1394-22-dev \ + libavresample-dev +RUN cd && wget https://github.com/opencv/opencv/archive/4.3.0.tar.gz && tar -xf 4.3.0.tar.gz && rm *.tar.gz +RUN cd && wget https://github.com/opencv/opencv_contrib/archive/4.3.0.tar.gz && tar -xf 4.3.0.tar.gz && rm *.tar.gz +RUN cd && \ + cd opencv-4.3.0 && mkdir build && cd build && \ + cmake -D CMAKE_BUILD_TYPE=RELEASE \ + -D CMAKE_INSTALL_PREFIX=/usr/local \ + -D INSTALL_PYTHON_EXAMPLES=OFF \ + -D INSTALL_C_EXAMPLES=OFF \ + -D OPENCV_EXTRA_MODULES_PATH='~/opencv_contrib-4.3.0/modules' \ + -D BUILD_EXAMPLES=OFF \ + -D WITH_CUDA=ON \ + -D CUDA_ARCH_BIN=7.2 \ + -D CUDA_ARCH_PTX="" \ + -D ENABLE_FAST_MATH=ON \ + -D CUDA_FAST_MATH=ON \ + -D WITH_CUBLAS=ON \ + -D WITH_LIBV4L=ON \ + -D WITH_GSTREAMER=ON \ + -D WITH_GSTREAMER_0_10=OFF \ + -D WITH_TBB=ON \ + ../ && make -j12 && make install +RUN apt clean + + diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 0000000..aec202a --- /dev/null +++ b/docker/README.md @@ -0,0 +1,21 @@ +# Use the prebuilt image +``` +# build image +docker build -t tkdnn:build -f Dockerfile . +``` + +# Build Base Docker image +``` +# make nvidia docker working +# follow this guide: https://github.com/NVIDIA/nvidia-docker + +# dowload tensorrt +# from: https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.0/7.0.0.11/local_repo/nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb + +# build image +docker build -t ceccocats/tkdnn:latest -f Dockerfile.base . + +# run image +docker run -ti --gpus all --rm ceccocats/tkdnn:latest bash +``` + diff --git a/include/tkDNN/CenternetDetection.h b/include/tkDNN/CenternetDetection.h index 10fccec..3c8cfbb 100644 --- a/include/tkDNN/CenternetDetection.h +++ b/include/tkDNN/CenternetDetection.h @@ -73,9 +73,9 @@ public: CenternetDetection() {}; ~CenternetDetection() {}; - bool init(const std::string& tensor_path, const int n_classes=80); - void preprocess(cv::Mat &frame); - void postprocess(); + bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3); + void preprocess(cv::Mat &frame, const int bi=0); + void postprocess(const int bi=0,const bool mAP=false); }; diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h new file mode 100644 index 0000000..089c4d6 --- /dev/null +++ b/include/tkDNN/DarknetParser.h @@ -0,0 +1,51 @@ +#pragma once +#include +#include "tkDNN/tkdnn.h" + +namespace tk { namespace dnn { + + struct darknetFields_t{ + std::string type = ""; + int width = 0; + int height = 0; + int channels = 3; + int batch_normalize=0; + int groups = 1; + int group_id = 0; + int filters=1; + int size_x=1; + int size_y=1; + int stride_x=1; + int stride_y=1; + int padding_x = 0; + int padding_y = 0; + int n_mask = 0; + int classes = 20; + int num = 1; + int pad = 0; + int coords = 4; + int nms_kind = 0; + int new_coords= 0; + float scale_xy = 1; + float nms_thresh = 0.45; + std::vector layers; + std::string activation = "linear"; + + friend std::ostream& operator<<(std::ostream& os, const darknetFields_t& f){ + os << f.width << " " << f.height << " " << f.channels << " " << f.batch_normalize<< " " << f.filters << " " << f.activation<< " " << f.scale_xy; + return os; + } + }; + + std::string darknetParseType(const std::string& line); + bool divideNameAndValue(const std::string& line, std::string&name, std::string& value); + std::vector fromStringToIntVec(const std::string& line, const char delimiter); + + bool darknetParseFields(const std::string& line, darknetFields_t& fields); + tk::dnn::Network *darknetAddNet(darknetFields_t &fields); + void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &f, std::string wgs_path, + std::vector &netLayers, const std::vector& names); + std::vector darknetReadNames(const std::string& names_file); + tk::dnn::Network* darknetParser(const std::string& cfg_file, const std::string& wgs_path, const std::string& names_file); + +}} diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index ccb379c..0498d41 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -14,7 +14,7 @@ #include "tkdnn.h" -//#define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. +// #define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. #ifdef OPENCV_CUDACONTRIB #include @@ -30,10 +30,12 @@ class DetectionNN { tk::dnn::NetworkRT *netRT = nullptr; dnnType *input_d; - cv::Size originalSize; + std::vector originalSize; cv::Scalar colors[256]; + int nBatches = 1; + #ifdef OPENCV_CUDACONTRIB cv::cuda::GpuMat bgr[3]; cv::cuda::GpuMat imagePreproc; @@ -47,21 +49,26 @@ class DetectionNN { * This method preprocess the image, before feeding it to the NN. * * @param frame original frame to adapt for inference. + * @param bi batch index */ - virtual void preprocess(cv::Mat &frame) = 0; + virtual void preprocess(cv::Mat &frame, const int bi=0) = 0; /** * This method postprocess the output of the NN to obtain the correct * boundig boxes. * + * @param bi batch index + * @param mAP set to true only if all the probabilities for a bounding + * box are needed, as in some cases for the mAP calculation */ - virtual void postprocess() = 0; + virtual void postprocess(const int bi=0,const bool mAP=false) = 0; public: int classes = 0; float confThreshold = 0.3; /*threshold on the confidence of the boxes*/ std::vector detected; /*bounding boxes in output*/ + std::vector> batchDetected; /*bounding boxes in output*/ std::vector stats; /*keeps track of inference times (ms)*/ std::vector classesNames; @@ -69,66 +76,76 @@ class DetectionNN { ~DetectionNN(){}; /** - * Method used to inialize the class, allocate memory and compute + * Method used to initialize the class, allocate memory and compute * needed data. * - * @param tensor_path path to the rt file og the NN. + * @param tensor_path path to the rt file of the NN. * @param n_classes number of classes for the given dataset. + * @param n_batches maximum number of batches to use in inference * @return true if everything is correct, false otherwise. */ - virtual bool init(const std::string& tensor_path, const int n_classes=80) = 0; + virtual bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3) = 0; /** * This method performs the whole detection of the NN. * - * @param frame frame to run detection on. + * @param frames frames to run detection on. + * @param cur_batches number of batches to use in inference * @param save_times if set to true, preprocess, inference and postprocess times * are saved on a csv file, otherwise not. * @param times pointer to the output stream where to write times + * @param mAP set to true only if all the probabilities for a bounding + * box are needed, as in some cases for the mAP calculation */ - void update(cv::Mat &frame, bool save_times=false, std::ofstream *times=nullptr){ - if(!frame.data) - FatalError("No image data feed to detection"); - + void update(std::vector& frames, const int cur_batches=1, bool save_times=false, std::ofstream *times=nullptr, const bool mAP=false){ if(save_times && times==nullptr) FatalError("save_times set to true, but no valid ofstream given"); + if(cur_batches > nBatches) + FatalError("A batch size greater than nBatches cannot be used"); - originalSize = frame.size(); - printCenteredTitle(" TENSORRT detection ", '=', 30); + originalSize.clear(); + if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); { - TIMER_START - preprocess(frame); - TIMER_STOP + TKDNN_TSTART + for(int bi=0; biinput_dim; + dim.n = cur_batches; { - dim.print(); - TIMER_START + if(TKDNN_VERBOSE) dim.print(); + TKDNN_TSTART netRT->infer(dim, input_d); - TIMER_STOP - dim.print(); + TKDNN_TSTOP + if(TKDNN_VERBOSE) dim.print(); stats.push_back(t_ns); if(save_times) *times<& frames) { tk::dnn::box b; int x0, w, x1, y0, h, y1; int objClass; @@ -137,24 +154,26 @@ class DetectionNN { int baseline = 0; float font_scale = 0.5; int thickness = 2; - // draw dets - for(int i=0; i is the net bidir */ - bool returnSeq = false; /**> if false return only the result of last timestep */ + bool returnSeq = false; /**> if false return only the result of last timestamp */ int stateSize = 0; /**> number of hidden states */ - int seqLen = 0; /**> number of timesteps */ + int seqLen = 0; /**> number of timestamp */ int numLayers = 1; /**> number of internal layers */ protected: @@ -326,7 +367,7 @@ public: /** - Deformable Convolutionl 2d layer + Deformable Convolutional 2d layer */ class DeformConv2d : public LayerWgs { @@ -408,7 +449,7 @@ protected: /** - Avaible pooling functions (padding on tkDNN is not supported) + Available pooling functions (padding on tkDNN is not supported) */ typedef enum { POOLING_MAX = 0, @@ -419,7 +460,7 @@ typedef enum { /** Pooling layer - currenty supported only 2d pooing (also on 3d input) + currently supported only 2d pooing (also on 3d input) */ class Pooling : public Layer { @@ -468,7 +509,7 @@ public: class Route : public Layer { public: - Route(Network *net, Layer **layers, int layers_n); + Route(Network *net, Layer **layers, int layers_n, int groups = 1, int group_id = 0); virtual ~Route(); virtual layerType_t getLayerType() { return LAYER_ROUTE; }; @@ -478,12 +519,14 @@ public: static const int MAX_LAYERS = 32; Layer *layers[MAX_LAYERS]; //ids of layers to be merged int layers_n; //number of layers + int groups; + int group_id; }; /** Reorg layer - Mantain same dimension but change C*H*W distribution + Maintains same dimension but change C*H*W distribution */ class Reorg : public Layer { @@ -516,7 +559,7 @@ public: /** Upsample layer - Mantain same dimension but change C*H*W distribution + Maintains same dimension but change C*H*W distribution */ class Upsample : public Layer { @@ -535,6 +578,7 @@ struct box { int cl; float x, y, w, h; float prob; + std::vector probs; void print() { @@ -576,24 +620,28 @@ public: int sort_class; }; - Yolo(Network *net, int classes, int num, std::string fname_weights,int n_masks=3, float scale_xy=1); + enum nmsKind_t {GREEDY_NMS=0, DIOU_NMS=1}; + + Yolo(Network *net, int classes, int num, std::string fname_weights,int n_masks=3, float scale_xy=1, double nms_thresh=0.45, nmsKind_t nsm_kind=GREEDY_NMS, int new_coords=0); virtual ~Yolo(); virtual layerType_t getLayerType() { return LAYER_YOLO; }; - int classes, num, n_masks; + int classes, num, n_masks, new_coords; dnnType *mask_h, *mask_d; //anchors dnnType *bias_h, *bias_d; //anchors float scaleXY; + double nms_thresh; + nmsKind_t nsm_kind; std::vector classesNames; virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); - int computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh); + int computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh, int new_coords=0); dnnType *predictions; - static const int MAX_DETECTIONS = 2048; + static const int MAX_DETECTIONS = 8192*2; static Yolo::detection *allocateDetections(int nboxes, int classes); - static void mergeDetections(Yolo::detection *dets, int ndets, int classes); + static void mergeDetections(Yolo::detection *dets, int ndets, int classes, double nms_thresh=0.45, nmsKind_t nsm_kind=GREEDY_NMS); }; /** diff --git a/include/tkDNN/MobilenetDetection.h b/include/tkDNN/MobilenetDetection.h index fea1449..9a5fedc 100644 --- a/include/tkDNN/MobilenetDetection.h +++ b/include/tkDNN/MobilenetDetection.h @@ -65,9 +65,9 @@ public: MobilenetDetection() {}; ~MobilenetDetection() {}; - bool init(const std::string& tensor_path, const int n_classes); - void preprocess(cv::Mat &frame); - void postprocess(); + bool init(const std::string& tensor_path, const int n_classes, const int n_batches=1, const float conf_thresh=0.3); + void preprocess(cv::Mat &frame, const int bi=0); + void postprocess(const int bi=0,const bool mAP=false); }; diff --git a/include/tkDNN/Network.h b/include/tkDNN/Network.h index 0e8fef8..b78acff 100644 --- a/include/tkDNN/Network.h +++ b/include/tkDNN/Network.h @@ -7,12 +7,12 @@ namespace tk { namespace dnn { /** - Data rapresentation beetween layers + Data representation between layers n = batch size c = channels - h = heigth (lines) + h = height (lines) w = width (rows) - l = lenght (3rd dimension) + l = length (3rd dimension) */ struct dataDim_t { @@ -40,9 +40,10 @@ class Network { public: Network(dataDim_t input_dim); virtual ~Network(); + void releaseLayers(); /** - Do inferece for every added layer + Do inference for every added layer */ dnnType* infer(dataDim_t &dim, dnnType* data); diff --git a/include/tkDNN/NetworkRT.h b/include/tkDNN/NetworkRT.h index ee1f728..4c6c816 100644 --- a/include/tkDNN/NetworkRT.h +++ b/include/tkDNN/NetworkRT.h @@ -28,7 +28,7 @@ using namespace nvinfer1; #include "pluginsRT/ActivationMishRT.h" #include "pluginsRT/ReorgRT.h" #include "pluginsRT/RegionRT.h" -//#include "pluginsRT/RouteRT.h" +#include "pluginsRT/RouteRT.h" #include "pluginsRT/ShortcutRT.h" #include "pluginsRT/YoloRT.h" #include "pluginsRT/UpsampleRT.h" @@ -91,7 +91,7 @@ public: } /** - Do inferece + Do inference */ dnnType* infer(dataDim_t &dim, dnnType* data); void enqueue(int batchSize = 1); diff --git a/include/tkDNN/NetworkViz.h b/include/tkDNN/NetworkViz.h new file mode 100644 index 0000000..c8b1bea --- /dev/null +++ b/include/tkDNN/NetworkViz.h @@ -0,0 +1,12 @@ +#pragma once +#include +#include +#include "tkdnn.h" + +namespace tk { namespace dnn { + +cv::Mat vizFloat2colorMap(cv::Mat map); +cv::Mat vizData2Mat(dnnType *dataInput, tk::dnn::dataDim_t dim, int imgdim); +cv::Mat vizLayer2Mat(tk::dnn::Network *net, int layer, int imgdim = 1000); + +}} diff --git a/include/tkDNN/Yolo3Detection.h b/include/tkDNN/Yolo3Detection.h index e8be562..100a720 100644 --- a/include/tkDNN/Yolo3Detection.h +++ b/include/tkDNN/Yolo3Detection.h @@ -24,9 +24,9 @@ public: Yolo3Detection() {}; ~Yolo3Detection() {}; - bool init(const std::string& tensor_path, const int n_classes=80); - void preprocess(cv::Mat &frame); - void postprocess(); + bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3); + void preprocess(cv::Mat &frame, const int bi=0); + void postprocess(const int bi=0,const bool mAP=false); }; diff --git a/include/tkDNN/evaluation.h b/include/tkDNN/evaluation.h index d76bb7d..128eba0 100644 --- a/include/tkDNN/evaluation.h +++ b/include/tkDNN/evaluation.h @@ -73,12 +73,12 @@ double computeMap( std::vector &images,const int classes, * all the recall levels are evaluated, otherwise only * map_point recall levels are used. For COCO evaluation * 101 points are used. - * @param map_step step used to increment IoU theshold + * @param map_step step used to increment IoU threshold * @param map_levels number of IoU step to perform * @param verbose is set to true, prints on screen additional info * @param write_on_file if set to true, the results produced by this function * are written on file - * @param net name of the considerd neural network + * @param net name of the considered neural network * * @return mAP IoU_tresh:IoU_tresh+map_step*map_levels (e.g. mAP 0.5:0.95 when * map_step=0.05 and map_levels=10) @@ -89,7 +89,7 @@ double computeMapNIoULevels(std::vector &images,const int classes, const int map_levels=10, const bool verbose=false, const bool write_on_file = false, std::string net = ""); /** - * This method computes the numper of True Positive (TP), False Positive (FP), + * This method computes the number of True Positive (TP), False Positive (FP), * False Negative (FN), precision, recall and f1-score. * Those values are computer over all the detections, over all the classes. * @@ -101,13 +101,16 @@ double computeMapNIoULevels(std::vector &images,const int classes, * @param verbose is set to true, prints on screen additional info * @param write_on_file if set to true, the results produced by this function * are written on file - * @param net name of the considerd neural network + * @param net name of the considered neural network */ void computeTPFPFN( std::vector &images,const int classes, const float IoU_thresh=0.5, const float conf_thresh=0.3, bool verbose=false, const bool write_on_file=false, std::string net=""); + +void printJsonCOCOFormat(std::ofstream *out_file, const std::string image_path, std::vector bbox, const int classes, const int w, const int h); + }} #endif /*EVALUATION_H*/ diff --git a/include/tkDNN/models/Yolo3.h b/include/tkDNN/models/Yolo3.h deleted file mode 100644 index cd69b32..0000000 --- a/include/tkDNN/models/Yolo3.h +++ /dev/null @@ -1,289 +0,0 @@ -int preYoloFilters = (classes+5)*3; - -std::string input_bin = bin_path + "/layers/input.bin"; -std::vector output_bins = { - bin_path + "/debug/layer82_out.bin", - bin_path + "/debug/layer94_out.bin", - bin_path + "/debug/layer106_out.bin" -}; -std::string c0_bin = bin_path + "/layers/c0.bin"; -std::string c1_bin = bin_path + "/layers/c1.bin"; -std::string c2_bin = bin_path + "/layers/c2.bin"; -std::string c3_bin = bin_path + "/layers/c3.bin"; -std::string c5_bin = bin_path + "/layers/c5.bin"; -std::string c6_bin = bin_path + "/layers/c6.bin"; -std::string c7_bin = bin_path + "/layers/c7.bin"; -std::string c9_bin = bin_path + "/layers/c9.bin"; -std::string c10_bin = bin_path + "/layers/c10.bin"; -std::string c12_bin = bin_path + "/layers/c12.bin"; -std::string c13_bin = bin_path + "/layers/c13.bin"; -std::string c14_bin = bin_path + "/layers/c14.bin"; -std::string c16_bin = bin_path + "/layers/c16.bin"; -std::string c17_bin = bin_path + "/layers/c17.bin"; -std::string c19_bin = bin_path + "/layers/c19.bin"; -std::string c20_bin = bin_path + "/layers/c20.bin"; -std::string c22_bin = bin_path + "/layers/c22.bin"; -std::string c23_bin = bin_path + "/layers/c23.bin"; -std::string c25_bin = bin_path + "/layers/c25.bin"; -std::string c26_bin = bin_path + "/layers/c26.bin"; -std::string c28_bin = bin_path + "/layers/c28.bin"; -std::string c29_bin = bin_path + "/layers/c29.bin"; -std::string c31_bin = bin_path + "/layers/c31.bin"; -std::string c32_bin = bin_path + "/layers/c32.bin"; -std::string c34_bin = bin_path + "/layers/c34.bin"; -std::string c35_bin = bin_path + "/layers/c35.bin"; -std::string c37_bin = bin_path + "/layers/c37.bin"; -std::string c38_bin = bin_path + "/layers/c38.bin"; -std::string c39_bin = bin_path + "/layers/c39.bin"; -std::string c41_bin = bin_path + "/layers/c41.bin"; -std::string c42_bin = bin_path + "/layers/c42.bin"; -std::string c44_bin = bin_path + "/layers/c44.bin"; -std::string c45_bin = bin_path + "/layers/c45.bin"; -std::string c47_bin = bin_path + "/layers/c47.bin"; -std::string c48_bin = bin_path + "/layers/c48.bin"; -std::string c50_bin = bin_path + "/layers/c50.bin"; -std::string c51_bin = bin_path + "/layers/c51.bin"; -std::string c53_bin = bin_path + "/layers/c53.bin"; -std::string c54_bin = bin_path + "/layers/c54.bin"; -std::string c56_bin = bin_path + "/layers/c56.bin"; -std::string c57_bin = bin_path + "/layers/c57.bin"; -std::string c59_bin = bin_path + "/layers/c59.bin"; -std::string c60_bin = bin_path + "/layers/c60.bin"; -std::string c62_bin = bin_path + "/layers/c62.bin"; -std::string c63_bin = bin_path + "/layers/c63.bin"; -std::string c64_bin = bin_path + "/layers/c64.bin"; -std::string c66_bin = bin_path + "/layers/c66.bin"; -std::string c67_bin = bin_path + "/layers/c67.bin"; -std::string c69_bin = bin_path + "/layers/c69.bin"; -std::string c70_bin = bin_path + "/layers/c70.bin"; -std::string c72_bin = bin_path + "/layers/c72.bin"; -std::string c73_bin = bin_path + "/layers/c73.bin"; -std::string c75_bin = bin_path + "/layers/c75.bin"; -std::string c76_bin = bin_path + "/layers/c76.bin"; -std::string c77_bin = bin_path + "/layers/c77.bin"; -std::string c78_bin = bin_path + "/layers/c78.bin"; -std::string c79_bin = bin_path + "/layers/c79.bin"; -std::string c80_bin = bin_path + "/layers/c80.bin"; -std::string c81_bin = bin_path + "/layers/c81.bin"; -std::string g82_bin = bin_path + "/layers/g82.bin"; -std::string c84_bin = bin_path + "/layers/c84.bin"; -std::string c87_bin = bin_path + "/layers/c87.bin"; -std::string c88_bin = bin_path + "/layers/c88.bin"; -std::string c89_bin = bin_path + "/layers/c89.bin"; -std::string c90_bin = bin_path + "/layers/c90.bin"; -std::string c91_bin = bin_path + "/layers/c91.bin"; -std::string c92_bin = bin_path + "/layers/c92.bin"; -std::string c93_bin = bin_path + "/layers/c93.bin"; -std::string g94_bin = bin_path + "/layers/g94.bin"; -std::string c96_bin = bin_path + "/layers/c96.bin"; -std::string c99_bin = bin_path + "/layers/c99.bin"; -std::string c100_bin = bin_path + "/layers/c100.bin"; -std::string c101_bin = bin_path + "/layers/c101.bin"; -std::string c102_bin = bin_path + "/layers/c102.bin"; -std::string c103_bin = bin_path + "/layers/c103.bin"; -std::string c104_bin = bin_path + "/layers/c104.bin"; -std::string c105_bin = bin_path + "/layers/c105.bin"; -std::string g106_bin = bin_path + "/layers/g106.bin"; - -tk::dnn::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true); -tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c1 (&net, 64, 3, 3, 2, 2, 1, 1, c1_bin, true); -tk::dnn::Activation a1 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c2 (&net, 32, 1, 1, 1, 1, 0, 0, c2_bin, true); -tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c3 (&net, 64, 3, 3, 1, 1, 1, 1, c3_bin, true); -tk::dnn::Activation a3 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s4 (&net, &a1); -tk::dnn::Conv2d c5 (&net, 128, 3, 3, 2, 2, 1, 1, c5_bin, true); -tk::dnn::Activation a5 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c6 (&net, 64, 1, 1, 1, 1, 0, 0, c6_bin, true); -tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c7 (&net, 128, 3, 3, 1, 1, 1, 1, c7_bin, true); -tk::dnn::Activation a7 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s8 (&net, &a5); -tk::dnn::Conv2d c9 (&net, 64, 1, 1, 1, 1, 0, 0, c9_bin, true); -tk::dnn::Activation a9 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c10 (&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true); -tk::dnn::Activation a10 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s11 (&net, &s8); - -tk::dnn::Conv2d c12 (&net, 256, 3, 3, 2, 2, 1, 1, c12_bin, true); -tk::dnn::Activation a12 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c13 (&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true); -tk::dnn::Activation a13 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c14 (&net, 256, 3, 3, 1, 1, 1, 1, c14_bin, true); -tk::dnn::Activation a14 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s15 (&net, &a12); - -tk::dnn::Conv2d c16 (&net, 128, 1, 1, 1, 1, 0, 0, c16_bin, true); -tk::dnn::Activation a16 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c17 (&net, 256, 3, 3, 1, 1, 1, 1, c17_bin, true); -tk::dnn::Activation a17 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s18 (&net, &s15); -tk::dnn::Conv2d c19 (&net, 128, 1, 1, 1, 1, 0, 0, c19_bin, true); -tk::dnn::Activation a19 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c20 (&net, 256, 3, 3, 1, 1, 1, 1, c20_bin, true); -tk::dnn::Activation a20 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s21 (&net, &s18); -tk::dnn::Conv2d c22 (&net, 128, 1, 1, 1, 1, 0, 0, c22_bin, true); -tk::dnn::Activation a22 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c23 (&net, 256, 3, 3, 1, 1, 1, 1, c23_bin, true); -tk::dnn::Activation a23 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s24 (&net, &s21); -tk::dnn::Conv2d c25 (&net, 128, 1, 1, 1, 1, 0, 0, c25_bin, true); -tk::dnn::Activation a25 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c26 (&net, 256, 3, 3, 1, 1, 1, 1, c26_bin, true); -tk::dnn::Activation a26 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s27 (&net, &s24); -tk::dnn::Conv2d c28 (&net, 128, 1, 1, 1, 1, 0, 0, c28_bin, true); -tk::dnn::Activation a28 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c29 (&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true); -tk::dnn::Activation a29 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s30 (&net, &s27); -tk::dnn::Conv2d c31 (&net, 128, 1, 1, 1, 1, 0, 0, c31_bin, true); -tk::dnn::Activation a31 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c32 (&net, 256, 3, 3, 1, 1, 1, 1, c32_bin, true); -tk::dnn::Activation a32 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s33 (&net, &s30); -tk::dnn::Conv2d c34 (&net, 128, 1, 1, 1, 1, 0, 0, c34_bin, true); -tk::dnn::Activation a34 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c35 (&net, 256, 3, 3, 1, 1, 1, 1, c35_bin, true); -tk::dnn::Activation a35 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s36 (&net, &s33); - -tk::dnn::Conv2d c37 (&net, 512, 3, 3, 2, 2, 1, 1, c37_bin, true); -tk::dnn::Activation a37 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c38 (&net, 256, 1, 1, 1, 1, 0, 0, c38_bin, true); -tk::dnn::Activation a38 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c39 (&net, 512, 3, 3, 1, 1, 1, 1, c39_bin, true); -tk::dnn::Activation a39 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s40 (&net, &a37); - -tk::dnn::Conv2d c41 (&net, 256, 1, 1, 1, 1, 0, 0, c41_bin, true); -tk::dnn::Activation a41 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c42 (&net, 512, 3, 3, 1, 1, 1, 1, c42_bin, true); -tk::dnn::Activation a42 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s43 (&net, &s40); -tk::dnn::Conv2d c44 (&net, 256, 1, 1, 1, 1, 0, 0, c44_bin, true); -tk::dnn::Activation a44 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c45 (&net, 512, 3, 3, 1, 1, 1, 1, c45_bin, true); -tk::dnn::Activation a45 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s46 (&net, &s43); -tk::dnn::Conv2d c47 (&net, 256, 1, 1, 1, 1, 0, 0, c47_bin, true); -tk::dnn::Activation a47 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c48 (&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true); -tk::dnn::Activation a48 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s49 (&net, &s46); -tk::dnn::Conv2d c50 (&net, 256, 1, 1, 1, 1, 0, 0, c50_bin, true); -tk::dnn::Activation a50 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c51 (&net, 512, 3, 3, 1, 1, 1, 1, c51_bin, true); -tk::dnn::Activation a51 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s52 (&net, &s49); -tk::dnn::Conv2d c53 (&net, 256, 1, 1, 1, 1, 0, 0, c53_bin, true); -tk::dnn::Activation a53 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c54 (&net, 512, 3, 3, 1, 1, 1, 1, c54_bin, true); -tk::dnn::Activation a54 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s55 (&net, &s52); -tk::dnn::Conv2d c56 (&net, 256, 1, 1, 1, 1, 0, 0, c56_bin, true); -tk::dnn::Activation a56 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c57 (&net, 512, 3, 3, 1, 1, 1, 1, c57_bin, true); -tk::dnn::Activation a57 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s58 (&net, &s55); -tk::dnn::Conv2d c59 (&net, 256, 1, 1, 1, 1, 0, 0, c59_bin, true); -tk::dnn::Activation a59 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c60 (&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true); -tk::dnn::Activation a60 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s61 (&net, &s58); - -tk::dnn::Conv2d c62 (&net,1024, 3, 3, 2, 2, 1, 1, c62_bin, true); -tk::dnn::Activation a62 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c63 (&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true); -tk::dnn::Activation a63 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c64 (&net,1024, 3, 3, 1, 1, 1, 1, c64_bin, true); -tk::dnn::Activation a64 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s65 (&net, &a62); - -tk::dnn::Conv2d c66 (&net, 512, 1, 1, 1, 1, 0, 0, c66_bin, true); -tk::dnn::Activation a66 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c67 (&net,1024, 3, 3, 1, 1, 1, 1, c67_bin, true); -tk::dnn::Activation a67 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s68 (&net, &s65); - -tk::dnn::Conv2d c69 (&net, 512, 1, 1, 1, 1, 0, 0, c69_bin, true); -tk::dnn::Activation a69 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c70 (&net,1024, 3, 3, 1, 1, 1, 1, c70_bin, true); -tk::dnn::Activation a70 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s71 (&net, &s68); - -tk::dnn::Conv2d c72 (&net, 512, 1, 1, 1, 1, 0, 0, c72_bin, true); -tk::dnn::Activation a72 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c73 (&net,1024, 3, 3, 1, 1, 1, 1, c73_bin, true); -tk::dnn::Activation a73 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Shortcut s74 (&net, &s71); - -tk::dnn::Conv2d c75 (&net, 512, 1, 1, 1, 1, 0, 0, c75_bin, true); -tk::dnn::Activation a75 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c76 (&net,1024, 3, 3, 1, 1, 1, 1, c76_bin, true); -tk::dnn::Activation a76 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c77 (&net, 512, 1, 1, 1, 1, 0, 0, c77_bin, true); -tk::dnn::Activation a77 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c78 (&net,1024, 3, 3, 1, 1, 1, 1, c78_bin, true); -tk::dnn::Activation a78 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c79 (&net, 512, 1, 1, 1, 1, 0, 0, c79_bin, true); -tk::dnn::Activation a79 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c80 (&net,1024, 3, 3, 1, 1, 1, 1, c80_bin, true); -tk::dnn::Activation a80 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c81 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c81_bin, false); -tk::dnn::Yolo yolo0 (&net, classes, 3, g82_bin); - -tk::dnn::Layer *m83_layers[1] = { &a79 }; -tk::dnn::Route m83 (&net, m83_layers, 1); -tk::dnn::Conv2d c84 (&net, 256, 1, 1, 1, 1, 0, 0, c84_bin, true); -tk::dnn::Activation a84 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Upsample u85 (&net, 2); - -tk::dnn::Layer *m86_layers[2] = { &u85, &s61 }; -tk::dnn::Route m86 (&net, m86_layers, 2); -tk::dnn::Conv2d c87 (&net, 256, 1, 1, 1, 1, 0, 0, c87_bin, true); -tk::dnn::Activation a87 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c88 (&net, 512, 3, 3, 1, 1, 1, 1, c88_bin, true); -tk::dnn::Activation a88 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c89 (&net, 256, 1, 1, 1, 1, 0, 0, c89_bin, true); -tk::dnn::Activation a89 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c90 (&net, 512, 3, 3, 1, 1, 1, 1, c90_bin, true); -tk::dnn::Activation a90 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c91 (&net, 256, 1, 1, 1, 1, 0, 0, c91_bin, true); -tk::dnn::Activation a91 (&net, tk::dnn::ACTIVATION_LEAKY); - -tk::dnn::Conv2d c92 (&net, 512, 3, 3, 1, 1, 1, 1, c92_bin, true); -tk::dnn::Activation a92 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c93 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c93_bin, false); -tk::dnn::Yolo yolo1 (&net, classes, 3, g94_bin); - -tk::dnn::Layer *m95_layers[1] = { &a91 }; -tk::dnn::Route m95 (&net, m95_layers, 1); -tk::dnn::Conv2d c96 (&net, 128, 1, 1, 1, 1, 0, 0, c96_bin, true); -tk::dnn::Activation a96 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Upsample u97 (&net, 2); - -tk::dnn::Layer *m98_layers[2] = { &u97, &s36 }; -tk::dnn::Route m98 (&net, m98_layers, 2); -tk::dnn::Conv2d c99 (&net, 128, 1, 1, 1, 1, 0, 0, c99_bin, true); -tk::dnn::Activation a99 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c100 (&net, 256, 3, 3, 1, 1, 1, 1, c100_bin, true); -tk::dnn::Activation a100 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c101 (&net, 128, 1, 1, 1, 1, 0, 0, c101_bin, true); -tk::dnn::Activation a101 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c102 (&net, 256, 3, 3, 1, 1, 1, 1, c102_bin, true); -tk::dnn::Activation a102 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c103 (&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true); -tk::dnn::Activation a103 (&net, tk::dnn::ACTIVATION_LEAKY); - -tk::dnn::Conv2d c104 (&net, 256, 3, 3, 1, 1, 1, 1, c104_bin, true); -tk::dnn::Activation a104 (&net, tk::dnn::ACTIVATION_LEAKY); -tk::dnn::Conv2d c105 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c105_bin, false); -tk::dnn::Yolo yolo2 (&net, classes, 3, g106_bin); - -yolo[0] = &yolo0; -yolo[1] = &yolo1; -yolo[2] = &yolo2; \ No newline at end of file diff --git a/include/tkDNN/pluginsRT/DeformableConvRT.h b/include/tkDNN/pluginsRT/DeformableConvRT.h index bff6370..225a24e 100644 --- a/include/tkDNN/pluginsRT/DeformableConvRT.h +++ b/include/tkDNN/pluginsRT/DeformableConvRT.h @@ -89,7 +89,7 @@ public: for(int b=0; bgroups = groups; + this->group_id = group_id; } ~RouteRT(){ @@ -22,7 +24,7 @@ public: Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override { int out_c = 0; for(int i=0; i(outputs[0]); - int offset = 0; - for(int i=0; i(inputs[i]); - int in_dim = c_in[i]*h*w; - checkCuda( cudaMemcpyAsync(dstData + offset, input, in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream) ); - offset += in_dim; + for(int b=0; b(inputs[i]); + int in_dim = c_in[i]*h*w; + int part_in_dim = in_dim / this->groups; + checkCuda( cudaMemcpyAsync(dstData + b*c*w*h + offset, input + b*c*w*h*groups + this->group_id*part_in_dim, part_in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream) ); + offset += part_in_dim; + } } return 0; @@ -65,11 +71,13 @@ public: virtual size_t getSerializationSize() override { - return (4+MAX_INPUTS)*sizeof(int); + return (6+MAX_INPUTS)*sizeof(int); } virtual void serialize(void* buffer) override { char *buf = reinterpret_cast(buffer); + tk::dnn::writeBUF(buf, groups); + tk::dnn::writeBUF(buf, group_id); tk::dnn::writeBUF(buf, in); for(int i=0; iclasses = classes; this->num = num; this->n_masks = n_masks; this->scaleXY = scale_xy; + this->nms_thresh = nms_thresh; + this->nms_kind = nms_kind; + this->new_coords = new_coords; mask = new dnnType[n_masks]; bias = new dnnType[num*n_masks*2]; @@ -64,7 +67,10 @@ public: for (int b = 0; b < batchSize; ++b){ for(int n = 0; n < n_masks; ++n){ int index = entry_index(b, n*w*h, 0); - activationLOGISTICForward(srcData + index, dstData + index, 2*w*h, stream); + if (new_coords == 1) + activationLOGISTICForward(srcData + index, dstData + index, 4*w*h, stream); //x,y,w,h + else + activationLOGISTICForward(srcData + index, dstData + index, 2*w*h, stream); //x,y if (this->scaleXY != 1) scalAdd(dstData + index, 2 * w*h, this->scaleXY, -0.5*(this->scaleXY - 1), 1); @@ -79,7 +85,7 @@ public: virtual size_t getSerializationSize() override { - return 6*sizeof(int) + sizeof(float)+ n_masks*sizeof(dnnType) + num*n_masks*2*sizeof(dnnType) + YOLORT_CLASSNAME_W*classes*sizeof(char); + return 8*sizeof(int) + 2*sizeof(float)+ n_masks*sizeof(dnnType) + num*n_masks*2*sizeof(dnnType) + YOLORT_CLASSNAME_W*classes*sizeof(char); } virtual void serialize(void* buffer) override { @@ -87,10 +93,13 @@ public: tk::dnn::writeBUF(buf, classes); tk::dnn::writeBUF(buf, num); tk::dnn::writeBUF(buf, n_masks); + tk::dnn::writeBUF(buf, scaleXY); + tk::dnn::writeBUF(buf, nms_thresh); + tk::dnn::writeBUF(buf, nms_kind); + tk::dnn::writeBUF(buf, new_coords); tk::dnn::writeBUF(buf, c); tk::dnn::writeBUF(buf, h); tk::dnn::writeBUF(buf, w); - tk::dnn::writeBUF(buf, scaleXY); for(int i=0; i classesNames; dnnType *mask; diff --git a/include/tkDNN/test.h b/include/tkDNN/test.h new file mode 100644 index 0000000..13c943e --- /dev/null +++ b/include/tkDNN/test.h @@ -0,0 +1,77 @@ + +#include +int testInference(std::vector input_bins, std::vector output_bins, + tk::dnn::Network *net, tk::dnn::NetworkRT *netRT = nullptr) { + + std::vector outputs; + for(int i=0; inum_layers; i++) { + if(net->layers[i]->final) + outputs.push_back(net->layers[i]); + } + // no final layers, set last as output + if(outputs.size() == 0) { + outputs.push_back(net->layers[net->num_layers-1]); + } + + + // check input + if(input_bins.size() != 1) { + FatalError("currently support only 1 input"); + } + if(output_bins.size() != outputs.size()) { + std::cout<input_dim.tot(), &input_h, &data); + + // outputs + dnnType *cudnn_out[outputs.size()], *rt_out[outputs.size()]; + + tk::dnn::dataDim_t dim1 = net->input_dim; //input dim + printCenteredTitle(" CUDNN inference ", '=', 30); { + dim1.print(); + TKDNN_TSTART + net->infer(dim1, data); + TKDNN_TSTOP + dim1.print(); + } + for(int i=0; idstData; + + if(netRT != nullptr) { + tk::dnn::dataDim_t dim2 = net->input_dim; + printCenteredTitle(" TENSORRT inference ", '=', 30); { + dim2.print(); + TKDNN_TSTART + netRT->infer(dim2, data); + TKDNN_TSTOP + dim2.print(); + } + for(int i=0; ibuffersRT[i+1]; + } + + int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0; + for(int i=0; i> $out_file print_output $? imuodom test_net yolo4 - test_net resnet101_cnet + test_net yolo4x + test_net yolo4_berkeley + test_net yolo4tiny test_net yolo3 + test_net yolo3_berkeley + test_net yolo3_coco4 test_net yolo3_flir test_net yolo3_512 - test_net yolo3_tiny + test_net yolo3tiny + test_net yolo3tiny_512 + test_net yolo2 + test_net yolo2_voc + #test_net yolo2tiny test_net csresnext50-panet-spp - test_net mobilenetv2ssd - test_net yolo3_tiny512 - test_net yolo_tiny - test_net mobilenetv2ssd512 - test_net mnist - test_net yolo - test_net yolo3_berkeley - test_net yolo_voc + #test_net csresnext50-panet-spp_berkeley + test_net resnet101_cnet test_net dla34_cnet - test_net yolo3_coco4 - + test_net mobilenetv2ssd + test_net mobilenetv2ssd512 + test_net bdd-mobilenetv2ssd done echo "If errors occured, check logfile $out_file" diff --git a/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index 97668e6..46757f4 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -3,10 +3,12 @@ namespace tk { namespace dnn { -bool CenternetDetection::init(const std::string& tensor_path, const int n_classes){ +bool CenternetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh){ std::cout<<(tensor_path).c_str()<<"\n"; netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str() ); classes = n_classes; + nBatches = n_batches; + confThreshold = conf_thresh; dim = netRT->input_dim; @@ -41,7 +43,7 @@ bool CenternetDetection::init(const std::string& tensor_path, const int n_classe trans = cv::Mat(cv::Size(3,2), CV_32F); trans2 = cv::Mat(cv::Size(3,2), CV_32F); - checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*netRT->input_dim.tot())); + checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*netRT->input_dim.tot() * nBatches)); dim_hm = tk::dnn::dataDim_t(1, 80, 128, 128, 1); dim_wh = tk::dnn::dataDim_t(1, 2, 128, 128, 1); @@ -98,7 +100,7 @@ bool CenternetDetection::init(const std::string& tensor_path, const int n_classe checkCuda(cudaMemcpy(mean_d, mean, 3*sizeof(float), cudaMemcpyHostToDevice)); checkCuda(cudaMemcpy(stddev_d, stddev, 3*sizeof(float), cudaMemcpyHostToDevice)); #else - checkCuda(cudaMallocHost(&input, sizeof(dnnType)*netRT->input_dim.tot())); + checkCuda(cudaMallocHost(&input, sizeof(dnnType)*netRT->input_dim.tot()* nBatches)); mean << 0.408, 0.447, 0.47; stddev << 0.289, 0.274, 0.278; #endif @@ -120,13 +122,13 @@ bool CenternetDetection::init(const std::string& tensor_path, const int n_classe } -void CenternetDetection::preprocess(cv::Mat &frame){ +void CenternetDetection::preprocess(cv::Mat &frame, const int bi){ // -----------------------------------pre-process ------------------------------------------ // auto start_t = std::chrono::steady_clock::now(); // auto step_t = std::chrono::steady_clock::now(); // auto end_t = std::chrono::steady_clock::now(); - cv::Size sz = originalSize; + cv::Size sz = originalSize[bi]; // std::cout<<"image: "<(end_t - step_t).count() << " us" << std::endl; // step_t = end_t; - checkCuda(cudaMemcpy(input_d, d_ptrs, dim2.tot()*sizeof(dnnType), cudaMemcpyDeviceToDevice)); + checkCuda(cudaMemcpy(input_d+ netRT->input_dim.tot()*bi, d_ptrs, dim2.tot()*sizeof(dnnType), cudaMemcpyDeviceToDevice)); // end_t = std::chrono::steady_clock::now(); // std::cout << " TIME Memcpy to input_d: " << std::chrono::duration_cast(end_t - step_t).count() << " us" << std::endl; @@ -254,18 +256,18 @@ void CenternetDetection::preprocess(cv::Mat &frame){ int idx = i*imageF.rows*imageF.cols; int ch = dim2.c-3 +i; // std::cout<<"i: "<input_dim.tot()*bi], (void*)bgr[ch].data, imageF.rows*imageF.cols*sizeof(dnnType)); } - checkCuda(cudaMemcpyAsync(input_d, input, dim2.tot()*sizeof(dnnType), cudaMemcpyHostToDevice)); + checkCuda(cudaMemcpyAsync(input_d+ netRT->input_dim.tot()*bi, input+ netRT->input_dim.tot()*bi, dim2.tot()*sizeof(dnnType), cudaMemcpyHostToDevice)); #endif } -void CenternetDetection::postprocess(){ +void CenternetDetection::postprocess(const int bi, const bool mAP){ dnnType *rt_out[4]; - rt_out[0] = (dnnType *)netRT->buffersRT[1]; - rt_out[1] = (dnnType *)netRT->buffersRT[2]; - rt_out[2] = (dnnType *)netRT->buffersRT[3]; - rt_out[3] = (dnnType *)netRT->buffersRT[4]; + rt_out[0] = (dnnType *)netRT->buffersRT[1]+ netRT->buffersDIM[1].tot()*bi; + rt_out[1] = (dnnType *)netRT->buffersRT[2]+ netRT->buffersDIM[2].tot()*bi; + rt_out[2] = (dnnType *)netRT->buffersRT[3]+ netRT->buffersDIM[3].tot()*bi; + rt_out[3] = (dnnType *)netRT->buffersRT[4]+ netRT->buffersDIM[4].tot()*bi; // auto start_t = std::chrono::steady_clock::now(); // auto step_t = std::chrono::steady_clock::now(); @@ -370,10 +372,10 @@ void CenternetDetection::postprocess(){ // std::cout<<"th: "<(end_t - step_t).count() << " us" << std::endl; // step_t = end_t; diff --git a/src/Conv2d.cpp b/src/Conv2d.cpp index 4704c66..b57cf58 100644 --- a/src/Conv2d.cpp +++ b/src/Conv2d.cpp @@ -62,25 +62,30 @@ void Conv2d::initCUDNN(bool back) { // init workspace workSpace = NULL; ws_sizeInBytes = 0; + int algo_count = 0; if(back) { - checkCUDNN( cudnnGetConvolutionBackwardDataAlgorithm(net->cudnnHandle, - filterDesc, dstTensor, convDesc, srcTensor, - CUDNN_CONVOLUTION_BWD_DATA_PREFER_FASTEST, 0, &bwAlgo) ); + checkCUDNN( cudnnGetConvolutionBackwardDataAlgorithm_v7(net->cudnnHandle, + filterDesc, dstTensor, convDesc, srcTensor, 1, &algo_count, &bwAlgo) ); checkCUDNN(cudnnGetConvolutionBackwardDataWorkspaceSize(net->cudnnHandle, - filterDesc, dstTensor, convDesc, srcTensor, - bwAlgo, &ws_sizeInBytes)); + filterDesc, dstTensor, convDesc, srcTensor, + bwAlgo.algo, &ws_sizeInBytes)); + // invert tensors srcTensorDesc = dstTensor; dstTensorDesc = srcTensor; } else { - checkCUDNN( cudnnGetConvolutionForwardAlgorithm(net->cudnnHandle, - srcTensor, filterDesc, convDesc, dstTensor, - CUDNN_CONVOLUTION_FWD_PREFER_FASTEST, 0, &algo) ); - checkCUDNN(cudnnGetConvolutionForwardWorkspaceSize(net->cudnnHandle, - srcTensor, filterDesc, convDesc, dstTensor, - algo, &ws_sizeInBytes)); + + checkCUDNN( cudnnGetConvolutionForwardAlgorithm_v7(net->cudnnHandle, + srcTensor, filterDesc, convDesc, dstTensor, + 1, &algo_count, &algo) ); + checkCUDNN(cudnnGetConvolutionForwardWorkspaceSize(net->cudnnHandle, + srcTensor, filterDesc, convDesc, dstTensor, + algo.algo, &ws_sizeInBytes)); } + + if(algo_count < 1) + FatalError("Cannot retrieve convolutional algo"); } void Conv2d::inferCUDNN(dnnType* srcData, bool back) { @@ -91,12 +96,12 @@ void Conv2d::inferCUDNN(dnnType* srcData, bool back) { checkCUDNN(cudnnConvolutionBackwardData(net->cudnnHandle, &alpha, filterDesc, data_d, srcTensorDesc, srcData, - convDesc, bwAlgo, workSpace, ws_sizeInBytes, + convDesc, bwAlgo.algo, workSpace, ws_sizeInBytes, &beta, dstTensorDesc, dstData)); } else { checkCUDNN(cudnnConvolutionForward(net->cudnnHandle, &alpha, srcTensorDesc, srcData, filterDesc, - data_d, convDesc, algo, workSpace, ws_sizeInBytes, + data_d, convDesc, algo.algo, workSpace, ws_sizeInBytes, &beta, dstTensorDesc, dstData)); } diff --git a/src/DarknetParser.cpp b/src/DarknetParser.cpp new file mode 100644 index 0000000..7b5410c --- /dev/null +++ b/src/DarknetParser.cpp @@ -0,0 +1,273 @@ +#include "tkDNN/DarknetParser.h" + +namespace tk { namespace dnn { + + std::string darknetParseType(const std::string& line){ + size_t start = line.find("["); + size_t end = line.find("]"); + if( start == std::string::npos || end == std::string::npos) + return ""; + start++; + std::string type = line.substr(start, end-start); + return type; + } + + bool divideNameAndValue(const std::string& line, std::string&name, std::string& value){ + size_t sep = line.find("="); + if(sep == std::string::npos) + return false; + + name = line.substr(0, sep); + value = line.substr(sep+1, line.size() - (sep+1)); + return true; + } + + std::vector fromStringToIntVec(const std::string& line, const char delimiter){ + std::stringstream linestream(line); + std::string value; + std::vector values; + + while(getline(linestream,value,delimiter)) + values.push_back(std::stoi(value)); + return values; + } + + bool darknetParseFields(const std::string& line, darknetFields_t& fields){ + + std::string name,value; + if(!divideNameAndValue(line, name, value)) + return false; + + if(name.find("new_coords") != std::string::npos) + fields.new_coords = std::stoi(value); + else if(name.find("width") != std::string::npos) + fields.width = std::stoi(value); + else if(name.find("height") != std::string::npos) + fields.height = std::stoi(value); + else if(name.find("channels") != std::string::npos) + fields.channels = std::stoi(value); + else if(name.find("batch_normalize") != std::string::npos) + fields.batch_normalize = std::stoi(value); + else if(name.find("filters") != std::string::npos) + fields.filters = std::stoi(value); + else if(name.find("activation") != std::string::npos) + fields.activation = value; + else if(name.find("size") != std::string::npos){ + fields.size_x = std::stoi(value); + fields.size_y = std::stoi(value); + } + else if(name.find("size_x") != std::string::npos) + fields.size_x = std::stoi(value); + else if(name.find("size_y") != std::string::npos) + fields.size_y = std::stoi(value); + else if(name.find("stride") != std::string::npos){ + fields.stride_x = std::stoi(value); + fields.stride_y = std::stoi(value); + } + else if(name.find("stride_x") != std::string::npos) + fields.stride_x = std::stoi(value); + else if(name.find("stride_y") != std::string::npos) + fields.stride_y = std::stoi(value); + else if(name.find("pad") != std::string::npos) + fields.pad = std::stoi(value); + else if(name.find("classes") != std::string::npos) + fields.classes = std::stoi(value); + else if(name.find("num") != std::string::npos) + fields.num = std::stoi(value); + else if(name.find("coords") != std::string::npos) + fields.coords = std::stoi(value); + else if(name.find("groups") != std::string::npos) + fields.groups = std::stoi(value); + else if(name.find("group_id") != std::string::npos) + fields.group_id = std::stoi(value); + else if(name.find("scale_x_y") != std::string::npos) + fields.scale_xy = std::stof(value); + else if(name.find("beta_nms") != std::string::npos) + fields.nms_thresh = std::stof(value); + else if(name.find("nms_kind") != std::string::npos){ + if(value == "greedynms") fields.nms_kind = 0; + else if(value == "diounms") fields.nms_kind = 1; + else std::cout<<"Not supported nms_kind "< &netLayers, const std::vector& names) { + if(net == nullptr) + FatalError("Cant add a layer without a Net\n"); + + // padding compute + if(f.pad == 1) { + f.padding_x = f.padding_y = f.size_x /2; + } + //std::cout<<"Add layer: "<= netLayers.size()) FatalError("impossible to shortcut\n"); + //std::cout<<"shortcut to "<getLayerName()<<"\n"; + netLayers.push_back(new tk::dnn::Shortcut(net, netLayers[layerIdx])); + + } else if(f.type == "upsample") { + netLayers.push_back(new tk::dnn::Upsample(net, f.stride_x)); + + } else if(f.type == "route") { + if(f.layers.size() == 0) FatalError("no layers to Route\n"); + std::vector layers; + for(int i=0; i= netLayers.size()) FatalError("impossible to route\n"); + //std::cout<<"Route to "<getLayerName()<<"\n"; + layers.push_back(netLayers[layerIdx]); + } + netLayers.push_back(new tk::dnn::Route(net, layers.data(), layers.size(), f.groups, f.group_id)); + + } else if(f.type == "reorg") { + netLayers.push_back(new tk::dnn::Reorg(net, f.stride_x)); + + } else if(f.type == "region") { + netLayers.push_back(new tk::dnn::Region(net, f.classes, f.coords, f.num)); + + } else if(f.type == "yolo") { + std::string wgs = wgs_path + "/g" + std::to_string(netLayers.size()) + ".bin"; + //printf("%d %d %s %d %f\n", f.classes, f.num/f.n_mask, wgs.c_str(), f.n_mask, f.scale_xy); + tk::dnn::Yolo *l = new tk::dnn::Yolo(net, f.classes, f.num/f.n_mask, wgs, f.n_mask, f.scale_xy, f.nms_thresh, (tk::dnn::Yolo::nmsKind_t) f.nms_kind, f.new_coords); + if(names.size() != f.classes) + FatalError("Mismatch between number of classes and names"); + l->classesNames = names; + netLayers.push_back(l); + + } else{ + FatalError("layer not supported: " + f.type); + } + + // add activation + if(netLayers.size() > 0 && f.activation != "linear") { + tkdnnActivationMode_t act; + if(f.activation == "relu") act = tkdnnActivationMode_t(CUDNN_ACTIVATION_RELU); + else if(f.activation == "leaky") act = tk::dnn::ACTIVATION_LEAKY; + else if(f.activation == "mish") act = tk::dnn::ACTIVATION_MISH; + else { FatalError("activation not supported: " + f.activation); } + netLayers[netLayers.size()-1] = new tk::dnn::Activation(net, act); + }; + } + + std::vector darknetReadNames(const std::string& names_file){ + std::ifstream if_names(names_file); + if(!if_names.is_open()) + FatalError("cloud not open names file: " + names_file); + + std::vector names; + std::string line; + while(std::getline(if_names, line)) + if(line != "") + names.push_back(line); + + if_names.close(); + return names; + } + + tk::dnn::Network* darknetParser(const std::string& cfg_file, const std::string& wgs_path, const std::string& names_file) { + + tk::dnn::Network *net = nullptr; + + // layers without activations to retrieve correct id number + std::vector netLayers; + + std::ifstream if_cfg(cfg_file); + if(!if_cfg.is_open()) + FatalError("cloud not open cfg file: " + cfg_file); + + std::vector names = darknetReadNames(names_file); + + darknetFields_t fields; // will be filled with layers fields + std::string line; + while(std::getline(if_cfg, line)) { + // remove comments + std::size_t found = line.find("#"); + if ( found != std::string::npos ) { + line = line.substr(0, found); + } + + // skip empty lines + if(line.size() == 0) + continue; + + std::string type = darknetParseType(line); + if(type.size() > 0) { + // end of filled type + if(fields.type != "") { + if(fields.type == "net") + net = darknetAddNet(fields); + else + darknetAddLayer(net, fields, wgs_path, netLayers, names); + } + + // new type + //std::cout<<"type: "<cublasHandle, CUBLAS_OP_T, dim_x, dim_y, &alpha, diff --git a/src/Int8BatchStream.cpp b/src/Int8BatchStream.cpp index dd4399f..fdc1db2 100644 --- a/src/Int8BatchStream.cpp +++ b/src/Int8BatchStream.cpp @@ -132,21 +132,14 @@ void BatchStream::readCVimage(std::string inputFileName, std::vector& res void BatchStream::readLabels(std::string inputFileName, std::vector& ris) { std::ifstream is(inputFileName.c_str()); - //read only the first number: the image sub-portion class - while (true) { + + std::string line; + while (std::getline(is, line)) + { + std::istringstream iss(line); float val; - is >> val; - if (!is) { - break; - } - // insert the first number and skip all others + if(!(iss >> val)) { break; } // error ris.push_back(val); - while( true ) { - char c; - is >> c; - if (is.peek() == '\n') //detect "\n" - break; - } } } diff --git a/src/LSTM.cpp b/src/LSTM.cpp index 6ecf4fd..7b87711 100644 --- a/src/LSTM.cpp +++ b/src/LSTM.cpp @@ -86,7 +86,11 @@ LSTM::LSTM( Network *net, int hiddensize, bool returnSeq, std::string fname_weig // RNN descriptors checkCUDNN(cudnnCreateRNNDescriptor(&rnnDesc)); - checkCUDNN(cudnnSetRNNDescriptor(net->cudnnHandle, +#if CUDNN_MAJOR > 7 + checkCUDNN(cudnnSetRNNDescriptor_v6(net->cudnnHandle, +#else + checkCUDNN(cudnnSetRNNDescriptor(net->cudnnHandle, +#endif rnnDesc, stateSize, numLayers, dropoutDesc, cudnnRNNInputMode_t::CUDNN_LINEAR_INPUT, //(bidirectional ? cudnnDirectionMode_t::CUDNN_BIDIRECTIONAL : cudnnDirectionMode_t::CUDNN_UNIDIRECTIONAL), @@ -129,7 +133,7 @@ LSTM::LSTM( Network *net, int hiddensize, bool returnSeq, std::string fname_weig output_dim = input_dim; output_dim.c = stateSize*(bidirectional ? 2 : 1); - // if retunseq is disabled only the last timestep is returned + // if retunseq is disabled only the last timestamp is returned if(!returnSeq) { output_dim.h = 1; output_dim.w = 1; @@ -250,7 +254,7 @@ dnnType* LSTM::infer(dataDim_t &dim, dnnType* srcData) { rnnDesc, seqLen, // number of time steps (nT) x_desc_vec_.data(), // input array of desc (nT*nC_in) - srcF, // input pointer + srcF, // input pointer hx_desc_, // initial hidden state desc hx_ptr, // initial hidden state pointer cx_desc_, // initial cell state desc @@ -277,7 +281,7 @@ dnnType* LSTM::infer(dataDim_t &dim, dnnType* srcData) { rnnDesc, seqLen, // number of time steps (nT) x_desc_vec_.data(), // input array of desc (nT*nC_in) - srcB, // input pointer + srcB, // input pointer hx_desc_, // initial hidden state desc hx_ptr, // initial hidden state pointer cx_desc_, // initial cell state desc @@ -285,7 +289,7 @@ dnnType* LSTM::infer(dataDim_t &dim, dnnType* srcData) { w_desc_, // weights desc wb_ptr, // weights pointer y_desc_vec_.data(), // output desc (nT*nC_out) - dstB_NR, // output pointer + dstB_NR, // output pointer hy_desc_, // final hidden state desc hy_ptr, // final hidden state pointer cy_desc_, // final cell state desc @@ -303,7 +307,7 @@ dnnType* LSTM::infer(dataDim_t &dim, dnnType* srcData) { one_output_dim.c*sizeof(dnnType), cudaMemcpyDeviceToDevice)); } - // if retunseq is disabled only the last timestep is returned + // if retunseq is disabled only the last timestamp is returned if(returnSeq) { // forward transpose matrixTranspose(net->cublasHandle, dstF, dstData, diff --git a/src/Layer.cpp b/src/Layer.cpp index 9f04ca5..a355b90 100644 --- a/src/Layer.cpp +++ b/src/Layer.cpp @@ -24,6 +24,11 @@ Layer::~Layer() { checkCUDNN( cudnnDestroyTensorDescriptor(srcTensorDesc) ); checkCUDNN( cudnnDestroyTensorDescriptor(dstTensorDesc) ); + + if(dstData != nullptr) { + cudaFree(dstData); + dstData = nullptr; + } } }} \ No newline at end of file diff --git a/src/LayerWgs.cpp b/src/LayerWgs.cpp index 017563f..a761327 100644 --- a/src/LayerWgs.cpp +++ b/src/LayerWgs.cpp @@ -95,7 +95,6 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost); //mean array - cudaMemcpy(tmp_d, mean_h, b_size*sizeof(float), cudaMemcpyHostToDevice); float2half(tmp_d, mean16_d, b_size); cudaMemcpy(mean16_h, mean16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost); @@ -106,27 +105,17 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, float2half(tmp_d, variance16_d, b_size); cudaMemcpy(variance16_h, variance16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost); - //conver scales + //convert scales float2half(scales_d, scales16_d, b_size); cudaMemcpy(scales16_h, scales16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost); + + cudaFree(tmp_d); } } LayerWgs::~LayerWgs() { - - delete [] data_h; - delete [] bias_h; - checkCuda( cudaFree(data_d) ); - checkCuda( cudaFree(bias_d) ); - - if(batchnorm) { - delete [] scales_h; - delete [] mean_h; - delete [] variance_h; - checkCuda( cudaFree(scales_d) ); - checkCuda( cudaFree(mean_d) ); - checkCuda( cudaFree(variance_d) ); - } + releaseHost(); + releaseDevice(); } }} diff --git a/src/MobilenetDetection.cpp b/src/MobilenetDetection.cpp index 99b7a0c..3c54e28 100644 --- a/src/MobilenetDetection.cpp +++ b/src/MobilenetDetection.cpp @@ -126,11 +126,13 @@ float MobilenetDetection::iou(const tk::dnn::box &a, const tk::dnn::box &b){ return iou; } -bool MobilenetDetection::init(const std::string& tensor_path, const int n_classes){ +bool MobilenetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh){ std::cout<<(tensor_path).c_str()<<"\n"; netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str()); imageSize = netRT->input_dim.h; classes = n_classes; + nBatches = n_batches; + confThreshold = conf_thresh; SSDSpec specs[N_SSDSPEC]; @@ -157,9 +159,9 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe generate_ssd_priors(specs, N_SSDSPEC); #ifndef OPENCV_CUDACONTRIB - checkCuda(cudaMallocHost(&input, sizeof(dnnType) * netRT->input_dim.tot())); + checkCuda(cudaMallocHost(&input, sizeof(dnnType) * netRT->input_dim.tot() * nBatches)); #endif - checkCuda(cudaMalloc(&input_d, sizeof(dnnType) * netRT->input_dim.tot())); + checkCuda(cudaMalloc(&input_d, sizeof(dnnType) * netRT->input_dim.tot() * nBatches)); locations_h = (float *)malloc(N_COORDS * nPriors * sizeof(float)); confidences_h = (float *)malloc(nPriors * classes * sizeof(float)); @@ -208,7 +210,7 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe return 1; } -void MobilenetDetection::preprocess(cv::Mat &frame){ +void MobilenetDetection::preprocess(cv::Mat &frame, const int bi){ #ifdef OPENCV_CUDACONTRIB //move original image on GPU cv::cuda::GpuMat orig_img, frame_nomean; @@ -224,7 +226,7 @@ void MobilenetDetection::preprocess(cv::Mat &frame){ for(int i=0; i < netRT->input_dim.c; i++){ int idx = i * imagePreproc.rows * imagePreproc.cols; - checkCuda( cudaMemcpy((void *)&input_d[idx], (void *)bgr[i].data, imagePreproc.rows * imagePreproc.cols* sizeof(float), cudaMemcpyDeviceToDevice) ); + checkCuda( cudaMemcpy((void *)&input_d[idx + netRT->input_dim.tot()*bi], (void *)bgr[i].data, imagePreproc.rows * imagePreproc.cols* sizeof(float), cudaMemcpyDeviceToDevice) ); } #else //resize image, remove mean, divide by std @@ -237,17 +239,17 @@ void MobilenetDetection::preprocess(cv::Mat &frame){ cv::split(imagePreproc, bgr); for (int i = 0; i < netRT->input_dim.c; i++){ int idx = i * imagePreproc.rows * imagePreproc.cols; - memcpy((void *)&input[idx], (void *)bgr[i].data, imagePreproc.rows * imagePreproc.cols * sizeof(dnnType)); + memcpy((void *)&input[idx + netRT->input_dim.tot()*bi], (void *)bgr[i].data, imagePreproc.rows * imagePreproc.cols * sizeof(dnnType)); } - checkCuda(cudaMemcpyAsync(input_d, input, netRT->input_dim.tot() * sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream)); + checkCuda(cudaMemcpyAsync(input_d+ netRT->input_dim.tot()*bi, input + netRT->input_dim.tot()*bi, netRT->input_dim.tot() * sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream)); #endif } -void MobilenetDetection::postprocess(){ +void MobilenetDetection::postprocess(const int bi, const bool mAP){ //get confidences and locations_h dnnType *rt_out[2]; - rt_out[0] = (dnnType *)netRT->buffersRT[3]; - rt_out[1] = (dnnType *)netRT->buffersRT[4]; + rt_out[0] = (dnnType *)netRT->buffersRT[3]+ netRT->buffersDIM[3].tot()*bi; + rt_out[1] = (dnnType *)netRT->buffersRT[4]+ netRT->buffersDIM[4].tot()*bi; detected.clear(); @@ -255,8 +257,8 @@ void MobilenetDetection::postprocess(){ checkCuda(cudaMemcpy(locations_h, rt_out[1], N_COORDS * nPriors * sizeof(float), cudaMemcpyDeviceToHost)); convert_locatios_to_boxes_and_center(); - int width = originalSize.width; - int height = originalSize.height; + int width = originalSize[bi].width; + int height = originalSize[bi].height; float *conf_per_class; for (int i = 1; i < classes; i++){ @@ -273,6 +275,10 @@ void MobilenetDetection::postprocess(){ b.w = locations_h[j * N_COORDS + 2]; b.h = locations_h[j * N_COORDS + 3]; + if(mAP) + for(int c=1; cinput_dim.tot()*bi, (float*)bgr_h.data, size*sizeof(dnnType), cudaMemcpyHostToDevice)); } #else cv::resize(frame, frame, cv::Size(netRT->input_dim.w, netRT->input_dim.h)); @@ -77,64 +85,69 @@ void Yolo3Detection::preprocess(cv::Mat &frame){ for(int i=0; iinput_dim.c; i++) { int idx = i*imagePreproc.rows*imagePreproc.cols; int ch = netRT->input_dim.c-1 -i; - memcpy((void*)&input[idx], (void*)bgr[ch].data, imagePreproc.rows*imagePreproc.cols*sizeof(dnnType)); + memcpy((void*)&input[idx + netRT->input_dim.tot()*bi], (void*)bgr[ch].data, imagePreproc.rows*imagePreproc.cols*sizeof(dnnType)); } - checkCuda(cudaMemcpyAsync(input_d, input, netRT->input_dim.tot()*sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream)); + checkCuda(cudaMemcpyAsync(input_d + netRT->input_dim.tot()*bi, input + netRT->input_dim.tot()*bi, netRT->input_dim.tot()*sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream)); #endif } -void Yolo3Detection::postprocess(){ +void Yolo3Detection::postprocess(const int bi, const bool mAP){ + //get yolo outputs dnnType *rt_out[netRT->pluginFactory->n_yolos]; - for(int i=0; ipluginFactory->n_yolos; i++) { - rt_out[i] = (dnnType*)netRT->buffersRT[i+1]; - } + for(int i=0; ipluginFactory->n_yolos; i++) + rt_out[i] = (dnnType*)netRT->buffersRT[i+1] + netRT->buffersDIM[i+1].tot()*bi; - float x_ratio = float(originalSize.width) / float(netRT->input_dim.w); - float y_ratio = float(originalSize.height) / float(netRT->input_dim.h); + float x_ratio = float(originalSize[bi].width) / float(netRT->input_dim.w); + float y_ratio = float(originalSize[bi].height) / float(netRT->input_dim.h); // compute dets nDets = 0; for(int i=0; ipluginFactory->n_yolos; i++) { yolo[i]->dstData = rt_out[i]; - yolo[i]->computeDetections(dets, nDets, netRT->input_dim.w, netRT->input_dim.h, confThreshold); + yolo[i]->computeDetections(dets, nDets, netRT->input_dim.w, netRT->input_dim.h, confThreshold, yolo[i]->new_coords); } - tk::dnn::Yolo::mergeDetections(dets, nDets, classes); + tk::dnn::Yolo::mergeDetections(dets, nDets, classes, yolo[0]->nms_thresh, yolo[0]->nsm_kind); // fill detected detected.clear(); for(int j=0; j= confThreshold) { - obj_class = c; - prob = dets[j].prob[c]; + int obj_class = c; + float prob = dets[j].prob[c]; + + tk::dnn::box res; + res.cl = obj_class; + res.prob = prob; + res.x = x0; + res.y = y0; + res.w = x1 - x0; + res.h = y1 - y0; + + // FIXME: this shuld be useless + // if(mAP) + // for(int c=0; c= 0) { - // convert to image coords - x0 = x_ratio*x0; - x1 = x_ratio*x1; - y0 = y_ratio*y0; - y1 = y_ratio*y1; - - tk::dnn::box res; - res.cl = obj_class; - res.prob = prob; - res.x = x0; - res.y = y0; - res.w = x1 - x0; - res.h = y1 - y0; - detected.push_back(res); - } } + batchDetected.push_back(detected); } diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 62f9e9b..f23c380 100644 --- a/src/evaluation.cpp +++ b/src/evaluation.cpp @@ -63,7 +63,7 @@ double computeMap( std::vector &images,const int classes, int gt_checked = 0; - // for each detection comput IoU with groundtruth and match detetcion and + // for each detection compute IoU with groundtruth and match detetcion and // groundtruth with IoU greater than IoU_thresh for(auto &img:images){ for(size_t i=0; i &images,const int classes, } } - //compute average precision for each class. Two methods are avaible, + //compute average precision for each class. Two methods are available, //based on map_points required double mean_average_precision = 0; double last_recall, last_precision, delta_recall; @@ -287,7 +287,7 @@ void computeTPFPFN( std::vector &images,const int classes, } } - //count all TP, FP, FN and compute precsion, recall and f1-score + //count all TP, FP, FN and compute precision, recall and f1-score double avg_precision = 0, avg_recall = 0, f1_score = 0; int TP = 0, FP = 0, FN = 0; for(size_t i=0; i &images,const int classes, std::cout<<"avg precision: "< bbox, const int classes, const int w, const int h) +{ + int coco_ids[] = { 1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90 }; + std::string id = image_path.substr(image_path.find("images/")+7, image_path.find(".jpg") - image_path.find("images/") -7); + int image_id = std::stoi(id); + for (int i = 0; i < bbox.size(); ++i) { + float xmin = bbox[i].x ; + float xmax = bbox[i].x + float(bbox[i].w); + float ymin = bbox[i].y; + float ymax = bbox[i].y + float(bbox[i].h); + + //limit to image borders + if (xmin < 0) xmin = 0; + if (ymin < 0) ymin = 0; + if (xmax > w) xmax = w; + if (ymax > h) ymax = h; + + float bx = xmin; + float by = ymin; + float bw = xmax - xmin; + float bh = ymax - ymin; + + if(bbox[i].probs.size() == classes) + for (int j = 0; j < classes; ++j) { + //min threshold confidence is set in DetectionNN.h + if (bbox[i].probs[j] > 0) { + + *out_file << "{\"image_id\":" << image_id << + ", \"category_id\":" << coco_ids[j] << + ", \"bbox\":[" << bx << ", " << by << ", " << bw << ", " << bh << + "], \"score\":" << bbox[i].probs[j] << "},\n"; + } + } + else + *out_file << "{\"image_id\":" << image_id << + ", \"category_id\":" << coco_ids[bbox[i].cl] << + ", \"bbox\":[" << bx << ", " << by << ", " << bw << ", " << bh << + "], \"score\":" << bbox[i].prob << "},\n"; + } +} + }} diff --git a/src/kernels/activation.mish.cu b/src/kernels/activation_mish.cu similarity index 58% rename from src/kernels/activation.mish.cu rename to src/kernels/activation_mish.cu index fd55c8a..8900061 100644 --- a/src/kernels/activation.mish.cu +++ b/src/kernels/activation_mish.cu @@ -3,20 +3,39 @@ #define MISH_THRESHOLD 20 -__device__ float tanh_activate_kernel(float x){return (2/(1 + expf(-2*x)) - 1);} -__device__ float softplus_kernel(float x, float threshold = 20) { +__device__ +float tanh_activate_kernel(float x){return (2/(1 + expf(-2*x)) - 1);} + +__device__ +float softplus_kernel(float x, float threshold = 20) { if (x > threshold) return x; // too large else if (x < -threshold) return expf(x); // too small return logf(expf(x) + 1); } + + +__device__ +float mish_yashas(float x) { + float e = __expf(x); + if (x <= -18.0f) + return x * e; + + float n = e * e + 2 * e; + if (x <= -5.0f) + return x * __fdividef(n, n + 2); + + return x - 2 * __fdividef(x, n + 2); +} + // https://github.com/digantamisra98/Mish // https://github.com/AlexeyAB/darknet/blob/master/src/activation_kernels.cu __global__ void activation_mish(dnnType *input, dnnType *output, int size) { int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x; if (i < size) - output[i] = input[i] * tanh_activate_kernel( softplus_kernel(input[i], MISH_THRESHOLD)); + // output[i] = input[i] * tanh_activate_kernel( softplus_kernel(input[i], MISH_THRESHOLD)); + output[i] = mish_yashas(input[i]); } /** diff --git a/src/utils.cpp b/src/utils.cpp index c678b15..65030f0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -26,10 +26,11 @@ void downloadWeightsifDoNotExist(const std::string& input_bin, const std::string std::string wget_cmd = "wget " + weights_url + " -O " + test_folder + "/weights.zip"; std::string unzip_cmd = "unzip " + test_folder + "/weights.zip -d" + test_folder; std::string rm_cmd = "rm " + test_folder + "/weights.zip"; - system(mkdir_cmd.c_str()); - system(wget_cmd.c_str()); - system(unzip_cmd.c_str()); - system(rm_cmd.c_str()); + int err = 0; + err = system(mkdir_cmd.c_str()); + err = system(wget_cmd.c_str()); + err = system(unzip_cmd.c_str()); + err = system(rm_cmd.c_str()); } } @@ -196,6 +197,12 @@ void getMemUsage(double& vm_usage_kb, double& resident_set_kb){ resident_set_kb = rss * page_size_kb; } +void printCudaMemUsage() { + size_t free, total; + checkCuda( cudaMemGetInfo(&free, &total) ); + std::cout<<"GPU free memory: "< -#include -#include "tkdnn.h" - -int main() -{ - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 320, 544, 1); - tk::dnn::Network net(dim); - - // create bdd-csresnext50-panet-spp model - std::string bin_path = "bdd-csresnext50-panet-spp"; - int classes = 10; - tk::dnn::Yolo *yolo[3]; - - std::string input_bin = bin_path + "/layers/input.bin"; - std::string output_bin = bin_path + "/debug/layer137_out.bin"; - std::vector output_bins = { - bin_path + "/debug/layer115_out.bin", - bin_path + "/debug/layer126_out.bin", - bin_path + "/debug/layer137_out.bin"}; - std::string c0_bin = bin_path + "/layers/c0.bin"; - std::string c2_bin = bin_path + "/layers/c2.bin"; - std::string c4_bin = bin_path + "/layers/c4.bin"; - std::string c5_bin = bin_path + "/layers/c5.bin"; - std::string c6_bin = bin_path + "/layers/c6.bin"; - std::string c7_bin = bin_path + "/layers/c7.bin"; - std::string c9_bin = bin_path + "/layers/c9.bin"; - std::string c10_bin = bin_path + "/layers/c10.bin"; - std::string c11_bin = bin_path + "/layers/c11.bin"; - std::string c13_bin = bin_path + "/layers/c13.bin"; - std::string c14_bin = bin_path + "/layers/c14.bin"; - std::string c15_bin = bin_path + "/layers/c15.bin"; - std::string c17_bin = bin_path + "/layers/c17.bin"; - std::string c19_bin = bin_path + "/layers/c19.bin"; - std::string c20_bin = bin_path + "/layers/c20.bin"; - std::string c21_bin = bin_path + "/layers/c21.bin"; - std::string c23_bin = bin_path + "/layers/c23.bin"; - std::string c24_bin = bin_path + "/layers/c24.bin"; - std::string c25_bin = bin_path + "/layers/c25.bin"; - std::string c26_bin = bin_path + "/layers/c26.bin"; - std::string c28_bin = bin_path + "/layers/c28.bin"; - std::string c29_bin = bin_path + "/layers/c29.bin"; - std::string c30_bin = bin_path + "/layers/c30.bin"; - std::string c32_bin = bin_path + "/layers/c32.bin"; - std::string c33_bin = bin_path + "/layers/c33.bin"; - std::string c34_bin = bin_path + "/layers/c34.bin"; - std::string c36_bin = bin_path + "/layers/c36.bin"; - std::string c38_bin = bin_path + "/layers/c38.bin"; - std::string c39_bin = bin_path + "/layers/c39.bin"; - std::string c40_bin = bin_path + "/layers/c40.bin"; - std::string c42_bin = bin_path + "/layers/c42.bin"; - std::string c43_bin = bin_path + "/layers/c43.bin"; - std::string c44_bin = bin_path + "/layers/c44.bin"; - std::string c45_bin = bin_path + "/layers/c45.bin"; - std::string c47_bin = bin_path + "/layers/c47.bin"; - std::string c48_bin = bin_path + "/layers/c48.bin"; - std::string c49_bin = bin_path + "/layers/c49.bin"; - std::string c51_bin = bin_path + "/layers/c51.bin"; - std::string c52_bin = bin_path + "/layers/c52.bin"; - std::string c53_bin = bin_path + "/layers/c53.bin"; - std::string c55_bin = bin_path + "/layers/c55.bin"; - std::string c56_bin = bin_path + "/layers/c56.bin"; - std::string c57_bin = bin_path + "/layers/c57.bin"; - std::string c59_bin = bin_path + "/layers/c59.bin"; - std::string c60_bin = bin_path + "/layers/c60.bin"; - std::string c61_bin = bin_path + "/layers/c61.bin"; - std::string c63_bin = bin_path + "/layers/c63.bin"; - std::string c65_bin = bin_path + "/layers/c65.bin"; - std::string c66_bin = bin_path + "/layers/c66.bin"; - std::string c67_bin = bin_path + "/layers/c67.bin"; - std::string c69_bin = bin_path + "/layers/c69.bin"; - std::string c70_bin = bin_path + "/layers/c70.bin"; - std::string c71_bin = bin_path + "/layers/c71.bin"; - std::string c72_bin = bin_path + "/layers/c72.bin"; - std::string c74_bin = bin_path + "/layers/c74.bin"; - std::string c75_bin = bin_path + "/layers/c75.bin"; - std::string c76_bin = bin_path + "/layers/c76.bin"; - std::string c78_bin = bin_path + "/layers/c78.bin"; - std::string c80_bin = bin_path + "/layers/c80.bin"; - std::string c81_bin = bin_path + "/layers/c81.bin"; - std::string c82_bin = bin_path + "/layers/c82.bin"; - std::string c83_bin = bin_path + "/layers/c83.bin"; - std::string c90_bin = bin_path + "/layers/c90.bin"; - std::string c91_bin = bin_path + "/layers/c91.bin"; - std::string c92_bin = bin_path + "/layers/c92.bin"; - std::string c93_bin = bin_path + "/layers/c93.bin"; - std::string c96_bin = bin_path + "/layers/c96.bin"; - std::string c98_bin = bin_path + "/layers/c98.bin"; - std::string c99_bin = bin_path + "/layers/c99.bin"; - std::string c100_bin = bin_path + "/layers/c100.bin"; - std::string c101_bin = bin_path + "/layers/c101.bin"; - std::string c102_bin = bin_path + "/layers/c102.bin"; - std::string c103_bin = bin_path + "/layers/c103.bin"; - std::string c106_bin = bin_path + "/layers/c106.bin"; - std::string c108_bin = bin_path + "/layers/c108.bin"; - std::string c109_bin = bin_path + "/layers/c109.bin"; - std::string c110_bin = bin_path + "/layers/c110.bin"; - std::string c111_bin = bin_path + "/layers/c111.bin"; - std::string c112_bin = bin_path + "/layers/c112.bin"; - std::string c113_bin = bin_path + "/layers/c113.bin"; - std::string c114_bin = bin_path + "/layers/c114.bin"; - std::string c117_bin = bin_path + "/layers/c117.bin"; - std::string c119_bin = bin_path + "/layers/c119.bin"; - std::string c120_bin = bin_path + "/layers/c120.bin"; - std::string c121_bin = bin_path + "/layers/c121.bin"; - std::string c122_bin = bin_path + "/layers/c122.bin"; - std::string c123_bin = bin_path + "/layers/c123.bin"; - std::string c124_bin = bin_path + "/layers/c124.bin"; - std::string c125_bin = bin_path + "/layers/c125.bin"; - std::string c128_bin = bin_path + "/layers/c128.bin"; - std::string c130_bin = bin_path + "/layers/c130.bin"; - std::string c131_bin = bin_path + "/layers/c131.bin"; - std::string c132_bin = bin_path + "/layers/c132.bin"; - std::string c133_bin = bin_path + "/layers/c133.bin"; - std::string c134_bin = bin_path + "/layers/c134.bin"; - std::string c135_bin = bin_path + "/layers/c135.bin"; - std::string c136_bin = bin_path + "/layers/c136.bin"; - std::string g115_bin = bin_path + "/layers/g115.bin"; - std::string g126_bin = bin_path + "/layers/g126.bin"; - std::string g137_bin = bin_path + "/layers/g137.bin"; - - // downloadWeightsifDoNotExist(input_bin, bin_path, "https://cloud.hipert.unimore.it/s//download"); - - tk::dnn::Conv2d c0(&net, 64, 7, 7, 2, 2, 3, 3, c0_bin, true); - tk::dnn::Activation a0(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2(&net, 128, 1, 1, 1, 1, 0, 0, c2_bin, true); - tk::dnn::Activation a2(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r3_layers[1] = {&p1}; - tk::dnn::Route r3(&net, r3_layers, 1); - - tk::dnn::Conv2d c4(&net, 64, 1, 1, 1, 1, 0, 0, c4_bin, true); - tk::dnn::Activation a4(&net, tk::dnn::ACTIVATION_LEAKY); - - // //1-1 - tk::dnn::Conv2d c5(&net, 128, 1, 1, 1, 1, 0, 0, c5_bin, true); - tk::dnn::Activation a5(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c6(&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true, false, 32, false); - tk::dnn::Activation a6(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c7(&net, 128, 1, 1, 1, 1, 0, 0, c7_bin, true); - - tk::dnn::Shortcut s8(&net, &a4); - tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY); - - //1-2 - tk::dnn::Conv2d c9(&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true); - tk::dnn::Activation a9(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c10(&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true, false, 32); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c11(&net, 128, 1, 1, 1, 1, 0, 0, c11_bin, true); - - tk::dnn::Shortcut s12(&net, &a8); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - - //1-3 - tk::dnn::Conv2d c13(&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 128, 3, 3, 1, 1, 1, 1, c14_bin, true, false, 32); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 128, 1, 1, 1, 1, 0, 0, c15_bin, true); - - tk::dnn::Shortcut s16(&net, &a12); - tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_LEAKY); - - // //1-T - tk::dnn::Conv2d c17(&net, 128, 1, 1, 1, 1, 0, 0, c17_bin, true); - tk::dnn::Activation a17(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r18_layers[2] = {&a17, &a2}; - tk::dnn::Route r18(&net, r18_layers, 2); - - tk::dnn::Conv2d c19(&net, 256, 1, 1, 1, 1, 0, 0, c19_bin, true); - tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c20(&net, 256, 3, 3, 2, 2, 1, 1, c20_bin, true, false, 32); - tk::dnn::Activation a20(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c21(&net, 256, 1, 1, 1, 1, 0, 0, c21_bin, true); - - tk::dnn::Layer *r22_layers[2] = {&a20}; - tk::dnn::Route r22(&net, r22_layers, 1); - - tk::dnn::Conv2d c23(&net, 256, 1, 1, 1, 1, 0, 0, c23_bin, true); - - //2-1 - tk::dnn::Conv2d c24(&net, 256, 1, 1, 1, 1, 0, 0, c24_bin, true); - tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c25(&net, 256, 3, 3, 1, 1, 1, 1, c25_bin, true, false, 32); - tk::dnn::Activation a25(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c26(&net, 256, 1, 1, 1, 1, 0, 0, c26_bin, true); - - tk::dnn::Shortcut s27(&net, &c23); - tk::dnn::Activation a27(&net, tk::dnn::ACTIVATION_LEAKY); - - //2-2 - tk::dnn::Conv2d c28(&net, 256, 1, 1, 1, 1, 0, 0, c28_bin, true); - tk::dnn::Activation a28(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c29(&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true, false, 32); - tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c30(&net, 256, 1, 1, 1, 1, 0, 0, c30_bin, true); - - tk::dnn::Shortcut s31(&net, &a27); - tk::dnn::Activation a31(&net, tk::dnn::ACTIVATION_LEAKY); - - //2-3 - tk::dnn::Conv2d c32(&net, 256, 1, 1, 1, 1, 0, 0, c32_bin, true); - tk::dnn::Activation a32(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c33(&net, 256, 3, 3, 1, 1, 1, 1, c33_bin, true, false, 32); - tk::dnn::Activation a33(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c34(&net, 256, 1, 1, 1, 1, 0, 0, c34_bin, true); - - tk::dnn::Shortcut s35(&net, &a31); - tk::dnn::Activation a35(&net, tk::dnn::ACTIVATION_LEAKY); - - // //2-T - tk::dnn::Conv2d c36(&net, 256, 1, 1, 1, 1, 0, 0, c36_bin, true); - tk::dnn::Activation a36(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r37_layers[2] = {&a36, &c21}; - tk::dnn::Route r37(&net, r37_layers, 2); - - tk::dnn::Conv2d c38(&net, 512, 1, 1, 1, 1, 0, 0, c38_bin, true); - tk::dnn::Activation a38(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c39(&net, 512, 3, 3, 2, 2, 1, 1, c39_bin, true, false, 32); - tk::dnn::Activation a39(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c40(&net, 512, 1, 1, 1, 1, 0, 0, c40_bin, true); - - tk::dnn::Layer *r41_layers[2] = {&a39}; - tk::dnn::Route r41(&net, r41_layers, 1); - - tk::dnn::Conv2d c42(&net, 512, 1, 1, 1, 1, 0, 0, c42_bin, true); - - //3-1 - tk::dnn::Conv2d c43(&net, 512, 1, 1, 1, 1, 0, 0, c43_bin, true); - tk::dnn::Activation a43(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c44(&net, 512, 3, 3, 1, 1, 1, 1, c44_bin, true, false, 32); - tk::dnn::Activation a44(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c45(&net, 512, 1, 1, 1, 1, 0, 0, c45_bin, true); - - tk::dnn::Shortcut s46(&net, &c42); - tk::dnn::Activation a46(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-2 - tk::dnn::Conv2d c47(&net, 512, 1, 1, 1, 1, 0, 0, c47_bin, true); - tk::dnn::Activation a47(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c48(&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true, false, 32); - tk::dnn::Activation a48(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c49(&net, 512, 1, 1, 1, 1, 0, 0, c49_bin, true); - - tk::dnn::Shortcut s50(&net, &a46); - tk::dnn::Activation a50(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-3 - tk::dnn::Conv2d c51(&net, 512, 1, 1, 1, 1, 0, 0, c51_bin, true); - tk::dnn::Activation a51(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c52(&net, 512, 3, 3, 1, 1, 1, 1, c52_bin, true, false, 32); - tk::dnn::Activation a52(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c53(&net, 512, 1, 1, 1, 1, 0, 0, c53_bin, true); - - tk::dnn::Shortcut s54(&net, &a50); - tk::dnn::Activation a54(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-4 - tk::dnn::Conv2d c55(&net, 512, 1, 1, 1, 1, 0, 0, c55_bin, true); - tk::dnn::Activation a55(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c56(&net, 512, 3, 3, 1, 1, 1, 1, c56_bin, true, false, 32); - tk::dnn::Activation a56(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c57(&net, 512, 1, 1, 1, 1, 0, 0, c57_bin, true); - - tk::dnn::Shortcut s58(&net, &a54); - tk::dnn::Activation a58(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-5 - tk::dnn::Conv2d c59(&net, 512, 1, 1, 1, 1, 0, 0, c59_bin, true); - tk::dnn::Activation a59(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c60(&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true, false, 32); - tk::dnn::Activation a60(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c61(&net, 512, 1, 1, 1, 1, 0, 0, c61_bin, true); - - tk::dnn::Shortcut s62(&net, &a58); - tk::dnn::Activation a62(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-T - tk::dnn::Conv2d c63(&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true); - tk::dnn::Activation a63(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r64_layers[2] = {&a63, &c40}; - tk::dnn::Route r64(&net, r64_layers, 2); - - tk::dnn::Conv2d c65(&net, 1024, 1, 1, 1, 1, 0, 0, c65_bin, true); - tk::dnn::Activation a65(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c66(&net, 1024, 3, 3, 2, 2, 1, 1, c66_bin, true, false, 32); - tk::dnn::Activation a66(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c67(&net, 1024, 1, 1, 1, 1, 0, 0, c67_bin, true); - tk::dnn::Activation a67(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r68_layers[2] = {&a66}; - tk::dnn::Route r68(&net, r68_layers, 1); - - tk::dnn::Conv2d c69(&net, 1024, 1, 1, 1, 1, 0, 0, c69_bin, true); - tk::dnn::Activation a69(&net, tk::dnn::ACTIVATION_LEAKY); - - //4-1 - tk::dnn::Conv2d c70(&net, 1024, 1, 1, 1, 1, 0, 0, c70_bin, true); - tk::dnn::Activation a70(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c71(&net, 1024, 3, 3, 1, 1, 1, 1, c71_bin, true, false, 32); - tk::dnn::Activation a71(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c72(&net, 1024, 1, 1, 1, 1, 0, 0, c72_bin, true); - - tk::dnn::Shortcut s73(&net, &a69); - tk::dnn::Activation a73(&net, tk::dnn::ACTIVATION_LEAKY); - - //4-2 - tk::dnn::Conv2d c74(&net, 1024, 1, 1, 1, 1, 0, 0, c74_bin, true); - tk::dnn::Activation a74(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c75(&net, 1024, 3, 3, 1, 1, 1, 1, c75_bin, true, false, 32); - tk::dnn::Activation a75(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c76(&net, 1024, 1, 1, 1, 1, 0, 0, c76_bin, true); - - tk::dnn::Shortcut s77(&net, &a73); - tk::dnn::Activation a77(&net, tk::dnn::ACTIVATION_LEAKY); - - //4-T - tk::dnn::Conv2d c78(&net, 1024, 1, 1, 1, 1, 0, 0, c78_bin, true); - tk::dnn::Activation a78(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r79_layers[2] = {&a78, &a67}; - tk::dnn::Route r79(&net, r79_layers, 2); - - tk::dnn::Conv2d c80(&net, 2048, 1, 1, 1, 1, 0, 0, c80_bin, true); - tk::dnn::Activation a80(&net, tk::dnn::ACTIVATION_LEAKY); - - // //////////////////// - - tk::dnn::Conv2d c81(&net, 512, 1, 1, 1, 1, 0, 0, c81_bin, true); - tk::dnn::Activation a81(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c82(&net, 1024, 3, 3, 1, 1, 1, 1, c82_bin, true); - tk::dnn::Activation a82(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c83(&net, 512, 1, 1, 1, 1, 0, 0, c83_bin, true); - tk::dnn::Activation a83(&net, tk::dnn::ACTIVATION_LEAKY); - - //SPP - tk::dnn::Pooling p84(&net, 5, 5, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r85_layers[1] = {&a83}; - tk::dnn::Route r85(&net, r85_layers, 1); - - tk::dnn::Pooling p86(&net, 9, 9, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r87_layers[1] = {&a83}; - tk::dnn::Route r87(&net, r87_layers, 1); - - tk::dnn::Pooling p88(&net, 13, 13, 1, 1, 12, 12, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r89_layers[4] = {&p88, &p86, &p84, &a83}; - tk::dnn::Route r89(&net, r89_layers, 4); - //END SPP - - tk::dnn::Conv2d c90(&net, 512, 1, 1, 1, 1, 0, 0, c90_bin, true); - tk::dnn::Activation a90(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c91(&net, 1024, 3, 3, 1, 1, 1, 1, c91_bin, true); - tk::dnn::Activation a91(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c92(&net, 512, 1, 1, 1, 1, 0, 0, c92_bin, true); - tk::dnn::Activation a92(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c93(&net, 256, 1, 1, 1, 1, 0, 0, c93_bin, true); - tk::dnn::Activation a93(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u94(&net, 2); - tk::dnn::Layer *r95_layers[1] = {&a65}; - tk::dnn::Route r95(&net, r95_layers, 1); - tk::dnn::Conv2d c96(&net, 256, 1, 1, 1, 1, 0, 0, c96_bin, true); - tk::dnn::Activation a96(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r97_layers[2] = {&a96,&u94}; - tk::dnn::Route r97(&net, r97_layers, 2); - - tk::dnn::Conv2d c98(&net, 256, 1, 1, 1, 1, 0, 0, c98_bin, true); - tk::dnn::Activation a98(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c99(&net, 512, 3, 3, 1, 1, 1, 1, c99_bin, true); - tk::dnn::Activation a99(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c100(&net, 256, 1, 1, 1, 1, 0, 0, c100_bin, true); - tk::dnn::Activation a100(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c101(&net, 512, 3, 3, 1, 1, 1, 1, c101_bin, true); - tk::dnn::Activation a101(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c102(&net, 256, 1, 1, 1, 1, 0, 0, c102_bin, true); - tk::dnn::Activation a102(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c103(&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true); - tk::dnn::Activation a103(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u104(&net, 2); - tk::dnn::Layer *r105_layers[1] = {&a38}; - tk::dnn::Route r105(&net, r105_layers, 1); - tk::dnn::Conv2d c106(&net, 128, 1, 1, 1, 1, 0, 0, c106_bin, true); - tk::dnn::Activation a106(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r107_layers[2] = {&a106,&u104}; - tk::dnn::Route r107(&net, r107_layers, 2); - - - tk::dnn::Conv2d c108(&net, 128, 1, 1, 1, 1, 0, 0, c108_bin, true); - tk::dnn::Activation a108(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c109(&net, 256, 3, 3, 1, 1, 1, 1, c109_bin, true); - tk::dnn::Activation a109(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c110(&net, 128, 1, 1, 1, 1, 0, 0, c110_bin, true); - tk::dnn::Activation a110(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c111(&net, 256, 3, 3, 1, 1, 1, 1, c111_bin, true); - tk::dnn::Activation a111(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c112(&net, 128, 1, 1, 1, 1, 0, 0, c112_bin, true); - tk::dnn::Activation a112(&net, tk::dnn::ACTIVATION_LEAKY); - - // ########################### - - tk::dnn::Conv2d c113(&net, 256, 3, 3, 1, 1, 1, 1, c113_bin, true); - tk::dnn::Activation a113(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c114(&net, 45, 1, 1, 1, 1, 0, 0, c114_bin, false); - tk::dnn::Yolo yolo115(&net, classes, 3, g115_bin); - - tk::dnn::Layer *r116_layers[1] = {&a112}; - tk::dnn::Route r116(&net, r116_layers, 1); - tk::dnn::Conv2d c117(&net, 256, 3, 3, 2, 2, 1, 1, c117_bin, true); - tk::dnn::Activation a117(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r118_layers[2] = {&a117,&a102}; - tk::dnn::Route r118(&net, r118_layers, 2); - - tk::dnn::Conv2d c119(&net, 256, 1, 1, 1, 1, 0, 0, c119_bin, true); - tk::dnn::Activation a119(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c120(&net, 512, 3, 3, 1, 1, 1, 1, c120_bin, true); - tk::dnn::Activation a120(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c121(&net, 256, 1, 1, 1, 1, 0, 0, c121_bin, true); - tk::dnn::Activation a121(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c122(&net, 512, 3, 3, 1, 1, 1, 1, c122_bin, true); - tk::dnn::Activation a122(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c123(&net, 256, 1, 1, 1, 1, 0, 0, c123_bin, true); - tk::dnn::Activation a123(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c124(&net, 512, 3, 3, 1, 1, 1, 1, c124_bin, true); - tk::dnn::Activation a124(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c125(&net, 45, 1, 1, 1, 1, 0, 0, c125_bin, false); - tk::dnn::Yolo yolo126(&net, classes, 3, g126_bin); - - tk::dnn::Layer *r127_layers[1] = {&a123}; - tk::dnn::Route r127(&net, r127_layers, 1); - tk::dnn::Conv2d c128(&net, 512, 3, 3, 2, 2, 1, 1, c128_bin, true); - tk::dnn::Activation a128(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r129_layers[2] = {&a128,&a92}; - tk::dnn::Route r129(&net, r129_layers, 2); - - tk::dnn::Conv2d c130(&net, 512, 1, 1, 1, 1, 0, 0, c130_bin, true); - tk::dnn::Activation a130(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c131(&net, 1024, 3, 3, 1, 1, 1, 1, c131_bin, true); - tk::dnn::Activation a131(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c132(&net, 512, 1, 1, 1, 1, 0, 0, c132_bin, true); - tk::dnn::Activation a132(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c133(&net, 1024, 3, 3, 1, 1, 1, 1, c133_bin, true); - tk::dnn::Activation a133(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c134(&net, 512, 1, 1, 1, 1, 0, 0, c134_bin, true); - tk::dnn::Activation a134(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c135(&net, 1024, 3, 3, 1, 1, 1, 1, c135_bin, true); - tk::dnn::Activation a135(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c136(&net, 45, 1, 1, 1, 1, 0, 0, c136_bin, false); - tk::dnn::Yolo yolo137(&net, classes, 3, g137_bin); - - yolo[0] = &yolo115; - yolo[1] = &yolo126; - yolo[2] = &yolo137; - - // fill classes names - for (int i = 0; i < 3; i++) - { - yolo[i]->classesNames = {"person","car","truck","bus","motor","bike","rider","traffic light","traffic sign","train"}; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - // //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("bdd-csresnext50-panet-spp")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for (int i = 0; i < 3; i++) - out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); - { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - for (int i = 0; i < 3; i++) - cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for (int i = 0; i < 3; i++) - yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for (int j = 0; j < ndets; j++) - { - tk::dnn::Yolo::box b = dets[j].bbox; - int x0 = (b.x - b.w / 2.); - int x1 = (b.x + b.w / 2.); - int y0 = (b.y - b.h / 2.); - int y1 = (b.y + b.h / 2.); - - int cl = 0; - for (int c = 0; c < classes; ++c) - { - float prob = dets[j].prob[c]; - if (prob > 0) - cl = c; - } - std::cout << cl << ": " << x0 << " " << y0 << " " << x1 << " " << y1 << "\n"; - } - TIMER_STOP - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); - { - dim2.print(); - TIMER_START - netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - for (int i = 0; i < 3; i++) - rt_out[i] = (dnnType *)netRT.buffersRT[i + 1]; - - int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0; - for (int i = 0; i < 3; i++) - { - printCenteredTitle((std::string(" YOLO ") + std::to_string(i) + " CHECK RESULTS ").c_str(), '=', 30); - dnnType *out, *out_h; - int odim = out_dim[i].tot(); - readBinaryFile(output_bins[i], odim, &out_h, &out); - std::cout<<"CUDNN vs correct"; - ret_cudnn |= checkResult(odim, cudnn_out[i], out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - ret_tensorrt |= checkResult(odim, rt_out[i], out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - } - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/build_models.sh b/tests/build_models.sh deleted file mode 100644 index c6b5fe2..0000000 --- a/tests/build_models.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -if [ "$1" == "download" ]; then - wget https://github.com/ceccocats/tkDNN/releases/download/testData/tkDNN_testwg.tar.gz --no-check-certificate - tar -xf tkDNN_testwg.tar.gz - rm tkDNN_testwg.tar.gz - exit -fi - -echo "build test Model" -cd test -python test_model.py -cd .. -cd mnist -python mnist_model.py -cd .. -echo "export weights" -python weights_exporter.py test/net.h5 --output test/layers -python caffe_weights_exporter.py mnist/lenet.prototxt mnist/lenet.caffemodel --output mnist/layers diff --git a/tests/dla34_cnet/dla34_cnet.cpp b/tests/centernet/dla34_cnet/dla34_cnet.cpp similarity index 99% rename from tests/dla34_cnet/dla34_cnet.cpp rename to tests/centernet/dla34_cnet/dla34_cnet.cpp index 1461094..d62a203 100644 --- a/tests/dla34_cnet/dla34_cnet.cpp +++ b/tests/centernet/dla34_cnet/dla34_cnet.cpp @@ -486,9 +486,9 @@ int main() printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART net.infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } @@ -496,9 +496,9 @@ int main() printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART netRT.infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } diff --git a/tests/dla34_cnet3d/dla34_cnet3d.cpp b/tests/centernet/dla34_cnet3d/dla34_cnet3d.cpp similarity index 99% rename from tests/dla34_cnet3d/dla34_cnet3d.cpp rename to tests/centernet/dla34_cnet3d/dla34_cnet3d.cpp index 9766b45..939d4c5 100644 --- a/tests/dla34_cnet3d/dla34_cnet3d.cpp +++ b/tests/centernet/dla34_cnet3d/dla34_cnet3d.cpp @@ -516,9 +516,9 @@ int main() printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART net.infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } @@ -526,9 +526,9 @@ int main() printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART netRT.infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } diff --git a/tests/resnet101_cnet/resnet101_cnet.cpp b/tests/centernet/resnet101_cnet/resnet101_cnet.cpp similarity index 99% rename from tests/resnet101_cnet/resnet101_cnet.cpp rename to tests/centernet/resnet101_cnet/resnet101_cnet.cpp index d48043b..7554923 100644 --- a/tests/resnet101_cnet/resnet101_cnet.cpp +++ b/tests/centernet/resnet101_cnet/resnet101_cnet.cpp @@ -361,9 +361,9 @@ int main() printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART net.infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } @@ -373,9 +373,9 @@ int main() printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART netRT.infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } diff --git a/tests/resnet101_cnet3d/resnet101_cnet3d.cpp b/tests/centernet/resnet101_cnet3d/resnet101_cnet3d.cpp similarity index 99% rename from tests/resnet101_cnet3d/resnet101_cnet3d.cpp rename to tests/centernet/resnet101_cnet3d/resnet101_cnet3d.cpp index 5d084be..396c62a 100644 --- a/tests/resnet101_cnet3d/resnet101_cnet3d.cpp +++ b/tests/centernet/resnet101_cnet3d/resnet101_cnet3d.cpp @@ -391,9 +391,9 @@ int main() printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART net.infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } @@ -403,9 +403,9 @@ int main() printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART netRT.infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } diff --git a/tests/csresnext50-panet-spp/csresnext50-panet-spp.cpp b/tests/csresnext50-panet-spp/csresnext50-panet-spp.cpp deleted file mode 100644 index 11a40ae..0000000 --- a/tests/csresnext50-panet-spp/csresnext50-panet-spp.cpp +++ /dev/null @@ -1,554 +0,0 @@ -#include -#include -#include "tkdnn.h" - -int main() -{ - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); - tk::dnn::Network net(dim); - - // create csresnext50-panet-spp model - std::string bin_path = "csresnext50-panet-spp"; - int classes = 80; - tk::dnn::Yolo *yolo[3]; - - std::string input_bin = bin_path + "/layers/input.bin"; - std::string output_bin = bin_path + "/debug/layer137_out.bin"; - std::vector output_bins = { - bin_path + "/debug/layer115_out.bin", - bin_path + "/debug/layer126_out.bin", - bin_path + "/debug/layer137_out.bin"}; - std::string c0_bin = bin_path + "/layers/c0.bin"; - std::string c2_bin = bin_path + "/layers/c2.bin"; - std::string c4_bin = bin_path + "/layers/c4.bin"; - std::string c5_bin = bin_path + "/layers/c5.bin"; - std::string c6_bin = bin_path + "/layers/c6.bin"; - std::string c7_bin = bin_path + "/layers/c7.bin"; - std::string c9_bin = bin_path + "/layers/c9.bin"; - std::string c10_bin = bin_path + "/layers/c10.bin"; - std::string c11_bin = bin_path + "/layers/c11.bin"; - std::string c13_bin = bin_path + "/layers/c13.bin"; - std::string c14_bin = bin_path + "/layers/c14.bin"; - std::string c15_bin = bin_path + "/layers/c15.bin"; - std::string c17_bin = bin_path + "/layers/c17.bin"; - std::string c19_bin = bin_path + "/layers/c19.bin"; - std::string c20_bin = bin_path + "/layers/c20.bin"; - std::string c21_bin = bin_path + "/layers/c21.bin"; - std::string c23_bin = bin_path + "/layers/c23.bin"; - std::string c24_bin = bin_path + "/layers/c24.bin"; - std::string c25_bin = bin_path + "/layers/c25.bin"; - std::string c26_bin = bin_path + "/layers/c26.bin"; - std::string c28_bin = bin_path + "/layers/c28.bin"; - std::string c29_bin = bin_path + "/layers/c29.bin"; - std::string c30_bin = bin_path + "/layers/c30.bin"; - std::string c32_bin = bin_path + "/layers/c32.bin"; - std::string c33_bin = bin_path + "/layers/c33.bin"; - std::string c34_bin = bin_path + "/layers/c34.bin"; - std::string c36_bin = bin_path + "/layers/c36.bin"; - std::string c38_bin = bin_path + "/layers/c38.bin"; - std::string c39_bin = bin_path + "/layers/c39.bin"; - std::string c40_bin = bin_path + "/layers/c40.bin"; - std::string c42_bin = bin_path + "/layers/c42.bin"; - std::string c43_bin = bin_path + "/layers/c43.bin"; - std::string c44_bin = bin_path + "/layers/c44.bin"; - std::string c45_bin = bin_path + "/layers/c45.bin"; - std::string c47_bin = bin_path + "/layers/c47.bin"; - std::string c48_bin = bin_path + "/layers/c48.bin"; - std::string c49_bin = bin_path + "/layers/c49.bin"; - std::string c51_bin = bin_path + "/layers/c51.bin"; - std::string c52_bin = bin_path + "/layers/c52.bin"; - std::string c53_bin = bin_path + "/layers/c53.bin"; - std::string c55_bin = bin_path + "/layers/c55.bin"; - std::string c56_bin = bin_path + "/layers/c56.bin"; - std::string c57_bin = bin_path + "/layers/c57.bin"; - std::string c59_bin = bin_path + "/layers/c59.bin"; - std::string c60_bin = bin_path + "/layers/c60.bin"; - std::string c61_bin = bin_path + "/layers/c61.bin"; - std::string c63_bin = bin_path + "/layers/c63.bin"; - std::string c65_bin = bin_path + "/layers/c65.bin"; - std::string c66_bin = bin_path + "/layers/c66.bin"; - std::string c67_bin = bin_path + "/layers/c67.bin"; - std::string c69_bin = bin_path + "/layers/c69.bin"; - std::string c70_bin = bin_path + "/layers/c70.bin"; - std::string c71_bin = bin_path + "/layers/c71.bin"; - std::string c72_bin = bin_path + "/layers/c72.bin"; - std::string c74_bin = bin_path + "/layers/c74.bin"; - std::string c75_bin = bin_path + "/layers/c75.bin"; - std::string c76_bin = bin_path + "/layers/c76.bin"; - std::string c78_bin = bin_path + "/layers/c78.bin"; - std::string c80_bin = bin_path + "/layers/c80.bin"; - std::string c81_bin = bin_path + "/layers/c81.bin"; - std::string c82_bin = bin_path + "/layers/c82.bin"; - std::string c83_bin = bin_path + "/layers/c83.bin"; - std::string c90_bin = bin_path + "/layers/c90.bin"; - std::string c91_bin = bin_path + "/layers/c91.bin"; - std::string c92_bin = bin_path + "/layers/c92.bin"; - std::string c93_bin = bin_path + "/layers/c93.bin"; - std::string c96_bin = bin_path + "/layers/c96.bin"; - std::string c98_bin = bin_path + "/layers/c98.bin"; - std::string c99_bin = bin_path + "/layers/c99.bin"; - std::string c100_bin = bin_path + "/layers/c100.bin"; - std::string c101_bin = bin_path + "/layers/c101.bin"; - std::string c102_bin = bin_path + "/layers/c102.bin"; - std::string c103_bin = bin_path + "/layers/c103.bin"; - std::string c106_bin = bin_path + "/layers/c106.bin"; - std::string c108_bin = bin_path + "/layers/c108.bin"; - std::string c109_bin = bin_path + "/layers/c109.bin"; - std::string c110_bin = bin_path + "/layers/c110.bin"; - std::string c111_bin = bin_path + "/layers/c111.bin"; - std::string c112_bin = bin_path + "/layers/c112.bin"; - std::string c113_bin = bin_path + "/layers/c113.bin"; - std::string c114_bin = bin_path + "/layers/c114.bin"; - std::string c117_bin = bin_path + "/layers/c117.bin"; - std::string c119_bin = bin_path + "/layers/c119.bin"; - std::string c120_bin = bin_path + "/layers/c120.bin"; - std::string c121_bin = bin_path + "/layers/c121.bin"; - std::string c122_bin = bin_path + "/layers/c122.bin"; - std::string c123_bin = bin_path + "/layers/c123.bin"; - std::string c124_bin = bin_path + "/layers/c124.bin"; - std::string c125_bin = bin_path + "/layers/c125.bin"; - std::string c128_bin = bin_path + "/layers/c128.bin"; - std::string c130_bin = bin_path + "/layers/c130.bin"; - std::string c131_bin = bin_path + "/layers/c131.bin"; - std::string c132_bin = bin_path + "/layers/c132.bin"; - std::string c133_bin = bin_path + "/layers/c133.bin"; - std::string c134_bin = bin_path + "/layers/c134.bin"; - std::string c135_bin = bin_path + "/layers/c135.bin"; - std::string c136_bin = bin_path + "/layers/c136.bin"; - std::string g115_bin = bin_path + "/layers/g115.bin"; - std::string g126_bin = bin_path + "/layers/g126.bin"; - std::string g137_bin = bin_path + "/layers/g137.bin"; - - downloadWeightsifDoNotExist(input_bin, bin_path, "https://cloud.hipert.unimore.it/s/Kcs4xBozwY4wFx8/download"); - - tk::dnn::Conv2d c0(&net, 64, 7, 7, 2, 2, 3, 3, c0_bin, true); - tk::dnn::Activation a0(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2(&net, 128, 1, 1, 1, 1, 0, 0, c2_bin, true); - tk::dnn::Activation a2(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r3_layers[1] = {&p1}; - tk::dnn::Route r3(&net, r3_layers, 1); - - tk::dnn::Conv2d c4(&net, 64, 1, 1, 1, 1, 0, 0, c4_bin, true); - tk::dnn::Activation a4(&net, tk::dnn::ACTIVATION_LEAKY); - - // //1-1 - tk::dnn::Conv2d c5(&net, 128, 1, 1, 1, 1, 0, 0, c5_bin, true); - tk::dnn::Activation a5(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c6(&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true, false, 32, false); - tk::dnn::Activation a6(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c7(&net, 128, 1, 1, 1, 1, 0, 0, c7_bin, true); - - tk::dnn::Shortcut s8(&net, &a4); - tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY); - - //1-2 - tk::dnn::Conv2d c9(&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true); - tk::dnn::Activation a9(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c10(&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true, false, 32); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c11(&net, 128, 1, 1, 1, 1, 0, 0, c11_bin, true); - - tk::dnn::Shortcut s12(&net, &a8); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - - //1-3 - tk::dnn::Conv2d c13(&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 128, 3, 3, 1, 1, 1, 1, c14_bin, true, false, 32); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 128, 1, 1, 1, 1, 0, 0, c15_bin, true); - - tk::dnn::Shortcut s16(&net, &a12); - tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_LEAKY); - - // //1-T - tk::dnn::Conv2d c17(&net, 128, 1, 1, 1, 1, 0, 0, c17_bin, true); - tk::dnn::Activation a17(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r18_layers[2] = {&a17, &a2}; - tk::dnn::Route r18(&net, r18_layers, 2); - - tk::dnn::Conv2d c19(&net, 256, 1, 1, 1, 1, 0, 0, c19_bin, true); - tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c20(&net, 256, 3, 3, 2, 2, 1, 1, c20_bin, true, false, 32); - tk::dnn::Activation a20(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c21(&net, 256, 1, 1, 1, 1, 0, 0, c21_bin, true); - - tk::dnn::Layer *r22_layers[2] = {&a20}; - tk::dnn::Route r22(&net, r22_layers, 1); - - tk::dnn::Conv2d c23(&net, 256, 1, 1, 1, 1, 0, 0, c23_bin, true); - - //2-1 - tk::dnn::Conv2d c24(&net, 256, 1, 1, 1, 1, 0, 0, c24_bin, true); - tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c25(&net, 256, 3, 3, 1, 1, 1, 1, c25_bin, true, false, 32); - tk::dnn::Activation a25(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c26(&net, 256, 1, 1, 1, 1, 0, 0, c26_bin, true); - - tk::dnn::Shortcut s27(&net, &c23); - tk::dnn::Activation a27(&net, tk::dnn::ACTIVATION_LEAKY); - - //2-2 - tk::dnn::Conv2d c28(&net, 256, 1, 1, 1, 1, 0, 0, c28_bin, true); - tk::dnn::Activation a28(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c29(&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true, false, 32); - tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c30(&net, 256, 1, 1, 1, 1, 0, 0, c30_bin, true); - - tk::dnn::Shortcut s31(&net, &a27); - tk::dnn::Activation a31(&net, tk::dnn::ACTIVATION_LEAKY); - - //2-3 - tk::dnn::Conv2d c32(&net, 256, 1, 1, 1, 1, 0, 0, c32_bin, true); - tk::dnn::Activation a32(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c33(&net, 256, 3, 3, 1, 1, 1, 1, c33_bin, true, false, 32); - tk::dnn::Activation a33(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c34(&net, 256, 1, 1, 1, 1, 0, 0, c34_bin, true); - - tk::dnn::Shortcut s35(&net, &a31); - tk::dnn::Activation a35(&net, tk::dnn::ACTIVATION_LEAKY); - - // //2-T - tk::dnn::Conv2d c36(&net, 256, 1, 1, 1, 1, 0, 0, c36_bin, true); - tk::dnn::Activation a36(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r37_layers[2] = {&a36, &c21}; - tk::dnn::Route r37(&net, r37_layers, 2); - - tk::dnn::Conv2d c38(&net, 512, 1, 1, 1, 1, 0, 0, c38_bin, true); - tk::dnn::Activation a38(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c39(&net, 512, 3, 3, 2, 2, 1, 1, c39_bin, true, false, 32); - tk::dnn::Activation a39(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c40(&net, 512, 1, 1, 1, 1, 0, 0, c40_bin, true); - - tk::dnn::Layer *r41_layers[2] = {&a39}; - tk::dnn::Route r41(&net, r41_layers, 1); - - tk::dnn::Conv2d c42(&net, 512, 1, 1, 1, 1, 0, 0, c42_bin, true); - - //3-1 - tk::dnn::Conv2d c43(&net, 512, 1, 1, 1, 1, 0, 0, c43_bin, true); - tk::dnn::Activation a43(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c44(&net, 512, 3, 3, 1, 1, 1, 1, c44_bin, true, false, 32); - tk::dnn::Activation a44(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c45(&net, 512, 1, 1, 1, 1, 0, 0, c45_bin, true); - - tk::dnn::Shortcut s46(&net, &c42); - tk::dnn::Activation a46(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-2 - tk::dnn::Conv2d c47(&net, 512, 1, 1, 1, 1, 0, 0, c47_bin, true); - tk::dnn::Activation a47(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c48(&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true, false, 32); - tk::dnn::Activation a48(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c49(&net, 512, 1, 1, 1, 1, 0, 0, c49_bin, true); - - tk::dnn::Shortcut s50(&net, &a46); - tk::dnn::Activation a50(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-3 - tk::dnn::Conv2d c51(&net, 512, 1, 1, 1, 1, 0, 0, c51_bin, true); - tk::dnn::Activation a51(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c52(&net, 512, 3, 3, 1, 1, 1, 1, c52_bin, true, false, 32); - tk::dnn::Activation a52(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c53(&net, 512, 1, 1, 1, 1, 0, 0, c53_bin, true); - - tk::dnn::Shortcut s54(&net, &a50); - tk::dnn::Activation a54(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-4 - tk::dnn::Conv2d c55(&net, 512, 1, 1, 1, 1, 0, 0, c55_bin, true); - tk::dnn::Activation a55(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c56(&net, 512, 3, 3, 1, 1, 1, 1, c56_bin, true, false, 32); - tk::dnn::Activation a56(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c57(&net, 512, 1, 1, 1, 1, 0, 0, c57_bin, true); - - tk::dnn::Shortcut s58(&net, &a54); - tk::dnn::Activation a58(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-5 - tk::dnn::Conv2d c59(&net, 512, 1, 1, 1, 1, 0, 0, c59_bin, true); - tk::dnn::Activation a59(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c60(&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true, false, 32); - tk::dnn::Activation a60(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c61(&net, 512, 1, 1, 1, 1, 0, 0, c61_bin, true); - - tk::dnn::Shortcut s62(&net, &a58); - tk::dnn::Activation a62(&net, tk::dnn::ACTIVATION_LEAKY); - - //3-T - tk::dnn::Conv2d c63(&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true); - tk::dnn::Activation a63(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r64_layers[2] = {&a63, &c40}; - tk::dnn::Route r64(&net, r64_layers, 2); - - tk::dnn::Conv2d c65(&net, 1024, 1, 1, 1, 1, 0, 0, c65_bin, true); - tk::dnn::Activation a65(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c66(&net, 1024, 3, 3, 2, 2, 1, 1, c66_bin, true, false, 32); - tk::dnn::Activation a66(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c67(&net, 1024, 1, 1, 1, 1, 0, 0, c67_bin, true); - tk::dnn::Activation a67(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r68_layers[2] = {&a66}; - tk::dnn::Route r68(&net, r68_layers, 1); - - tk::dnn::Conv2d c69(&net, 1024, 1, 1, 1, 1, 0, 0, c69_bin, true); - tk::dnn::Activation a69(&net, tk::dnn::ACTIVATION_LEAKY); - - //4-1 - tk::dnn::Conv2d c70(&net, 1024, 1, 1, 1, 1, 0, 0, c70_bin, true); - tk::dnn::Activation a70(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c71(&net, 1024, 3, 3, 1, 1, 1, 1, c71_bin, true, false, 32); - tk::dnn::Activation a71(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c72(&net, 1024, 1, 1, 1, 1, 0, 0, c72_bin, true); - - tk::dnn::Shortcut s73(&net, &a69); - tk::dnn::Activation a73(&net, tk::dnn::ACTIVATION_LEAKY); - - //4-2 - tk::dnn::Conv2d c74(&net, 1024, 1, 1, 1, 1, 0, 0, c74_bin, true); - tk::dnn::Activation a74(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c75(&net, 1024, 3, 3, 1, 1, 1, 1, c75_bin, true, false, 32); - tk::dnn::Activation a75(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c76(&net, 1024, 1, 1, 1, 1, 0, 0, c76_bin, true); - - tk::dnn::Shortcut s77(&net, &a73); - tk::dnn::Activation a77(&net, tk::dnn::ACTIVATION_LEAKY); - - //4-T - tk::dnn::Conv2d c78(&net, 1024, 1, 1, 1, 1, 0, 0, c78_bin, true); - tk::dnn::Activation a78(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *r79_layers[2] = {&a78, &a67}; - tk::dnn::Route r79(&net, r79_layers, 2); - - tk::dnn::Conv2d c80(&net, 2048, 1, 1, 1, 1, 0, 0, c80_bin, true); - tk::dnn::Activation a80(&net, tk::dnn::ACTIVATION_LEAKY); - - // //////////////////// - - tk::dnn::Conv2d c81(&net, 512, 1, 1, 1, 1, 0, 0, c81_bin, true); - tk::dnn::Activation a81(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c82(&net, 1024, 3, 3, 1, 1, 1, 1, c82_bin, true); - tk::dnn::Activation a82(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c83(&net, 512, 1, 1, 1, 1, 0, 0, c83_bin, true); - tk::dnn::Activation a83(&net, tk::dnn::ACTIVATION_LEAKY); - - //SPP - tk::dnn::Pooling p84(&net, 5, 5, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r85_layers[1] = {&a83}; - tk::dnn::Route r85(&net, r85_layers, 1); - - tk::dnn::Pooling p86(&net, 9, 9, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r87_layers[1] = {&a83}; - tk::dnn::Route r87(&net, r87_layers, 1); - - tk::dnn::Pooling p88(&net, 13, 13, 1, 1, 12, 12, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r89_layers[4] = {&p88, &p86, &p84, &a83}; - tk::dnn::Route r89(&net, r89_layers, 4); - //END SPP - - tk::dnn::Conv2d c90(&net, 512, 1, 1, 1, 1, 0, 0, c90_bin, true); - tk::dnn::Activation a90(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c91(&net, 1024, 3, 3, 1, 1, 1, 1, c91_bin, true); - tk::dnn::Activation a91(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c92(&net, 512, 1, 1, 1, 1, 0, 0, c92_bin, true); - tk::dnn::Activation a92(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c93(&net, 256, 1, 1, 1, 1, 0, 0, c93_bin, true); - tk::dnn::Activation a93(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u94(&net, 2); - tk::dnn::Layer *r95_layers[1] = {&a65}; - tk::dnn::Route r95(&net, r95_layers, 1); - tk::dnn::Conv2d c96(&net, 256, 1, 1, 1, 1, 0, 0, c96_bin, true); - tk::dnn::Activation a96(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r97_layers[2] = {&a96,&u94}; - tk::dnn::Route r97(&net, r97_layers, 2); - - tk::dnn::Conv2d c98(&net, 256, 1, 1, 1, 1, 0, 0, c98_bin, true); - tk::dnn::Activation a98(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c99(&net, 512, 3, 3, 1, 1, 1, 1, c99_bin, true); - tk::dnn::Activation a99(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c100(&net, 256, 1, 1, 1, 1, 0, 0, c100_bin, true); - tk::dnn::Activation a100(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c101(&net, 512, 3, 3, 1, 1, 1, 1, c101_bin, true); - tk::dnn::Activation a101(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c102(&net, 256, 1, 1, 1, 1, 0, 0, c102_bin, true); - tk::dnn::Activation a102(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c103(&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true); - tk::dnn::Activation a103(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u104(&net, 2); - tk::dnn::Layer *r105_layers[1] = {&a38}; - tk::dnn::Route r105(&net, r105_layers, 1); - tk::dnn::Conv2d c106(&net, 128, 1, 1, 1, 1, 0, 0, c106_bin, true); - tk::dnn::Activation a106(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r107_layers[2] = {&a106,&u104}; - tk::dnn::Route r107(&net, r107_layers, 2); - - - tk::dnn::Conv2d c108(&net, 128, 1, 1, 1, 1, 0, 0, c108_bin, true); - tk::dnn::Activation a108(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c109(&net, 256, 3, 3, 1, 1, 1, 1, c109_bin, true); - tk::dnn::Activation a109(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c110(&net, 128, 1, 1, 1, 1, 0, 0, c110_bin, true); - tk::dnn::Activation a110(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c111(&net, 256, 3, 3, 1, 1, 1, 1, c111_bin, true); - tk::dnn::Activation a111(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c112(&net, 128, 1, 1, 1, 1, 0, 0, c112_bin, true); - tk::dnn::Activation a112(&net, tk::dnn::ACTIVATION_LEAKY); - - // ########################### - - tk::dnn::Conv2d c113(&net, 256, 3, 3, 1, 1, 1, 1, c113_bin, true); - tk::dnn::Activation a113(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c114(&net, 255, 1, 1, 1, 1, 0, 0, c114_bin, false); - tk::dnn::Yolo yolo115(&net, classes, 3, g115_bin); - - tk::dnn::Layer *r116_layers[1] = {&a112}; - tk::dnn::Route r116(&net, r116_layers, 1); - tk::dnn::Conv2d c117(&net, 256, 3, 3, 2, 2, 1, 1, c117_bin, true); - tk::dnn::Activation a117(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r118_layers[2] = {&a117,&a102}; - tk::dnn::Route r118(&net, r118_layers, 2); - - tk::dnn::Conv2d c119(&net, 256, 1, 1, 1, 1, 0, 0, c119_bin, true); - tk::dnn::Activation a119(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c120(&net, 512, 3, 3, 1, 1, 1, 1, c120_bin, true); - tk::dnn::Activation a120(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c121(&net, 256, 1, 1, 1, 1, 0, 0, c121_bin, true); - tk::dnn::Activation a121(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c122(&net, 512, 3, 3, 1, 1, 1, 1, c122_bin, true); - tk::dnn::Activation a122(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c123(&net, 256, 1, 1, 1, 1, 0, 0, c123_bin, true); - tk::dnn::Activation a123(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c124(&net, 512, 3, 3, 1, 1, 1, 1, c124_bin, true); - tk::dnn::Activation a124(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c125(&net, 255, 1, 1, 1, 1, 0, 0, c125_bin, false); - tk::dnn::Yolo yolo126(&net, classes, 3, g126_bin); - - tk::dnn::Layer *r127_layers[1] = {&a123}; - tk::dnn::Route r127(&net, r127_layers, 1); - tk::dnn::Conv2d c128(&net, 512, 3, 3, 2, 2, 1, 1, c128_bin, true); - tk::dnn::Activation a128(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r129_layers[2] = {&a128,&a92}; - tk::dnn::Route r129(&net, r129_layers, 2); - - tk::dnn::Conv2d c130(&net, 512, 1, 1, 1, 1, 0, 0, c130_bin, true); - tk::dnn::Activation a130(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c131(&net, 1024, 3, 3, 1, 1, 1, 1, c131_bin, true); - tk::dnn::Activation a131(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c132(&net, 512, 1, 1, 1, 1, 0, 0, c132_bin, true); - tk::dnn::Activation a132(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c133(&net, 1024, 3, 3, 1, 1, 1, 1, c133_bin, true); - tk::dnn::Activation a133(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c134(&net, 512, 1, 1, 1, 1, 0, 0, c134_bin, true); - tk::dnn::Activation a134(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c135(&net, 1024, 3, 3, 1, 1, 1, 1, c135_bin, true); - tk::dnn::Activation a135(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c136(&net, 255, 1, 1, 1, 1, 0, 0, c136_bin, false); - tk::dnn::Yolo yolo137(&net, classes, 3, g137_bin); - - yolo[0] = &yolo115; - yolo[1] = &yolo126; - yolo[2] = &yolo137; - - // fill classes names - for (int i = 0; i < 3; i++) - { - yolo[i]->classesNames = {"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"}; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - // //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("csresnext50-panet-spp")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for (int i = 0; i < 3; i++) - out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); - { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - for (int i = 0; i < 3; i++) - cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for (int i = 0; i < 3; i++) - yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for (int j = 0; j < ndets; j++) - { - tk::dnn::Yolo::box b = dets[j].bbox; - int x0 = (b.x - b.w / 2.); - int x1 = (b.x + b.w / 2.); - int y0 = (b.y - b.h / 2.); - int y1 = (b.y + b.h / 2.); - - int cl = 0; - for (int c = 0; c < classes; ++c) - { - float prob = dets[j].prob[c]; - if (prob > 0) - cl = c; - } - std::cout << cl << ": " << x0 << " " << y0 << " " << x1 << " " << y1 << "\n"; - } - TIMER_STOP - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); - { - dim2.print(); - TIMER_START - netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - for (int i = 0; i < 3; i++) - rt_out[i] = (dnnType *)netRT.buffersRT[i + 1]; - - int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0; - for (int i = 0; i < 3; i++) - { - printCenteredTitle((std::string(" YOLO ") + std::to_string(i) + " CHECK RESULTS ").c_str(), '=', 30); - dnnType *out, *out_h; - int odim = out_dim[i].tot(); - readBinaryFile(output_bins[i], odim, &out_h, &out); - std::cout<<"CUDNN vs correct"; - ret_cudnn |= checkResult(odim, cudnn_out[i], out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - ret_tensorrt |= checkResult(odim, rt_out[i], out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - } - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/csresnext50-panet-spp/csresnext50-panet-spp.cfg b/tests/darknet/cfg/csresnext50-panet-spp.cfg similarity index 100% rename from tests/csresnext50-panet-spp/csresnext50-panet-spp.cfg rename to tests/darknet/cfg/csresnext50-panet-spp.cfg diff --git a/tests/bdd-csresnext50-panet-spp/berkeleycsresnetx50.cfg b/tests/darknet/cfg/csresnext50-panet-spp_berkeley.cfg similarity index 100% rename from tests/bdd-csresnext50-panet-spp/berkeleycsresnetx50.cfg rename to tests/darknet/cfg/csresnext50-panet-spp_berkeley.cfg diff --git a/tests/yolo/yolo.cfg b/tests/darknet/cfg/yolo2.cfg similarity index 100% rename from tests/yolo/yolo.cfg rename to tests/darknet/cfg/yolo2.cfg diff --git a/tests/yolo_voc/yolo_voc.cfg b/tests/darknet/cfg/yolo2_voc.cfg similarity index 100% rename from tests/yolo_voc/yolo_voc.cfg rename to tests/darknet/cfg/yolo2_voc.cfg diff --git a/tests/yolo_tiny/tiny-yolo.cfg b/tests/darknet/cfg/yolo2tiny.cfg similarity index 97% rename from tests/yolo_tiny/tiny-yolo.cfg rename to tests/darknet/cfg/yolo2tiny.cfg index 630a209..2884bb4 100644 --- a/tests/yolo_tiny/tiny-yolo.cfg +++ b/tests/darknet/cfg/yolo2tiny.cfg @@ -1,5 +1,5 @@ [net] - Training +# Training batch=64 subdivisions=8 # Testing @@ -90,9 +90,9 @@ stride=1 pad=1 activation=leaky -#[maxpool] -#size=2 -#stride=1 +[maxpool] +size=2 +stride=1 [convolutional] batch_normalize=1 diff --git a/tests/yolo3/yolov3.cfg b/tests/darknet/cfg/yolo3.cfg similarity index 100% rename from tests/yolo3/yolov3.cfg rename to tests/darknet/cfg/yolo3.cfg diff --git a/tests/yolo3_512tp/yolo3512.cfg b/tests/darknet/cfg/yolo3_512.cfg similarity index 93% rename from tests/yolo3_512tp/yolo3512.cfg rename to tests/darknet/cfg/yolo3_512.cfg index 00ea6e9..032d49a 100644 --- a/tests/yolo3_512tp/yolo3512.cfg +++ b/tests/darknet/cfg/yolo3_512.cfg @@ -1,10 +1,10 @@ [net] # Testing -#batch=1 -#subdivisions=1 +# batch=1 +# subdivisions=1 # Training -batch=16 -subdivisions=1 +batch=32 +subdivisions=32 width=512 height=512 channels=3 @@ -600,14 +600,14 @@ activation=leaky size=1 stride=1 pad=1 -filters=24 +filters=255 activation=linear [yolo] mask = 6,7,8 -anchors = 10.256,16.494, 11.724,18.558, 17.678,16.437, 25.619,14.985, 46.845,79.02, 58.643,81.204, 23.646,208.56, 30.837,211.57, 37.921,211.16 -classes=3 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 num=9 jitter=.3 ignore_thresh = .7 @@ -633,6 +633,7 @@ stride=2 layers = -1, 61 + [convolutional] batch_normalize=1 filters=256 @@ -685,14 +686,14 @@ activation=leaky size=1 stride=1 pad=1 -filters=24 +filters=255 activation=linear [yolo] mask = 3,4,5 -anchors = 10.256,16.494, 11.724,18.558, 17.678,16.437, 25.619,14.985, 46.845,79.02, 58.643,81.204, 23.646,208.56, 30.837,211.57, 37.921,211.16 -classes=3 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 num=9 jitter=.3 ignore_thresh = .7 @@ -772,16 +773,17 @@ activation=leaky size=1 stride=1 pad=1 -filters=24 +filters=255 activation=linear [yolo] mask = 0,1,2 -anchors = 10.256,16.494, 11.724,18.558, 17.678,16.437, 25.619,14.985, 46.845,79.02, 58.643,81.204, 23.646,208.56, 30.837,211.57, 37.921,211.16 -classes=3 +anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326 +classes=80 num=9 jitter=.3 ignore_thresh = .7 truth_thresh = 1 random=1 + diff --git a/tests/yolo3_berkeley/yolo3_berkeley.cfg b/tests/darknet/cfg/yolo3_berkeley.cfg similarity index 100% rename from tests/yolo3_berkeley/yolo3_berkeley.cfg rename to tests/darknet/cfg/yolo3_berkeley.cfg diff --git a/tests/yolo3_coco4/yolov3-coco4.cfg b/tests/darknet/cfg/yolo3_coco4.cfg similarity index 100% rename from tests/yolo3_coco4/yolov3-coco4.cfg rename to tests/darknet/cfg/yolo3_coco4.cfg diff --git a/tests/yolo3_flir/yolo3_flir.cfg b/tests/darknet/cfg/yolo3_flir.cfg similarity index 100% rename from tests/yolo3_flir/yolo3_flir.cfg rename to tests/darknet/cfg/yolo3_flir.cfg diff --git a/tests/yolo3_tiny/yolov3-tiny.cfg b/tests/darknet/cfg/yolo3tiny.cfg similarity index 100% rename from tests/yolo3_tiny/yolov3-tiny.cfg rename to tests/darknet/cfg/yolo3tiny.cfg diff --git a/tests/yolo3_tiny512tp/yolo3tiny512.cfg b/tests/darknet/cfg/yolo3tiny_512.cfg similarity index 87% rename from tests/yolo3_tiny512tp/yolo3tiny512.cfg rename to tests/darknet/cfg/yolo3tiny_512.cfg index baecead..049a3a6 100644 --- a/tests/yolo3_tiny512tp/yolo3tiny512.cfg +++ b/tests/darknet/cfg/yolo3tiny_512.cfg @@ -124,15 +124,15 @@ activation=leaky size=1 stride=1 pad=1 -filters=24 +filters=255 activation=linear [yolo] mask = 3,4,5 -anchors = 10.638,16.801, 13.183,19.091, 24.568,12.24, 54.462,77.421, 29.199,210.49, 37.495,212.21 -classes=3 +anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 +classes=80 num=6 jitter=.3 ignore_thresh = .7 @@ -168,13 +168,13 @@ activation=leaky size=1 stride=1 pad=1 -filters=24 +filters=255 activation=linear [yolo] mask = 0,1,2 -anchors = 10.638,16.801, 13.183,19.091, 24.568,12.24, 54.462,77.421, 29.199,210.49, 37.495,212.21 -classes=3 +anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 +classes=80 num=6 jitter=.3 ignore_thresh = .7 diff --git a/tests/yolo4/yolov4.cfg b/tests/darknet/cfg/yolo4.cfg similarity index 100% rename from tests/yolo4/yolov4.cfg rename to tests/darknet/cfg/yolo4.cfg diff --git a/tests/darknet/cfg/yolo4_berkeley.cfg b/tests/darknet/cfg/yolo4_berkeley.cfg new file mode 100644 index 0000000..b11c0a7 --- /dev/null +++ b/tests/darknet/cfg/yolo4_berkeley.cfg @@ -0,0 +1,1159 @@ +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=16 +width=544 +height=320 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 20000 +policy=steps +steps=16000d,18000 +scales=.1,.1 + +#cutmix=1 +mosaic=1 + +#:104x104 54:52x52 85:26x26 104:13x13 for 416 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-7 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-10 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-16 + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=mish + +########################## + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = 85 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = 54 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +########################## + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=45 +activation=linear + + +[yolo] +mask = 0,1,2 +anchors = 6, 7, 14, 11, 9, 19, 26, 20, 18, 42, 48, 35, 74, 65, 126, 99, 183,169 +classes=10 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +scale_x_y = 1.2 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=leaky + +[route] +layers = -1, -16 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=45 +activation=linear + + +[yolo] +mask = 3,4,5 +anchors = 6, 7, 14, 11, 9, 19, 26, 20, 18, 42, 48, 35, 74, 65, 126, 99, 183,169 +classes=10 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +scale_x_y = 1.1 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=leaky + +[route] +layers = -1, -37 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +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=45 +activation=linear + + +[yolo] +mask = 6,7,8 +anchors = 6, 7, 14, 11, 9, 19, 26, 20, 18, 42, 48, 35, 74, 65, 126, 99, 183,169 +classes=10 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + diff --git a/tests/darknet/cfg/yolo4_mmr.cfg b/tests/darknet/cfg/yolo4_mmr.cfg new file mode 100644 index 0000000..90a7204 --- /dev/null +++ b/tests/darknet/cfg/yolo4_mmr.cfg @@ -0,0 +1,1158 @@ +[net] +batch=1 +subdivisions=1 +# Training +width=512 +height=512 +# width=608 +# height=608 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.0013 +burn_in=1000 +max_batches = 16000 +policy=steps +steps=12800,14400 +scales=.1,.1 + +#cutmix=1 +mosaic=1 + +#:104x104 54:52x52 85:26x26 104:13x13 for 416 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-7 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-10 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-16 + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=mish + +########################## + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = 85 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = 54 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +########################## + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=27 +activation=linear + + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=4 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +scale_x_y = 1.2 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=leaky + +[route] +layers = -1, -16 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=27 +activation=linear + + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=4 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +scale_x_y = 1.1 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=leaky + +[route] +layers = -1, -37 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +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=27 +activation=linear + + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=4 +num=9 +jitter=.3 +ignore_thresh = .7 +truth_thresh = 1 +random=1 +scale_x_y = 1.05 +iou_thresh=0.213 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +nms_kind=greedynms +beta_nms=0.6 +max_delta=5 + diff --git a/tests/yolo_224/yolo_224.cfg b/tests/darknet/cfg/yolo4tiny.cfg similarity index 66% rename from tests/yolo_224/yolo_224.cfg rename to tests/darknet/cfg/yolo4tiny.cfg index dd9206c..dc6f5bf 100644 --- a/tests/yolo_224/yolo_224.cfg +++ b/tests/darknet/cfg/yolo4tiny.cfg @@ -3,10 +3,10 @@ #batch=1 #subdivisions=1 # Training - batch=64 - subdivisions=16 -width=224 -height=224 +batch=64 +subdivisions=1 +width=416 +height=416 channels=3 momentum=0.9 decay=0.0005 @@ -15,7 +15,7 @@ saturation = 1.5 exposure = 1.5 hue=.1 -learning_rate=0.001 +learning_rate=0.00261 burn_in=1000 max_batches = 500200 policy=steps @@ -26,13 +26,17 @@ scales=.1,.1 batch_normalize=1 filters=32 size=3 -stride=1 +stride=2 pad=1 activation=leaky -[maxpool] -size=2 +[convolutional] +batch_normalize=1 +filters=64 +size=3 stride=2 +pad=1 +activation=leaky [convolutional] batch_normalize=1 @@ -42,217 +46,236 @@ 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 - -[convolutional] -batch_normalize=1 -size=1 -stride=1 -pad=1 -filters=64 -activation=leaky - -[reorg] -stride=2 - -[route] -layers=-1,-4 +layers=-1 +groups=2 +group_id=1 [convolutional] batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1,-2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -6,-1 + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1 +groups=2 +group_id=1 + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1,-2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -6,-1 + +[maxpool] +size=2 +stride=2 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers=-1 +groups=2 +group_id=1 + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -1,-2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=leaky + +[route] +layers = -6,-1 + +[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 -filters=1024 activation=leaky [convolutional] size=1 stride=1 pad=1 -filters=425 +filters=255 activation=linear -[region] -anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828 -bias_match=1 + +[yolo] +mask = 3,4,5 +anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 classes=80 -coords=4 -num=5 -softmax=1 +num=6 jitter=.3 -rescore=1 +scale_x_y = 1.05 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +ignore_thresh = .7 +truth_thresh = 1 +random=0 +resize=1.5 +nms_kind=greedynms +beta_nms=0.6 -object_scale=5 -noobject_scale=1 -class_scale=1 -coord_scale=1 +[route] +layers = -4 -absolute=1 -thresh = .6 -random=1 +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=leaky + +[upsample] +stride=2 + +[route] +layers = -1, 23 + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + +[yolo] +mask = 1,2,3 +anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319 +classes=80 +num=6 +jitter=.3 +scale_x_y = 1.05 +cls_normalizer=1.0 +iou_normalizer=0.07 +iou_loss=ciou +ignore_thresh = .7 +truth_thresh = 1 +random=0 +resize=1.5 +nms_kind=greedynms +beta_nms=0.6 diff --git a/tests/darknet/cfg/yolo4x.cfg b/tests/darknet/cfg/yolo4x.cfg new file mode 100644 index 0000000..89f2564 --- /dev/null +++ b/tests/darknet/cfg/yolo4x.cfg @@ -0,0 +1,1427 @@ +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=8 +width=672 +height=672 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500500 +policy=steps +steps=400000,450000 +scales=.1,.1 + +mosaic=1 + +letter_box=1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=40 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +# Downsample + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=80 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=80 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-13 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-34 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-34 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1280 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-19 + +[convolutional] +batch_normalize=1 +filters=1280 +size=1 +stride=1 +pad=1 +activation=mish + +########################## 6 0 6 6 3 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1, -15 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 94 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[route] +layers = -1, -8 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 57 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=mish + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=160 +activation=mish + +[route] +layers = -1, -8 + +[convolutional] +batch_normalize=1 +filters=160 +size=1 +stride=1 +pad=1 +activation=mish + +########################## + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +objectness_smooth=0 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=4.0 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=320 +activation=mish + +[route] +layers = -1, -22 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=320 +activation=mish + +[route] +layers = -1,-8 + +[convolutional] +batch_normalize=1 +filters=320 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=1.0 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1, -55 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=640 +activation=mish + +[route] +layers = -1,-8 + +[convolutional] +batch_normalize=1 +filters=640 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1280 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=80 +num=9 +jitter=.1 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=0.4 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 diff --git a/tests/darknet/csresnext50-panet-spp.cpp b/tests/darknet/csresnext50-panet-spp.cpp new file mode 100644 index 0000000..a366e14 --- /dev/null +++ b/tests/darknet/csresnext50-panet-spp.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "csresnext50-panet-spp"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer115_out.bin", + bin_path + "/debug/layer126_out.bin", + bin_path + "/debug/layer137_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/csresnext50-panet-spp.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/Kcs4xBozwY4wFx8/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/csresnext50-panet-spp_berkeley.cpp b/tests/darknet/csresnext50-panet-spp_berkeley.cpp new file mode 100644 index 0000000..a8ba59f --- /dev/null +++ b/tests/darknet/csresnext50-panet-spp_berkeley.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "csresnext50-panet-spp_berkeley"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer115_out.bin", + bin_path + "/debug/layer126_out.bin", + bin_path + "/debug/layer137_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/csresnext50-panet-spp_berkeley.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/berkeley.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/q82qHAtqpoaFYo5/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/names/berkeley.names b/tests/darknet/names/berkeley.names new file mode 100644 index 0000000..321e633 --- /dev/null +++ b/tests/darknet/names/berkeley.names @@ -0,0 +1,10 @@ +person +car +truck +bus +motor +bike +rider +traffic light +traffic sign +train \ No newline at end of file diff --git a/tests/darknet/names/coco.names b/tests/darknet/names/coco.names new file mode 100644 index 0000000..ca76c80 --- /dev/null +++ b/tests/darknet/names/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/tests/darknet/names/coco4.names b/tests/darknet/names/coco4.names new file mode 100644 index 0000000..82cb5c4 --- /dev/null +++ b/tests/darknet/names/coco4.names @@ -0,0 +1,4 @@ +person +bicycle +car +motorbike diff --git a/tests/darknet/names/flir.names b/tests/darknet/names/flir.names new file mode 100644 index 0000000..03f4d8a --- /dev/null +++ b/tests/darknet/names/flir.names @@ -0,0 +1,3 @@ +person +bike +car diff --git a/tests/darknet/names/mmr.names b/tests/darknet/names/mmr.names new file mode 100644 index 0000000..701a1fc --- /dev/null +++ b/tests/darknet/names/mmr.names @@ -0,0 +1,4 @@ +blue-cone +yellow-cone +orange-cone +big-orange-cone \ No newline at end of file diff --git a/tests/darknet/names/voc.names b/tests/darknet/names/voc.names new file mode 100644 index 0000000..8420ab3 --- /dev/null +++ b/tests/darknet/names/voc.names @@ -0,0 +1,20 @@ +aeroplane +bicycle +bird +boat +bottle +bus +car +cat +chair +cow +diningtable +dog +horse +motorbike +person +pottedplant +sheep +sofa +train +tvmonitor diff --git a/tests/darknet/viz_yolo3.cpp b/tests/darknet/viz_yolo3.cpp new file mode 100644 index 0000000..9e53116 --- /dev/null +++ b/tests/darknet/viz_yolo3.cpp @@ -0,0 +1,70 @@ +#include +#include +#include +#include + +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" +#include "NetworkViz.h" + +int main(int argc, char *argv[]) { + if(argc <2) + FatalError("you must provide an input image"); + std::string input_image = argv[1]; + std::string bin_path = "yolo3"; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(wgs_path, bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + // input data + dnnType *input_d; + checkCuda( cudaMalloc(&input_d, sizeof(dnnType)*net->input_dim.tot())); + + // load image + cv::Mat frame, frameFloat; + frame = cv::imread(input_image); + cv::resize(frame, frame, cv::Size(net->input_dim.w, net->input_dim.h)); + frame.convertTo(frameFloat, CV_32FC3, 1/255.0); + + //split channels + cv::Mat bgr[3]; + cv::split(frameFloat,bgr);//split source + + //write channels + for(int i=0; iinput_dim.c; i++) { + int idx = i*frameFloat.rows*frameFloat.cols; + int ch = net->input_dim.c-1 -i; + checkCuda( cudaMemcpy(input_d + idx, (void*)bgr[ch].data, frameFloat.rows*frameFloat.cols*sizeof(dnnType), cudaMemcpyHostToDevice)); + } + + tk::dnn::dataDim_t dim = net->input_dim; + dim.print(); + std::cout<<"infer\n"; + net->infer(dim, input_d); + + // output directory + std::string output_viz = "viz/"; + system( (std::string("mkdir -p ") + output_viz).c_str() ); + + for(int i=0; inum_layers; i++) { + std::string output_png = output_viz + "/layer" + std::to_string(i) + ".png"; + std::cout<<"saving "<releaseLayers(); + delete net; + return 0; +} + + \ No newline at end of file diff --git a/tests/darknet/yolo2.cpp b/tests/darknet/yolo2.cpp new file mode 100644 index 0000000..978c137 --- /dev/null +++ b/tests/darknet/yolo2.cpp @@ -0,0 +1,32 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo2"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/layers/output.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo2.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/nf4PJ3k8bxBETwL/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo2_voc.cpp b/tests/darknet/yolo2_voc.cpp new file mode 100644 index 0000000..94111e6 --- /dev/null +++ b/tests/darknet/yolo2_voc.cpp @@ -0,0 +1,33 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo2_voc"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/layers/output.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo2_voc.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/voc.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/DJC5Fi2pEjfNDP9/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} + diff --git a/tests/darknet/yolo2tiny.cpp b/tests/darknet/yolo2tiny.cpp new file mode 100644 index 0000000..cc12109 --- /dev/null +++ b/tests/darknet/yolo2tiny.cpp @@ -0,0 +1,33 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo2tiny"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/layers/output.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo2tiny.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + // FIXME: wrong weights + //downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s//download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3.cpp b/tests/darknet/yolo3.cpp new file mode 100644 index 0000000..d9a684b --- /dev/null +++ b/tests/darknet/yolo3.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo3"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer82_out.bin", + bin_path + "/debug/layer94_out.bin", + bin_path + "/debug/layer106_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} \ No newline at end of file diff --git a/tests/darknet/yolo3_512.cpp b/tests/darknet/yolo3_512.cpp new file mode 100644 index 0000000..6a5c20e --- /dev/null +++ b/tests/darknet/yolo3_512.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo3_512"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer82_out.bin", + bin_path + "/debug/layer94_out.bin", + bin_path + "/debug/layer106_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3_512.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/RGecMeGLD4cXEWL/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3_berkeley.cpp b/tests/darknet/yolo3_berkeley.cpp new file mode 100644 index 0000000..016a8a2 --- /dev/null +++ b/tests/darknet/yolo3_berkeley.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo3_berkeley"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer82_out.bin", + bin_path + "/debug/layer94_out.bin", + bin_path + "/debug/layer106_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3_berkeley.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/berkeley.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/o5cHa4AjTKS64oD/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3_coco4.cpp b/tests/darknet/yolo3_coco4.cpp new file mode 100644 index 0000000..eaf9bd8 --- /dev/null +++ b/tests/darknet/yolo3_coco4.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo3_coco4"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer82_out.bin", + bin_path + "/debug/layer94_out.bin", + bin_path + "/debug/layer106_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3_coco4.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco4.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/o27NDzSAartbyc4/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3_flir.cpp b/tests/darknet/yolo3_flir.cpp new file mode 100644 index 0000000..24aac7f --- /dev/null +++ b/tests/darknet/yolo3_flir.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo3_flir"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer82_out.bin", + bin_path + "/debug/layer94_out.bin", + bin_path + "/debug/layer106_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3_flir.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/flir.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/62DECncmF6bMMiH/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3tiny.cpp b/tests/darknet/yolo3tiny.cpp new file mode 100644 index 0000000..c33f7a8 --- /dev/null +++ b/tests/darknet/yolo3tiny.cpp @@ -0,0 +1,33 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo3tiny"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer16_out.bin", + bin_path + "/debug/layer23_out.bin", + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3tiny.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/LMcSHtWaLeps8yN/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3tiny_512.cpp b/tests/darknet/yolo3tiny_512.cpp new file mode 100644 index 0000000..ce4ce86 --- /dev/null +++ b/tests/darknet/yolo3tiny_512.cpp @@ -0,0 +1,33 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo3tiny_512"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer16_out.bin", + bin_path + "/debug/layer23_out.bin", + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3tiny_512.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/8Zt6bHwHADqP4JC/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo4.cpp b/tests/darknet/yolo4.cpp new file mode 100644 index 0000000..65ac6ee --- /dev/null +++ b/tests/darknet/yolo4.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer139_out.bin", + bin_path + "/debug/layer150_out.bin", + bin_path + "/debug/layer161_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo4_berkeley.cpp b/tests/darknet/yolo4_berkeley.cpp new file mode 100644 index 0000000..89e9f04 --- /dev/null +++ b/tests/darknet/yolo4_berkeley.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4_berkeley"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer139_out.bin", + bin_path + "/debug/layer150_out.bin", + bin_path + "/debug/layer161_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4_berkeley.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/berkeley.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/nkWFa5fgb4NTdnB/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo4_mmr.cpp b/tests/darknet/yolo4_mmr.cpp new file mode 100644 index 0000000..85649b2 --- /dev/null +++ b/tests/darknet/yolo4_mmr.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4_mmr"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer139_out.bin", + bin_path + "/debug/layer150_out.bin", + bin_path + "/debug/layer161_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4_mmr.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/mmr.names"; + // downloadWeightsifDoNotExist(input_bins[0], bin_path, ""); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo4tiny.cpp b/tests/darknet/yolo4tiny.cpp new file mode 100644 index 0000000..44fbac8 --- /dev/null +++ b/tests/darknet/yolo4tiny.cpp @@ -0,0 +1,33 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4tiny"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer30_out.bin", + bin_path + "/debug/layer37_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4tiny.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download"); + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo4x.cpp b/tests/darknet/yolo4x.cpp new file mode 100644 index 0000000..b9ad003 --- /dev/null +++ b/tests/darknet/yolo4x.cpp @@ -0,0 +1,36 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4x"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector output_bins = { + bin_path + "/debug/layer168_out.bin", + bin_path + "/debug/layer185_out.bin", + bin_path + "/debug/layer202_out.bin" + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4x.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/BLPpiAigZJLorQD/download"); + + + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} diff --git a/tests/caffe_weights_exporter.py b/tests/exporters/caffe_weights_exporter.py similarity index 100% rename from tests/caffe_weights_exporter.py rename to tests/exporters/caffe_weights_exporter.py diff --git a/tests/weights_exporter.py b/tests/exporters/keras_weights_exporter.py similarity index 100% rename from tests/weights_exporter.py rename to tests/exporters/keras_weights_exporter.py diff --git a/tests/imuodom/imuodom.cpp b/tests/imuodom/imuodom.cpp index 9682f15..b924760 100644 --- a/tests/imuodom/imuodom.cpp +++ b/tests/imuodom/imuodom.cpp @@ -7,26 +7,18 @@ const char *i2_bin = "imuodom/layers/input2.bin"; const char *o0_bin = "imuodom/layers/output0.bin"; const char *o1_bin = "imuodom/layers/output1.bin"; -const char *c0_bin = "imuodom/layers/conv1d_7.bin"; -const char *c1_bin = "imuodom/layers/conv1d_8.bin"; -const char *c2_bin = "imuodom/layers/conv1d_9.bin"; -const char *c3_bin = "imuodom/layers/conv1d_10.bin"; -const char *c4_bin = "imuodom/layers/conv1d_11.bin"; -const char *c5_bin = "imuodom/layers/conv1d_12.bin"; -const char *l0_bin = "imuodom/layers/bidirectional_3.bin"; -const char *l1_bin = "imuodom/layers/bidirectional_4.bin"; -const char *d0_bin = "imuodom/layers/dense_3.bin"; -const char *d1_bin = "imuodom/layers/dense_4.bin"; - - int main() { + // V1 downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/ZAy34K5w2ixED6x/download"); + // V2 + //downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/BBSEbEbQbPKxp4s/download"); + tk::dnn::ImuOdom ImuNet; ImuNet.init("imuodom/layers/"); - const int N = 10000; //19513; + const int N = 19513; // Network layout tk::dnn::dataDim_t dim0(1, 4, 1, 100); @@ -54,13 +46,15 @@ int main() { int ret_cudnn = 0; for(int i=0; ienqueue(1, buffers, stream, nullptr); - TIMER_STOP + TKDNN_TSTOP checkCuda(cudaMemcpyAsync(output, buffers[outputIndex],10*sizeof(float), cudaMemcpyDeviceToHost, stream)); cudaStreamSynchronize(stream); } diff --git a/tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp b/tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp similarity index 99% rename from tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp rename to tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp index df3e617..c3c6472 100644 --- a/tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp +++ b/tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp @@ -134,7 +134,7 @@ const char *regression_header5 = "bdd-mobilenetv2ssd/layers/regression_headers-5 int main() { - // downloadWeightsifDoNotExist(input_bin, "bdd-mobilenetv2ssd", "https://cloud.hipert.unimore.it/s//download"); + downloadWeightsifDoNotExist(input_bin, "bdd-mobilenetv2ssd", "https://cloud.hipert.unimore.it/s/jzRBxcEJYJ99RLa/download"); int classes = 11; @@ -477,9 +477,9 @@ int main() printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART net.infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } @@ -492,9 +492,9 @@ int main() printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART netRT.infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } diff --git a/tests/mobilenetv2ssd/mobilenetv2ssd.cpp b/tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp similarity index 99% rename from tests/mobilenetv2ssd/mobilenetv2ssd.cpp rename to tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp index 787341f..58463a4 100644 --- a/tests/mobilenetv2ssd/mobilenetv2ssd.cpp +++ b/tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp @@ -477,9 +477,9 @@ int main() printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART net.infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } @@ -492,9 +492,9 @@ int main() printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART netRT.infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } diff --git a/tests/mobilenetv2ssd512/mobilenetv2ssd512.cpp b/tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp similarity index 99% rename from tests/mobilenetv2ssd512/mobilenetv2ssd512.cpp rename to tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp index 8886232..54b00c1 100644 --- a/tests/mobilenetv2ssd512/mobilenetv2ssd512.cpp +++ b/tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp @@ -476,9 +476,9 @@ int main() printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART net.infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } @@ -491,9 +491,9 @@ int main() printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART netRT.infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } diff --git a/tests/simple/test_simple.cpp b/tests/simple/test_simple.cpp index b2b0441..10b0d2f 100644 --- a/tests/simple/test_simple.cpp +++ b/tests/simple/test_simple.cpp @@ -38,18 +38,18 @@ int main() { tk::dnn::dataDim_t dim1 = dim; //input dim printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART out_data = net.infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } tk::dnn::dataDim_t dim2 = dim; printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART out_data2 = netRT.infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } diff --git a/tests/test_rtinference/rtinference.cpp b/tests/test_rtinference/rtinference.cpp index 1ca9763..a629168 100644 --- a/tests/test_rtinference/rtinference.cpp +++ b/tests/test_rtinference/rtinference.cpp @@ -30,7 +30,8 @@ int main(int argc, char *argv[]) { int ret_tensorrt = 0; std::cout<<"Testing with batchsize: "< -#include -#include "tkdnn.h" - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); - tk::dnn::Network net(dim); - - // create yolo3 model - std::string bin_path = "yolo3"; - downloadWeightsifDoNotExist("yolo3/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download"); - int classes = 80; - tk::dnn::Yolo *yolo [3]; - #include "models/Yolo3.h" - - - - // fill classes names - for(int i=0; i<3; i++) { - yolo[i]->classesNames = {"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"}; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for(int i=0; i<3; i++) out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - for(int i=0; i<3; i++) cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for(int i=0; i<3; i++) yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for(int j=0; j 0) - cl = c; - } - std::cout< -#include -#include "tkdnn.h" - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 512, 512, 1); - tk::dnn::Network net(dim); - - // create yolo3 model - std::string bin_path = "yolo3_512"; - downloadWeightsifDoNotExist("yolo3_512/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/RGecMeGLD4cXEWL/download"); - int classes = 80; - tk::dnn::Yolo *yolo [3]; - #include "models/Yolo3.h" - - - - // fill classes names - for(int i=0; i<3; i++) { - yolo[i]->classesNames = {"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"}; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_512")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for(int i=0; i<3; i++) out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - for(int i=0; i<3; i++) cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for(int i=0; i<3; i++) yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for(int j=0; j 0) - cl = c; - } - std::cout< -#include -#include "tkdnn.h" - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 512, 512, 1); - tk::dnn::Network net(dim); - - // create yolo3 model - std::string bin_path = "yolo3_512tp"; - // downloadWeightsifDoNotExist("yolo3_512tp/layers/input.bin", bin_path, ); - int classes = 3; - tk::dnn::Yolo *yolo [3]; - #include "models/Yolo3.h" - - // fill classes names - for(int i=0; i<3; i++) { - yolo[i]->classesNames = {"Dent", "Wrinkle", "UnsealedFlaps"}; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_512tp")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for(int i=0; i<3; i++) out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - for(int i=0; i<3; i++) cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for(int i=0; i<3; i++) yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for(int j=0; j 0) - cl = c; - } - std::cout< -#include -#include "tkdnn.h" - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 320, 544, 1); - tk::dnn::Network net(dim); - - // create yolo3 model - std::string bin_path = "yolo3_berkeley"; - downloadWeightsifDoNotExist("yolo3_berkeley/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/o5cHa4AjTKS64oD/download"); - int classes = 10; - tk::dnn::Yolo *yolo [3]; - #include "models/Yolo3.h" - - - - // fill classes names - for(int i=0; i<3; i++) { - yolo[i]->classesNames = {"person", "car", "truck", "bus", "motor", "bike", "rider", "traffic light", "traffic sign", "train"}; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_berkeley")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for(int i=0; i<3; i++) out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - for(int i=0; i<3; i++) cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for(int i=0; i<3; i++) yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for(int j=0; j 0) - cl = c; - } - std::cout< -#include -#include "tkdnn.h" - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); - tk::dnn::Network net(dim); - - // create yolo3 model - std::string bin_path = "yolo3_coco4"; - downloadWeightsifDoNotExist("yolo3_coco4/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/o27NDzSAartbyc4/download"); - int classes = 4; - tk::dnn::Yolo *yolo [3]; - #include "models/Yolo3.h" - - // fill classes names - for(int i=0; i<3; i++) { - yolo[i]->classesNames = {"person" , "bicycle" , "car" , "motorbike" }; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_coco4")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for(int i=0; i<3; i++) out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - for(int i=0; i<3; i++) cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for(int i=0; i<3; i++) yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for(int j=0; j 0) - cl = c; - } - std::cout< -#include -#include "tkdnn.h" - - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 1, 320, 544, 1); - tk::dnn::Network net(dim); - - // create yolo3 model - std::string bin_path = "yolo3_flir"; - downloadWeightsifDoNotExist("yolo3_flir/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/62DECncmF6bMMiH/download"); - - int classes = 3; - tk::dnn::Yolo *yolo [3]; - #include "models/Yolo3.h" - - // fill classes names - for(int i=0; i<3; i++) { - yolo[i]->classesNames = {"person", "bike", "car"}; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_flir")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for(int i=0; i<3; i++) out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - for(int i=0; i<3; i++) cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for(int i=0; i<3; i++) yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for(int j=0; j 0) - cl = c; - } - std::cout< -// #include -#include "tkdnn.h" - -const char *input_bin = "yolo3_tiny/layers/input.bin"; -const char *c0_bin = "yolo3_tiny/layers/c0.bin"; -const char *c2_bin = "yolo3_tiny/layers/c2.bin"; -const char *c4_bin = "yolo3_tiny/layers/c4.bin"; -const char *c6_bin = "yolo3_tiny/layers/c6.bin"; -const char *c8_bin = "yolo3_tiny/layers/c8.bin"; -const char *c10_bin = "yolo3_tiny/layers/c10.bin"; -const char *c12_bin = "yolo3_tiny/layers/c12.bin"; -const char *c13_bin = "yolo3_tiny/layers/c13.bin"; -const char *c14_bin = "yolo3_tiny/layers/c14.bin"; -const char *c15_bin = "yolo3_tiny/layers/c15.bin"; -const char *c18_bin = "yolo3_tiny/layers/c18.bin"; -const char *c21_bin = "yolo3_tiny/layers/c21.bin"; -const char *c22_bin = "yolo3_tiny/layers/c22.bin"; -const char *g16_bin = "yolo3_tiny/layers/g16.bin"; -const char *g23_bin = "yolo3_tiny/layers/g23.bin"; -// const char *output_bin = "yolo3_tiny/layers/output.bin"; - -const char *output_bin = "yolo3_tiny/debug/layer23_out.bin"; - -int main() { - - downloadWeightsifDoNotExist(input_bin, "yolo3_tiny", "https://cloud.hipert.unimore.it/s/LMcSHtWaLeps8yN/download"); - - int classes = 80; - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); - tk::dnn::Network net(dim); - - - tk::dnn::Conv2d c0 (&net, 16, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 32, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 64, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p5 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p7(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8(&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p9(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c10(&net, 512, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p11(&net, 2, 2, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - - tk::dnn::Conv2d c12(&net, 1024, 3, 3, 1, 1, 1, 1, c12_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c14_bin, true); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 255, 1, 1, 1, 1, 0, 0, c15_bin, false); - - tk::dnn::Yolo yolo0 (&net, classes, 2, g16_bin); - - tk::dnn::Layer *m17_layers[1] = { &a13 }; - tk::dnn::Route m17 (&net, m17_layers, 1); - tk::dnn::Conv2d c18(&net, 128, 1, 1, 1, 1, 0, 0, c18_bin, true); - tk::dnn::Activation a18(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u19 (&net, 2); - - tk::dnn::Layer *m20_layers[2] = { &u19, &a8 }; - tk::dnn::Route m20 (&net, m20_layers, 2); - - tk::dnn::Conv2d c21(&net, 256, 3, 3, 1, 1, 1, 1, c21_bin, true); - tk::dnn::Activation a21(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c22(&net, 255, 1, 1, 1, 1, 0, 0, c22_bin, false); - - tk::dnn::Yolo yolo1 (&net, classes, 2, g23_bin); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - // convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_tiny")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo3_tiny512/yolo3_tiny512.cpp b/tests/yolo3_tiny512/yolo3_tiny512.cpp deleted file mode 100644 index 38816f9..0000000 --- a/tests/yolo3_tiny512/yolo3_tiny512.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo3_tiny512/layers/input.bin"; -const char *c0_bin = "yolo3_tiny512/layers/c0.bin"; -const char *c2_bin = "yolo3_tiny512/layers/c2.bin"; -const char *c4_bin = "yolo3_tiny512/layers/c4.bin"; -const char *c6_bin = "yolo3_tiny512/layers/c6.bin"; -const char *c8_bin = "yolo3_tiny512/layers/c8.bin"; -const char *c10_bin = "yolo3_tiny512/layers/c10.bin"; -const char *c12_bin = "yolo3_tiny512/layers/c12.bin"; -const char *c13_bin = "yolo3_tiny512/layers/c13.bin"; -const char *c14_bin = "yolo3_tiny512/layers/c14.bin"; -const char *c15_bin = "yolo3_tiny512/layers/c15.bin"; -const char *c18_bin = "yolo3_tiny512/layers/c18.bin"; -const char *c21_bin = "yolo3_tiny512/layers/c21.bin"; -const char *c22_bin = "yolo3_tiny512/layers/c22.bin"; -const char *g16_bin = "yolo3_tiny512/layers/g16.bin"; -const char *g23_bin = "yolo3_tiny512/layers/g23.bin"; -// const char *output_bin = "yolo3_tiny512/layers/output.bin"; - -const char *output_bin = "yolo3_tiny512/debug/layer23_out.bin"; - -int main() { - - downloadWeightsifDoNotExist(input_bin, "yolo3_tiny512", "https://cloud.hipert.unimore.it/s/8Zt6bHwHADqP4JC/download"); - - int classes = 80; - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 512, 512, 1); - tk::dnn::Network net(dim); - - - tk::dnn::Conv2d c0 (&net, 16, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 32, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 64, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p5 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p7(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8(&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p9(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c10(&net, 512, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p11(&net, 2, 2, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - - tk::dnn::Conv2d c12(&net, 1024, 3, 3, 1, 1, 1, 1, c12_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c14_bin, true); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 255, 1, 1, 1, 1, 0, 0, c15_bin, false); - - tk::dnn::Yolo yolo0 (&net, classes, 2, g16_bin); - - tk::dnn::Layer *m17_layers[1] = { &a13 }; - tk::dnn::Route m17 (&net, m17_layers, 1); - tk::dnn::Conv2d c18(&net, 128, 1, 1, 1, 1, 0, 0, c18_bin, true); - tk::dnn::Activation a18(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u19 (&net, 2); - - tk::dnn::Layer *m20_layers[2] = { &u19, &a8 }; - tk::dnn::Route m20 (&net, m20_layers, 2); - - tk::dnn::Conv2d c21(&net, 256, 3, 3, 1, 1, 1, 1, c21_bin, true); - tk::dnn::Activation a21(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c22(&net, 255, 1, 1, 1, 1, 0, 0, c22_bin, false); - - tk::dnn::Yolo yolo1 (&net, classes, 2, g23_bin); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - // convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_tiny512")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo3_tiny512tp/yolo3_tiny512tp.cpp b/tests/yolo3_tiny512tp/yolo3_tiny512tp.cpp deleted file mode 100644 index 13a8b00..0000000 --- a/tests/yolo3_tiny512tp/yolo3_tiny512tp.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo3_tiny512tp/layers/input.bin"; -const char *c0_bin = "yolo3_tiny512tp/layers/c0.bin"; -const char *c2_bin = "yolo3_tiny512tp/layers/c2.bin"; -const char *c4_bin = "yolo3_tiny512tp/layers/c4.bin"; -const char *c6_bin = "yolo3_tiny512tp/layers/c6.bin"; -const char *c8_bin = "yolo3_tiny512tp/layers/c8.bin"; -const char *c10_bin = "yolo3_tiny512tp/layers/c10.bin"; -const char *c12_bin = "yolo3_tiny512tp/layers/c12.bin"; -const char *c13_bin = "yolo3_tiny512tp/layers/c13.bin"; -const char *c14_bin = "yolo3_tiny512tp/layers/c14.bin"; -const char *c15_bin = "yolo3_tiny512tp/layers/c15.bin"; -const char *c18_bin = "yolo3_tiny512tp/layers/c18.bin"; -const char *c21_bin = "yolo3_tiny512tp/layers/c21.bin"; -const char *c22_bin = "yolo3_tiny512tp/layers/c22.bin"; -const char *g16_bin = "yolo3_tiny512tp/layers/g16.bin"; -const char *g23_bin = "yolo3_tiny512tp/layers/g23.bin"; -// const char *output_bin = "yolo3_tiny512tp/layers/output.bin"; - -const char *output_bin = "yolo3_tiny512tp/debug/layer23_out.bin"; - -int main() { - - int classes = 3; - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 512, 512, 1); - tk::dnn::Network net(dim); - - - tk::dnn::Conv2d c0 (&net, 16, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 32, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 64, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p5 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p7(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8(&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p9(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c10(&net, 512, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p11(&net, 2, 2, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - - tk::dnn::Conv2d c12(&net, 1024, 3, 3, 1, 1, 1, 1, c12_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c14_bin, true); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 24, 1, 1, 1, 1, 0, 0, c15_bin, false); - - tk::dnn::Yolo yolo0 (&net, classes, 2, g16_bin); - - tk::dnn::Layer *m17_layers[1] = { &a13 }; - tk::dnn::Route m17 (&net, m17_layers, 1); - tk::dnn::Conv2d c18(&net, 128, 1, 1, 1, 1, 0, 0, c18_bin, true); - tk::dnn::Activation a18(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u19 (&net, 2); - - tk::dnn::Layer *m20_layers[2] = { &u19, &a8 }; - tk::dnn::Route m20 (&net, m20_layers, 2); - - tk::dnn::Conv2d c21(&net, 256, 3, 3, 1, 1, 1, 1, c21_bin, true); - tk::dnn::Activation a21(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c22(&net, 24, 1, 1, 1, 1, 0, 0, c22_bin, false); - - tk::dnn::Yolo yolo1 (&net, classes, 2, g23_bin); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - // convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_tiny512tp")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo3_tinyNM512/yolo3_tinyNM512.cpp b/tests/yolo3_tinyNM512/yolo3_tinyNM512.cpp deleted file mode 100644 index 7ffd603..0000000 --- a/tests/yolo3_tinyNM512/yolo3_tinyNM512.cpp +++ /dev/null @@ -1,127 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo3_tinyNM512/layers/input.bin"; -const char *c0_bin = "yolo3_tinyNM512/layers/c0.bin"; -const char *c2_bin = "yolo3_tinyNM512/layers/c2.bin"; -const char *c4_bin = "yolo3_tinyNM512/layers/c4.bin"; -const char *c6_bin = "yolo3_tinyNM512/layers/c6.bin"; -const char *c8_bin = "yolo3_tinyNM512/layers/c8.bin"; -const char *c10_bin = "yolo3_tinyNM512/layers/c10.bin"; -const char *c11_bin = "yolo3_tinyNM512/layers/c11.bin"; -const char *c12_bin = "yolo3_tinyNM512/layers/c12.bin"; -const char *c13_bin = "yolo3_tinyNM512/layers/c13.bin"; -const char *c14_bin = "yolo3_tinyNM512/layers/c14.bin"; -const char *c17_bin = "yolo3_tinyNM512/layers/c17.bin"; -const char *c20_bin = "yolo3_tinyNM512/layers/c20.bin"; -const char *c21_bin = "yolo3_tinyNM512/layers/c21.bin"; -const char *g15_bin = "yolo3_tinyNM512/layers/g15.bin"; -const char *g22_bin = "yolo3_tinyNM512/layers/g22.bin"; -// const char *output_bin = "yolo3_tinyNM512/layers/output.bin"; - -const char *output_bin = "yolo3_tinyNM512/debug/layer22_out.bin"; - -int main() { - - // downloadWeightsifDoNotExist(input_bin, "yolo3_tinyNM512", "https://cloud.hipert.unimore.it/s/wRW9nmkibSe5HoS/download"); - - int classes = 80; - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 512, 512, 1); - tk::dnn::Network net(dim); - - - tk::dnn::Conv2d c0 (&net, 16, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 32, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 64, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p5 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p7(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8(&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p9(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c10(&net, 512, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c12(&net, 1024, 3, 3, 1, 1, 1, 1, c11_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c12_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c13_bin, true); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 255, 1, 1, 1, 1, 0, 0, c14_bin, false); - - tk::dnn::Yolo yolo0 (&net, classes, 2, g15_bin); - - tk::dnn::Layer *m17_layers[1] = { &a13 }; - tk::dnn::Route m17 (&net, m17_layers, 1); - tk::dnn::Conv2d c18(&net, 128, 1, 1, 1, 1, 0, 0, c17_bin, true); - tk::dnn::Activation a18(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u19 (&net, 2); - - tk::dnn::Layer *m20_layers[2] = { &u19, &a8 }; - tk::dnn::Route m20 (&net, m20_layers, 2); - - tk::dnn::Conv2d c21(&net, 256, 3, 3, 1, 1, 1, 1, c20_bin, true); - tk::dnn::Activation a21(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c22(&net, 255, 1, 1, 1, 1, 0, 0, c21_bin, false); - - tk::dnn::Yolo yolo1 (&net, classes, 2, g22_bin); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - // convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo3_tinyNM512")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo4/yolo4.cpp b/tests/yolo4/yolo4.cpp deleted file mode 100644 index 72ba205..0000000 --- a/tests/yolo4/yolo4.cpp +++ /dev/null @@ -1,666 +0,0 @@ -#include -#include -#include "tkdnn.h" - -int main() -{ - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); - tk::dnn::Network net(dim); - - // create yolo4 model - std::string bin_path = "yolo4"; - int classes = 80; - tk::dnn::Yolo *yolo[3]; - - std::string input_bin = bin_path + "/layers/input.bin"; - - std::vector output_bins = { - bin_path + "/debug/layer139_out.bin", - bin_path + "/debug/layer150_out.bin", - bin_path + "/debug/layer161_out.bin"}; - std::string c0_bin = bin_path + "/layers/c0.bin"; - std::string c1_bin = bin_path + "/layers/c1.bin"; - std::string c2_bin = bin_path + "/layers/c2.bin"; - std::string c3_bin = bin_path + "/layers/c3.bin"; - std::string c4_bin = bin_path + "/layers/c4.bin"; - std::string c5_bin = bin_path + "/layers/c5.bin"; - std::string c6_bin = bin_path + "/layers/c6.bin"; - std::string c7_bin = bin_path + "/layers/c7.bin"; - std::string c8_bin = bin_path + "/layers/c8.bin"; - std::string c10_bin = bin_path + "/layers/c10.bin"; - std::string c11_bin = bin_path + "/layers/c11.bin"; - std::string c12_bin = bin_path + "/layers/c12.bin"; - std::string c13_bin = bin_path + "/layers/c13.bin"; - std::string c14_bin = bin_path + "/layers/c14.bin"; - std::string c15_bin = bin_path + "/layers/c15.bin"; - std::string c16_bin = bin_path + "/layers/c16.bin"; - std::string c17_bin = bin_path + "/layers/c17.bin"; - std::string c18_bin = bin_path + "/layers/c18.bin"; - std::string c19_bin = bin_path + "/layers/c19.bin"; - std::string c20_bin = bin_path + "/layers/c20.bin"; - std::string c21_bin = bin_path + "/layers/c21.bin"; - std::string c23_bin = bin_path + "/layers/c23.bin"; - std::string c24_bin = bin_path + "/layers/c24.bin"; - std::string c25_bin = bin_path + "/layers/c25.bin"; - std::string c26_bin = bin_path + "/layers/c26.bin"; - std::string c27_bin = bin_path + "/layers/c27.bin"; - std::string c28_bin = bin_path + "/layers/c28.bin"; - std::string c29_bin = bin_path + "/layers/c29.bin"; - std::string c30_bin = bin_path + "/layers/c30.bin"; - std::string c31_bin = bin_path + "/layers/c31.bin"; - std::string c32_bin = bin_path + "/layers/c32.bin"; - std::string c33_bin = bin_path + "/layers/c33.bin"; - std::string c34_bin = bin_path + "/layers/c34.bin"; - std::string c35_bin = bin_path + "/layers/c35.bin"; - std::string c36_bin = bin_path + "/layers/c36.bin"; - std::string c37_bin = bin_path + "/layers/c37.bin"; - std::string c38_bin = bin_path + "/layers/c38.bin"; - std::string c39_bin = bin_path + "/layers/c39.bin"; - std::string c40_bin = bin_path + "/layers/c40.bin"; - std::string c41_bin = bin_path + "/layers/c41.bin"; - std::string c42_bin = bin_path + "/layers/c42.bin"; - std::string c43_bin = bin_path + "/layers/c43.bin"; - std::string c44_bin = bin_path + "/layers/c44.bin"; - std::string c45_bin = bin_path + "/layers/c45.bin"; - std::string c46_bin = bin_path + "/layers/c46.bin"; - std::string c47_bin = bin_path + "/layers/c47.bin"; - std::string c48_bin = bin_path + "/layers/c48.bin"; - std::string c49_bin = bin_path + "/layers/c49.bin"; - std::string c50_bin = bin_path + "/layers/c50.bin"; - std::string c51_bin = bin_path + "/layers/c51.bin"; - std::string c52_bin = bin_path + "/layers/c52.bin"; - std::string c53_bin = bin_path + "/layers/c53.bin"; - std::string c54_bin = bin_path + "/layers/c54.bin"; - std::string c55_bin = bin_path + "/layers/c55.bin"; - std::string c56_bin = bin_path + "/layers/c56.bin"; - std::string c57_bin = bin_path + "/layers/c57.bin"; - std::string c58_bin = bin_path + "/layers/c58.bin"; - std::string c59_bin = bin_path + "/layers/c59.bin"; - std::string c60_bin = bin_path + "/layers/c60.bin"; - std::string c61_bin = bin_path + "/layers/c61.bin"; - std::string c62_bin = bin_path + "/layers/c62.bin"; - std::string c63_bin = bin_path + "/layers/c63.bin"; - std::string c65_bin = bin_path + "/layers/c65.bin"; - std::string c66_bin = bin_path + "/layers/c66.bin"; - std::string c67_bin = bin_path + "/layers/c67.bin"; - std::string c68_bin = bin_path + "/layers/c68.bin"; - std::string c69_bin = bin_path + "/layers/c69.bin"; - std::string c70_bin = bin_path + "/layers/c70.bin"; - std::string c71_bin = bin_path + "/layers/c71.bin"; - std::string c72_bin = bin_path + "/layers/c72.bin"; - std::string c74_bin = bin_path + "/layers/c74.bin"; - std::string c75_bin = bin_path + "/layers/c75.bin"; - std::string c76_bin = bin_path + "/layers/c76.bin"; - std::string c77_bin = bin_path + "/layers/c77.bin"; - std::string c78_bin = bin_path + "/layers/c78.bin"; - std::string c80_bin = bin_path + "/layers/c80.bin"; - std::string c81_bin = bin_path + "/layers/c81.bin"; - std::string c82_bin = bin_path + "/layers/c82.bin"; - std::string c83_bin = bin_path + "/layers/c83.bin"; - std::string c85_bin = bin_path + "/layers/c85.bin"; - std::string c86_bin = bin_path + "/layers/c86.bin"; - std::string c87_bin = bin_path + "/layers/c87.bin"; - std::string c89_bin = bin_path + "/layers/c89.bin"; - std::string c90_bin = bin_path + "/layers/c90.bin"; - std::string c91_bin = bin_path + "/layers/c91.bin"; - std::string c92_bin = bin_path + "/layers/c92.bin"; - std::string c93_bin = bin_path + "/layers/c93.bin"; - std::string c94_bin = bin_path + "/layers/c94.bin"; - std::string c96_bin = bin_path + "/layers/c96.bin"; - std::string c97_bin = bin_path + "/layers/c97.bin"; - std::string c98_bin = bin_path + "/layers/c98.bin"; - std::string c99_bin = bin_path + "/layers/c99.bin"; - std::string c100_bin = bin_path + "/layers/c100.bin"; - std::string c101_bin = bin_path + "/layers/c101.bin"; - std::string c102_bin = bin_path + "/layers/c102.bin"; - std::string c103_bin = bin_path + "/layers/c103.bin"; - std::string c104_bin = bin_path + "/layers/c104.bin"; - std::string c105_bin = bin_path + "/layers/c105.bin"; - std::string c106_bin = bin_path + "/layers/c106.bin"; - std::string c107_bin = bin_path + "/layers/c107.bin"; - std::string c108_bin = bin_path + "/layers/c108.bin"; - std::string c109_bin = bin_path + "/layers/c109.bin"; - std::string c110_bin = bin_path + "/layers/c110.bin"; - std::string c111_bin = bin_path + "/layers/c111.bin"; - std::string c112_bin = bin_path + "/layers/c112.bin"; - std::string c113_bin = bin_path + "/layers/c113.bin"; - std::string c114_bin = bin_path + "/layers/c114.bin"; - std::string c115_bin = bin_path + "/layers/c115.bin"; - std::string c116_bin = bin_path + "/layers/c116.bin"; - std::string c117_bin = bin_path + "/layers/c117.bin"; - std::string c119_bin = bin_path + "/layers/c119.bin"; - std::string c120_bin = bin_path + "/layers/c120.bin"; - std::string c121_bin = bin_path + "/layers/c121.bin"; - std::string c122_bin = bin_path + "/layers/c122.bin"; - std::string c123_bin = bin_path + "/layers/c123.bin"; - std::string c124_bin = bin_path + "/layers/c124.bin"; - std::string c125_bin = bin_path + "/layers/c125.bin"; - std::string c126_bin = bin_path + "/layers/c126.bin"; - std::string c127_bin = bin_path + "/layers/c127.bin"; - std::string c128_bin = bin_path + "/layers/c128.bin"; - std::string c130_bin = bin_path + "/layers/c130.bin"; - std::string c131_bin = bin_path + "/layers/c131.bin"; - std::string c132_bin = bin_path + "/layers/c132.bin"; - std::string c133_bin = bin_path + "/layers/c133.bin"; - std::string c134_bin = bin_path + "/layers/c134.bin"; - std::string c135_bin = bin_path + "/layers/c135.bin"; - std::string c136_bin = bin_path + "/layers/c136.bin"; - std::string c137_bin = bin_path + "/layers/c137.bin"; - std::string c138_bin = bin_path + "/layers/c138.bin"; - std::string c141_bin = bin_path + "/layers/c141.bin"; - std::string c142_bin = bin_path + "/layers/c142.bin"; - std::string c143_bin = bin_path + "/layers/c143.bin"; - std::string c144_bin = bin_path + "/layers/c144.bin"; - std::string c145_bin = bin_path + "/layers/c145.bin"; - std::string c146_bin = bin_path + "/layers/c146.bin"; - std::string c147_bin = bin_path + "/layers/c147.bin"; - std::string c148_bin = bin_path + "/layers/c148.bin"; - std::string c149_bin = bin_path + "/layers/c149.bin"; - std::string c150_bin = bin_path + "/layers/c150.bin"; - std::string c151_bin = bin_path + "/layers/c151.bin"; - std::string c152_bin = bin_path + "/layers/c152.bin"; - std::string c153_bin = bin_path + "/layers/c153.bin"; - std::string c154_bin = bin_path + "/layers/c154.bin"; - std::string c155_bin = bin_path + "/layers/c155.bin"; - std::string c156_bin = bin_path + "/layers/c156.bin"; - std::string c157_bin = bin_path + "/layers/c157.bin"; - std::string c158_bin = bin_path + "/layers/c158.bin"; - std::string c159_bin = bin_path + "/layers/c159.bin"; - std::string c160_bin = bin_path + "/layers/c160.bin"; - std::string g139_bin = bin_path + "/layers/g139.bin"; - std::string g150_bin = bin_path + "/layers/g150.bin"; - std::string g161_bin = bin_path + "/layers/g161.bin"; - - - downloadWeightsifDoNotExist(input_bin, bin_path, "https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download"); - - tk::dnn::Conv2d c0(&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0(&net, tk::dnn::ACTIVATION_MISH); - - // downsample - tk::dnn::Conv2d c1(&net, 64, 3, 3, 2, 2, 1, 1, c1_bin, true); - tk::dnn::Activation a1(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c2(&net, 64, 1, 1, 1, 1, 0, 0, c2_bin, true); - tk::dnn::Activation a2(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r3_layers[1] = {&a1}; - tk::dnn::Route r3(&net, r3_layers, 1); - - tk::dnn::Conv2d c4(&net, 64, 1, 1, 1, 1, 0, 0, c4_bin, true); - tk::dnn::Activation a4(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c5(&net, 32, 1, 1, 1, 1, 0, 0, c5_bin, true); - tk::dnn::Activation a5(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c6(&net, 64, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s7(&net, &a4); - - tk::dnn::Conv2d c8(&net, 64, 1, 1, 1, 1, 0, 0, c8_bin, true); - tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r9_layers[2] = {&a8, &a2}; - tk::dnn::Route r9(&net, r9_layers, 2); - - tk::dnn::Conv2d c10(&net, 64, 1, 1, 1, 1, 0, 0, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_MISH); - - // downsample - tk::dnn::Conv2d c11(&net, 128, 3, 3, 2, 2, 1, 1, c11_bin, true); - tk::dnn::Activation a11(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c12(&net, 64, 1, 1, 1, 1, 0, 0, c12_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r13_layers[1] = {&a11}; - tk::dnn::Route r13(&net, r13_layers, 1); - - tk::dnn::Conv2d c14(&net, 64, 1, 1, 1, 1, 0, 0, c14_bin, true); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c15(&net, 64, 1, 1, 1, 1, 0, 0, c15_bin, true); - tk::dnn::Activation a15(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c16(&net, 64, 3, 3, 1, 1, 1, 1, c16_bin, true); - tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s17(&net, &a14); - - tk::dnn::Conv2d c18(&net, 64, 1, 1, 1, 1, 0, 0, c18_bin, true); - tk::dnn::Activation a18(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c19(&net, 64, 3, 3, 1, 1, 1, 1, c19_bin, true); - tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s20(&net, &s17); - - tk::dnn::Conv2d c21(&net, 64, 1, 1, 1, 1, 0, 0, c21_bin, true); - tk::dnn::Activation a21(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r22_layers[2] = {&a21, &a12}; - tk::dnn::Route r22(&net, r22_layers, 2); - - tk::dnn::Conv2d c23(&net, 128, 1, 1, 1, 1, 0, 0, c23_bin, true); - tk::dnn::Activation a23(&net, tk::dnn::ACTIVATION_MISH); - - //downsample - tk::dnn::Conv2d c24(&net, 256, 3, 3, 2, 2, 1, 1, c24_bin, true); - tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c25(&net, 128, 1, 1, 1, 1, 0, 0, c25_bin, true); - tk::dnn::Activation a25(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r26_layers[1] = {&a24}; - tk::dnn::Route r26(&net, r26_layers, 1); - - tk::dnn::Conv2d c27(&net, 128, 1, 1, 1, 1, 0, 0, c27_bin, true); - tk::dnn::Activation a27(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c28(&net, 128, 1, 1, 1, 1, 0, 0, c28_bin, true); - tk::dnn::Activation a28(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c29(&net, 128, 3, 3, 1, 1, 1, 1, c29_bin, true); - tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s30(&net, &a27); - - tk::dnn::Conv2d c31(&net, 128, 1, 1, 1, 1, 0, 0, c31_bin, true); - tk::dnn::Activation a31(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c32(&net, 128, 3, 3, 1, 1, 1, 1, c32_bin, true); - tk::dnn::Activation a32(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s33(&net, &s30); - - tk::dnn::Conv2d c34(&net, 128, 1, 1, 1, 1, 0, 0, c34_bin, true); - tk::dnn::Activation a34(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c35(&net, 128, 3, 3, 1, 1, 1, 1, c35_bin, true); - tk::dnn::Activation a35(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s36(&net, &s33); - - tk::dnn::Conv2d c37(&net, 128, 1, 1, 1, 1, 0, 0, c37_bin, true); - tk::dnn::Activation a37(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c38(&net, 128, 3, 3, 1, 1, 1, 1, c38_bin, true); - tk::dnn::Activation a38(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s39(&net, &s36); - - tk::dnn::Conv2d c40(&net, 128, 1, 1, 1, 1, 0, 0, c40_bin, true); - tk::dnn::Activation a40(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c41(&net, 128, 3, 3, 1, 1, 1, 1, c41_bin, true); - tk::dnn::Activation a41(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s42(&net, &s39); - - tk::dnn::Conv2d c43(&net, 128, 1, 1, 1, 1, 0, 0, c43_bin, true); - tk::dnn::Activation a43(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c44(&net, 128, 3, 3, 1, 1, 1, 1, c44_bin, true); - tk::dnn::Activation a44(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s45(&net, &s42); - - tk::dnn::Conv2d c46(&net, 128, 1, 1, 1, 1, 0, 0, c46_bin, true); - tk::dnn::Activation a46(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c47(&net, 128, 3, 3, 1, 1, 1, 1, c47_bin, true); - tk::dnn::Activation a47(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s48(&net, &s45); - - tk::dnn::Conv2d c49(&net, 128, 1, 1, 1, 1, 0, 0, c49_bin, true); - tk::dnn::Activation a49(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c50(&net, 128, 3, 3, 1, 1, 1, 1, c50_bin, true); - tk::dnn::Activation a50(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s51(&net, &s48); - - tk::dnn::Conv2d c52(&net, 128, 1, 1, 1, 1, 0, 0, c52_bin, true); - tk::dnn::Activation a52(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r53_layers[2] = {&a52, &a25}; - tk::dnn::Route r53(&net, r53_layers, 2); - - tk::dnn::Conv2d c54(&net, 256, 1, 1, 1, 1, 0, 0, c54_bin, true); - tk::dnn::Activation a54(&net, tk::dnn::ACTIVATION_MISH); - - //downsample - tk::dnn::Conv2d c55(&net, 512, 3, 3, 2, 2, 1, 1, c55_bin, true); - tk::dnn::Activation a55(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c56(&net, 256, 1, 1, 1, 1, 0, 0, c56_bin, true); - tk::dnn::Activation a56(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r57_layers[1] = {&a55}; - tk::dnn::Route r57(&net, r57_layers, 1); - - tk::dnn::Conv2d c58(&net, 256, 1, 1, 1, 1, 0, 0, c58_bin, true); - tk::dnn::Activation a58(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c59(&net, 256, 1, 1, 1, 1, 0, 0, c59_bin, true); - tk::dnn::Activation a59(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c60(&net, 256, 3, 3, 1, 1, 1, 1, c60_bin, true); - tk::dnn::Activation a60(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s61(&net, &a58); - - tk::dnn::Conv2d c62(&net, 256, 1, 1, 1, 1, 0, 0, c62_bin, true); - tk::dnn::Activation a62(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c63(&net, 256, 3, 3, 1, 1, 1, 1, c63_bin, true); - tk::dnn::Activation a63(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s64(&net, &s61); - - tk::dnn::Conv2d c65(&net, 256, 1, 1, 1, 1, 0, 0, c65_bin, true); - tk::dnn::Activation a65(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c66(&net, 256, 3, 3, 1, 1, 1, 1, c66_bin, true); - tk::dnn::Activation a66(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s67(&net, &s64); - - tk::dnn::Conv2d c68(&net, 256, 1, 1, 1, 1, 0, 0, c68_bin, true); - tk::dnn::Activation a68(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c69(&net, 256, 3, 3, 1, 1, 1, 1, c69_bin, true); - tk::dnn::Activation a69(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s70(&net, &s67); - - tk::dnn::Conv2d c71(&net, 256, 1, 1, 1, 1, 0, 0, c71_bin, true); - tk::dnn::Activation a71(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c72(&net, 256, 3, 3, 1, 1, 1, 1, c72_bin, true); - tk::dnn::Activation a72(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s73(&net, &s70); - - tk::dnn::Conv2d c74(&net, 256, 1, 1, 1, 1, 0, 0, c74_bin, true); - tk::dnn::Activation a74(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c75(&net, 256, 3, 3, 1, 1, 1, 1, c75_bin, true); - tk::dnn::Activation a75(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s76(&net, &s73); - - tk::dnn::Conv2d c77(&net, 256, 1, 1, 1, 1, 0, 0, c77_bin, true); - tk::dnn::Activation a77(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c78(&net, 256, 3, 3, 1, 1, 1, 1, c78_bin, true); - tk::dnn::Activation a78(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s79(&net, &s76); - - tk::dnn::Conv2d c80(&net, 256, 1, 1, 1, 1, 0, 0, c80_bin, true); - tk::dnn::Activation a80(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c81(&net, 256, 3, 3, 1, 1, 1, 1, c81_bin, true); - tk::dnn::Activation a81(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s82(&net, &s79); - - tk::dnn::Conv2d c83(&net, 256, 1, 1, 1, 1, 0, 0, c83_bin, true); - tk::dnn::Activation a83(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r84_layers[2] = {&a83, &a56}; - tk::dnn::Route r84(&net, r84_layers, 2); - - tk::dnn::Conv2d c85(&net, 512, 1, 1, 1, 1, 0, 0, c85_bin, true); - tk::dnn::Activation a85(&net, tk::dnn::ACTIVATION_MISH); - - //downsample - tk::dnn::Conv2d c86(&net, 1024, 3, 3, 2, 2, 1, 1, c86_bin, true); - tk::dnn::Activation a86(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c87(&net, 512, 1, 1, 1, 1, 0, 0, c87_bin, true); - tk::dnn::Activation a87(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r88_layers[1] = {&a86}; - tk::dnn::Route r88(&net, r88_layers, 1); - - tk::dnn::Conv2d c89(&net, 512, 1, 1, 1, 1, 0, 0, c89_bin, true); - tk::dnn::Activation a89(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c90(&net, 512, 1, 1, 1, 1, 0, 0, c90_bin, true); - tk::dnn::Activation a90(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c91(&net, 512, 3, 3, 1, 1, 1, 1, c91_bin, true); - tk::dnn::Activation a91(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s92(&net, &a89); - - tk::dnn::Conv2d c93(&net, 512, 1, 1, 1, 1, 0, 0, c93_bin, true); - tk::dnn::Activation a93(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c94(&net, 512, 3, 3, 1, 1, 1, 1, c94_bin, true); - tk::dnn::Activation a94(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s95(&net, &s92); - - tk::dnn::Conv2d c96(&net, 512, 1, 1, 1, 1, 0, 0, c96_bin, true); - tk::dnn::Activation a96(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c97(&net, 512, 3, 3, 1, 1, 1, 1, c97_bin, true); - tk::dnn::Activation a97(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s98(&net, &s95); - - tk::dnn::Conv2d c99(&net, 512, 1, 1, 1, 1, 0, 0, c99_bin, true); - tk::dnn::Activation a99(&net, tk::dnn::ACTIVATION_MISH); - tk::dnn::Conv2d c100(&net, 512, 3, 3, 1, 1, 1, 1, c100_bin, true); - tk::dnn::Activation a100(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Shortcut s101(&net, &s98); - - tk::dnn::Conv2d c102(&net, 512, 1, 1, 1, 1, 0, 0, c102_bin, true); - tk::dnn::Activation a102(&net, tk::dnn::ACTIVATION_MISH); - - tk::dnn::Layer *r103_layers[2] = {&a102, &a87}; - tk::dnn::Route r103(&net, r103_layers, 2); - - tk::dnn::Conv2d c104(&net, 1024, 1, 1, 1, 1, 0, 0, c104_bin, true); - tk::dnn::Activation a104(&net, tk::dnn::ACTIVATION_MISH); - - - //################ - tk::dnn::Conv2d c105(&net, 512, 1, 1, 1, 1, 0, 0, c105_bin, true); - tk::dnn::Activation a105(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c106(&net, 1024, 3, 3, 1, 1, 1, 1, c106_bin, true); - tk::dnn::Activation a106(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c107(&net, 512, 1, 1, 1, 1, 0, 0, c107_bin, true); - tk::dnn::Activation a107(&net, tk::dnn::ACTIVATION_LEAKY); - - //SPP - tk::dnn::Pooling p108(&net, 5, 5, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r109_layers[1] = {&a107}; - tk::dnn::Route r109(&net, r109_layers, 1); - - tk::dnn::Pooling p110(&net, 9, 9, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r111_layers[1] = {&a107}; - tk::dnn::Route r111(&net, r111_layers, 1); - - tk::dnn::Pooling p112(&net, 13, 13, 1, 1, 12, 12, tk::dnn::POOLING_MAX_FIXEDSIZE); - tk::dnn::Layer *r113_layers[4] = {&p112, &p110, &p108, &a107}; - tk::dnn::Route r113(&net, r113_layers, 4); - //END SPP - - tk::dnn::Conv2d c114(&net, 512, 1, 1, 1, 1, 0, 0, c114_bin, true); - tk::dnn::Activation a114(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c115(&net, 1024, 3, 3, 1, 1, 1, 1, c115_bin, true); - tk::dnn::Activation a115(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c116(&net, 512, 1, 1, 1, 1, 0, 0, c116_bin, true); - tk::dnn::Activation a116(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c117(&net, 256, 1, 1, 1, 1, 0, 0, c117_bin, true); - tk::dnn::Activation a117(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u118(&net, 2); - tk::dnn::Layer *r119_layers[1] = {&a85}; - tk::dnn::Route r119(&net, r119_layers, 1); - tk::dnn::Conv2d c120(&net, 256, 1, 1, 1, 1, 0, 0, c120_bin, true); - tk::dnn::Activation a120(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r121_layers[2] = {&a120,&u118}; - tk::dnn::Route r121(&net, r121_layers, 2); - - tk::dnn::Conv2d c122(&net, 256, 1, 1, 1, 1, 0, 0, c122_bin, true); - tk::dnn::Activation a122(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c123(&net, 512, 3, 3, 1, 1, 1, 1, c123_bin, true); - tk::dnn::Activation a123(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c124(&net, 256, 1, 1, 1, 1, 0, 0, c124_bin, true); - tk::dnn::Activation a124(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c125(&net, 512, 3, 3, 1, 1, 1, 1, c125_bin, true); - tk::dnn::Activation a125(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c126(&net, 256, 1, 1, 1, 1, 0, 0, c126_bin, true); - tk::dnn::Activation a126(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c127(&net, 128, 1, 1, 1, 1, 0, 0, c127_bin, true); - tk::dnn::Activation a127(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Upsample u128(&net, 2); - tk::dnn::Layer *r129_layers[1] = {&a54}; - tk::dnn::Route r129(&net, r129_layers, 1); - tk::dnn::Conv2d c130(&net, 128, 1, 1, 1, 1, 0, 0, c130_bin, true); - tk::dnn::Activation a130(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r131_layers[2] = {&a130,&u128}; - tk::dnn::Route r131(&net, r131_layers, 2); - - - tk::dnn::Conv2d c132(&net, 128, 1, 1, 1, 1, 0, 0, c132_bin, true); - tk::dnn::Activation a132(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c133(&net, 256, 3, 3, 1, 1, 1, 1, c133_bin, true); - tk::dnn::Activation a133(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c134(&net, 128, 1, 1, 1, 1, 0, 0, c134_bin, true); - tk::dnn::Activation a134(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c135(&net, 256, 3, 3, 1, 1, 1, 1, c135_bin, true); - tk::dnn::Activation a135(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c136(&net, 128, 1, 1, 1, 1, 0, 0, c136_bin, true); - tk::dnn::Activation a136(&net, tk::dnn::ACTIVATION_LEAKY); - - - tk::dnn::Conv2d c137(&net, 256, 3, 3, 1, 1, 1, 1, c137_bin, true); - tk::dnn::Activation a137(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c138(&net, 255, 1, 1, 1, 1, 0, 0, c138_bin, false); - tk::dnn::Yolo yolo139(&net, classes, 3, g139_bin, 3, 1.2); - - tk::dnn::Layer *r140_layers[1] = {&a136}; - tk::dnn::Route r140(&net, r140_layers, 1); - tk::dnn::Conv2d c141(&net, 256, 3, 3, 2, 2, 1, 1, c141_bin, true); - tk::dnn::Activation a141(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r142_layers[2] = {&a141,&a126}; - tk::dnn::Route r142(&net, r142_layers, 2); - - tk::dnn::Conv2d c143(&net, 256, 1, 1, 1, 1, 0, 0, c143_bin, true); - tk::dnn::Activation a143(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c144(&net, 512, 3, 3, 1, 1, 1, 1, c144_bin, true); - tk::dnn::Activation a144(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c145(&net, 256, 1, 1, 1, 1, 0, 0, c145_bin, true); - tk::dnn::Activation a145(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c146(&net, 512, 3, 3, 1, 1, 1, 1, c146_bin, true); - tk::dnn::Activation a146(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c147(&net, 256, 1, 1, 1, 1, 0, 0, c147_bin, true); - tk::dnn::Activation a147(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c148(&net, 512, 3, 3, 1, 1, 1, 1, c148_bin, true); - tk::dnn::Activation a148(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c149(&net, 255, 1, 1, 1, 1, 0, 0, c149_bin, false); - tk::dnn::Yolo yolo150(&net, classes, 3, g150_bin, 3, 1.1); - - tk::dnn::Layer *r151_layers[1] = {&a147}; - tk::dnn::Route r151(&net, r151_layers, 1); - tk::dnn::Conv2d c152(&net, 512, 3, 3, 2, 2, 1, 1, c152_bin, true); - tk::dnn::Activation a152(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Layer *r153_layers[2] = {&a152,&a116}; - tk::dnn::Route r153(&net, r153_layers, 2); - - tk::dnn::Conv2d c154(&net, 512, 1, 1, 1, 1, 0, 0, c154_bin, true); - tk::dnn::Activation a154(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c155(&net, 1024, 3, 3, 1, 1, 1, 1, c155_bin, true); - tk::dnn::Activation a155(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c156(&net, 512, 1, 1, 1, 1, 0, 0, c156_bin, true); - tk::dnn::Activation a156(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c157(&net, 1024, 3, 3, 1, 1, 1, 1, c157_bin, true); - tk::dnn::Activation a157(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c158(&net, 512, 1, 1, 1, 1, 0, 0, c158_bin, true); - tk::dnn::Activation a158(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c159(&net, 1024, 3, 3, 1, 1, 1, 1, c159_bin, true); - tk::dnn::Activation a159(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c160(&net, 255, 1, 1, 1, 1, 0, 0, c160_bin, false); - tk::dnn::Yolo yolo161(&net, classes, 3, g161_bin, 3, 1.05); - - - - - - - yolo[0] = &yolo139; - yolo[1] = &yolo150; - yolo[2] = &yolo161; - - // fill classes names - for (int i = 0; i < 3; i++) - { - yolo[i]->classesNames = {"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"}; - } - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - // //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo4")); - - // the network have 3 outputs - tk::dnn::dataDim_t out_dim[3]; - for (int i = 0; i < 3; i++) - out_dim[i] = yolo[i]->output_dim; - dnnType *cudnn_out[3], *rt_out[3]; - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); - { - dim1.print(); - TIMER_START - net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - for (int i = 0; i < 3; i++) - cudnn_out[i] = yolo[i]->dstData; - - printCenteredTitle(" compute detections ", '=', 30); - TIMER_START - int ndets = 0; - tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); - for (int i = 0; i < 3; i++) - yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5); - tk::dnn::Yolo::mergeDetections(dets, ndets, classes); - - for (int j = 0; j < ndets; j++) - { - tk::dnn::Yolo::box b = dets[j].bbox; - int x0 = (b.x - b.w / 2.); - int x1 = (b.x + b.w / 2.); - int y0 = (b.y - b.h / 2.); - int y1 = (b.y + b.h / 2.); - - int cl = 0; - for (int c = 0; c < classes; ++c) - { - float prob = dets[j].prob[c]; - if (prob > 0) - cl = c; - } - std::cout << cl << ": " << x0 << " " << y0 << " " << x1 << " " << y1 << "\n"; - } - TIMER_STOP - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); - { - dim2.print(); - TIMER_START - netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - for (int i = 0; i < 3; i++) - rt_out[i] = (dnnType *)netRT.buffersRT[i + 1]; - - int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0; - for (int i = 0; i < 3; i++) - { - printCenteredTitle((std::string(" YOLO ") + std::to_string(i) + " CHECK RESULTS ").c_str(), '=', 30); - dnnType *out, *out_h; - int odim = out_dim[i].tot(); - readBinaryFile(output_bins[i], odim, &out_h, &out); - std::cout<<"CUDNN vs correct"; - ret_cudnn |= checkResult(odim, cudnn_out[i], out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - ret_tensorrt |= checkResult(odim, rt_out[i], out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - } - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo_224/yolo_224.cpp b/tests/yolo_224/yolo_224.cpp deleted file mode 100644 index c6d75ae..0000000 --- a/tests/yolo_224/yolo_224.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo_224/layers/input.bin"; -const char *c0_bin = "yolo_224/layers/c0.bin"; -const char *c2_bin = "yolo_224/layers/c2.bin"; -const char *c4_bin = "yolo_224/layers/c4.bin"; -const char *c5_bin = "yolo_224/layers/c5.bin"; -const char *c6_bin = "yolo_224/layers/c6.bin"; -const char *c8_bin = "yolo_224/layers/c8.bin"; -const char *c9_bin = "yolo_224/layers/c9.bin"; -const char *c10_bin = "yolo_224/layers/c10.bin"; -const char *c12_bin = "yolo_224/layers/c12.bin"; -const char *c13_bin = "yolo_224/layers/c13.bin"; -const char *c14_bin = "yolo_224/layers/c14.bin"; -const char *c15_bin = "yolo_224/layers/c15.bin"; -const char *c16_bin = "yolo_224/layers/c16.bin"; -const char *c18_bin = "yolo_224/layers/c18.bin"; -const char *c19_bin = "yolo_224/layers/c19.bin"; -const char *c20_bin = "yolo_224/layers/c20.bin"; -const char *c21_bin = "yolo_224/layers/c21.bin"; -const char *c22_bin = "yolo_224/layers/c22.bin"; -const char *c23_bin = "yolo_224/layers/c23.bin"; -const char *c24_bin = "yolo_224/layers/c24.bin"; -const char *c26_bin = "yolo_224/layers/c26.bin"; -const char *c29_bin = "yolo_224/layers/c29.bin"; -const char *c30_bin = "yolo_224/layers/c30.bin"; -const char *g31_bin = "yolo_224/layers/g31.bin"; -const char *output_bin = "yolo_224/layers/output.bin"; - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 224, 224, 1); - tk::dnn::Network net(dim); - - tk::dnn::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 64, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 128, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c5 (&net, 64, 1, 1, 1, 1, 0, 0, c5_bin, true); - tk::dnn::Activation a5 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p7 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8 (&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c9 (&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true); - tk::dnn::Activation a9 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c10(&net, 256, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p11(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c12(&net, 512, 3, 3, 1, 1, 1, 1, c12_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c14_bin, true); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 256, 1, 1, 1, 1, 0, 0, c15_bin, true); - tk::dnn::Activation a15(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c16(&net, 512, 3, 3, 1, 1, 1, 1, c16_bin, true); - tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p17(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c18(&net, 1024, 3, 3, 1, 1, 1, 1, c18_bin, true); - tk::dnn::Activation a18(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c19(&net, 512, 1, 1, 1, 1, 0, 0, c19_bin, true); - tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c20(&net, 1024, 3, 3, 1, 1, 1, 1, c20_bin, true); - tk::dnn::Activation a20(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c21(&net, 512, 1, 1, 1, 1, 0, 0, c21_bin, true); - tk::dnn::Activation a21(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c22(&net, 1024, 3, 3, 1, 1, 1, 1, c22_bin, true); - tk::dnn::Activation a22(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c23(&net, 1024, 3, 3, 1, 1, 1, 1, c23_bin, true); - tk::dnn::Activation a23(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c24(&net, 1024, 3, 3, 1, 1, 1, 1, c24_bin, true); - tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *m25_layers[1] = { &a16 }; - tk::dnn::Route m25(&net, m25_layers, 1); - tk::dnn::Conv2d c26(&net, 64, 1, 1, 1, 1, 0, 0, c26_bin, true); - tk::dnn::Activation a26(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Reorg r27(&net, 2); - - tk::dnn::Layer *m28_layers[2] = { &r27, &a24 }; - tk::dnn::Route m28(&net, m28_layers, 2); - - tk::dnn::Conv2d c29(&net, 1024, 3, 3, 1, 1, 1, 1, c29_bin, true); - tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c30(&net, 425, 1, 1, 1, 1, 0, 0, c30_bin, false); - tk::dnn::Region g31(&net, 80, 4, 5); - - tk::dnn::RegionInterpret rI(dim, g31.output_dim, 80, 4, 5, 0.6f, g31_bin); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo_224")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - - // std::cout<<"\n\nDetected objects: \n"; - // dnnType *output_h = new dnnType[rI.output_dim.tot()]; - // checkCuda(cudaMemcpy(output_h, out_data2, - // rI.output_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost)); - // rI.interpretData(output_h); - // rI.showImageResult(input_h); - - - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo_berkeley/yolo_berkeley.cpp b/tests/yolo_berkeley/yolo_berkeley.cpp deleted file mode 100644 index 1d40c15..0000000 --- a/tests/yolo_berkeley/yolo_berkeley.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo_berkeley/layers/input.bin"; -const char *c0_bin = "yolo_berkeley/layers/c0.bin"; -const char *c2_bin = "yolo_berkeley/layers/c2.bin"; -const char *c4_bin = "yolo_berkeley/layers/c4.bin"; -const char *c5_bin = "yolo_berkeley/layers/c5.bin"; -const char *c6_bin = "yolo_berkeley/layers/c6.bin"; -const char *c8_bin = "yolo_berkeley/layers/c8.bin"; -const char *c9_bin = "yolo_berkeley/layers/c9.bin"; -const char *c10_bin = "yolo_berkeley/layers/c10.bin"; -const char *c12_bin = "yolo_berkeley/layers/c12.bin"; -const char *c13_bin = "yolo_berkeley/layers/c13.bin"; -const char *c14_bin = "yolo_berkeley/layers/c14.bin"; -const char *c15_bin = "yolo_berkeley/layers/c15.bin"; -const char *c16_bin = "yolo_berkeley/layers/c16.bin"; -const char *c18_bin = "yolo_berkeley/layers/c18.bin"; -const char *c19_bin = "yolo_berkeley/layers/c19.bin"; -const char *c20_bin = "yolo_berkeley/layers/c20.bin"; -const char *c21_bin = "yolo_berkeley/layers/c21.bin"; -const char *c22_bin = "yolo_berkeley/layers/c22.bin"; -const char *c23_bin = "yolo_berkeley/layers/c23.bin"; -const char *c24_bin = "yolo_berkeley/layers/c24.bin"; -const char *c26_bin = "yolo_berkeley/layers/c26.bin"; -const char *c29_bin = "yolo_berkeley/layers/c29.bin"; -const char *c30_bin = "yolo_berkeley/layers/c30.bin"; -const char *g31_bin = "yolo_berkeley/layers/g31.bin"; -const char *output_bin = "yolo_berkeley/layers/output.bin"; - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 736, 1); - tk::dnn::Network net(dim); - - tk::dnn::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 64, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 128, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c5 (&net, 64, 1, 1, 1, 1, 0, 0, c5_bin, true); - tk::dnn::Activation a5 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p7 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8 (&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c9 (&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true); - tk::dnn::Activation a9 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c10(&net, 256, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p11(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c12(&net, 512, 3, 3, 1, 1, 1, 1, c12_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c14_bin, true); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 256, 1, 1, 1, 1, 0, 0, c15_bin, true); - tk::dnn::Activation a15(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c16(&net, 512, 3, 3, 1, 1, 1, 1, c16_bin, true); - tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p17(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c18(&net, 1024, 3, 3, 1, 1, 1, 1, c18_bin, true); - tk::dnn::Activation a18(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c19(&net, 512, 1, 1, 1, 1, 0, 0, c19_bin, true); - tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c20(&net, 1024, 3, 3, 1, 1, 1, 1, c20_bin, true); - tk::dnn::Activation a20(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c21(&net, 512, 1, 1, 1, 1, 0, 0, c21_bin, true); - tk::dnn::Activation a21(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c22(&net, 1024, 3, 3, 1, 1, 1, 1, c22_bin, true); - tk::dnn::Activation a22(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c23(&net, 1024, 3, 3, 1, 1, 1, 1, c23_bin, true); - tk::dnn::Activation a23(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c24(&net, 1024, 3, 3, 1, 1, 1, 1, c24_bin, true); - tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *m25_layers[1] = { &a16 }; - tk::dnn::Route m25(&net, m25_layers, 1); - tk::dnn::Conv2d c26(&net, 64, 1, 1, 1, 1, 0, 0, c26_bin, true); - tk::dnn::Activation a26(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Reorg r27(&net, 2); - - tk::dnn::Layer *m28_layers[2] = { &r27, &a24 }; - tk::dnn::Route m28(&net, m28_layers, 2); - - tk::dnn::Conv2d c29(&net, 1024, 3, 3, 1, 1, 1, 1, c29_bin, true); - tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c30(&net, 75, 1, 1, 1, 1, 0, 0, c30_bin, false); - tk::dnn::Region g31(&net, 10, 4, 5); - - tk::dnn::RegionInterpret rI(dim, g31.output_dim, 10, 4, 5, 0.3f, g31_bin); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo_berkeley")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - - // std::cout<<"\n\nDetected objects: \n"; - // dnnType *output_h = new dnnType[rI.output_dim.tot()]; - // checkCuda(cudaMemcpy(output_h, out_data2, - // rI.output_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost)); - // rI.interpretData(output_h); - // rI.showImageResult(input_h); - - - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo_berkeley/yolov2-voc-10-resize-test.cfg b/tests/yolo_berkeley/yolov2-voc-10-resize-test.cfg deleted file mode 100644 index 184b32c..0000000 --- a/tests/yolo_berkeley/yolov2-voc-10-resize-test.cfg +++ /dev/null @@ -1,259 +0,0 @@ -[net] -# Testing -batch=1 -subdivisions=1 -# Training -#batch=64 -#subdivisions=8 -height=416 -width=736 -channels=3 -momentum=0.9 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.001 -burn_in=1000 -max_batches = 80200 -policy=steps -steps=40000,60000 -scales=.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 - -[convolutional] -batch_normalize=1 -size=1 -stride=1 -pad=1 -filters=64 -activation=leaky - -[reorg] -stride=2 - -[route] -layers=-1,-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=leaky - -[convolutional] -size=1 -stride=1 -pad=1 -filters=75 -activation=linear - - -[region] -anchors = 0.4043,0.4167, 1.2109,1.1018, 2.7258,2.1215, 4.9477,3.9132, 7.9508,6.6806 -bias_match=1 -classes=10 -coords=4 -num=5 -softmax=1 -jitter=.3 -rescore=1 - -object_scale=5 -noobject_scale=1 -class_scale=1 -coord_scale=1 - -absolute=1 -thresh = .6 -random=0 -flip=1 diff --git a/tests/yolo_relu/yolo_relu.cfg b/tests/yolo_relu/yolo_relu.cfg deleted file mode 100644 index 0abab4e..0000000 --- a/tests/yolo_relu/yolo_relu.cfg +++ /dev/null @@ -1,258 +0,0 @@ -[net] -# Testing -#batch=1 -#subdivisions=1 -# Training - batch=64 - subdivisions=16 -width=608 -height=608 -channels=3 -momentum=0.9 -decay=0.0005 -angle=0 -saturation = 1.5 -exposure = 1.5 -hue=.1 - -learning_rate=0.001 -burn_in=1000 -max_batches = 500200 -policy=steps -steps=400000,450000 -scales=.1,.1 - -[convolutional] -batch_normalize=1 -filters=32 -size=3 -stride=1 -pad=1 -activation=relu - -[maxpool] -size=2 -stride=2 - -[convolutional] -batch_normalize=1 -filters=64 -size=3 -stride=1 -pad=1 -activation=relu - -[maxpool] -size=2 -stride=2 - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=64 -size=1 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=128 -size=3 -stride=1 -pad=1 -activation=relu - -[maxpool] -size=2 -stride=2 - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=128 -size=1 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=256 -size=3 -stride=1 -pad=1 -activation=relu - -[maxpool] -size=2 -stride=2 - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=256 -size=1 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=512 -size=3 -stride=1 -pad=1 -activation=relu - -[maxpool] -size=2 -stride=2 - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=512 -size=1 -stride=1 -pad=1 -activation=relu - -[convolutional] -batch_normalize=1 -filters=1024 -size=3 -stride=1 -pad=1 -activation=relu - - -####### - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=relu - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=relu - -[route] -layers=-9 - -[convolutional] -batch_normalize=1 -size=1 -stride=1 -pad=1 -filters=64 -activation=relu - -[reorg] -stride=2 - -[route] -layers=-1,-4 - -[convolutional] -batch_normalize=1 -size=3 -stride=1 -pad=1 -filters=1024 -activation=relu - -[convolutional] -size=1 -stride=1 -pad=1 -filters=425 -activation=linear - - -[region] -anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828 -bias_match=1 -classes=80 -coords=4 -num=5 -softmax=1 -jitter=.3 -rescore=1 - -object_scale=5 -noobject_scale=1 -class_scale=1 -coord_scale=1 - -absolute=1 -thresh = .6 -random=1 diff --git a/tests/yolo_relu/yolo_relu.cpp b/tests/yolo_relu/yolo_relu.cpp deleted file mode 100644 index 30f9f3e..0000000 --- a/tests/yolo_relu/yolo_relu.cpp +++ /dev/null @@ -1,155 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo_relu/layers/input.bin"; -const char *c0_bin = "yolo_relu/layers/c0.bin"; -const char *c2_bin = "yolo_relu/layers/c2.bin"; -const char *c4_bin = "yolo_relu/layers/c4.bin"; -const char *c5_bin = "yolo_relu/layers/c5.bin"; -const char *c6_bin = "yolo_relu/layers/c6.bin"; -const char *c8_bin = "yolo_relu/layers/c8.bin"; -const char *c9_bin = "yolo_relu/layers/c9.bin"; -const char *c10_bin = "yolo_relu/layers/c10.bin"; -const char *c12_bin = "yolo_relu/layers/c12.bin"; -const char *c13_bin = "yolo_relu/layers/c13.bin"; -const char *c14_bin = "yolo_relu/layers/c14.bin"; -const char *c15_bin = "yolo_relu/layers/c15.bin"; -const char *c16_bin = "yolo_relu/layers/c16.bin"; -const char *c18_bin = "yolo_relu/layers/c18.bin"; -const char *c19_bin = "yolo_relu/layers/c19.bin"; -const char *c20_bin = "yolo_relu/layers/c20.bin"; -const char *c21_bin = "yolo_relu/layers/c21.bin"; -const char *c22_bin = "yolo_relu/layers/c22.bin"; -const char *c23_bin = "yolo_relu/layers/c23.bin"; -const char *c24_bin = "yolo_relu/layers/c24.bin"; -const char *c26_bin = "yolo_relu/layers/c26.bin"; -const char *c29_bin = "yolo_relu/layers/c29.bin"; -const char *c30_bin = "yolo_relu/layers/c30.bin"; -const char *g31_bin = "yolo_relu/layers/g31.bin"; -const char *output_bin = "yolo_relu/layers/output.bin"; - -int main() { - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 608, 608, 1); - tk::dnn::Network net(dim); - - tk::dnn::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 64, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 128, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c5 (&net, 64, 1, 1, 1, 1, 0, 0, c5_bin, true); - tk::dnn::Activation a5 (&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Pooling p7 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8 (&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8 (&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c9 (&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true); - tk::dnn::Activation a9 (&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c10(&net, 256, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Pooling p11(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c12(&net, 512, 3, 3, 1, 1, 1, 1, c12_bin, true); - tk::dnn::Activation a12(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c14_bin, true); - tk::dnn::Activation a14(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c15(&net, 256, 1, 1, 1, 1, 0, 0, c15_bin, true); - tk::dnn::Activation a15(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c16(&net, 512, 3, 3, 1, 1, 1, 1, c16_bin, true); - tk::dnn::Activation a16(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Pooling p17(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c18(&net, 1024, 3, 3, 1, 1, 1, 1, c18_bin, true); - tk::dnn::Activation a18(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c19(&net, 512, 1, 1, 1, 1, 0, 0, c19_bin, true); - tk::dnn::Activation a19(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c20(&net, 1024, 3, 3, 1, 1, 1, 1, c20_bin, true); - tk::dnn::Activation a20(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c21(&net, 512, 1, 1, 1, 1, 0, 0, c21_bin, true); - tk::dnn::Activation a21(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c22(&net, 1024, 3, 3, 1, 1, 1, 1, c22_bin, true); - tk::dnn::Activation a22(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c23(&net, 1024, 3, 3, 1, 1, 1, 1, c23_bin, true); - tk::dnn::Activation a23(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c24(&net, 1024, 3, 3, 1, 1, 1, 1, c24_bin, true); - tk::dnn::Activation a24(&net, CUDNN_ACTIVATION_RELU); - - tk::dnn::Layer *m25_layers[1] = { &a16 }; - tk::dnn::Route m25(&net, m25_layers, 1); - tk::dnn::Conv2d c26(&net, 64, 1, 1, 1, 1, 0, 0, c26_bin, true); - tk::dnn::Activation a26(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Reorg r27(&net, 2); - - tk::dnn::Layer *m28_layers[2] = { &r27, &a24 }; - tk::dnn::Route m28(&net, m28_layers, 2); - - tk::dnn::Conv2d c29(&net, 1024, 3, 3, 1, 1, 1, 1, c29_bin, true); - tk::dnn::Activation a29(&net, CUDNN_ACTIVATION_RELU); - tk::dnn::Conv2d c30(&net, 425, 1, 1, 1, 1, 0, 0, c30_bin, false); - tk::dnn::Region g31(&net, 80, 4, 5); - - tk::dnn::RegionInterpret rI(dim, g31.output_dim, 80, 4, 5, 0.3f, g31_bin); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo_relu")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - - // std::cout<<"\n\nDetected objects: \n"; - // dnnType *output_h = new dnnType[rI.output_dim.tot()]; - // checkCuda(cudaMemcpy(output_h, out_data2, - // rI.output_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost)); - // rI.interpretData(output_h, 608, 608); - // rI.showImageResult(input_h); - - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo_tiny/yolo_tiny.cpp b/tests/yolo_tiny/yolo_tiny.cpp deleted file mode 100644 index dd6857e..0000000 --- a/tests/yolo_tiny/yolo_tiny.cpp +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo_tiny/layers/input.bin"; -const char *c0_bin = "yolo_tiny/layers/c0.bin"; -const char *c2_bin = "yolo_tiny/layers/c2.bin"; -const char *c4_bin = "yolo_tiny/layers/c4.bin"; -const char *c5_bin = "yolo_tiny/layers/c5.bin"; -const char *c6_bin = "yolo_tiny/layers/c6.bin"; -const char *c8_bin = "yolo_tiny/layers/c8.bin"; -const char *c10_bin = "yolo_tiny/layers/c10.bin"; -const char *c11_bin = "yolo_tiny/layers/c11.bin"; -const char *c12_bin = "yolo_tiny/layers/c12.bin"; -const char *c13_bin = "yolo_tiny/layers/c13.bin"; -const char *g14_bin = "yolo_tiny/layers/g14.bin"; -const char *output_bin = "yolo_tiny/layers/output.bin"; - -int main() { - - downloadWeightsifDoNotExist(input_bin, "yolo_tiny", "https://cloud.hipert.unimore.it/s/m3orfJr8pGrN5mQ/download"); - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); - tk::dnn::Network net(dim); - - tk::dnn::Conv2d c0 (&net, 16, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 32, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 64, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p5 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p7(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8(&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p9(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c10(&net, 512, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Conv2d c11(&net, 1024, 3, 3, 1, 1, 1, 1, c11_bin, true); - tk::dnn::Activation a11(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c12(&net, 512, 3, 3, 1, 1, 1, 1, c12_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c13(&net, 425, 1, 1, 1, 1, 0, 0, c13_bin, false); - tk::dnn::Region g14(&net, 80, 4, 5); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo_tiny")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -} diff --git a/tests/yolo_voc/yolo_voc.cpp b/tests/yolo_voc/yolo_voc.cpp deleted file mode 100644 index 868128b..0000000 --- a/tests/yolo_voc/yolo_voc.cpp +++ /dev/null @@ -1,156 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo_voc/layers/input.bin"; -const char *c0_bin = "yolo_voc/layers/c0.bin"; -const char *c2_bin = "yolo_voc/layers/c2.bin"; -const char *c4_bin = "yolo_voc/layers/c4.bin"; -const char *c5_bin = "yolo_voc/layers/c5.bin"; -const char *c6_bin = "yolo_voc/layers/c6.bin"; -const char *c8_bin = "yolo_voc/layers/c8.bin"; -const char *c9_bin = "yolo_voc/layers/c9.bin"; -const char *c10_bin = "yolo_voc/layers/c10.bin"; -const char *c12_bin = "yolo_voc/layers/c12.bin"; -const char *c13_bin = "yolo_voc/layers/c13.bin"; -const char *c14_bin = "yolo_voc/layers/c14.bin"; -const char *c15_bin = "yolo_voc/layers/c15.bin"; -const char *c16_bin = "yolo_voc/layers/c16.bin"; -const char *c18_bin = "yolo_voc/layers/c18.bin"; -const char *c19_bin = "yolo_voc/layers/c19.bin"; -const char *c20_bin = "yolo_voc/layers/c20.bin"; -const char *c21_bin = "yolo_voc/layers/c21.bin"; -const char *c22_bin = "yolo_voc/layers/c22.bin"; -const char *c23_bin = "yolo_voc/layers/c23.bin"; -const char *c24_bin = "yolo_voc/layers/c24.bin"; -const char *c26_bin = "yolo_voc/layers/c26.bin"; -const char *c29_bin = "yolo_voc/layers/c29.bin"; -const char *c30_bin = "yolo_voc/layers/c30.bin"; -const char *g31_bin = "yolo_voc/layers/g31.bin"; -const char *output_bin = "yolo_voc/layers/output.bin"; - -int main() { - - downloadWeightsifDoNotExist(input_bin, "yolo_voc", "https://cloud.hipert.unimore.it/s/DJC5Fi2pEjfNDP9/download"); - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); - tk::dnn::Network net(dim); - - tk::dnn::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true); - tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p1 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c2 (&net, 64, 3, 3, 1, 1, 1, 1, c2_bin, true); - tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p3 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c4 (&net, 128, 3, 3, 1, 1, 1, 1, c4_bin, true); - tk::dnn::Activation a4 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c5 (&net, 64, 1, 1, 1, 1, 0, 0, c5_bin, true); - tk::dnn::Activation a5 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c6 (&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true); - tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p7 (&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c8 (&net, 256, 3, 3, 1, 1, 1, 1, c8_bin, true); - tk::dnn::Activation a8 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c9 (&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true); - tk::dnn::Activation a9 (&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c10(&net, 256, 3, 3, 1, 1, 1, 1, c10_bin, true); - tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p11(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c12(&net, 512, 3, 3, 1, 1, 1, 1, c12_bin, true); - tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c13(&net, 256, 1, 1, 1, 1, 0, 0, c13_bin, true); - tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c14(&net, 512, 3, 3, 1, 1, 1, 1, c14_bin, true); - tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c15(&net, 256, 1, 1, 1, 1, 0, 0, c15_bin, true); - tk::dnn::Activation a15(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c16(&net, 512, 3, 3, 1, 1, 1, 1, c16_bin, true); - tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Pooling p17(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX); - - tk::dnn::Conv2d c18(&net, 1024, 3, 3, 1, 1, 1, 1, c18_bin, true); - tk::dnn::Activation a18(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c19(&net, 512, 1, 1, 1, 1, 0, 0, c19_bin, true); - tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c20(&net, 1024, 3, 3, 1, 1, 1, 1, c20_bin, true); - tk::dnn::Activation a20(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c21(&net, 512, 1, 1, 1, 1, 0, 0, c21_bin, true); - tk::dnn::Activation a21(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c22(&net, 1024, 3, 3, 1, 1, 1, 1, c22_bin, true); - tk::dnn::Activation a22(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c23(&net, 1024, 3, 3, 1, 1, 1, 1, c23_bin, true); - tk::dnn::Activation a23(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c24(&net, 1024, 3, 3, 1, 1, 1, 1, c24_bin, true); - tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_LEAKY); - - tk::dnn::Layer *m25_layers[1] = { &a16 }; - tk::dnn::Route m25(&net, m25_layers, 1); - tk::dnn::Conv2d c26(&net, 64, 1, 1, 1, 1, 0, 0, c26_bin, true); - tk::dnn::Activation a26(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Reorg r27(&net, 2); - - tk::dnn::Layer *m28_layers[2] = { &r27, &a24 }; - tk::dnn::Route m28(&net, m28_layers, 2); - - tk::dnn::Conv2d c29(&net, 1024, 3, 3, 1, 1, 1, 1, c29_bin, true); - tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY); - tk::dnn::Conv2d c30(&net, 125, 1, 1, 1, 1, 0, 0, c30_bin, false); - tk::dnn::Region g31(&net, 20, 4, 5); - - tk::dnn::RegionInterpret rI(dim, g31.output_dim, 20, 4, 5, 0.6f, g31_bin); - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, dim.tot(), &input_h, &data); - - //print network model - net.print(); - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("yolo_voc")); - - dnnType *out_data, *out_data2; // cudnn output, tensorRT output - - tk::dnn::dataDim_t dim1 = dim; //input dim - printCenteredTitle(" CUDNN inference ", '=', 30); { - dim1.print(); - TIMER_START - out_data = net.infer(dim1, data); - TIMER_STOP - dim1.print(); - } - - tk::dnn::dataDim_t dim2 = dim; - printCenteredTitle(" TENSORRT inference ", '=', 30); { - dim2.print(); - TIMER_START - out_data2 = netRT.infer(dim2, data); - TIMER_STOP - dim2.print(); - } - - printCenteredTitle(" CHECK RESULTS ", '=', 30); - dnnType *out, *out_h; - int out_dim = net.getOutputDim().tot(); - readBinaryFile(output_bin, out_dim, &out_h, &out); - std::cout<<"CUDNN vs correct"; - int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN; - std::cout<<"TRT vs correct"; - int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT; - std::cout<<"CUDNN vs TRT "; - int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; - - // std::cout<<"\n\nDetected objects: \n"; - // dnnType *output_h = new dnnType[rI.output_dim.tot()]; - // checkCuda(cudaMemcpy(output_h, out_data2, - // rI.output_dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost)); - // rI.interpretData(output_h); - // rI.showImageResult(input_h); - - return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; -}