From e3e5a133f5c9fc1b495ac829a390063578b08a4c Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sun, 12 Apr 2020 21:47:25 +0200 Subject: [PATCH 01/78] pull from repos --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17dbf8e..da20085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,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,7 +48,7 @@ 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}) From 29b99f4e61a4d4163442b4085f2705bd1f693804 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 14 Apr 2020 12:32:50 +0200 Subject: [PATCH 02/78] pull from repos --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 17dbf8e..709f255 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,7 +36,7 @@ include_directories(${EIGEN3_INCLUDE_DIR}) find_package(OpenCV REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV") -find_package(yaml-cpp REQUIRED) +#find_package(yaml-cpp REQUIRED) #------------------------------------------------------------------------------- # Build Libraries @@ -47,7 +47,7 @@ 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}) From 4a308467e6faf6c0d09dde2494a91ad045ff074b Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 14 Apr 2020 14:26:06 +0200 Subject: [PATCH 03/78] warning fix --- src/utils.cpp | 7 ++++--- tests/imuodom/imuodom.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index b196d1c..5186526 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -25,9 +25,10 @@ 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(wget_cmd.c_str()); - system(unzip_cmd.c_str()); - system(rm_cmd.c_str()); + int err = 0; + err = system(wget_cmd.c_str()); + err = system(unzip_cmd.c_str()); + err = system(rm_cmd.c_str()); } } diff --git a/tests/imuodom/imuodom.cpp b/tests/imuodom/imuodom.cpp index 98ab1be..5c73786 100644 --- a/tests/imuodom/imuodom.cpp +++ b/tests/imuodom/imuodom.cpp @@ -77,6 +77,6 @@ int main() { out1 += ImuNet.odim1.tot(); } - system("cat path.txt | gnuplot -p -e \"set datafile separator ' '; plot '-'\""); + int err = system("cat path.txt | gnuplot -p -e \"set datafile separator ' '; plot '-'\""); return ret_cudnn; } From c975a467b16e1bc84261932f728d8352f49d9369 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 28 Apr 2020 12:59:30 +0200 Subject: [PATCH 04/78] sensor close if not started fix --- include/tkDNN/ImuOdom.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/tkDNN/ImuOdom.h b/include/tkDNN/ImuOdom.h index 9dedaf9..e1c60cc 100644 --- a/include/tkDNN/ImuOdom.h +++ b/include/tkDNN/ImuOdom.h @@ -113,6 +113,10 @@ class ImuOdom { return true; } + void close() { + // TODO: dealloc :) + } + void update(dnnType *x0, dnnType *x1, dnnType *x2) { checkCuda( cudaMemcpy(i0_d, x0, dim0.tot()*sizeof(dnnType), cudaMemcpyHostToDevice) ); From 986ec5d00c710370360e7b24267007c38e5b95f0 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 28 Apr 2020 22:59:45 +0200 Subject: [PATCH 05/78] Update LICENSE --- LICENSE | 352 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 335 insertions(+), 17 deletions(-) diff --git a/LICENSE b/LICENSE index 0a93a39..d159169 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. + + + Copyright (C) + + 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. From 3e2d0630b7d67548d0d53c59e481d15330fe04a5 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Wed, 29 Apr 2020 13:07:26 +0200 Subject: [PATCH 06/78] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aeb3e02..a06a2b8 100644 --- a/README.md +++ b/README.md @@ -69,10 +69,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 From d6c28c5ba2654c4e80276bc83b7cfe1da9237d20 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Wed, 29 Apr 2020 18:09:50 +0200 Subject: [PATCH 07/78] Update README.md --- README.md | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index a06a2b8..0f6b607 100644 --- a/README.md +++ b/README.md @@ -114,9 +114,9 @@ python run_ssd_live_demo.py mb2-ssd-lite To run the an object detection demo follow these steps (example with yolov3): ``` -rm yolo3_FP32.rt # be sure to delete(or move) old tensorRT files +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 +./demo yolo3_fp32.rt ../demo/yolo_test.mp4 y ``` In general the demo program takes 4 parameters: ``` @@ -136,9 +136,9 @@ N.b. By default it is used FP32 inference 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). @@ -153,9 +153,9 @@ 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 +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. @@ -166,6 +166,21 @@ N.b. INT8 calibration requires TensorRT version greater than or equal to 6.0 ### BatchSize bigger than 1 ``` export TKDNN_BATCHSIZE=2 +# build tensorRT files +``` +This will create a TensorRT file with the desidered **max** batch size. +The test will still run with a batch of 1, but the created tensorRT can manage the desidered batch size. + +### Test batch Inference +``` +./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 From d8f034a7adc577428e492105ef453c8304c7cf63 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Wed, 29 Apr 2020 18:17:32 +0200 Subject: [PATCH 08/78] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0f6b607..8431079 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,7 @@ This will create a TensorRT file with the desidered **max** batch size. The test will still run with a batch of 1, but the created tensorRT can manage the desidered 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 From 4fd84b1876feafc701016c64614a30903c53e7f1 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Wed, 29 Apr 2020 18:34:06 +0200 Subject: [PATCH 09/78] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8431079..7f1016d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ 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. 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. +Accepted paper @ IRC 2020, will soon been published. +M. Verucchi, L. Bartoli, F. Bagni, F. Gatti, P. Burgio and M. Bertogna, "Real-Time clustering and LiDAR-camera fusion on embedded platforms for self-driving cars", in proceedings in IEEE Robotic Computing (2020) + ## Index - [tkDNN](#tkdnn) - [Index](#index) From 5ab2e63de43ea2967fc47c5cacaa173d7e61f39c Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sun, 3 May 2020 15:53:35 +0200 Subject: [PATCH 10/78] imu odom SEP model --- tests/imuodom/infer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/imuodom/infer.py b/tests/imuodom/infer.py index 3dcf44f..c25bb29 100644 --- a/tests/imuodom/infer.py +++ b/tests/imuodom/infer.py @@ -22,8 +22,8 @@ if __name__ == '__main__': print("DATA FORMAT: ", keras.backend.image_data_format()) - print("Load model: ", "ferrariS1.hdf5") - model = load_model("ferrariS1.hdf5") + print("Load model: ", "ferrariSEP.hdf5") + model = load_model("ferrariSEP.hdf5") model.summary() weights = model.get_weights() From 5a9ed44b6a9590a031096d16c8d630d5fe1ca837 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sun, 3 May 2020 15:54:39 +0200 Subject: [PATCH 11/78] SEP model --- include/tkDNN/ImuOdom.h | 17 ++++++++++++++--- tests/imuodom/imuodom.cpp | 21 ++++++--------------- tests/imuodom/infer.py | 4 ++-- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/include/tkDNN/ImuOdom.h b/include/tkDNN/ImuOdom.h index 9dedaf9..856407d 100644 --- a/include/tkDNN/ImuOdom.h +++ b/include/tkDNN/ImuOdom.h @@ -35,7 +35,8 @@ class ImuOdom { // output eigen CPU Eigen::MatrixXf deltaP, deltaQ; - Eigen::MatrixXd odomPOS, odomROT; + Eigen::MatrixXd odomPOS, odomEULER; + Eigen::Matrix3d odomROT; Eigen::Isometry3f tf = Eigen::Isometry3f::Identity(); ImuOdom() {} @@ -109,7 +110,7 @@ class ImuOdom { odomPOS = Eigen::MatrixXd::Zero(3, 1); odomROT = Eigen::MatrixXd::Identity(3, 3); - + odomEULER = Eigen::MatrixXd::Zero(3, 1); return true; } @@ -132,8 +133,18 @@ class ImuOdom { q.x() = deltaQ(1); q.y() = deltaQ(2); q.z() = deltaQ(3); - odomPOS = odomPOS + odomROT*deltaP.cast(); + odomPOS = odomPOS + deltaP.cast(); odomROT = odomROT * q.normalized().toRotationMatrix(); + + // compute euler + auto newEULER = odomROT.eulerAngles(0, 1, 2); + for(int i=0; i<3; i++) { + while( fabs(newEULER(i) - odomEULER(i)) > M_PI_2 ) { + newEULER(i) += newEULER(i) - odomEULER(i) > 0 ? -M_PI : +M_PI; + //std::cout<(); diff --git a/tests/imuodom/imuodom.cpp b/tests/imuodom/imuodom.cpp index 9682f15..723611b 100644 --- a/tests/imuodom/imuodom.cpp +++ b/tests/imuodom/imuodom.cpp @@ -7,18 +7,6 @@ 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() { downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/ZAy34K5w2ixED6x/download"); @@ -26,7 +14,7 @@ int main() { 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); @@ -60,7 +48,9 @@ int main() { //TIMER_STOP // log path - path< Date: Sun, 3 May 2020 15:56:30 +0200 Subject: [PATCH 12/78] Imu odom weights --- tests/imuodom/imuodom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/imuodom/imuodom.cpp b/tests/imuodom/imuodom.cpp index 723611b..f02b88d 100644 --- a/tests/imuodom/imuodom.cpp +++ b/tests/imuodom/imuodom.cpp @@ -9,7 +9,7 @@ const char *o1_bin = "imuodom/layers/output1.bin"; int main() { - downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/ZAy34K5w2ixED6x/download"); + downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/BBSEbEbQbPKxp4s/download"); tk::dnn::ImuOdom ImuNet; ImuNet.init("imuodom/layers/"); From ca7631250c87802768834b908b9fe9fc871e802a Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sun, 3 May 2020 19:12:10 +0200 Subject: [PATCH 13/78] filter yaw ok --- include/tkDNN/ImuOdom.h | 3 ++- tests/imuodom/imuodom.cpp | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/tkDNN/ImuOdom.h b/include/tkDNN/ImuOdom.h index 8d21951..58def96 100644 --- a/include/tkDNN/ImuOdom.h +++ b/include/tkDNN/ImuOdom.h @@ -137,7 +137,8 @@ class ImuOdom { q.x() = deltaQ(1); q.y() = deltaQ(2); q.z() = deltaQ(3); - odomPOS = odomPOS + deltaP.cast(); + odomPOS = odomPOS + odomROT*deltaP.cast(); // V1 + //odomPOS = odomPOS + deltaP.cast(); // V2 odomROT = odomROT * q.normalized().toRotationMatrix(); // compute euler diff --git a/tests/imuodom/imuodom.cpp b/tests/imuodom/imuodom.cpp index bcf131e..24be585 100644 --- a/tests/imuodom/imuodom.cpp +++ b/tests/imuodom/imuodom.cpp @@ -9,7 +9,11 @@ const char *o1_bin = "imuodom/layers/output1.bin"; int main() { - downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/BBSEbEbQbPKxp4s/download"); + // 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/"); From 533bb4878914982a72b3f0165cc94f4070b8a894 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 11 May 2020 11:57:58 +0200 Subject: [PATCH 14/78] Add json detection creation for codalab check Signed-off-by: Micaela Verucchi --- CMakeLists.txt | 12 + demo/demo/map.cpp | 57 +- include/tkDNN/CenternetDetection.h | 2 +- include/tkDNN/DetectionNN.h | 10 +- include/tkDNN/Layer.h | 3 +- include/tkDNN/MobilenetDetection.h | 2 +- include/tkDNN/Yolo3Detection.h | 2 +- include/tkDNN/evaluation.h | 3 + src/CenternetDetection.cpp | 2 +- src/MobilenetDetection.cpp | 6 +- src/Yolo3Detection.cpp | 5 +- src/evaluation.cpp | 43 +- .../bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp | 2 +- tests/test_rtinference/rtinference.cpp | 6 +- tests/yolo4/yolo4_320.cpp | 666 ++++++++++++++++++ tests/yolo4/yolo4_512.cpp | 666 ++++++++++++++++++ tests/yolo4/yolo4_608.cpp | 666 ++++++++++++++++++ 17 files changed, 2119 insertions(+), 34 deletions(-) create mode 100644 tests/yolo4/yolo4_320.cpp create mode 100644 tests/yolo4/yolo4_512.cpp create mode 100644 tests/yolo4/yolo4_608.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 028d375..7222825 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,18 @@ target_link_libraries(test_yolo3_flir tkDNN) add_executable(test_yolo4 tests/yolo4/yolo4.cpp) target_link_libraries(test_yolo4 tkDNN) +add_executable(test_yolo4_320 tests/yolo4/yolo4_320.cpp) +target_link_libraries(test_yolo4_320 tkDNN) + +add_executable(test_yolo4_512 tests/yolo4/yolo4_512.cpp) +target_link_libraries(test_yolo4_512 tkDNN) + +add_executable(test_yolo4_608 tests/yolo4/yolo4_608.cpp) +target_link_libraries(test_yolo4_608 tkDNN) + +add_executable(test_yolo4_berkeley tests/yolo4_berkeley/yolo4_berkeley.cpp) +target_link_libraries(test_yolo4_berkeley tkDNN) + add_executable(test_mobilenetv2ssd tests/mobilenetv2ssd/mobilenetv2ssd.cpp) target_link_libraries(test_mobilenetv2ssd tkDNN) diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index e12fc36..febb2bc 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -34,6 +34,7 @@ int main(int argc, char *argv[]) bool show = false; bool write_dets = false; bool write_res_on_file = true; + bool write_coco_json = true; int n_images = 5000; bool verbose; @@ -43,6 +44,7 @@ int main(int argc, char *argv[]) double vm_total = 0, rss_total = 0; double vm, rss; + //read args if(argc > 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); + //read images std::ifstream all_labels(labels_path); std::string l_filename; std::vector images; @@ -135,10 +143,13 @@ int main(int argc, char *argv[]) //inference detected_bbox.clear(); - detNN->update(dnn_input, write_res_on_file, ×); + detNN->update(dnn_input, write_res_on_file, ×, write_coco_json); frame = detNN->draw(frame); 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"))); @@ -167,17 +178,20 @@ int main(int argc, char *argv[]) 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(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); + } } images.push_back(f); @@ -193,6 +207,13 @@ int main(int argc, char *argv[]) } + + if(write_coco_json){ + coco_json.seekp (coco_json.tellp()-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/include/tkDNN/CenternetDetection.h b/include/tkDNN/CenternetDetection.h index 10fccec..92feba5 100644 --- a/include/tkDNN/CenternetDetection.h +++ b/include/tkDNN/CenternetDetection.h @@ -75,7 +75,7 @@ public: bool init(const std::string& tensor_path, const int n_classes=80); void preprocess(cv::Mat &frame); - void postprocess(); + void postprocess(const bool mAP=false); }; diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index ccb379c..a635b2d 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 @@ -55,11 +55,11 @@ class DetectionNN { * boundig boxes. * */ - virtual void postprocess() = 0; + virtual void postprocess(const bool mAP=false) = 0; public: int classes = 0; - float confThreshold = 0.3; /*threshold on the confidence of the boxes*/ + float confThreshold = 0.05; /*threshold on the confidence of the boxes*/ std::vector detected; /*bounding boxes in output*/ std::vector stats; /*keeps track of inference times (ms)*/ @@ -86,7 +86,7 @@ class DetectionNN { * are saved on a csv file, otherwise not. * @param times pointer to the output stream where to write times */ - void update(cv::Mat &frame, bool save_times=false, std::ofstream *times=nullptr){ + void update(cv::Mat &frame, bool save_times=false, std::ofstream *times=nullptr, const bool mAP=false){ if(!frame.data) FatalError("No image data feed to detection"); @@ -116,7 +116,7 @@ class DetectionNN { { TIMER_START - postprocess(); + postprocess(mAP); TIMER_STOP if(save_times) *times< probs; void print() { @@ -581,7 +582,7 @@ public: dnnType *predictions; - static const int MAX_DETECTIONS = 2048; + static const int MAX_DETECTIONS = 8192; static Yolo::detection *allocateDetections(int nboxes, int classes); static void mergeDetections(Yolo::detection *dets, int ndets, int classes); }; diff --git a/include/tkDNN/MobilenetDetection.h b/include/tkDNN/MobilenetDetection.h index fea1449..7271005 100644 --- a/include/tkDNN/MobilenetDetection.h +++ b/include/tkDNN/MobilenetDetection.h @@ -67,7 +67,7 @@ public: bool init(const std::string& tensor_path, const int n_classes); void preprocess(cv::Mat &frame); - void postprocess(); + void postprocess(const bool mAP=false); }; diff --git a/include/tkDNN/Yolo3Detection.h b/include/tkDNN/Yolo3Detection.h index e8be562..d0acd8b 100644 --- a/include/tkDNN/Yolo3Detection.h +++ b/include/tkDNN/Yolo3Detection.h @@ -26,7 +26,7 @@ public: bool init(const std::string& tensor_path, const int n_classes=80); void preprocess(cv::Mat &frame); - void postprocess(); + void postprocess(const bool mAP=false); }; diff --git a/include/tkDNN/evaluation.h b/include/tkDNN/evaluation.h index d76bb7d..8907d9d 100644 --- a/include/tkDNN/evaluation.h +++ b/include/tkDNN/evaluation.h @@ -108,6 +108,9 @@ void computeTPFPFN( std::vector &images,const int classes, 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/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index 97668e6..dcdb610 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -260,7 +260,7 @@ void CenternetDetection::preprocess(cv::Mat &frame){ #endif } -void CenternetDetection::postprocess(){ +void CenternetDetection::postprocess(const bool mAP){ dnnType *rt_out[4]; rt_out[0] = (dnnType *)netRT->buffersRT[1]; rt_out[1] = (dnnType *)netRT->buffersRT[2]; diff --git a/src/MobilenetDetection.cpp b/src/MobilenetDetection.cpp index 99b7a0c..d66a8cc 100644 --- a/src/MobilenetDetection.cpp +++ b/src/MobilenetDetection.cpp @@ -243,7 +243,7 @@ void MobilenetDetection::preprocess(cv::Mat &frame){ #endif } -void MobilenetDetection::postprocess(){ +void MobilenetDetection::postprocess(const bool mAP){ //get confidences and locations_h dnnType *rt_out[2]; rt_out[0] = (dnnType *)netRT->buffersRT[3]; @@ -273,6 +273,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; cpluginFactory->n_yolos]; for(int i=0; ipluginFactory->n_yolos; i++) { @@ -132,6 +132,9 @@ void Yolo3Detection::postprocess(){ res.y = y0; res.w = x1 - x0; res.h = y1 - y0; + if(mAP) + for(int c=0; c &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/tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp b/tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp index df3e617..1549983 100644 --- a/tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp +++ b/tests/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; diff --git a/tests/test_rtinference/rtinference.cpp b/tests/test_rtinference/rtinference.cpp index 1ca9763..4b6b21f 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: "<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/yolo4/yolo4_512.cpp b/tests/yolo4/yolo4_512.cpp new file mode 100644 index 0000000..963df75 --- /dev/null +++ b/tests/yolo4/yolo4_512.cpp @@ -0,0 +1,666 @@ +#include +#include +#include "tkdnn.h" + +int main() +{ + + // Network layout + tk::dnn::dataDim_t dim(1, 3, 512, 512, 1); + tk::dnn::Network net(dim); + + // create yolo4_512 model + std::string bin_path = "yolo4_512"; + 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_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 < 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/yolo4/yolo4_608.cpp b/tests/yolo4/yolo4_608.cpp new file mode 100644 index 0000000..64d8f34 --- /dev/null +++ b/tests/yolo4/yolo4_608.cpp @@ -0,0 +1,666 @@ +#include +#include +#include "tkdnn.h" + +int main() +{ + + // Network layout + tk::dnn::dataDim_t dim(1, 3, 608, 608, 1); + tk::dnn::Network net(dim); + + // create yolo4_608 model + std::string bin_path = "yolo4_608"; + 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_608")); + + // 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; +} From 2e3cb52cff46f5990e88aa3223e39e96df4c8702 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 11 May 2020 15:08:10 +0200 Subject: [PATCH 15/78] Add flag to disable visualization and save video Signed-off-by: Micaela Verucchi --- demo/demo/demo.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 75012b6..540ee25 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -34,6 +34,12 @@ int main(int argc, char *argv[]) { int n_classes = 80; if(argc > 4) n_classes = atoi(argv[4]); + bool show = true; + if(argc > 5) + show = atoi(argv[5]); + + if(!show) + SAVE_RESULT = true; tk::dnn::Yolo3Detection yolo; tk::dnn::CenternetDetection cnet; @@ -76,7 +82,8 @@ int main(int argc, char *argv[]) { cv::Mat frame; cv::Mat dnn_input; - cv::namedWindow("detection", cv::WINDOW_NORMAL); + if(show) + cv::namedWindow("detection", cv::WINDOW_NORMAL); std::vector detected_bbox; @@ -93,8 +100,10 @@ int main(int argc, char *argv[]) { detNN->update(dnn_input); frame = detNN->draw(frame); - cv::imshow("detection", frame); - cv::waitKey(1); + if(show){ + cv::imshow("detection", frame); + cv::waitKey(1); + } if(SAVE_RESULT) resultVideo << frame; } From 40456592fc6693ca224202a88d78bbaa20446cce Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Thu, 14 May 2020 16:41:51 +0200 Subject: [PATCH 16/78] Adapt detection classes to use batches, adapt demos, update README Signed-off-by: Micaela Verucchi --- README.md | 7 ++- demo/demo/demo.cpp | 58 ++++++++++++++--------- demo/demo/map.cpp | 17 +++---- include/tkDNN/CenternetDetection.h | 6 +-- include/tkDNN/DetectionNN.h | 75 ++++++++++++++++++------------ include/tkDNN/MobilenetDetection.h | 6 +-- include/tkDNN/Yolo3Detection.h | 6 +-- src/CenternetDetection.cpp | 26 ++++++----- src/MobilenetDetection.cpp | 22 +++++---- src/Yolo3Detection.cpp | 29 +++++++----- 10 files changed, 149 insertions(+), 103 deletions(-) diff --git a/README.md b/README.md index 7f1016d..0593bcb 100644 --- a/README.md +++ b/README.md @@ -123,13 +123,16 @@ rm yolo3_fp32.rt # be sure to delete(or move) old tensorRT files ``` In general the demo program takes 4 parameters: ``` -./demo +./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) + N.b. By default it is used FP32 inference ![demo](https://user-images.githubusercontent.com/11562617/72547657-540e7800-388d-11ea-83c6-49dfea2a0607.gif) @@ -218,6 +221,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 subit 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 | diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 540ee25..67d5786 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -34,9 +34,15 @@ int main(int argc, char *argv[]) { int n_classes = 80; if(argc > 4) n_classes = atoi(argv[4]); - bool show = true; + int n_batch = 1; if(argc > 5) - show = atoi(argv[5]); + n_batch = atoi(argv[5]); + bool show = true; + if(argc > 6) + show = atoi(argv[6]); + + if(n_batch < 1 || n_batch > 64) + FatalError("Batch dim not supported"); if(!show) SAVE_RESULT = true; @@ -63,7 +69,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); gRun = true; @@ -81,30 +87,40 @@ int main(int argc, char *argv[]) { } cv::Mat frame; - cv::Mat dnn_input; if(show) cv::namedWindow("detection", cv::WINDOW_NORMAL); - - std::vector detected_bbox; + + 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(); + for(int bi=0; bi< n_batch; ++bi){ + cap >> frame; + if(!frame.data) + break; + + batch_frame.push_back(frame); + + // this will be resized to the net format + batch_dnn_input.push_back(frame.clone()); + } + if(!frame.data) + break; + //inference - detNN->update(dnn_input); - frame = detNN->draw(frame); + detNN->update(batch_dnn_input); + detNN->draw(batch_frame); if(show){ - cv::imshow("detection", frame); - cv::waitKey(1); + for(int bi=0; bi< n_batch; ++bi){ + cv::imshow("detection", batch_frame[bi]); + cv::waitKey(1); + } } - if(SAVE_RESULT) + if(n_batch == 1 && SAVE_RESULT) resultVideo << frame; } @@ -112,10 +128,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: "< 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, ×, write_coco_json); - frame = detNN->draw(frame); + detNN->update(batch_dnn_input, write_res_on_file, ×, write_coco_json); + detNN->draw(batch_frames); detected_bbox = detNN->detected; if(write_coco_json) @@ -171,7 +172,7 @@ int main(int argc, char *argv[]) myfile << d.cl << " "<< d.prob << " "<< d.x << " "<< d.y << " "<< d.w << " "<< d.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) @@ -190,14 +191,14 @@ int main(int argc, char *argv[]) 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); + 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); } diff --git a/include/tkDNN/CenternetDetection.h b/include/tkDNN/CenternetDetection.h index 92feba5..227cb78 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(const bool mAP=false); + bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1); + void preprocess(cv::Mat &frame, const int bi=0); + void postprocess(const int bi=0,const bool mAP=false); }; diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index a635b2d..2948111 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -34,6 +34,8 @@ class DetectionNN { 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(const bool mAP=false) = 0; + virtual void postprocess(const int bi=0,const bool mAP=false) = 0; public: int classes = 0; - float confThreshold = 0.05; /*threshold on the confidence of the boxes*/ + 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; @@ -74,36 +81,41 @@ class DetectionNN { * * @param tensor_path path to the rt file og the NN. * @param n_classes number of classes for the given dataset. + * @param n_batches 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) = 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 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, const bool mAP=false){ - if(!frame.data) - FatalError("No image data feed to detection"); - + void update(std::vector& frames, 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"); - originalSize = frame.size(); printCenteredTitle(" TENSORRT detection ", '=', 30); { TIMER_START - preprocess(frame); + for(int bi=0; biinput_dim; + dim.n = nBatches; { dim.print(); TIMER_START @@ -114,9 +126,11 @@ class DetectionNN { if(save_times) *times<& frames) { tk::dnn::box b; int x0, w, x1, y0, h, y1; int objClass; @@ -137,24 +150,26 @@ class DetectionNN { int baseline = 0; float font_scale = 0.5; int thickness = 2; - // draw dets - for(int i=0; iinput_dim; @@ -41,7 +42,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 +99,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,7 +121,7 @@ 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(); @@ -212,7 +213,7 @@ void CenternetDetection::preprocess(cv::Mat &frame){ // std::cout << " TIME normalize: " << std::chrono::duration_cast(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 +255,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(const bool mAP){ +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[0].tot()*bi; + rt_out[1] = (dnnType *)netRT->buffersRT[2]+ netRT->buffersDIM[1].tot()*bi; + rt_out[2] = (dnnType *)netRT->buffersRT[3]+ netRT->buffersDIM[2].tot()*bi; + rt_out[3] = (dnnType *)netRT->buffersRT[4]+ netRT->buffersDIM[3].tot()*bi; // auto start_t = std::chrono::steady_clock::now(); // auto step_t = std::chrono::steady_clock::now(); @@ -389,6 +390,7 @@ void CenternetDetection::postprocess(const bool mAP){ } } + batchDetected.push_back(detected); // end_t = std::chrono::steady_clock::now(); // std::cout << " TIME detections: " << std::chrono::duration_cast(end_t - step_t).count() << " us" << std::endl; // step_t = end_t; diff --git a/src/MobilenetDetection.cpp b/src/MobilenetDetection.cpp index d66a8cc..4289d96 100644 --- a/src/MobilenetDetection.cpp +++ b/src/MobilenetDetection.cpp @@ -126,11 +126,12 @@ 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){ 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; SSDSpec specs[N_SSDSPEC]; @@ -157,9 +158,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 +209,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 +225,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 +238,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(const bool mAP){ +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(); @@ -302,6 +303,7 @@ void MobilenetDetection::postprocess(const bool mAP){ boxes = remaining; } } + batchDetected.push_back(detected); } diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index 18173f4..fc5e1d0 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -3,12 +3,16 @@ namespace tk { namespace dnn { -bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) { +bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, const int n_batches) { //convert network to tensorRT std::cout<<(tensor_path).c_str()<<"\n"; netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str() ); + nBatches = n_batches; + tk::dnn::dataDim_t idim = netRT->input_dim; + idim.n = nBatches; + if(netRT->pluginFactory->n_yolos < 2 ) { FatalError("this is not yolo3"); } @@ -19,7 +23,7 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) { num = yRT->num; nMasks = yRT->n_masks; - // make a yolo layer for interpret predictions + // make a yolo layer to interpret predictions yolo[i] = new tk::dnn::Yolo(nullptr, classes, nMasks, ""); // yolo without input and bias yolo[i]->mask_h = new dnnType[nMasks]; yolo[i]->bias_h = new dnnType[num*nMasks*2]; @@ -31,9 +35,9 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) { dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); #ifndef OPENCV_CUDACONTRIB - checkCuda(cudaMallocHost(&input, sizeof(dnnType)*netRT->input_dim.tot())); + checkCuda(cudaMallocHost(&input, sizeof(dnnType)*idim.tot())); #endif - checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*netRT->input_dim.tot())); + checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*idim.tot())); // class colors precompute for(int c=0; cinput_dim.c-1 -i; bgr[ch].download(bgr_h); //TODO: don't copy back on CPU - checkCuda( cudaMemcpy(input_d + i*size, (float*)bgr_h.data, size*sizeof(dnnType), cudaMemcpyHostToDevice)); + checkCuda( cudaMemcpy(input_d + i*size + netRT->input_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,18 +81,18 @@ 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(const bool mAP){ +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); @@ -138,6 +142,7 @@ void Yolo3Detection::postprocess(const bool mAP){ detected.push_back(res); } } + batchDetected.push_back(detected); } From 5d01a3f6295cadc26090d4ab95d0193b31d94fcf Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Thu, 14 May 2020 17:13:38 +0200 Subject: [PATCH 17/78] Fix Centernet postprocessing Signed-off-by: Micaela Verucchi --- src/CenternetDetection.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index cef1375..5d01cc3 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -263,10 +263,10 @@ void CenternetDetection::preprocess(cv::Mat &frame, const int bi){ void CenternetDetection::postprocess(const int bi, const bool mAP){ dnnType *rt_out[4]; - rt_out[0] = (dnnType *)netRT->buffersRT[1]+ netRT->buffersDIM[0].tot()*bi; - rt_out[1] = (dnnType *)netRT->buffersRT[2]+ netRT->buffersDIM[1].tot()*bi; - rt_out[2] = (dnnType *)netRT->buffersRT[3]+ netRT->buffersDIM[2].tot()*bi; - rt_out[3] = (dnnType *)netRT->buffersRT[4]+ netRT->buffersDIM[3].tot()*bi; + 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(); From 23b40de508f7b2e9ae79dab0269cb3a3f4734681 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Fri, 15 May 2020 09:41:27 +0200 Subject: [PATCH 18/78] Add verbose define Signed-off-by: Micaela Verucchi --- demo/demo/demo.cpp | 2 +- include/tkDNN/DetectionNN.h | 6 +++--- include/tkDNN/utils.h | 8 +++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 67d5786..afa5577 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) { 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: "<input_dim; dim.n = nBatches; { - dim.print(); + if(VERBOSE) dim.print(); TIMER_START netRT->infer(dim, input_d); TIMER_STOP - dim.print(); + if(VERBOSE) dim.print(); stats.push_back(t_ns); if(save_times) *times< Date: Fri, 15 May 2020 09:48:59 +0200 Subject: [PATCH 19/78] Add yolo4_berkeley test Signed-off-by: Micaela Verucchi --- tests/yolo4_berkeley/yolo4_berkeley.cfg | 1159 +++++++++++++++++++++++ tests/yolo4_berkeley/yolo4_berkeley.cpp | 666 +++++++++++++ 2 files changed, 1825 insertions(+) create mode 100644 tests/yolo4_berkeley/yolo4_berkeley.cfg create mode 100644 tests/yolo4_berkeley/yolo4_berkeley.cpp diff --git a/tests/yolo4_berkeley/yolo4_berkeley.cfg b/tests/yolo4_berkeley/yolo4_berkeley.cfg new file mode 100644 index 0000000..b11c0a7 --- /dev/null +++ b/tests/yolo4_berkeley/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/yolo4_berkeley/yolo4_berkeley.cpp b/tests/yolo4_berkeley/yolo4_berkeley.cpp new file mode 100644 index 0000000..d10ad59 --- /dev/null +++ b/tests/yolo4_berkeley/yolo4_berkeley.cpp @@ -0,0 +1,666 @@ +#include +#include +#include "tkdnn.h" + +int main() +{ + + // Network layout + tk::dnn::dataDim_t dim(1, 3, 320, 544, 1); + tk::dnn::Network net(dim); + + // create yolo4_berkeley model + std::string bin_path = "yolo4_berkeley"; + int classes = 10; + 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, 45, 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, 45, 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, 45, 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","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("yolo4_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 < 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; +} From 377310af5073e9f56289989662e9be4d406f6c18 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Tue, 19 May 2020 09:32:27 +0200 Subject: [PATCH 20/78] Add variable batch for detector update Signed-off-by: Micaela Verucchi --- demo/demo/demo.cpp | 2 +- demo/demo/map.cpp | 2 +- include/tkDNN/DetectionNN.h | 13 ++++++++----- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index afa5577..76b451d 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -111,7 +111,7 @@ int main(int argc, char *argv[]) { break; //inference - detNN->update(batch_dnn_input); + detNN->update(batch_dnn_input, n_batch); detNN->draw(batch_frame); if(show){ diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index 89f2c0f..aefc834 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -144,7 +144,7 @@ int main(int argc, char *argv[]) //inference detected_bbox.clear(); - detNN->update(batch_dnn_input, write_res_on_file, ×, write_coco_json); + detNN->update(batch_dnn_input,1,write_res_on_file, ×, write_coco_json); detNN->draw(batch_frames); detected_bbox = detNN->detected; diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index 3c56490..fc9a137 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -81,7 +81,7 @@ class DetectionNN { * * @param tensor_path path to the rt file og the NN. * @param n_classes number of classes for the given dataset. - * @param n_batches number of batches to use in inference + * @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, const int n_batches=1) = 0; @@ -90,20 +90,23 @@ class DetectionNN { * This method performs the whole detection of the NN. * * @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(std::vector& frames, bool save_times=false, std::ofstream *times=nullptr, const bool mAP=false){ + 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"); if(VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); { TIMER_START - for(int bi=0; biinput_dim; - dim.n = nBatches; + dim.n = cur_batches; { if(VERBOSE) dim.print(); TIMER_START @@ -129,7 +132,7 @@ class DetectionNN { batchDetected.clear(); { TIMER_START - for(int bi=0; bi Date: Tue, 19 May 2020 16:33:45 +0200 Subject: [PATCH 21/78] Fix original size Signed-off-by: Micaela Verucchi --- include/tkDNN/DetectionNN.h | 5 +++-- src/CenternetDetection.cpp | 2 +- src/MobilenetDetection.cpp | 4 ++-- src/Yolo3Detection.cpp | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index fc9a137..2e64be8 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -30,7 +30,7 @@ class DetectionNN { tk::dnn::NetworkRT *netRT = nullptr; dnnType *input_d; - cv::Size originalSize; + std::vector originalSize; cv::Scalar colors[256]; @@ -103,13 +103,14 @@ class DetectionNN { if(cur_batches > nBatches) FatalError("A batch size greater than nBatches cannot be used"); + originalSize.clear(); if(VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); { TIMER_START for(int bi=0; bipluginFactory->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; From 90dd1d95f3daa9c97fa779ad92c66b4d3691a3d0 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Thu, 28 May 2020 14:44:07 +0200 Subject: [PATCH 22/78] Update LICENSE --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index d159169..2a878a9 100644 --- a/LICENSE +++ b/LICENSE @@ -290,8 +290,8 @@ 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. - - Copyright (C) + 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 From d936e5f740d2ead3286a907e5f3310de85e819ae Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Sat, 30 May 2020 16:57:53 +0200 Subject: [PATCH 23/78] Add mish_yashas Signed-off-by: Micaela Verucchi --- ...{activation.mish.cu => activation_mish.cu} | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) rename src/kernels/{activation.mish.cu => activation_mish.cu} (58%) 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]); } /** From 4e1c7a70b10ab2c4eb39bf1e361aa6e1bfd20ee9 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sat, 30 May 2020 16:58:40 +0200 Subject: [PATCH 24/78] darknet parser interface --- include/tkDNN/DarknetParser.h | 17 +++++++++++++++++ tests/yolo3/yolo3.cpp | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 include/tkDNN/DarknetParser.h diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h new file mode 100644 index 0000000..bc1a8da --- /dev/null +++ b/include/tkDNN/DarknetParser.h @@ -0,0 +1,17 @@ +#pragma once +#include +#include "tkdnn.h" + +namespace tk { namespace dnn { + + tk::dnn::Network* DarknetParser(std::string cfg) { + + tk::dnn::dataDim_t dim; + tk::dnn::Network *net = new tk::dnn::Network(dim); + + + } + + + +}} diff --git a/tests/yolo3/yolo3.cpp b/tests/yolo3/yolo3.cpp index e783f31..324a4c6 100644 --- a/tests/yolo3/yolo3.cpp +++ b/tests/yolo3/yolo3.cpp @@ -1,17 +1,23 @@ #include #include #include "tkdnn.h" +#include "DarknetParser.h" int main() { - // Network layout - tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); - tk::dnn::Network net(dim); + tk::dnn::Network *net = tk::dnn::DarknetParser("../../tests/yolo3/yolo3.cfg"); + // 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" @@ -30,9 +36,10 @@ int main() { //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; @@ -96,4 +103,5 @@ int main() { ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; } return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; + */ } From 15105e90d30e0dc6877a9bee7686f90a31731b38 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Sat, 30 May 2020 17:25:48 +0200 Subject: [PATCH 25/78] Add parseType Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 13 ++++++++++--- tests/yolo3/yolo3.cpp | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index bc1a8da..c07d813 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -9,9 +9,16 @@ namespace tk { namespace dnn { tk::dnn::dataDim_t dim; tk::dnn::Network *net = new tk::dnn::Network(dim); - + } + + std::string parseType(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; } - - }} diff --git a/tests/yolo3/yolo3.cpp b/tests/yolo3/yolo3.cpp index 324a4c6..9187a54 100644 --- a/tests/yolo3/yolo3.cpp +++ b/tests/yolo3/yolo3.cpp @@ -6,6 +6,7 @@ int main() { tk::dnn::Network *net = tk::dnn::DarknetParser("../../tests/yolo3/yolo3.cfg"); + tk::dnn::parseType("[net]"); // Network layout //tk::dnn::dataDim_t dim(1, 3, 416, 416, 1); From 548a3dd33c7aa8a064544e954db503109d4ee5eb Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sat, 30 May 2020 17:27:22 +0200 Subject: [PATCH 26/78] parse line by line --- include/tkDNN/DarknetParser.h | 22 +++++++++++++++++++++- tests/yolo3/yolo3.cpp | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index bc1a8da..7238c99 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -4,12 +4,32 @@ namespace tk { namespace dnn { - tk::dnn::Network* DarknetParser(std::string cfg) { + tk::dnn::Network* DarknetParser(std::string cfg_file) { tk::dnn::dataDim_t dim; tk::dnn::Network *net = new tk::dnn::Network(dim); + std::ifstream if_cfg(cfg_file); + if(!if_cfg.is_open()) + FatalError("cloud not open cfg file: " + cfg_file); + 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 = parseType(line); + if(type.size() > 0) { + std::cout<<"type: "< Date: Sat, 30 May 2020 17:57:48 +0200 Subject: [PATCH 27/78] Add darknetParseFields Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 41 ++++++++++++++++++++++++++++++++++- tests/yolo3/yolo3.cpp | 5 +++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index c921d2c..09d8dce 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -7,9 +7,21 @@ namespace tk { namespace dnn { struct darknetFields_t{ int width = 0; int height = 0; + int channels = 0; + int batch_normalize=0; + int filters=0; + int size=0; + int stride=0; + int pad=0; + std::string activation = ""; }; + std::ostream& operator<<(std::ostream& os, const darknetFields_t& f){ + os << f.width << " " << f.height << " " << f.channels << " " << f.batch_normalize<< " " << f.filters<< " " << f.size<< " " << f.stride << " " << f.pad << " " << f.activation; + return os; + } + std::string darknetParseType(const std::string& line){ size_t start = line.find("["); size_t end = line.find("]"); @@ -20,8 +32,35 @@ namespace tk { namespace dnn { return type; } - darknetFields_t parseFields(const std::string& line){ + 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; + } + + bool darknetParseFields(const std::string& line, darknetFields_t& fields){ + + std::string name,value; + if(!divideNameAndValue(line, name, value)) + return false; + std::cout< Date: Sat, 30 May 2020 17:59:00 +0200 Subject: [PATCH 28/78] parse layer and network --- include/tkDNN/DarknetParser.h | 58 ++++++++++++++++++++++++++++++----- tests/yolo3/yolo3.cpp | 2 +- 2 files changed, 52 insertions(+), 8 deletions(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index c921d2c..76be28c 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -5,9 +5,10 @@ namespace tk { namespace dnn { struct darknetFields_t{ + std::string type = ""; int width = 0; int height = 0; - + int channels = 3; }; std::string darknetParseType(const std::string& line){ @@ -20,21 +21,37 @@ namespace tk { namespace dnn { return type; } - darknetFields_t parseFields(const std::string& line){ - + bool darknetParseFields(const std::string& line, darknetFields_t &fields){ + return true; } + tk::dnn::Network *darknetAddNet(darknetFields_t &fields) { + std::cout<<"Add Net: "< 0) { - std::cout<<"type: "< Date: Sat, 30 May 2020 18:00:22 +0200 Subject: [PATCH 29/78] Add some fields Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 8 ++++++++ tests/yolo3/yolo3.cpp | 2 ++ 2 files changed, 10 insertions(+) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index 09d8dce..d8e8b59 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -59,6 +59,14 @@ namespace tk { namespace dnn { fields.batch_normalize = std::stoi(value); else if (name == "filters") fields.filters = std::stoi(value); + else if (name == "size") + fields.size = std::stoi(value); + else if (name == "stride") + fields.stride = std::stoi(value); + else if (name == "pad") + fields.pad = std::stoi(value); + else if (name == "activation") + fields.activation = value; return true; } diff --git a/tests/yolo3/yolo3.cpp b/tests/yolo3/yolo3.cpp index f74faa5..f1602da 100644 --- a/tests/yolo3/yolo3.cpp +++ b/tests/yolo3/yolo3.cpp @@ -10,6 +10,8 @@ int main() { tk::dnn::darknetFields_t f; tk::dnn::darknetParseFields("width=40", f); tk::dnn::darknetParseFields("height=40", f); + tk::dnn::darknetParseFields("channels=40", f); + tk::dnn::darknetParseFields("activation=leaky", f); std::cout< Date: Sat, 30 May 2020 18:02:20 +0200 Subject: [PATCH 30/78] layer parser --- include/tkDNN/DarknetParser.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index 76be28c..5ba2e54 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -38,6 +38,14 @@ namespace tk { namespace dnn { std::cout<<"Add layer: "< Date: Sat, 30 May 2020 18:10:14 +0200 Subject: [PATCH 31/78] Modify darknetFields_t Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index d8e8b59..8c8309f 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -9,16 +9,25 @@ namespace tk { namespace dnn { int height = 0; int channels = 0; int batch_normalize=0; + int groups = 0; int filters=0; - int size=0; - int stride=0; - int pad=0; + int size_x=0; + int size_y=0; + int stride_x=0; + int stride_y=0; + int padding_x = 0; + int padding_y = 0; + int n_mask = 0; + int classes = 0; + int num = 0; + float scale_xy = 0; + std::vector layers; std::string activation = ""; }; std::ostream& operator<<(std::ostream& os, const darknetFields_t& f){ - os << f.width << " " << f.height << " " << f.channels << " " << f.batch_normalize<< " " << f.filters<< " " << f.size<< " " << f.stride << " " << f.pad << " " << f.activation; + os << f.width << " " << f.height << " " << f.channels << " " << f.batch_normalize<< " " << f.filters << " " << " " << f.activation; return os; } @@ -59,12 +68,6 @@ namespace tk { namespace dnn { fields.batch_normalize = std::stoi(value); else if (name == "filters") fields.filters = std::stoi(value); - else if (name == "size") - fields.size = std::stoi(value); - else if (name == "stride") - fields.stride = std::stoi(value); - else if (name == "pad") - fields.pad = std::stoi(value); else if (name == "activation") fields.activation = value; From e5e6654b1d29be9ce20c94fea5bafbc92750fa6c Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Sat, 30 May 2020 18:44:17 +0200 Subject: [PATCH 32/78] Add fields to darknetParseFields Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 63 +++++++++++++++++++++++++++++------ tests/yolo3/yolo3.cpp | 6 ++-- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index 8c8309f..c640d99 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -20,6 +20,7 @@ namespace tk { namespace dnn { int n_mask = 0; int classes = 0; int num = 0; + int pad = 0; float scale_xy = 0; std::vector layers; std::string activation = ""; @@ -27,7 +28,7 @@ namespace tk { namespace dnn { }; std::ostream& operator<<(std::ostream& os, const darknetFields_t& f){ - os << f.width << " " << f.height << " " << f.channels << " " << f.batch_normalize<< " " << f.filters << " " << " " << f.activation; + os << f.width << " " << f.height << " " << f.channels << " " << f.batch_normalize<< " " << f.filters << " " << f.activation<< " " << f.scale_xy; return os; } @@ -51,26 +52,68 @@ namespace tk { namespace dnn { 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; - std::cout< Date: Sat, 30 May 2020 19:03:29 +0200 Subject: [PATCH 33/78] Add group field Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index c640d99..be87768 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -101,6 +101,8 @@ namespace tk { namespace dnn { fields.classes = std::stoi(value); else if(name.find("num") != std::string::npos) fields.num = std::stoi(value); + else if(name.find("groups") != std::string::npos) + fields.groups = std::stoi(value); else if(name.find("scale_xy") != std::string::npos) fields.scale_xy = std::stof(value); else if(name.find("from") != std::string::npos) From 6d81473b2a6dab2652f8f72baeb07c8c7bcf285c Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sat, 30 May 2020 22:11:00 +0200 Subject: [PATCH 34/78] yolo3 parsed ok --- include/tkDNN/DarknetParser.h | 8 +++++--- tests/yolo3/yolo3.cpp | 12 +++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index 9a1a500..61040f9 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -140,15 +140,17 @@ namespace tk { namespace dnn { if(f.type == "convolutional") { std::string wgs = wgs_path + "/c" + std::to_string(netLayers.size()) + ".bin"; printf("%d (%d,%d) (%d,%d) (%d,%d) %s %d %d\n", f.filters, f.size_x, f.size_y, f.stride_x, f.stride_y, f.padding_x, f.padding_y, wgs.c_str(), f.batch_normalize, f.groups); - netLayers.push_back(new tk::dnn::Conv2d(net, f.filters, f.size_x, f.size_y, f.stride_x, - f.stride_y, f.padding_x, f.padding_y, wgs, f.batch_normalize, false, f.groups)); + tk::dnn::Conv2d *l= new tk::dnn::Conv2d(net, f.filters, f.size_x, f.size_y, f.stride_x, + f.stride_y, f.padding_x, f.padding_y, wgs, f.batch_normalize, false, f.groups); if(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); } - new tk::dnn::Activation(net, act); + netLayers.push_back(new tk::dnn::Activation(net, act)); + } else { + netLayers.push_back(l); } } else if(f.type == "shortcut") { if(f.layers.size() != 1) FatalError("no layers to shortcut\n"); diff --git a/tests/yolo3/yolo3.cpp b/tests/yolo3/yolo3.cpp index 70f0b9f..1036261 100644 --- a/tests/yolo3/yolo3.cpp +++ b/tests/yolo3/yolo3.cpp @@ -12,7 +12,6 @@ int main() { tk::dnn::Network *net = tk::dnn::darknetParser("../tests/yolo3/yolov3.cfg", "yolo3/layers"); net->print(); - std::vector yolo; for(int i=0; inum_layers; i++) { if(net->layers[i]->getLayerType() == tk::dnn::layerType_t::LAYER_YOLO) @@ -24,6 +23,10 @@ int main() { 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"}; } + //convert network to tensorRT + tk::dnn::NetworkRT netRT(net, net->getNetworkRTName("yolo3")); + + std::string input_bin = bin_path + "/layers/input.bin"; std::vector output_bins = { bin_path + "/debug/layer82_out.bin", @@ -36,16 +39,12 @@ int main() { dnnType *input_h; readBinaryFile(input_bin, net->input_dim.tot(), &input_h, &data); - - //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 = net->input_dim; //input dim + tk::dnn::dataDim_t dim1 = net->input_dim; //input dim printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); TIMER_START @@ -80,5 +79,4 @@ int main() { ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT; } return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; - } From 826fcc97c8b38e890465ed02112b1e307fbace36 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 1 Jun 2020 10:34:48 +0200 Subject: [PATCH 35/78] Read classes' names from file Signed-off-by: Micaela Verucchi --- .gitignore | 2 + include/tkDNN/DarknetParser.h | 28 +++++++++--- tests/yolo3/coco.names | 80 +++++++++++++++++++++++++++++++++++ tests/yolo3/yolo3.cpp | 7 +-- 4 files changed, 106 insertions(+), 11 deletions(-) create mode 100644 tests/yolo3/coco.names diff --git a/.gitignore b/.gitignore index 85a8b85..d62c96d 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/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index 61040f9..0f0e12a 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -127,7 +127,7 @@ namespace tk { namespace dnn { } - void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &f, std::string wgs_path, std::vector &netLayers) { + void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &f, std::string wgs_path, std::vector &netLayers, const std::vector& names) { if(net == nullptr) FatalError("Cant add a layer without a Net\n"); @@ -180,14 +180,30 @@ namespace tk { namespace dnn { } 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); - netLayers.push_back(new tk::dnn::Yolo(net, f.classes, f.num/f.n_mask, wgs, 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); + l->classesNames = names; + netLayers.push_back(l); } else{ FatalError("layer not supported: " + f.type); } } - tk::dnn::Network* darknetParser(std::string cfg_file, std::string wgs_path) { + 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)) + 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; @@ -198,6 +214,8 @@ namespace tk { namespace dnn { 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)) { @@ -218,7 +236,7 @@ namespace tk { namespace dnn { if(fields.type == "net") net = darknetAddNet(fields); else - darknetAddLayer(net, fields, wgs_path, netLayers); + darknetAddLayer(net, fields, wgs_path, netLayers, names); } // new type @@ -237,7 +255,7 @@ namespace tk { namespace dnn { // end of filled type if(fields.type != "") { - darknetAddLayer(net, fields, wgs_path, netLayers); + darknetAddLayer(net, fields, wgs_path, netLayers, names); } if(net == nullptr) { diff --git a/tests/yolo3/coco.names b/tests/yolo3/coco.names new file mode 100644 index 0000000..ca76c80 --- /dev/null +++ b/tests/yolo3/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/yolo3/yolo3.cpp b/tests/yolo3/yolo3.cpp index 1036261..89b8283 100644 --- a/tests/yolo3/yolo3.cpp +++ b/tests/yolo3/yolo3.cpp @@ -9,7 +9,7 @@ int main() { std::string bin_path = "yolo3"; downloadWeightsifDoNotExist("yolo3/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download"); - tk::dnn::Network *net = tk::dnn::darknetParser("../tests/yolo3/yolov3.cfg", "yolo3/layers"); + tk::dnn::Network *net = tk::dnn::darknetParser("../tests/yolo3/yolov3.cfg", "yolo3/layers", "../tests/yolo3/coco.names"); net->print(); std::vector yolo; @@ -18,11 +18,6 @@ int main() { yolo.push_back((tk::dnn::Yolo*)net->layers[i]); } - // 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"}; - } - //convert network to tensorRT tk::dnn::NetworkRT netRT(net, net->getNetworkRTName("yolo3")); From a6eef498fabf1ce09a1d67fe61b91f03561ad7de Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 1 Jun 2020 10:39:13 +0200 Subject: [PATCH 36/78] Check Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index 0f0e12a..9008670 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -181,6 +181,8 @@ namespace tk { namespace dnn { 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); + if(names.size() != f.classes) + FatalError("Mismatch between number of classes and names"); l->classesNames = names; netLayers.push_back(l); @@ -197,7 +199,8 @@ namespace tk { namespace dnn { std::vector names; std::string line; while(std::getline(if_names, line)) - names.push_back(line); + if(line != "") + names.push_back(line); if_names.close(); return names; From d8fbee58d8e417ca6649c9b216fe388b2d5c4ed7 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 1 Jun 2020 10:42:06 +0200 Subject: [PATCH 37/78] Add names files Signed-off-by: Micaela Verucchi --- tests/yolo3/berkeley.names | 10 ++++++++++ tests/yolo3/voc.names | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 tests/yolo3/berkeley.names create mode 100644 tests/yolo3/voc.names diff --git a/tests/yolo3/berkeley.names b/tests/yolo3/berkeley.names new file mode 100644 index 0000000..321e633 --- /dev/null +++ b/tests/yolo3/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/yolo3/voc.names b/tests/yolo3/voc.names new file mode 100644 index 0000000..8420ab3 --- /dev/null +++ b/tests/yolo3/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 From d2e2669b6d9170bd3c68a11cfd432d22afd315fc Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Mon, 1 Jun 2020 12:22:55 +0200 Subject: [PATCH 38/78] darknet parse all net to be tested --- CMakeLists.txt | 130 +--- include/tkDNN/models/Yolo3.h | 289 -------- include/tkDNN/test.h | 68 ++ scripts/test_all_tests.sh | 10 +- src/Network.cpp | 3 +- src/NetworkRT.cpp | 2 +- src/Yolo.cpp | 3 +- tests/{ => backbones}/dla34/dla34.cpp | 0 .../dla34/dla34_weightsexporter.py | 0 tests/{ => backbones}/dla34/env_dla34.yml | 0 .../resnet101/env_resnet101.yml | 0 tests/{ => backbones}/resnet101/resnet101.cpp | 0 .../resnet101/resnet101_weightsexporter.py | 0 .../bdd-csresnext50-panet-spp.cpp | 554 --------------- tests/build_models.sh | 18 - .../{ => centernet}/dla34_cnet/dla34_cnet.cpp | 0 .../resnet101_cnet/resnet101_cnet.cpp | 0 .../csresnext50-panet-spp.cpp | 554 --------------- .../cfg}/csresnext50-panet-spp.cfg | 0 .../cfg/csresnext50-panet-spp_berkeley.cfg} | 0 .../{yolo/yolo.cfg => darknet/cfg/yolo2.cfg} | 0 .../cfg/yolo2_voc.cfg} | 0 .../cfg/yolo2tiny.cfg} | 0 .../yolov3.cfg => darknet/cfg/yolo3.cfg} | 0 .../cfg/yolo3_512.cfg} | 28 +- .../cfg}/yolo3_berkeley.cfg | 0 .../cfg/yolo3_coco4.cfg} | 0 .../cfg}/yolo3_flir.cfg | 0 .../cfg/yolo3tiny.cfg} | 0 .../cfg/yolo3tiny_512.cfg} | 12 +- .../yolov4.cfg => darknet/cfg/yolo4.cfg} | 0 tests/darknet/csresnext50-panet-spp.cpp | 33 + .../csresnext50-panet-spp_berkeley.cpp | 33 + tests/{yolo3 => darknet/names}/berkeley.names | 0 tests/{yolo3 => darknet/names}/coco.names | 0 tests/darknet/names/coco4.names | 4 + tests/darknet/names/flir.names | 3 + tests/{yolo3 => darknet/names}/voc.names | 0 tests/darknet/yolo2.cpp | 31 + tests/darknet/yolo2_voc.cpp | 32 + tests/darknet/yolo2tiny.cpp | 31 + tests/darknet/yolo3.cpp | 33 + tests/darknet/yolo3_512.cpp | 33 + tests/darknet/yolo3_berkeley.cpp | 33 + tests/darknet/yolo3_coco4.cpp | 33 + tests/darknet/yolo3_flir.cpp | 33 + tests/darknet/yolo3tiny.cpp | 31 + tests/darknet/yolo3tiny512.cpp | 31 + tests/darknet/yolo4.cpp | 33 + .../{ => exporters}/caffe_weights_exporter.py | 0 .../keras_weights_exporter.py} | 0 .../bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp | 0 .../mobilenetv2ssd/mobilenetv2ssd.cpp | 0 .../mobilenetv2ssd512/mobilenetv2ssd512.cpp | 0 tests/yolo/yolo.cpp | 157 ----- tests/yolo3/yolo3.cpp | 77 -- tests/yolo3_512/yolo3_512.cpp | 99 --- tests/yolo3_512tp/yolo3_512tp.cpp | 97 --- tests/yolo3_berkeley/yolo3_berkeley.cpp | 99 --- tests/yolo3_coco4/yolo3_coco4.cpp | 97 --- tests/yolo3_flir/yolo3_flir.cpp | 100 --- tests/yolo3_tiny/yolo3_tiny.cpp | 130 ---- tests/yolo3_tiny512/yolo3_tiny512.cpp | 128 ---- tests/yolo3_tiny512tp/yolo3_tiny512tp.cpp | 127 ---- tests/yolo3_tinyNM512/yolo3_tinyNM512.cpp | 127 ---- tests/yolo4/yolo4.cpp | 666 ------------------ tests/yolo_224/yolo_224.cfg | 258 ------- tests/yolo_224/yolo_224.cpp | 156 ---- tests/yolo_berkeley/yolo_berkeley.cpp | 156 ---- .../yolov2-voc-10-resize-test.cfg | 259 ------- tests/yolo_relu/yolo_relu.cfg | 258 ------- tests/yolo_relu/yolo_relu.cpp | 155 ---- tests/yolo_tiny/yolo_tiny.cpp | 100 --- tests/yolo_voc/yolo_voc.cpp | 156 ---- 74 files changed, 560 insertions(+), 4940 deletions(-) delete mode 100644 include/tkDNN/models/Yolo3.h create mode 100644 include/tkDNN/test.h rename tests/{ => backbones}/dla34/dla34.cpp (100%) rename tests/{ => backbones}/dla34/dla34_weightsexporter.py (100%) rename tests/{ => backbones}/dla34/env_dla34.yml (100%) rename tests/{ => backbones}/resnet101/env_resnet101.yml (100%) rename tests/{ => backbones}/resnet101/resnet101.cpp (100%) rename tests/{ => backbones}/resnet101/resnet101_weightsexporter.py (100%) delete mode 100644 tests/bdd-csresnext50-panet-spp/bdd-csresnext50-panet-spp.cpp delete mode 100644 tests/build_models.sh rename tests/{ => centernet}/dla34_cnet/dla34_cnet.cpp (100%) rename tests/{ => centernet}/resnet101_cnet/resnet101_cnet.cpp (100%) delete mode 100644 tests/csresnext50-panet-spp/csresnext50-panet-spp.cpp rename tests/{csresnext50-panet-spp => darknet/cfg}/csresnext50-panet-spp.cfg (100%) rename tests/{bdd-csresnext50-panet-spp/berkeleycsresnetx50.cfg => darknet/cfg/csresnext50-panet-spp_berkeley.cfg} (100%) rename tests/{yolo/yolo.cfg => darknet/cfg/yolo2.cfg} (100%) rename tests/{yolo_voc/yolo_voc.cfg => darknet/cfg/yolo2_voc.cfg} (100%) rename tests/{yolo_tiny/tiny-yolo.cfg => darknet/cfg/yolo2tiny.cfg} (100%) rename tests/{yolo3/yolov3.cfg => darknet/cfg/yolo3.cfg} (100%) rename tests/{yolo3_512tp/yolo3512.cfg => darknet/cfg/yolo3_512.cfg} (93%) rename tests/{yolo3_berkeley => darknet/cfg}/yolo3_berkeley.cfg (100%) rename tests/{yolo3_coco4/yolov3-coco4.cfg => darknet/cfg/yolo3_coco4.cfg} (100%) rename tests/{yolo3_flir => darknet/cfg}/yolo3_flir.cfg (100%) rename tests/{yolo3_tiny/yolov3-tiny.cfg => darknet/cfg/yolo3tiny.cfg} (100%) rename tests/{yolo3_tiny512tp/yolo3tiny512.cfg => darknet/cfg/yolo3tiny_512.cfg} (87%) rename tests/{yolo4/yolov4.cfg => darknet/cfg/yolo4.cfg} (100%) create mode 100644 tests/darknet/csresnext50-panet-spp.cpp create mode 100644 tests/darknet/csresnext50-panet-spp_berkeley.cpp rename tests/{yolo3 => darknet/names}/berkeley.names (100%) rename tests/{yolo3 => darknet/names}/coco.names (100%) create mode 100644 tests/darknet/names/coco4.names create mode 100644 tests/darknet/names/flir.names rename tests/{yolo3 => darknet/names}/voc.names (100%) create mode 100644 tests/darknet/yolo2.cpp create mode 100644 tests/darknet/yolo2_voc.cpp create mode 100644 tests/darknet/yolo2tiny.cpp create mode 100644 tests/darknet/yolo3.cpp create mode 100644 tests/darknet/yolo3_512.cpp create mode 100644 tests/darknet/yolo3_berkeley.cpp create mode 100644 tests/darknet/yolo3_coco4.cpp create mode 100644 tests/darknet/yolo3_flir.cpp create mode 100644 tests/darknet/yolo3tiny.cpp create mode 100644 tests/darknet/yolo3tiny512.cpp create mode 100644 tests/darknet/yolo4.cpp rename tests/{ => exporters}/caffe_weights_exporter.py (100%) rename tests/{weights_exporter.py => exporters/keras_weights_exporter.py} (100%) rename tests/{ => mobilenet}/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp (100%) rename tests/{ => mobilenet}/mobilenetv2ssd/mobilenetv2ssd.cpp (100%) rename tests/{ => mobilenet}/mobilenetv2ssd512/mobilenetv2ssd512.cpp (100%) delete mode 100644 tests/yolo/yolo.cpp delete mode 100644 tests/yolo3/yolo3.cpp delete mode 100644 tests/yolo3_512/yolo3_512.cpp delete mode 100644 tests/yolo3_512tp/yolo3_512tp.cpp delete mode 100644 tests/yolo3_berkeley/yolo3_berkeley.cpp delete mode 100644 tests/yolo3_coco4/yolo3_coco4.cpp delete mode 100644 tests/yolo3_flir/yolo3_flir.cpp delete mode 100644 tests/yolo3_tiny/yolo3_tiny.cpp delete mode 100644 tests/yolo3_tiny512/yolo3_tiny512.cpp delete mode 100644 tests/yolo3_tiny512tp/yolo3_tiny512tp.cpp delete mode 100644 tests/yolo3_tinyNM512/yolo3_tinyNM512.cpp delete mode 100644 tests/yolo4/yolo4.cpp delete mode 100644 tests/yolo_224/yolo_224.cfg delete mode 100644 tests/yolo_224/yolo_224.cpp delete mode 100644 tests/yolo_berkeley/yolo_berkeley.cpp delete mode 100644 tests/yolo_berkeley/yolov2-voc-10-resize-test.cfg delete mode 100644 tests/yolo_relu/yolo_relu.cfg delete mode 100644 tests/yolo_relu/yolo_relu.cpp delete mode 100644 tests/yolo_tiny/yolo_tiny.cpp delete mode 100644 tests/yolo_voc/yolo_voc.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 77da651..376c175 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,6 +54,7 @@ target_link_libraries(tkDNN ${tkdnn_LIBS}) #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) @@ -63,91 +64,43 @@ 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_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_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) + +# DEMOS add_executable(test_rtinference tests/test_rtinference/rtinference.cpp) target_link_libraries(test_rtinference tkDNN) @@ -171,18 +124,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/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/test.h b/include/tkDNN/test.h new file mode 100644 index 0000000..0b810da --- /dev/null +++ b/include/tkDNN/test.h @@ -0,0 +1,68 @@ + +#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]); + } + + // 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(); + TIMER_START + net->infer(dim1, data); + TIMER_STOP + dim1.print(); + } + for(int i=0; idstData; + + if(netRT != nullptr) { + tk::dnn::dataDim_t dim2 = net->input_dim; + printCenteredTitle(" TENSORRT inference ", '=', 30); { + dim2.print(); + TIMER_START + netRT->infer(dim2, data); + TIMER_STOP + dim2.print(); + } + for(int i=0; ibuffersRT[i+1]; + } + + int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0; + for(int i=0; idstData; - - 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 100% rename from tests/dla34_cnet/dla34_cnet.cpp rename to tests/centernet/dla34_cnet/dla34_cnet.cpp diff --git a/tests/resnet101_cnet/resnet101_cnet.cpp b/tests/centernet/resnet101_cnet/resnet101_cnet.cpp similarity index 100% rename from tests/resnet101_cnet/resnet101_cnet.cpp rename to tests/centernet/resnet101_cnet/resnet101_cnet.cpp 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 100% rename from tests/yolo_tiny/tiny-yolo.cfg rename to tests/darknet/cfg/yolo2tiny.cfg 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/csresnext50-panet-spp.cpp b/tests/darknet/csresnext50-panet-spp.cpp new file mode 100644 index 0000000..f2f66f6 --- /dev/null +++ b/tests/darknet/csresnext50-panet-spp.cpp @@ -0,0 +1,33 @@ +#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 = "../tests/darknet/cfg/csresnext50-panet-spp.cfg"; + std::string name_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); + 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..ca21399 --- /dev/null +++ b/tests/darknet/csresnext50-panet-spp_berkeley.cpp @@ -0,0 +1,33 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "bdd-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 = "../tests/darknet/cfg/csresnext50-panet-spp_berkeley.cfg"; + std::string name_path = "../tests/darknet/names/berkeley.names"; + // 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); + delete net; + delete netRT; + return ret; +} diff --git a/tests/yolo3/berkeley.names b/tests/darknet/names/berkeley.names similarity index 100% rename from tests/yolo3/berkeley.names rename to tests/darknet/names/berkeley.names diff --git a/tests/yolo3/coco.names b/tests/darknet/names/coco.names similarity index 100% rename from tests/yolo3/coco.names rename to tests/darknet/names/coco.names 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/yolo3/voc.names b/tests/darknet/names/voc.names similarity index 100% rename from tests/yolo3/voc.names rename to tests/darknet/names/voc.names diff --git a/tests/darknet/yolo2.cpp b/tests/darknet/yolo2.cpp new file mode 100644 index 0000000..e6b40a5 --- /dev/null +++ b/tests/darknet/yolo2.cpp @@ -0,0 +1,31 @@ +#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 = "../tests/darknet/cfg/yolo2.cfg"; + std::string name_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); + 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..2efcbcb --- /dev/null +++ b/tests/darknet/yolo2_voc.cpp @@ -0,0 +1,32 @@ +#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 = "../tests/darknet/cfg/yolo2_voc.cfg"; + std::string name_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); + delete net; + delete netRT; + return ret; +} + diff --git a/tests/darknet/yolo2tiny.cpp b/tests/darknet/yolo2tiny.cpp new file mode 100644 index 0000000..fefdaa5 --- /dev/null +++ b/tests/darknet/yolo2tiny.cpp @@ -0,0 +1,31 @@ +#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 = "../tests/darknet/cfg/yolo2tiny.cfg"; + std::string name_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); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3.cpp b/tests/darknet/yolo3.cpp new file mode 100644 index 0000000..b96d79a --- /dev/null +++ b/tests/darknet/yolo3.cpp @@ -0,0 +1,33 @@ +#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 = "../tests/darknet/cfg/yolo3.cfg"; + std::string name_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); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3_512.cpp b/tests/darknet/yolo3_512.cpp new file mode 100644 index 0000000..11a7839 --- /dev/null +++ b/tests/darknet/yolo3_512.cpp @@ -0,0 +1,33 @@ +#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 = "../tests/darknet/cfg/yolo3_512.cfg"; + std::string name_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); + 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..6c3512c --- /dev/null +++ b/tests/darknet/yolo3_berkeley.cpp @@ -0,0 +1,33 @@ +#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 = "../tests/darknet/cfg/yolo3_berkeley.cfg"; + std::string name_path = "../tests/darknet/names/barkeley.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); + 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..cf69a26 --- /dev/null +++ b/tests/darknet/yolo3_coco4.cpp @@ -0,0 +1,33 @@ +#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 = "../tests/darknet/cfg/yolo3_coco4.cfg"; + std::string name_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); + 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..fd5c1d5 --- /dev/null +++ b/tests/darknet/yolo3_flir.cpp @@ -0,0 +1,33 @@ +#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 = "../tests/darknet/cfg/yolo3_flir.cfg"; + std::string name_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); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3tiny.cpp b/tests/darknet/yolo3tiny.cpp new file mode 100644 index 0000000..247b152 --- /dev/null +++ b/tests/darknet/yolo3tiny.cpp @@ -0,0 +1,31 @@ +#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/layer23_out.bin", + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = "../tests/darknet/cfg/yolo3tiny.cfg"; + std::string name_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); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo3tiny512.cpp b/tests/darknet/yolo3tiny512.cpp new file mode 100644 index 0000000..495033a --- /dev/null +++ b/tests/darknet/yolo3tiny512.cpp @@ -0,0 +1,31 @@ +#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/layer23_out.bin", + }; + std::string wgs_path = bin_path + "/layers"; + std::string cfg_path = "../tests/darknet/cfg/yolo3tiny_512.cfg"; + std::string name_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); + delete net; + delete netRT; + return ret; +} diff --git a/tests/darknet/yolo4.cpp b/tests/darknet/yolo4.cpp new file mode 100644 index 0000000..70257d2 --- /dev/null +++ b/tests/darknet/yolo4.cpp @@ -0,0 +1,33 @@ +#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 = "../tests/darknet/cfg/yolo4.cfg"; + std::string name_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); + 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/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp b/tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp similarity index 100% rename from tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp rename to tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp diff --git a/tests/mobilenetv2ssd/mobilenetv2ssd.cpp b/tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp similarity index 100% rename from tests/mobilenetv2ssd/mobilenetv2ssd.cpp rename to tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp diff --git a/tests/mobilenetv2ssd512/mobilenetv2ssd512.cpp b/tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp similarity index 100% rename from tests/mobilenetv2ssd512/mobilenetv2ssd512.cpp rename to tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp diff --git a/tests/yolo/yolo.cpp b/tests/yolo/yolo.cpp deleted file mode 100644 index e47fd8f..0000000 --- a/tests/yolo/yolo.cpp +++ /dev/null @@ -1,157 +0,0 @@ -#include -#include "tkdnn.h" - -const char *input_bin = "yolo/layers/input.bin"; -const char *c0_bin = "yolo/layers/c0.bin"; -const char *c2_bin = "yolo/layers/c2.bin"; -const char *c4_bin = "yolo/layers/c4.bin"; -const char *c5_bin = "yolo/layers/c5.bin"; -const char *c6_bin = "yolo/layers/c6.bin"; -const char *c8_bin = "yolo/layers/c8.bin"; -const char *c9_bin = "yolo/layers/c9.bin"; -const char *c10_bin = "yolo/layers/c10.bin"; -const char *c12_bin = "yolo/layers/c12.bin"; -const char *c13_bin = "yolo/layers/c13.bin"; -const char *c14_bin = "yolo/layers/c14.bin"; -const char *c15_bin = "yolo/layers/c15.bin"; -const char *c16_bin = "yolo/layers/c16.bin"; -const char *c18_bin = "yolo/layers/c18.bin"; -const char *c19_bin = "yolo/layers/c19.bin"; -const char *c20_bin = "yolo/layers/c20.bin"; -const char *c21_bin = "yolo/layers/c21.bin"; -const char *c22_bin = "yolo/layers/c22.bin"; -const char *c23_bin = "yolo/layers/c23.bin"; -const char *c24_bin = "yolo/layers/c24.bin"; -const char *c26_bin = "yolo/layers/c26.bin"; -const char *c29_bin = "yolo/layers/c29.bin"; -const char *c30_bin = "yolo/layers/c30.bin"; -const char *g31_bin = "yolo/layers/g31.bin"; -const char *output_bin = "yolo/layers/output.bin"; - -int main() { - - downloadWeightsifDoNotExist(input_bin, "yolo", "https://cloud.hipert.unimore.it/s/nf4PJ3k8bxBETwL/download"); - - // 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, 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")); - - 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/yolo3/yolo3.cpp b/tests/yolo3/yolo3.cpp deleted file mode 100644 index 89b8283..0000000 --- a/tests/yolo3/yolo3.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include "tkdnn.h" -#include "DarknetParser.h" - -int main() { - - // create yolo3 model - std::string bin_path = "yolo3"; - downloadWeightsifDoNotExist("yolo3/layers/input.bin", bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download"); - - tk::dnn::Network *net = tk::dnn::darknetParser("../tests/yolo3/yolov3.cfg", "yolo3/layers", "../tests/yolo3/coco.names"); - net->print(); - - std::vector yolo; - for(int i=0; inum_layers; i++) { - if(net->layers[i]->getLayerType() == tk::dnn::layerType_t::LAYER_YOLO) - yolo.push_back((tk::dnn::Yolo*)net->layers[i]); - } - - //convert network to tensorRT - tk::dnn::NetworkRT netRT(net, net->getNetworkRTName("yolo3")); - - - 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" - }; - - // Load input - dnnType *data; - dnnType *input_h; - readBinaryFile(input_bin, net->input_dim.tot(), &input_h, &data); - - // 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 = net->input_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; - - - tk::dnn::dataDim_t dim2 = net->input_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/yolo3_512/yolo3_512.cpp b/tests/yolo3_512/yolo3_512.cpp deleted file mode 100644 index 5e796c1..0000000 --- a/tests/yolo3_512/yolo3_512.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include -#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.cfg b/tests/yolo_224/yolo_224.cfg deleted file mode 100644 index dd9206c..0000000 --- a/tests/yolo_224/yolo_224.cfg +++ /dev/null @@ -1,258 +0,0 @@ -[net] -# Testing -#batch=1 -#subdivisions=1 -# Training - batch=64 - subdivisions=16 -width=224 -height=224 -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=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=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_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; -} From 18794d52c28be700c79f5e7d927122802a8b12d2 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Mon, 1 Jun 2020 14:55:08 +0200 Subject: [PATCH 39/78] darknet parser tested --- include/tkDNN/DarknetParser.h | 47 ++++++++++++++----- include/tkDNN/Network.h | 1 + include/tkDNN/test.h | 5 ++ scripts/test_all_tests.sh | 3 +- src/Network.cpp | 8 +++- src/Region.cpp | 3 +- tests/darknet/cfg/yolo2tiny.cfg | 8 ++-- tests/darknet/csresnext50-panet-spp.cpp | 1 + .../csresnext50-panet-spp_berkeley.cpp | 4 +- tests/darknet/yolo2.cpp | 3 +- tests/darknet/yolo2_voc.cpp | 1 + tests/darknet/yolo2tiny.cpp | 6 ++- tests/darknet/yolo3.cpp | 3 +- tests/darknet/yolo3_512.cpp | 1 + tests/darknet/yolo3_berkeley.cpp | 3 +- tests/darknet/yolo3_coco4.cpp | 1 + tests/darknet/yolo3_flir.cpp | 1 + tests/darknet/yolo3tiny.cpp | 4 +- .../{yolo3tiny512.cpp => yolo3tiny_512.cpp} | 4 +- tests/darknet/yolo4.cpp | 1 + tests/darknet/yolo4_berkeley.cpp | 34 ++++++++++++++ 21 files changed, 112 insertions(+), 30 deletions(-) rename tests/darknet/{yolo3tiny512.cpp => yolo3tiny_512.cpp} (89%) create mode 100644 tests/darknet/yolo4_berkeley.cpp diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index 9008670..a918a5b 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -22,6 +22,7 @@ namespace tk { namespace dnn { int classes = 20; int num = 1; int pad = 0; + int coords = 4; float scale_xy = 1; std::vector layers; std::string activation = "linear"; @@ -102,9 +103,11 @@ namespace tk { namespace dnn { 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("scale_xy") != std::string::npos) + else if(name.find("scale_x_y") != std::string::npos) fields.scale_xy = std::stof(value); else if(name.find("from") != std::string::npos) fields.layers.push_back(std::stof(value)); @@ -135,23 +138,25 @@ namespace tk { namespace dnn { if(f.pad == 1) { f.padding_x = f.padding_y = f.size_x /2; } - std::cout<<"Add layer: "< 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){ @@ -244,7 +265,7 @@ namespace tk { namespace dnn { // new type //std::cout<<"type: "< input_bins, std::vector 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) { diff --git a/scripts/test_all_tests.sh b/scripts/test_all_tests.sh index 1a621f7..b530606 100644 --- a/scripts/test_all_tests.sh +++ b/scripts/test_all_tests.sh @@ -78,9 +78,10 @@ do test_net yolo3_512 test_net yolo3tiny test_net csresnext50-panet-spp + #test_net csresnext50-panet-spp_berkeley test_net mobilenetv2ssd test_net yolo3tiny_512 - test_net yolo2tiny + #test_net yolo2tiny test_net mobilenetv2ssd512 test_net mnist test_net yolo2 diff --git a/src/Network.cpp b/src/Network.cpp index 6801ba3..9adcc48 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -59,12 +59,16 @@ Network::Network(dataDim_t input_dim) { } Network::~Network() { - for(int i=0; iclasses = classes; this->coords = coords; this->num = num; diff --git a/tests/darknet/cfg/yolo2tiny.cfg b/tests/darknet/cfg/yolo2tiny.cfg index 630a209..2884bb4 100644 --- a/tests/darknet/cfg/yolo2tiny.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/darknet/csresnext50-panet-spp.cpp b/tests/darknet/csresnext50-panet-spp.cpp index f2f66f6..1da95b2 100644 --- a/tests/darknet/csresnext50-panet-spp.cpp +++ b/tests/darknet/csresnext50-panet-spp.cpp @@ -27,6 +27,7 @@ int main() { 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 index ca21399..47bbfd4 100644 --- a/tests/darknet/csresnext50-panet-spp_berkeley.cpp +++ b/tests/darknet/csresnext50-panet-spp_berkeley.cpp @@ -5,7 +5,7 @@ #include "DarknetParser.h" int main() { - std::string bin_path = "bdd-csresnext50-panet-spp"; + std::string bin_path = "csresnext50-panet-spp_berkeley"; std::vector input_bins = { bin_path + "/layers/input.bin" }; @@ -17,6 +17,7 @@ int main() { std::string wgs_path = bin_path + "/layers"; std::string cfg_path = "../tests/darknet/cfg/csresnext50-panet-spp_berkeley.cfg"; std::string name_path = "../tests/darknet/names/berkeley.names"; + // FIXME: wrong weights // downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s//download"); // parse darknet network @@ -27,6 +28,7 @@ int main() { 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.cpp b/tests/darknet/yolo2.cpp index e6b40a5..7a46c31 100644 --- a/tests/darknet/yolo2.cpp +++ b/tests/darknet/yolo2.cpp @@ -10,7 +10,7 @@ int main() { bin_path + "/layers/input.bin" }; std::vector output_bins = { - bin_path + "layers/output.bin" + bin_path + "/layers/output.bin" }; std::string wgs_path = bin_path + "/layers"; std::string cfg_path = "../tests/darknet/cfg/yolo2.cfg"; @@ -25,6 +25,7 @@ int main() { 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 index 2efcbcb..eab215b 100644 --- a/tests/darknet/yolo2_voc.cpp +++ b/tests/darknet/yolo2_voc.cpp @@ -25,6 +25,7 @@ int main() { 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 index fefdaa5..64faa36 100644 --- a/tests/darknet/yolo2tiny.cpp +++ b/tests/darknet/yolo2tiny.cpp @@ -10,12 +10,13 @@ int main() { bin_path + "/layers/input.bin" }; std::vector output_bins = { - bin_path + "layers/output.bin" + bin_path + "/layers/output.bin" }; std::string wgs_path = bin_path + "/layers"; std::string cfg_path = "../tests/darknet/cfg/yolo2tiny.cfg"; std::string name_path = "../tests/darknet/names/coco.names"; - downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/nf4PJ3k8bxBETwL/download"); + // 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); @@ -25,6 +26,7 @@ int main() { 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 index b96d79a..ea53b84 100644 --- a/tests/darknet/yolo3.cpp +++ b/tests/darknet/yolo3.cpp @@ -26,7 +26,8 @@ int main() { //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); + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); delete net; delete netRT; return ret; diff --git a/tests/darknet/yolo3_512.cpp b/tests/darknet/yolo3_512.cpp index 11a7839..a67c3a7 100644 --- a/tests/darknet/yolo3_512.cpp +++ b/tests/darknet/yolo3_512.cpp @@ -27,6 +27,7 @@ int main() { 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 index 6c3512c..a71fe83 100644 --- a/tests/darknet/yolo3_berkeley.cpp +++ b/tests/darknet/yolo3_berkeley.cpp @@ -16,7 +16,7 @@ int main() { }; std::string wgs_path = bin_path + "/layers"; std::string cfg_path = "../tests/darknet/cfg/yolo3_berkeley.cfg"; - std::string name_path = "../tests/darknet/names/barkeley.names"; + std::string name_path = "../tests/darknet/names/berkeley.names"; downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/o5cHa4AjTKS64oD/download"); // parse darknet network @@ -27,6 +27,7 @@ int main() { 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 index cf69a26..a651430 100644 --- a/tests/darknet/yolo3_coco4.cpp +++ b/tests/darknet/yolo3_coco4.cpp @@ -27,6 +27,7 @@ int main() { 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 index fd5c1d5..678f10f 100644 --- a/tests/darknet/yolo3_flir.cpp +++ b/tests/darknet/yolo3_flir.cpp @@ -27,6 +27,7 @@ int main() { 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 index 247b152..01fc6f9 100644 --- a/tests/darknet/yolo3tiny.cpp +++ b/tests/darknet/yolo3tiny.cpp @@ -10,7 +10,8 @@ int main() { bin_path + "/layers/input.bin" }; std::vector output_bins = { - bin_path + "debug/layer23_out.bin", + bin_path + "/debug/layer16_out.bin", + bin_path + "/debug/layer23_out.bin", }; std::string wgs_path = bin_path + "/layers"; std::string cfg_path = "../tests/darknet/cfg/yolo3tiny.cfg"; @@ -25,6 +26,7 @@ int main() { 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/yolo3tiny512.cpp b/tests/darknet/yolo3tiny_512.cpp similarity index 89% rename from tests/darknet/yolo3tiny512.cpp rename to tests/darknet/yolo3tiny_512.cpp index 495033a..8153b0d 100644 --- a/tests/darknet/yolo3tiny512.cpp +++ b/tests/darknet/yolo3tiny_512.cpp @@ -10,7 +10,8 @@ int main() { bin_path + "/layers/input.bin" }; std::vector output_bins = { - bin_path + "debug/layer23_out.bin", + bin_path + "/debug/layer16_out.bin", + bin_path + "/debug/layer23_out.bin", }; std::string wgs_path = bin_path + "/layers"; std::string cfg_path = "../tests/darknet/cfg/yolo3tiny_512.cfg"; @@ -25,6 +26,7 @@ int main() { 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 index 70257d2..80b12ce 100644 --- a/tests/darknet/yolo4.cpp +++ b/tests/darknet/yolo4.cpp @@ -27,6 +27,7 @@ int main() { 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..db534b7 --- /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 = "../tests/darknet/cfg/yolo4_berkeley.cfg"; + std::string name_path = "../tests/darknet/names/berkeley.names"; + 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; +} From a0e4e9f209641a2d43f0fbcf799445d91c8e1364 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 1 Jun 2020 15:17:53 +0200 Subject: [PATCH 40/78] Modify yolov4_berkeley link for download, clean to merge with master Signed-off-by: Micaela Verucchi --- CMakeLists.txt | 9 - demo/demo/map.cpp | 2 +- include/tkDNN/DetectionNN.h | 8 +- include/tkDNN/utils.h | 4 +- tests/yolo4/yolo4_320.cpp | 666 ------------------------ tests/yolo4/yolo4_512.cpp | 666 ------------------------ tests/yolo4/yolo4_608.cpp | 666 ------------------------ tests/yolo4_berkeley/yolo4_berkeley.cpp | 2 +- 8 files changed, 8 insertions(+), 2015 deletions(-) delete mode 100644 tests/yolo4/yolo4_320.cpp delete mode 100644 tests/yolo4/yolo4_512.cpp delete mode 100644 tests/yolo4/yolo4_608.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 1e80b87..ef593ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,15 +116,6 @@ target_link_libraries(test_yolo3_flir tkDNN) add_executable(test_yolo4 tests/yolo4/yolo4.cpp) target_link_libraries(test_yolo4 tkDNN) -add_executable(test_yolo4_320 tests/yolo4/yolo4_320.cpp) -target_link_libraries(test_yolo4_320 tkDNN) - -add_executable(test_yolo4_512 tests/yolo4/yolo4_512.cpp) -target_link_libraries(test_yolo4_512 tkDNN) - -add_executable(test_yolo4_608 tests/yolo4/yolo4_608.cpp) -target_link_libraries(test_yolo4_608 tkDNN) - add_executable(test_yolo4_berkeley tests/yolo4_berkeley/yolo4_berkeley.cpp) target_link_libraries(test_yolo4_berkeley tkDNN) diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index aefc834..60aa7fa 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -210,7 +210,7 @@ int main(int argc, char *argv[]) } if(write_coco_json){ - coco_json.seekp (coco_json.tellp()-2); + coco_json.seekp (coco_json.tellp() - std::streampos(2)); coco_json << "\n]\n"; coco_json.close(); } diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index 2e64be8..144ded5 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 @@ -104,7 +104,7 @@ class DetectionNN { FatalError("A batch size greater than nBatches cannot be used"); originalSize.clear(); - if(VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); + if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); { TIMER_START for(int bi=0; biinput_dim; dim.n = cur_batches; { - if(VERBOSE) dim.print(); + if(TKDNN_VERBOSE) dim.print(); TIMER_START netRT->infer(dim, input_d); TIMER_STOP - if(VERBOSE) dim.print(); + if(TKDNN_VERBOSE) dim.print(); stats.push_back(t_ns); if(save_times) *times< -#include -#include "tkdnn.h" - -int main() -{ - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 320, 320, 1); - tk::dnn::Network net(dim); - - // create yolo4_320 model - std::string bin_path = "yolo4_320"; - 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_320")); - - // 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/yolo4/yolo4_512.cpp b/tests/yolo4/yolo4_512.cpp deleted file mode 100644 index 963df75..0000000 --- a/tests/yolo4/yolo4_512.cpp +++ /dev/null @@ -1,666 +0,0 @@ -#include -#include -#include "tkdnn.h" - -int main() -{ - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 512, 512, 1); - tk::dnn::Network net(dim); - - // create yolo4_512 model - std::string bin_path = "yolo4_512"; - 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_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 < 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/yolo4/yolo4_608.cpp b/tests/yolo4/yolo4_608.cpp deleted file mode 100644 index 64d8f34..0000000 --- a/tests/yolo4/yolo4_608.cpp +++ /dev/null @@ -1,666 +0,0 @@ -#include -#include -#include "tkdnn.h" - -int main() -{ - - // Network layout - tk::dnn::dataDim_t dim(1, 3, 608, 608, 1); - tk::dnn::Network net(dim); - - // create yolo4_608 model - std::string bin_path = "yolo4_608"; - 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_608")); - - // 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/yolo4_berkeley/yolo4_berkeley.cpp b/tests/yolo4_berkeley/yolo4_berkeley.cpp index d10ad59..f80a0ac 100644 --- a/tests/yolo4_berkeley/yolo4_berkeley.cpp +++ b/tests/yolo4_berkeley/yolo4_berkeley.cpp @@ -174,7 +174,7 @@ int main() std::string g161_bin = bin_path + "/layers/g161.bin"; - downloadWeightsifDoNotExist(input_bin, bin_path, "https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download"); + downloadWeightsifDoNotExist(input_bin, bin_path, "https://cloud.hipert.unimore.it/s/nkWFa5fgb4NTdnB/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); From c8ed6d782a143e25972fc6797e044188e2d308c9 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Mon, 1 Jun 2020 16:15:29 +0200 Subject: [PATCH 41/78] all test ok --- include/tkDNN/DarknetParser.h | 12 ++++++------ include/tkDNN/DetectionNN.h | 12 ++++++------ include/tkDNN/test.h | 8 ++++---- include/tkDNN/utils.h | 6 +++--- tests/backbones/dla34/dla34.cpp | 8 ++++---- tests/backbones/resnet101/resnet101.cpp | 8 ++++---- tests/centernet/dla34_cnet/dla34_cnet.cpp | 8 ++++---- tests/centernet/resnet101_cnet/resnet101_cnet.cpp | 8 ++++---- tests/imuodom/imuodom.cpp | 4 ++-- tests/mnist/test_mnist.cpp | 8 ++++---- tests/mnist/test_mnistRT.cpp | 8 ++++---- .../bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp | 8 ++++---- tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp | 8 ++++---- .../mobilenetv2ssd512/mobilenetv2ssd512.cpp | 8 ++++---- tests/simple/test_simple.cpp | 8 ++++---- tests/test_rtinference/rtinference.cpp | 4 ++-- 16 files changed, 63 insertions(+), 63 deletions(-) diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index a918a5b..cbeed48 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -124,7 +124,7 @@ namespace tk { namespace dnn { } tk::dnn::Network *darknetAddNet(darknetFields_t &fields) { - std::cout<<"Add Net: "<= netLayers.size()) FatalError("impossible to shortcut\n"); - std::cout<<"shortcut to "<getLayerName()<<"\n"; + //std::cout<<"shortcut to "<getLayerName()<<"\n"; netLayers.push_back(new tk::dnn::Shortcut(net, netLayers[layerIdx])); } else if(f.type == "upsample") { @@ -177,7 +177,7 @@ namespace tk { namespace dnn { if(layerIdx < 0) layerIdx = netLayers.size() + layerIdx; if(layerIdx < 0 || layerIdx >= netLayers.size()) FatalError("impossible to route\n"); - std::cout<<"Route to "<getLayerName()<<"\n"; + //std::cout<<"Route to "<getLayerName()<<"\n"; layers.push_back(netLayers[layerIdx]); } netLayers.push_back(new tk::dnn::Route(net, layers.data(), layers.size())); @@ -190,7 +190,7 @@ namespace tk { namespace dnn { } 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); + //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); if(names.size() != f.classes) FatalError("Mismatch between number of classes and names"); diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index 144ded5..030cf8f 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -106,14 +106,14 @@ class DetectionNN { originalSize.clear(); if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30); { - TIMER_START + TKDNN_TSTART for(int bi=0; biinfer(dim, input_d); - TIMER_STOP + TKDNN_TSTOP if(TKDNN_VERBOSE) dim.print(); stats.push_back(t_ns); if(save_times) *times< input_bins, std::vector tk::dnn::dataDim_t dim1 = net->input_dim; //input dim printCenteredTitle(" CUDNN inference ", '=', 30); { dim1.print(); - TIMER_START + TKDNN_TSTART net->infer(dim1, data); - TIMER_STOP + TKDNN_TSTOP dim1.print(); } for(int i=0; idstData; @@ -45,9 +45,9 @@ int testInference(std::vector input_bins, std::vector tk::dnn::dataDim_t dim2 = net->input_dim; printCenteredTitle(" TENSORRT inference ", '=', 30); { dim2.print(); - TIMER_START + TKDNN_TSTART netRT->infer(dim2, data); - TIMER_STOP + TKDNN_TSTOP dim2.print(); } for(int i=0; ibuffersRT[i+1]; diff --git a/include/tkDNN/utils.h b/include/tkDNN/utils.h index cc9a4cd..f9f6ae7 100644 --- a/include/tkDNN/utils.h +++ b/include/tkDNN/utils.h @@ -39,15 +39,15 @@ #define TKDNN_VERBOSE 0 // Simple Timer -#define TIMER_START timespec start, end; \ +#define TKDNN_TSTART timespec start, end; \ clock_gettime(CLOCK_MONOTONIC, &start); -#define TIMER_STOP_C(col, show) clock_gettime(CLOCK_MONOTONIC, &end); \ +#define TKDNN_TSTOP_C(col, show) clock_gettime(CLOCK_MONOTONIC, &end); \ double t_ns = ((double)(end.tv_sec - start.tv_sec) * 1.0e9 + \ (double)(end.tv_nsec - start.tv_nsec))/1.0e6; \ if(show) std::cout<enqueue(1, buffers, stream, nullptr); - TIMER_STOP + TKDNN_TSTOP checkCuda(cudaMemcpyAsync(output, buffers[outputIndex],10*sizeof(float), cudaMemcpyDeviceToHost, stream)); cudaStreamSynchronize(stream); } diff --git a/tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp b/tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp index 1549983..c3c6472 100644 --- a/tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp +++ b/tests/mobilenet/bdd-mobilenetv2ssd/bdd-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/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp b/tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp index 787341f..58463a4 100644 --- a/tests/mobilenet/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/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp b/tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp index 8886232..54b00c1 100644 --- a/tests/mobilenet/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 4b6b21f..a629168 100644 --- a/tests/test_rtinference/rtinference.cpp +++ b/tests/test_rtinference/rtinference.cpp @@ -42,9 +42,9 @@ int main(int argc, char *argv[]) { checkCuda(cudaMemcpy(input_d, input, idim.tot()*sizeof(dnnType), cudaMemcpyHostToDevice)); tk::dnn::dataDim_t dim = idim; - TIMER_START + TKDNN_TSTART netRT.infer(dim, input_d); - TIMER_STOP + TKDNN_TSTOP total_time+= t_ns; // control output From 2f243f26e5d07b9c0fc89a5aa7bd120cdf9af223 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Mon, 1 Jun 2020 19:04:39 +0200 Subject: [PATCH 42/78] readme update --- README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0593bcb..3a73bec 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,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. ``` @@ -113,6 +112,34 @@ cd pytorch-ssd conda env create -f env_mobv2ssd.yml python run_ssd_live_demo.py mb2-ssd-lite ``` + +## Darknet Parser +tkDNN implement and easy parser for darknet cfg files, a network can be converted with *tk::dnn::darknetParser*: +``` +// example of parsing yolo4 +tk::dnn::Network *net = tk::dnn::darknetParser("yolov4.cfg", "yolov4/layers", "coco.names"); +net->print(); +``` +All models from darknet are now parsed directly from cfg, you still need to export the weights with the descripted tools in the previus section. +
+ Supported layers + convolutional + maxpool + avgpool + shortcut + upsample + route + reorg + region + yolo +
+
+ Supported activations + relu + leaky + mish +
+ ## Run the demo To run the an object detection demo follow these steps (example with yolov3): From 0458f361b1589f9ea9c61bdbdeccf932a4b37ce1 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Mon, 1 Jun 2020 21:03:37 +0200 Subject: [PATCH 43/78] release layer wgs and version update --- include/tkDNN/Layer.h | 64 +++++++++++++++++++++++++++++++++++-------- include/tkDNN/tkdnn.h | 2 +- src/LayerWgs.cpp | 25 +++++------------ 3 files changed, 60 insertions(+), 31 deletions(-) diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index e2295a7..9154e1b 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -108,24 +108,64 @@ public: // additional bias for DCN bool additional_bias; - dnnType *bias2_h, *bias2_d; + dnnType *bias2_h = nullptr, *bias2_d = nullptr; //batchnorm bool batchnorm; - dnnType *power_h; - dnnType *scales_h, *scales_d; - dnnType *mean_h, *mean_d; - dnnType *variance_h, *variance_d; + dnnType *power_h = nullptr; + dnnType *scales_h = nullptr, *scales_d = nullptr; + dnnType *mean_h = nullptr, *mean_d = nullptr; + dnnType *variance_h = nullptr, *variance_d = nullptr; //fp16 - __half *data16_h, *bias16_h; - __half *data16_d, *bias16_d; - __half *bias216_h, *bias216_d; + __half *data16_h = nullptr, *bias16_h = nullptr; + __half *data16_d = nullptr, *bias16_d = nullptr; + __half *bias216_h = nullptr, *bias216_d = nullptr; - __half *power16_h, *power16_d; - __half *scales16_h, *scales16_d; - __half *mean16_h, *mean16_d; - __half *variance16_h, *variance16_d; + __half *power16_h = nullptr; + __half *scales16_h = nullptr, *scales16_d = nullptr; + __half *mean16_h = nullptr, *mean16_d = nullptr; + __half *variance16_h = nullptr, *variance16_d = nullptr; + + void releaseHost(bool release32 = true, bool release16 = true) { + if(release32) { + if( data_h != nullptr) { delete [] data_h; data_h = nullptr; } + if( bias_h != nullptr) { delete [] bias_h; bias_h = nullptr; } + if( bias2_h != nullptr) { delete [] bias2_h; bias2_h = nullptr; } + if( scales_h != nullptr) { delete [] scales_h; scales_h = nullptr; } + if( mean_h != nullptr) { delete [] mean_h; mean_h = nullptr; } + if(variance_h != nullptr) { delete [] variance_h; variance_h = nullptr; } + if( power_h != nullptr) { delete [] power_h; power_h = nullptr; } + } + if(net->fp16 && release16) { + if( data16_h != nullptr) { delete [] data16_h; data16_h = nullptr; } + if( bias16_h != nullptr) { delete [] bias16_h; bias16_h = nullptr; } + if( bias216_h != nullptr) { delete [] bias216_h; bias216_h = nullptr; } + if( scales16_h != nullptr) { delete [] scales16_h; scales16_h = nullptr; } + if( mean16_h != nullptr) { delete [] mean16_h; mean16_h = nullptr; } + if(variance16_h != nullptr) { delete [] variance16_h; variance16_h = nullptr; } + if( power16_h != nullptr) { delete [] power16_h; power16_h = nullptr; } + + } + } + void releaseDevice(bool release32 = true, bool release16 = true) { + if(release32) { + if( data_d != nullptr) { cudaFree( data_d); data_d = nullptr; } + if( bias_d != nullptr) { cudaFree( bias_d); bias_d = nullptr; } + if( bias2_d != nullptr) { cudaFree( bias2_d); bias2_d = nullptr; } + if( scales_d != nullptr) { cudaFree( scales_d); scales_d = nullptr; } + if( mean_d != nullptr) { cudaFree( mean_d); mean_d = nullptr; } + if(variance_d != nullptr) { cudaFree(variance_d); variance_d = nullptr; } + } + if(net->fp16 && release16) { + if( data16_d != nullptr) { cudaFree( data16_d); data16_d = nullptr; } + if( bias16_d != nullptr) { cudaFree( bias16_d); bias16_d = nullptr; } + if( bias216_d != nullptr) { cudaFree( bias216_d); bias216_d = nullptr; } + if( scales16_d != nullptr) { cudaFree( scales16_d); scales16_d = nullptr; } + if( mean16_d != nullptr) { cudaFree( mean16_d); mean16_d = nullptr; } + if(variance16_d != nullptr) { cudaFree(variance16_d); variance16_d = nullptr; } + } + } }; diff --git a/include/tkDNN/tkdnn.h b/include/tkDNN/tkdnn.h index 554daa1..26aaa0b 100644 --- a/include/tkDNN/tkdnn.h +++ b/include/tkDNN/tkdnn.h @@ -5,4 +5,4 @@ #include "Layer.h" #include "NetworkRT.h" -#define TKDNN_VERSION 400 +#define TKDNN_VERSION 500 diff --git a/src/LayerWgs.cpp b/src/LayerWgs.cpp index 017563f..21edf79 100644 --- a/src/LayerWgs.cpp +++ b/src/LayerWgs.cpp @@ -80,7 +80,7 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, variance16_h = new __half[b_size]; scales16_h = new __half[b_size]; - cudaMalloc(&power16_d, b_size*sizeof(__half)); + //cudaMalloc(&power16_d, b_size*sizeof(__half)); cudaMalloc(&mean16_d, b_size*sizeof(__half)); cudaMalloc(&variance16_d, b_size*sizeof(__half)); cudaMalloc(&scales16_d, b_size*sizeof(__half)); @@ -91,11 +91,10 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, //init power array of ones cudaMemcpy(tmp_d, power_h, b_size*sizeof(float), cudaMemcpyHostToDevice); - float2half(tmp_d, power16_d, b_size); - cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost); + //float2half(tmp_d, power16_d, b_size); + //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); @@ -109,24 +108,14 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, //conver 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(); } }} From 62e4a3f779053123f9f18370eb63f8b3595bc92a Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 2 Jun 2020 12:43:06 +0200 Subject: [PATCH 44/78] memory release --- include/tkDNN/Layer.h | 5 +++-- include/tkDNN/utils.h | 1 + src/Layer.cpp | 5 +++++ src/LayerWgs.cpp | 6 +++--- src/Network.cpp | 1 + src/NetworkRT.cpp | 1 + src/utils.cpp | 6 ++++++ 7 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index 9154e1b..9bd8432 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -50,7 +50,7 @@ public: } void setFinal() { this->final = true; } dataDim_t input_dim, output_dim; - dnnType *dstData; //where results will be putted + dnnType *dstData = nullptr; //where results will be putted int id = 0; bool final; //if the layer is the final one @@ -122,7 +122,7 @@ public: __half *data16_d = nullptr, *bias16_d = nullptr; __half *bias216_h = nullptr, *bias216_d = nullptr; - __half *power16_h = nullptr; + __half *power16_h = nullptr, *power16_d = nullptr; __half *scales16_h = nullptr, *scales16_d = nullptr; __half *mean16_h = nullptr, *mean16_d = nullptr; __half *variance16_h = nullptr, *variance16_d = nullptr; @@ -164,6 +164,7 @@ public: if( scales16_d != nullptr) { cudaFree( scales16_d); scales16_d = nullptr; } if( mean16_d != nullptr) { cudaFree( mean16_d); mean16_d = nullptr; } if(variance16_d != nullptr) { cudaFree(variance16_d); variance16_d = nullptr; } + if( power16_d != nullptr) { cudaFree( power16_d); power16_d = nullptr; } } } }; diff --git a/include/tkDNN/utils.h b/include/tkDNN/utils.h index f9f6ae7..aa73e9e 100644 --- a/include/tkDNN/utils.h +++ b/include/tkDNN/utils.h @@ -116,5 +116,6 @@ void matrixMulAdd( cublasHandle_t handle, dnnType* srcData, dnnType* dstData, dnnType* add_vector, int dim, dnnType mul); void getMemUsage(double& vm_usage_kb, double& resident_set_kb); +void printCudaMemUsage(); void removePathAndExtension(const std::string &full_string, std::string &name); #endif //UTILS_H 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 21edf79..4afb7cc 100644 --- a/src/LayerWgs.cpp +++ b/src/LayerWgs.cpp @@ -80,7 +80,7 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, variance16_h = new __half[b_size]; scales16_h = new __half[b_size]; - //cudaMalloc(&power16_d, b_size*sizeof(__half)); + cudaMalloc(&power16_d, b_size*sizeof(__half)); cudaMalloc(&mean16_d, b_size*sizeof(__half)); cudaMalloc(&variance16_d, b_size*sizeof(__half)); cudaMalloc(&scales16_d, b_size*sizeof(__half)); @@ -91,8 +91,8 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs, //init power array of ones cudaMemcpy(tmp_d, power_h, b_size*sizeof(float), cudaMemcpyHostToDevice); - //float2half(tmp_d, power16_d, b_size); - //cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost); + float2half(tmp_d, power16_d, b_size); + cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost); //mean array cudaMemcpy(tmp_d, mean_h, b_size*sizeof(float), cudaMemcpyHostToDevice); diff --git a/src/Network.cpp b/src/Network.cpp index 9adcc48..7fa291f 100644 --- a/src/Network.cpp +++ b/src/Network.cpp @@ -128,6 +128,7 @@ void Network::print() { } printCenteredTitle("", '=', 60); std::cout<<"\n"; + printCudaMemUsage(); } const char *Network::getNetworkRTName(const char *network_name){ networkName = network_name; diff --git a/src/NetworkRT.cpp b/src/NetworkRT.cpp index 0824eba..9f53b06 100644 --- a/src/NetworkRT.cpp +++ b/src/NetworkRT.cpp @@ -134,6 +134,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) { networkRT->markOutput(*input); std::cout<<"Selected maxBatchSize: "<getMaxBatchSize()<<"\n"; + printCudaMemUsage(); std::cout<<"Building tensorRT cuda engine...\n"; #if NV_TENSORRT_MAJOR >= 6 engineRT = builderRT->buildEngineWithConfig(*networkRT, *configRT); diff --git a/src/utils.cpp b/src/utils.cpp index 3bd9119..65030f0 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -197,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: "< Date: Wed, 3 Jun 2020 11:01:17 +0200 Subject: [PATCH 45/78] Update README.md --- README.md | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3a73bec..fdfc877 100644 --- a/README.md +++ b/README.md @@ -177,24 +177,31 @@ N.b. Using FP16 inference will lead to some errors in the results (first or seco ### 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 insted 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 +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 ``` -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 ``` From 20303ac32ef8e28ca0ff94be633478d7755ae307 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 9 Jun 2020 20:53:05 +0200 Subject: [PATCH 46/78] cudnn8 compile --- src/LSTM.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/LSTM.cpp b/src/LSTM.cpp index 6ecf4fd..511fbee 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), From be9e327aef7fb9c251ab31bca5f7a923b31395e2 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Tue, 9 Jun 2020 21:01:19 +0200 Subject: [PATCH 47/78] Fix minor, update readme Signed-off-by: Micaela Verucchi --- .gitignore | 2 +- README.md | 9 +++++++++ demo/demo/map.cpp | 4 ++-- scripts/install_OpenCV4.sh | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index d62c96d..b56526f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,4 @@ build/ *.pk *.table demo/COCO_val2017 -demo/BDD100k_val \ No newline at end of file +demo/BDD100K_val \ No newline at end of file diff --git a/README.md b/README.md index fdfc877..1175465 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,18 @@ 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. 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 one of the following papers. For use in commercial solutions, write at gattifrancesco@hotmail.it or refer to https://hipert.unimore.it/ . + +``` Accepted paper @ IRC 2020, will soon been published. M. Verucchi, L. Bartoli, F. Bagni, F. Gatti, P. Burgio and M. Bertogna, "Real-Time clustering and LiDAR-camera fusion on embedded platforms for self-driving cars", in proceedings in IEEE Robotic Computing (2020) +Accepted paper @ ETFA 2020, will soon been published. +M. Verucchi, G. Brilli, D. Sapienza, M. Verasani, M. Arena, F. Gatti, A. Capotondi, R. Cavicchioli, M. Bertogna, M. Solieri +"A Systematic Assessment of Embedded Neural Networks for Object Detection", in IEEE International Conference on Emerging Technologies and Factory Automation (2020) +``` + ## Index - [tkDNN](#tkdnn) - [Index](#index) diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index 60aa7fa..d724db0 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -153,7 +153,7 @@ int main(int argc, char *argv[]) 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){ @@ -169,7 +169,7 @@ 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(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); diff --git a/scripts/install_OpenCV4.sh b/scripts/install_OpenCV4.sh index 8862cdc..f57c87b 100644 --- a/scripts/install_OpenCV4.sh +++ b/scripts/install_OpenCV4.sh @@ -62,5 +62,5 @@ make -j4 sudo make install sudo ldconfig -cd '~/Downloads/opencv4/lib/python3.6/site-packages' +cd ~/Downloads/opencv4/lib/python3.6/site-packages ln -s /usr/local/lib/python3.6/site-packages/cv2.cpython-36m-aarch64-linux-gnu.so cv2.so From ab6d2d1766ea6761e79715a4c3c2eb60a19dc399 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Fri, 12 Jun 2020 11:39:46 +0200 Subject: [PATCH 48/78] Update README Signed-off-by: Micaela Verucchi --- README.md | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1175465..19b98a2 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,40 @@ The main goal of this project is to exploit NVIDIA boards as much as possible to If you use tkDNN in your research, please cite one of the following papers. For use in commercial solutions, write at gattifrancesco@hotmail.it or refer to https://hipert.unimore.it/ . ``` -Accepted paper @ IRC 2020, will soon been published. +Accepted paper @ IRC 2020, will soon be published. M. Verucchi, L. Bartoli, F. Bagni, F. Gatti, P. Burgio and M. Bertogna, "Real-Time clustering and LiDAR-camera fusion on embedded platforms for self-driving cars", in proceedings in IEEE Robotic Computing (2020) -Accepted paper @ ETFA 2020, will soon been published. +Accepted paper @ ETFA 2020, will soon be published. M. Verucchi, G. Brilli, D. Sapienza, M. Verasani, M. Arena, F. Gatti, A. Capotondi, R. Cavicchioli, M. Bertogna, M. Solieri "A Systematic Assessment of Embedded Neural Networks for Object Detection", in IEEE International Conference on Emerging Technologies and Factory Automation (2020) ``` +## Results +Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimesion 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 ); + * 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 | +| 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 | - | - | + ## Index - [tkDNN](#tkdnn) - [Index](#index) From 567dc0f75d5951eb677f95a14e8d3d9216d90634 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sun, 14 Jun 2020 12:57:29 +0200 Subject: [PATCH 49/78] cmake cudnn fix --- CMakeLists.txt | 2 + cmake/FindCUDNN.cmake | 91 +++++++++++++++++++++++++++++-------------- 2 files changed, 64 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 376c175..4a64372 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,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") 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 From cbfc8ea4f2d8d52763b36e2c8ad2db4d4aa9d621 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sun, 14 Jun 2020 13:01:45 +0200 Subject: [PATCH 50/78] serialize fix --- src/NetworkRT.cpp | 2 +- tests/darknet/yolo3.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/NetworkRT.cpp b/src/NetworkRT.cpp index 9f53b06..6e86de1 100644 --- a/src/NetworkRT.cpp +++ b/src/NetworkRT.cpp @@ -595,7 +595,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, DeformConv2d *l) { bool NetworkRT::serialize(const char *filename) { - std::ofstream p(filename); + std::ofstream p(filename, std::ios::binary); if (!p) { FatalError("could not open plan output file"); return false; diff --git a/tests/darknet/yolo3.cpp b/tests/darknet/yolo3.cpp index ea53b84..464c3cf 100644 --- a/tests/darknet/yolo3.cpp +++ b/tests/darknet/yolo3.cpp @@ -5,19 +5,19 @@ #include "DarknetParser.h" int main() { - std::string bin_path = "yolo3"; + std::string bin_path = "yolov3-sppx"; 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" + bin_path + "/debug/layer89_out.bin", + bin_path + "/debug/layer101_out.bin", + bin_path + "/debug/layer113_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo3.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; - downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download"); + std::string cfg_path = "../tests/darknet/cfg/yolov3-sppx.cfg"; + std::string name_path = "../tests/darknet/names/coco4.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); From 6dff675db7a9f58798535dfce8029b2dddac174b Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Sun, 14 Jun 2020 13:03:48 +0200 Subject: [PATCH 51/78] fix wrong commit --- tests/darknet/yolo3.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/darknet/yolo3.cpp b/tests/darknet/yolo3.cpp index 464c3cf..e73d226 100644 --- a/tests/darknet/yolo3.cpp +++ b/tests/darknet/yolo3.cpp @@ -5,19 +5,19 @@ #include "DarknetParser.h" int main() { - std::string bin_path = "yolov3-sppx"; + std::string bin_path = "yolo3"; std::vector input_bins = { bin_path + "/layers/input.bin" }; std::vector output_bins = { - bin_path + "/debug/layer89_out.bin", - bin_path + "/debug/layer101_out.bin", - bin_path + "/debug/layer113_out.bin" + 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 = "../tests/darknet/cfg/yolov3-sppx.cfg"; - std::string name_path = "../tests/darknet/names/coco4.names"; - //downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download"); + std::string cfg_path = "../tests/darknet/cfg/yolo3.cfg"; + std::string name_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); @@ -31,4 +31,4 @@ int main() { delete net; delete netRT; return ret; -} +} \ No newline at end of file From 285c77d6dd22fba207ec9c5fb5a43b3551e1e62a Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 15 Jun 2020 17:15:37 +0200 Subject: [PATCH 52/78] Imptove relative paths Signed-off-by: Micaela Verucchi Francesco Gatti --- CMakeLists.txt | 1 + tests/darknet/csresnext50-panet-spp.cpp | 4 ++-- tests/darknet/csresnext50-panet-spp_berkeley.cpp | 4 ++-- tests/darknet/yolo2.cpp | 4 ++-- tests/darknet/yolo2_voc.cpp | 4 ++-- tests/darknet/yolo2tiny.cpp | 4 ++-- tests/darknet/yolo3.cpp | 4 ++-- tests/darknet/yolo3_512.cpp | 4 ++-- tests/darknet/yolo3_berkeley.cpp | 4 ++-- tests/darknet/yolo3_coco4.cpp | 4 ++-- tests/darknet/yolo3_flir.cpp | 4 ++-- tests/darknet/yolo3tiny.cpp | 4 ++-- tests/darknet/yolo3tiny_512.cpp | 4 ++-- tests/darknet/yolo4.cpp | 4 ++-- tests/darknet/yolo4_berkeley.cpp | 4 ++-- 15 files changed, 29 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4a64372..8c8619d 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 diff --git a/tests/darknet/csresnext50-panet-spp.cpp b/tests/darknet/csresnext50-panet-spp.cpp index 1da95b2..a366e14 100644 --- a/tests/darknet/csresnext50-panet-spp.cpp +++ b/tests/darknet/csresnext50-panet-spp.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer137_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/csresnext50-panet-spp.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; + 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 diff --git a/tests/darknet/csresnext50-panet-spp_berkeley.cpp b/tests/darknet/csresnext50-panet-spp_berkeley.cpp index 47bbfd4..3cd0d52 100644 --- a/tests/darknet/csresnext50-panet-spp_berkeley.cpp +++ b/tests/darknet/csresnext50-panet-spp_berkeley.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer137_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/csresnext50-panet-spp_berkeley.cfg"; - std::string name_path = "../tests/darknet/names/berkeley.names"; + 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"; // FIXME: wrong weights // downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s//download"); diff --git a/tests/darknet/yolo2.cpp b/tests/darknet/yolo2.cpp index 7a46c31..978c137 100644 --- a/tests/darknet/yolo2.cpp +++ b/tests/darknet/yolo2.cpp @@ -13,8 +13,8 @@ int main() { bin_path + "/layers/output.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo2.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; + 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 diff --git a/tests/darknet/yolo2_voc.cpp b/tests/darknet/yolo2_voc.cpp index eab215b..94111e6 100644 --- a/tests/darknet/yolo2_voc.cpp +++ b/tests/darknet/yolo2_voc.cpp @@ -13,8 +13,8 @@ int main() { bin_path + "/layers/output.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo2_voc.cfg"; - std::string name_path = "../tests/darknet/names/voc.names"; + 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 diff --git a/tests/darknet/yolo2tiny.cpp b/tests/darknet/yolo2tiny.cpp index 64faa36..cc12109 100644 --- a/tests/darknet/yolo2tiny.cpp +++ b/tests/darknet/yolo2tiny.cpp @@ -13,8 +13,8 @@ int main() { bin_path + "/layers/output.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo2tiny.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; + 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"); diff --git a/tests/darknet/yolo3.cpp b/tests/darknet/yolo3.cpp index e73d226..d9a684b 100644 --- a/tests/darknet/yolo3.cpp +++ b/tests/darknet/yolo3.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer106_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo3.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; + 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 diff --git a/tests/darknet/yolo3_512.cpp b/tests/darknet/yolo3_512.cpp index a67c3a7..6a5c20e 100644 --- a/tests/darknet/yolo3_512.cpp +++ b/tests/darknet/yolo3_512.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer106_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo3_512.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; + 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 diff --git a/tests/darknet/yolo3_berkeley.cpp b/tests/darknet/yolo3_berkeley.cpp index a71fe83..016a8a2 100644 --- a/tests/darknet/yolo3_berkeley.cpp +++ b/tests/darknet/yolo3_berkeley.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer106_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo3_berkeley.cfg"; - std::string name_path = "../tests/darknet/names/berkeley.names"; + 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 diff --git a/tests/darknet/yolo3_coco4.cpp b/tests/darknet/yolo3_coco4.cpp index a651430..eaf9bd8 100644 --- a/tests/darknet/yolo3_coco4.cpp +++ b/tests/darknet/yolo3_coco4.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer106_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo3_coco4.cfg"; - std::string name_path = "../tests/darknet/names/coco4.names"; + 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 diff --git a/tests/darknet/yolo3_flir.cpp b/tests/darknet/yolo3_flir.cpp index 678f10f..24aac7f 100644 --- a/tests/darknet/yolo3_flir.cpp +++ b/tests/darknet/yolo3_flir.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer106_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo3_flir.cfg"; - std::string name_path = "../tests/darknet/names/flir.names"; + 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 diff --git a/tests/darknet/yolo3tiny.cpp b/tests/darknet/yolo3tiny.cpp index 01fc6f9..c33f7a8 100644 --- a/tests/darknet/yolo3tiny.cpp +++ b/tests/darknet/yolo3tiny.cpp @@ -14,8 +14,8 @@ int main() { bin_path + "/debug/layer23_out.bin", }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo3tiny.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; + 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 diff --git a/tests/darknet/yolo3tiny_512.cpp b/tests/darknet/yolo3tiny_512.cpp index 8153b0d..ce4ce86 100644 --- a/tests/darknet/yolo3tiny_512.cpp +++ b/tests/darknet/yolo3tiny_512.cpp @@ -14,8 +14,8 @@ int main() { bin_path + "/debug/layer23_out.bin", }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo3tiny_512.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; + 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 diff --git a/tests/darknet/yolo4.cpp b/tests/darknet/yolo4.cpp index 80b12ce..65ac6ee 100644 --- a/tests/darknet/yolo4.cpp +++ b/tests/darknet/yolo4.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer161_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo4.cfg"; - std::string name_path = "../tests/darknet/names/coco.names"; + 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 diff --git a/tests/darknet/yolo4_berkeley.cpp b/tests/darknet/yolo4_berkeley.cpp index 8642eb1..89e9f04 100644 --- a/tests/darknet/yolo4_berkeley.cpp +++ b/tests/darknet/yolo4_berkeley.cpp @@ -15,8 +15,8 @@ int main() { bin_path + "/debug/layer161_out.bin" }; std::string wgs_path = bin_path + "/layers"; - std::string cfg_path = "../tests/darknet/cfg/yolo4_berkeley.cfg"; - std::string name_path = "../tests/darknet/names/berkeley.names"; + 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 From 3d3a2427c9d17e6bc7ac83b56486568b1adba180 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 16 Jun 2020 12:36:45 +0200 Subject: [PATCH 53/78] viz yolo3 --- include/tkDNN/DarknetParser.h | 2 +- include/tkDNN/NetworkViz.h | 12 ++++++ include/tkDNN/utils.h | 4 ++ src/NetworkViz.cpp | 69 +++++++++++++++++++++++++++++++++++ tests/darknet/viz_yolo3.cpp | 54 +++++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 include/tkDNN/NetworkViz.h create mode 100644 src/NetworkViz.cpp create mode 100644 tests/darknet/viz_yolo3.cpp diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index cbeed48..cd7fa48 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -1,6 +1,6 @@ #pragma once #include -#include "tkdnn.h" +#include "tkDNN/tkdnn.h" namespace tk { namespace dnn { 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/utils.h b/include/tkDNN/utils.h index aa73e9e..538a3f3 100644 --- a/include/tkDNN/utils.h +++ b/include/tkDNN/utils.h @@ -118,4 +118,8 @@ void matrixMulAdd( cublasHandle_t handle, dnnType* srcData, dnnType* dstData, void getMemUsage(double& vm_usage_kb, double& resident_set_kb); void printCudaMemUsage(); void removePathAndExtension(const std::string &full_string, std::string &name); +static inline bool isCudaPointer(void *data) { + cudaPointerAttributes attr; + return cudaPointerGetAttributes(&attr, data) == 0; +} #endif //UTILS_H diff --git a/src/NetworkViz.cpp b/src/NetworkViz.cpp new file mode 100644 index 0000000..6ac274c --- /dev/null +++ b/src/NetworkViz.cpp @@ -0,0 +1,69 @@ +#include +#include +#include +#include +#include "tkDNN/NetworkViz.h" + +namespace tk { namespace dnn { + +cv::Mat vizFloat2colorMap(cv::Mat map) { + + double min; + double max; + cv::minMaxIdx(map, &min, &max); + cv::Mat adjMap; + // expand your range to 0..255. Similar to histEq(); + map.convertTo(adjMap,CV_8UC1, 255 / (max-min), -min); + //return adjMap; + + + cv::Mat falseColorsMap; + applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_HOT); + return falseColorsMap; +} + +cv::Mat vizData2Mat(dnnType *dataInput, tk::dnn::dataDim_t dim, int imgdim) { + dnnType *data = nullptr; + + // copy to CPU + if(isCudaPointer(dataInput)) { + data = new dnnType[dim.tot()]; + checkCuda( cudaMemcpy(data, dataInput, dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost) ); + } else { + data = dataInput; + } + + int gridDim = ceil(sqrt(dim.c)); + cv::Size gridSize(dim.w*gridDim, dim.h*gridDim); + cv::Mat grid = cv::Mat(gridSize, CV_8UC3, cv::Scalar(0)); + + for(int i=0; i= net->num_layers) + FatalError("Could not viz layer\n"); + return vizData2Mat(net->layers[layer]->dstData, net->layers[layer]->output_dim, imgdim); + + //cv::imwrite("viz/layer" + std::to_string(layer) + ".png", viz); + //cv::imshow("layer", viz); + //cv::waitKey(0); +} + +}} \ No newline at end of file diff --git a/tests/darknet/viz_yolo3.cpp b/tests/darknet/viz_yolo3.cpp new file mode 100644 index 0000000..374f7dd --- /dev/null +++ b/tests/darknet/viz_yolo3.cpp @@ -0,0 +1,54 @@ +#include +#include +#include + +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" +#include "NetworkViz.h" + +int main() { + std::string bin_path = "yolo3"; + std::vector input_bins = { + bin_path + "/layers/input.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(); + + // Load input and infer + dnnType *input_d; + dnnType *input_h; + readBinaryFile(input_bins[0], net->input_dim.tot(), &input_h, &input_d); + 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 From 1b8f45703f0f42a5a9bd1ca45fdda556345984c2 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 16 Jun 2020 12:41:48 +0200 Subject: [PATCH 54/78] darknet parser cpp --- include/tkDNN/DarknetParser.h | 272 ++-------------------------------- src/DarknetParser.cpp | 261 ++++++++++++++++++++++++++++++++ 2 files changed, 274 insertions(+), 259 deletions(-) create mode 100644 src/DarknetParser.cpp diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index cd7fa48..f36469b 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -27,267 +27,21 @@ namespace tk { namespace dnn { 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::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){ - 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("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("scale_x_y") != std::string::npos) - fields.scale_xy = std::stof(value); - else if(name.find("from") != std::string::npos) - fields.layers.push_back(std::stof(value)); - else if(name.find("mask") != std::string::npos){ - auto vec = fromStringToIntVec(value, ','); - fields.n_mask = vec.size(); - } - else if(name.find("layers") != std::string::npos) - fields.layers = fromStringToIntVec(value, ','); - - else - std::cout<<"Not supported field: "< &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())); - - } 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); - 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 retrive 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: "< 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/src/DarknetParser.cpp b/src/DarknetParser.cpp new file mode 100644 index 0000000..5092595 --- /dev/null +++ b/src/DarknetParser.cpp @@ -0,0 +1,261 @@ +#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("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("scale_x_y") != std::string::npos) + fields.scale_xy = std::stof(value); + else if(name.find("from") != std::string::npos) + fields.layers.push_back(std::stof(value)); + else if(name.find("mask") != std::string::npos){ + auto vec = fromStringToIntVec(value, ','); + fields.n_mask = vec.size(); + } + else if(name.find("layers") != std::string::npos) + fields.layers = fromStringToIntVec(value, ','); + + else + std::cout<<"Not supported field: "< &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())); + + } 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); + 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 retrive 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: "< Date: Tue, 16 Jun 2020 12:44:12 +0200 Subject: [PATCH 55/78] dealloc in test.h fix #36 --- include/tkDNN/test.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/tkDNN/test.h b/include/tkDNN/test.h index be3d891..4e238ff 100644 --- a/include/tkDNN/test.h +++ b/include/tkDNN/test.h @@ -1,7 +1,7 @@ #include int testInference(std::vector input_bins, std::vector output_bins, - tk::dnn::Network *net, tk::dnn::NetworkRT *netRT = nullptr) { + tk::dnn::Network *net, tk::dnn::NetworkRT *netRT = nullptr) { std::vector outputs; for(int i=0; inum_layers; i++) { @@ -67,7 +67,11 @@ int testInference(std::vector input_bins, std::vector 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; - } \ No newline at end of file + delete [] out_h; + checkCuda( cudaFree(out) ); + } + delete [] input_h; + checkCuda( cudaFree(data) ); + return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt; +} \ No newline at end of file From 1dfc69ba8916f913282c1fb68a117cdc72468f78 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 16 Jun 2020 13:19:30 +0200 Subject: [PATCH 56/78] viz yolo3 preprocess --- tests/darknet/viz_yolo3.cpp | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/tests/darknet/viz_yolo3.cpp b/tests/darknet/viz_yolo3.cpp index 374f7dd..9e53116 100644 --- a/tests/darknet/viz_yolo3.cpp +++ b/tests/darknet/viz_yolo3.cpp @@ -1,32 +1,49 @@ #include #include #include +#include #include "tkdnn.h" #include "test.h" #include "DarknetParser.h" #include "NetworkViz.h" -int main() { +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::vector input_bins = { - bin_path + "/layers/input.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"); + 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(); - // Load input and infer + // input data dnnType *input_d; - dnnType *input_h; - readBinaryFile(input_bins[0], net->input_dim.tot(), &input_h, &input_d); - tk::dnn::dataDim_t dim = net->input_dim; + 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); @@ -44,7 +61,6 @@ int main() { //cv::waitKey(0); } - delete [] input_h; checkCuda(cudaFree(input_d)); net->releaseLayers(); delete net; From 2817ade782cc13b8f42d9616e4b3a935400b5179 Mon Sep 17 00:00:00 2001 From: Omar Alvarez Date: Mon, 22 Jun 2020 13:40:15 +0200 Subject: [PATCH 57/78] Fix parsing label files with unexpected chars --- src/Int8BatchStream.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) 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; - } } } From 61aa24c6b7716b833c8a0840dc0c47a00ca7e8ff Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Tue, 30 Jun 2020 15:19:03 +0200 Subject: [PATCH 58/78] yolov4tiny works on CUDNN Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 1 + include/tkDNN/Layer.h | 4 +- src/DarknetParser.cpp | 4 +- src/Route.cpp | 10 +- tests/darknet/cfg/yolo4tiny.cfg | 281 ++++++++++++++++++++++++++++++++ tests/darknet/yolo4tiny.cpp | 33 ++++ 6 files changed, 328 insertions(+), 5 deletions(-) create mode 100644 tests/darknet/cfg/yolo4tiny.cfg create mode 100644 tests/darknet/yolo4tiny.cpp diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index f36469b..29d1e8e 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -11,6 +11,7 @@ namespace tk { namespace dnn { 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; diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index 9bd8432..bd544b2 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -509,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; }; @@ -519,6 +519,8 @@ 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; }; diff --git a/src/DarknetParser.cpp b/src/DarknetParser.cpp index 5092595..7bbc7ba 100644 --- a/src/DarknetParser.cpp +++ b/src/DarknetParser.cpp @@ -75,6 +75,8 @@ namespace tk { namespace dnn { 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("from") != std::string::npos) @@ -148,7 +150,7 @@ namespace tk { namespace dnn { //std::cout<<"Route to "<getLayerName()<<"\n"; layers.push_back(netLayers[layerIdx]); } - netLayers.push_back(new tk::dnn::Route(net, layers.data(), layers.size())); + 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)); diff --git a/src/Route.cpp b/src/Route.cpp index 39bb14e..816566e 100644 --- a/src/Route.cpp +++ b/src/Route.cpp @@ -5,7 +5,7 @@ namespace tk { namespace dnn { -Route::Route(Network *net, Layer **layers, int layers_n) : Layer(net) { +Route::Route(Network *net, Layer **layers, int layers_n, int groups, int group_id) : Layer(net) { // copy input layers if(layers_n > MAX_LAYERS) { @@ -15,6 +15,8 @@ Route::Route(Network *net, Layer **layers, int layers_n) : Layer(net) { this->layers[i] = layers[i]; } this->layers_n = layers_n; + this->groups = groups; + this->group_id = group_id; //get dims output_dim.l = 1; @@ -32,6 +34,7 @@ Route::Route(Network *net, Layer **layers, int layers_n) : Layer(net) { output_dim.c += layers[i]->output_dim.c; } + output_dim.c /= this->groups; input_dim = output_dim; checkCuda( cudaMalloc(&dstData, output_dim.tot()*sizeof(dnnType)) ); @@ -49,8 +52,9 @@ dnnType* Route::infer(dataDim_t &dim, dnnType* srcData) { for(int i=0; idstData; int in_dim = layers[i]->output_dim.tot(); - checkCuda( cudaMemcpy(dstData + offset, input, in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice)); - offset += in_dim; + int part_in_dim = in_dim / this->groups; + checkCuda( cudaMemcpy(dstData + offset, input + this->group_id*part_in_dim, part_in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice)); + offset += part_in_dim; } //update data dimensions diff --git a/tests/darknet/cfg/yolo4tiny.cfg b/tests/darknet/cfg/yolo4tiny.cfg new file mode 100644 index 0000000..dc6f5bf --- /dev/null +++ b/tests/darknet/cfg/yolo4tiny.cfg @@ -0,0 +1,281 @@ +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=1 +width=416 +height=416 +channels=3 +momentum=0.9 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.00261 +burn_in=1000 +max_batches = 500200 +policy=steps +steps=400000,450000 +scales=.1,.1 + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=leaky + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=leaky + +[route] +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 +activation=leaky + +[convolutional] +size=1 +stride=1 +pad=1 +filters=255 +activation=linear + + + +[yolo] +mask = 3,4,5 +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 + +[route] +layers = -4 + +[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/yolo4tiny.cpp b/tests/darknet/yolo4tiny.cpp new file mode 100644 index 0000000..d9011a8 --- /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, nullptr); + net->releaseLayers(); + delete net; + // delete netRT; + return ret; +} From fe2e4eae92324d4c03482e20b5746ebc6aed75c5 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Tue, 30 Jun 2020 15:52:58 +0200 Subject: [PATCH 59/78] yolo4tiny works on tensorRT :dolphin: :dolphin: :dolphin: :dolphin: Signed-off-by: Micaela Verucchi --- include/tkDNN/NetworkRT.h | 2 +- include/tkDNN/pluginsRT/RouteRT.h | 17 ++++++++++++----- src/NetworkRT.cpp | 19 +++++++++++-------- tests/darknet/yolo4tiny.cpp | 6 +++--- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/include/tkDNN/NetworkRT.h b/include/tkDNN/NetworkRT.h index ee1f728..66b4f3d 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" diff --git a/include/tkDNN/pluginsRT/RouteRT.h b/include/tkDNN/pluginsRT/RouteRT.h index 0e94a97..263893f 100644 --- a/include/tkDNN/pluginsRT/RouteRT.h +++ b/include/tkDNN/pluginsRT/RouteRT.h @@ -8,7 +8,9 @@ class RouteRT : public IPlugin { */ public: - RouteRT() { + RouteRT(int groups, int group_id) { + this->groups = 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(inputs[i]); int in_dim = c_in[i]*h*w; - checkCuda( cudaMemcpyAsync(dstData + offset, input, in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream) ); - offset += in_dim; + int part_in_dim = in_dim / this->groups; + checkCuda( cudaMemcpyAsync(dstData + offset, input + this->group_id*part_in_dim, part_in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream) ); + offset += part_in_dim; } return 0; @@ -65,11 +69,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; iaddConcatenation(tens, l->layers_n); - //IPlugin *plugin = new RouteRT(); - //IPluginLayer *lRT = networkRT->addPlugin(tens, l->layers_n, *plugin); - checkNULL(lRT); + if(l->groups > 1){ + IPlugin *plugin = new RouteRT(l->groups, l->group_id); + IPluginLayer *lRT = networkRT->addPlugin(tens, l->layers_n, *plugin); + checkNULL(lRT); + return lRT; + } + IConcatenationLayer *lRT = networkRT->addConcatenation(tens, l->layers_n); + checkNULL(lRT); return lRT; } @@ -766,9 +769,9 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa r->w = readBUF(buf); return r; } -/* + if(name.find("Route") == 0) { - RouteRT *r = new RouteRT(); + RouteRT *r = new RouteRT(readBUF(buf),readBUF(buf)); r->in = readBUF(buf); for(int i=0; ic_in[i] = readBUF(buf); @@ -777,7 +780,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa r->w = readBUF(buf); return r; } -*/ + if(name.find("Deformable") == 0) { DeformableConvRT *r = new DeformableConvRT(readBUF(buf), readBUF(buf), readBUF(buf), readBUF(buf), readBUF(buf), readBUF(buf), diff --git a/tests/darknet/yolo4tiny.cpp b/tests/darknet/yolo4tiny.cpp index d9011a8..44fbac8 100644 --- a/tests/darknet/yolo4tiny.cpp +++ b/tests/darknet/yolo4tiny.cpp @@ -23,11 +23,11 @@ int main() { net->print(); //convert network to tensorRT - // tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); - int ret = testInference(input_bins, output_bins, net, nullptr); + int ret = testInference(input_bins, output_bins, net, netRT); net->releaseLayers(); delete net; - // delete netRT; + delete netRT; return ret; } From 04602f395236d993d79cff7d1be5ced3ae738b0b Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Tue, 30 Jun 2020 19:37:16 +0200 Subject: [PATCH 60/78] Yolo4-tiny batched fix #59 --- README.md | 2 ++ include/tkDNN/pluginsRT/RouteRT.h | 18 ++++++++++-------- scripts/test_all_tests.sh | 1 + 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 19b98a2..3ff6fe7 100644 --- a/README.md +++ b/README.md @@ -317,6 +317,8 @@ This demo also creates a json file named ```net_name_COCO_res.json``` containing | 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 | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download) | ## References diff --git a/include/tkDNN/pluginsRT/RouteRT.h b/include/tkDNN/pluginsRT/RouteRT.h index 263893f..23f30b7 100644 --- a/include/tkDNN/pluginsRT/RouteRT.h +++ b/include/tkDNN/pluginsRT/RouteRT.h @@ -52,16 +52,18 @@ public: } virtual int enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream) override { - + dnnType *dstData = reinterpret_cast(outputs[0]); - int offset = 0; - for(int i=0; i(inputs[i]); - int in_dim = c_in[i]*h*w; - int part_in_dim = in_dim / this->groups; - checkCuda( cudaMemcpyAsync(dstData + offset, input + this->group_id*part_in_dim, part_in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream) ); - offset += part_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; diff --git a/scripts/test_all_tests.sh b/scripts/test_all_tests.sh index 193a90c..770aa22 100644 --- a/scripts/test_all_tests.sh +++ b/scripts/test_all_tests.sh @@ -74,6 +74,7 @@ do test_net yolo4 test_net yolo4_berkeley + test_net yolo4tiny test_net yolo3 test_net yolo3_berkeley test_net yolo3_coco4 From 7c2155decfc2d225f523350d55fb6d773d3b3b6c Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Wed, 1 Jul 2020 11:56:46 +0200 Subject: [PATCH 61/78] Add weights download link for csresnext50-panet-spp_berkeley ( fix #63 ) Signed-off-by: Micaela Verucchi --- tests/darknet/csresnext50-panet-spp_berkeley.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/darknet/csresnext50-panet-spp_berkeley.cpp b/tests/darknet/csresnext50-panet-spp_berkeley.cpp index 3cd0d52..a8ba59f 100644 --- a/tests/darknet/csresnext50-panet-spp_berkeley.cpp +++ b/tests/darknet/csresnext50-panet-spp_berkeley.cpp @@ -17,8 +17,7 @@ int main() { 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"; - // FIXME: wrong weights - // downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s//download"); + 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); From b12cf0d7c2599f36e7e564ba19868c6885ecca6d Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Mon, 13 Jul 2020 19:50:00 +0200 Subject: [PATCH 62/78] docker --- docker/Dockerfile | 7 ++++++ docker/Dockerfile.base | 57 ++++++++++++++++++++++++++++++++++++++++++ docker/README.md | 21 ++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 docker/Dockerfile create mode 100644 docker/Dockerfile.base create mode 100644 docker/README.md 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..a3edf3c --- /dev/null +++ b/docker/README.md @@ -0,0 +1,21 @@ +# Use the prebuilt image +``` +# build image +docker build -t tkdnn:build -f Dockerfile-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 +``` + From b2df9fc1107ca63301df42a0fbd0483189eda7d9 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Mon, 13 Jul 2020 19:51:09 +0200 Subject: [PATCH 63/78] Update README.md --- docker/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/README.md b/docker/README.md index a3edf3c..aec202a 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,7 +1,7 @@ # Use the prebuilt image ``` # build image -docker build -t tkdnn:build -f Dockerfile-f Dockerfile . +docker build -t tkdnn:build -f Dockerfile . ``` # Build Base Docker image From c4aad7fe95e0f8ed45fd175d565d1926d2880f6c Mon Sep 17 00:00:00 2001 From: tk Date: Thu, 16 Jul 2020 18:16:09 +0200 Subject: [PATCH 64/78] Patch for CUDNN 8.0.1 Signed-off-by: tk --- include/tkDNN/Layer.h | 4 ++-- src/Conv2d.cpp | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index bd544b2..f2ec56d 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -273,8 +273,8 @@ public: protected: cudnnFilterDescriptor_t filterDesc; cudnnConvolutionDescriptor_t convDesc; - cudnnConvolutionFwdAlgo_t algo; - cudnnConvolutionBwdDataAlgo_t bwAlgo; + cudnnConvolutionFwdAlgoPerf_t algo; + cudnnConvolutionBwdDataAlgoPerf_t bwAlgo; cudnnTensorDescriptor_t biasTensorDesc; void initCUDNN(bool back = false); diff --git a/src/Conv2d.cpp b/src/Conv2d.cpp index 4704c66..595fec7 100644 --- a/src/Conv2d.cpp +++ b/src/Conv2d.cpp @@ -63,23 +63,23 @@ void Conv2d::initCUDNN(bool back) { workSpace = NULL; ws_sizeInBytes = 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, 0, &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, 0, &algo) ); + checkCUDNN(cudnnGetConvolutionForwardWorkspaceSize(net->cudnnHandle, + srcTensor, filterDesc, convDesc, dstTensor, + algo.algo, &ws_sizeInBytes)); } } @@ -91,12 +91,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)); } From 6a68f19b2ceb61542fe87533fb193f696d30c664 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Thu, 16 Jul 2020 18:37:37 +0200 Subject: [PATCH 65/78] Fix patch from @ahmedius2 , tkDNN now supports CUDNN 8.0.1 (Fix #74) Signed-off-by: Micaela Verucchi Francesco Gatti --- src/Conv2d.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Conv2d.cpp b/src/Conv2d.cpp index 595fec7..b57cf58 100644 --- a/src/Conv2d.cpp +++ b/src/Conv2d.cpp @@ -62,9 +62,10 @@ void Conv2d::initCUDNN(bool back) { // init workspace workSpace = NULL; ws_sizeInBytes = 0; + int algo_count = 0; if(back) { checkCUDNN( cudnnGetConvolutionBackwardDataAlgorithm_v7(net->cudnnHandle, - filterDesc, dstTensor, convDesc, srcTensor, 1, 0, &bwAlgo) ); + filterDesc, dstTensor, convDesc, srcTensor, 1, &algo_count, &bwAlgo) ); checkCUDNN(cudnnGetConvolutionBackwardDataWorkspaceSize(net->cudnnHandle, filterDesc, dstTensor, convDesc, srcTensor, bwAlgo.algo, &ws_sizeInBytes)); @@ -74,13 +75,17 @@ void Conv2d::initCUDNN(bool back) { srcTensorDesc = dstTensor; dstTensorDesc = srcTensor; } else { + checkCUDNN( cudnnGetConvolutionForwardAlgorithm_v7(net->cudnnHandle, srcTensor, filterDesc, convDesc, dstTensor, - 1, 0, &algo) ); + 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) { From f4970d1e6faab505c2caf1d6833cf7490a971a0e Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Fri, 17 Jul 2020 14:37:10 +0200 Subject: [PATCH 66/78] Update README.md --- README.md | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3ff6fe7..a1b5b16 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,9 @@ # 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 one of the following papers. For use in commercial solutions, write at gattifrancesco@hotmail.it or refer to https://hipert.unimore.it/ . +If you use tkDNN in your research, please cite one of the following papers. For use in commercial solutions, write at gattifrancesco@hotmail.it and micaela.verucchi@unimore.it or refer to https://hipert.unimore.it/ . ``` Accepted paper @ IRC 2020, will soon be published. @@ -175,15 +175,25 @@ All models from darknet are now parsed directly from cfg, you still need to expo mish -## Run the demo +## Run the demo +This is an example using yolov4. -To run the an object detection demo follow these steps (example with yolov3): +To run the an object detection first create the .rt file by running: ``` -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 +rm yolo4_fp32.rt # be sure to delete(or move) old tensorRT files +./test_yolo4 # run the yolo test (is slow) ``` -In general the demo program takes 4 parameters: +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 succesfully created your rt file, run the demo: +``` +./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y +``` +In general the demo program takes 6 parameters: ``` ./demo ``` @@ -197,6 +207,7 @@ where N.b. By default it is used FP32 inference + ![demo](https://user-images.githubusercontent.com/11562617/72547657-540e7800-388d-11ea-83c6-49dfea2a0607.gif) ### FP16 inference From 3a0802d70c7a6286ac1ca871efc2498550295aa5 Mon Sep 17 00:00:00 2001 From: Francesco Gatti Date: Mon, 27 Jul 2020 13:45:42 +0200 Subject: [PATCH 67/78] Resolve detection objects pick by prob threshold. Before this it will only pick the last object with prob > thresh wich is absolutely wrong Now it picks all the objects with prob > thesh. fixes #94 --- src/Yolo3Detection.cpp | 47 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index c76af20..27f393f 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -113,34 +113,35 @@ void Yolo3Detection::postprocess(const int bi, const bool mAP){ int x1 = (b.x+b.w/2.); int y0 = (b.y-b.h/2.); int y1 = (b.y+b.h/2.); - int obj_class = -1; - float prob = 0; + for(int c=0; c= confThreshold) { - obj_class = c; - prob = dets[j].prob[c]; + int obj_class = c; + float prob = dets[j].prob[c]; + + // 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; + + // 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; - if(mAP) - for(int c=0; c Date: Mon, 27 Jul 2020 13:52:39 +0200 Subject: [PATCH 68/78] fix coords convert --- src/Yolo3Detection.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index 27f393f..606c6d1 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -114,17 +114,17 @@ void Yolo3Detection::postprocess(const int bi, const bool mAP){ int y0 = (b.y-b.h/2.); int y1 = (b.y+b.h/2.); + // convert to image coords + x0 = x_ratio*x0; + x1 = x_ratio*x1; + y0 = y_ratio*y0; + y1 = y_ratio*y1; + for(int c=0; c= confThreshold) { int obj_class = c; float prob = dets[j].prob[c]; - // 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; From f778e1aa998f894654b24c0ab9ad759c0eb14019 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Wed, 5 Aug 2020 19:55:10 +0200 Subject: [PATCH 69/78] Fixed boxes to float, add conf thresh as param Signed-off-by: Micaela Verucchi --- README.md | 3 ++- demo/config.yaml | 2 +- demo/demo/demo.cpp | 5 ++++- demo/demo/map.cpp | 2 +- include/tkDNN/CenternetDetection.h | 2 +- include/tkDNN/DetectionNN.h | 2 +- include/tkDNN/MobilenetDetection.h | 2 +- include/tkDNN/Yolo3Detection.h | 2 +- src/CenternetDetection.cpp | 3 ++- src/MobilenetDetection.cpp | 3 ++- src/Yolo3Detection.cpp | 11 ++++++----- 11 files changed, 22 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index a1b5b16..d9b5755 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ Once you have succesfully created your rt file, run the demo: ``` ./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y ``` -In general the demo program takes 6 parameters: +In general the demo program takes 7 parameters: ``` ./demo ``` @@ -204,6 +204,7 @@ where * ``````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 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 76b451d..9f50d0b 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -40,6 +40,9 @@ int main(int argc, char *argv[]) { 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"); @@ -69,7 +72,7 @@ int main(int argc, char *argv[]) { FatalError("Network type not allowed (3rd parameter)\n"); } - detNN->init(net, n_classes, n_batch); + detNN->init(net, n_classes, n_batch, conf_thresh); gRun = true; diff --git a/demo/demo/map.cpp b/demo/demo/map.cpp index d724db0..356e35a 100644 --- a/demo/demo/map.cpp +++ b/demo/demo/map.cpp @@ -105,7 +105,7 @@ int main(int argc, char *argv[]) default: FatalError("Network type not allowed (3rd parameter)\n"); } - detNN->init(net, n_classes); + detNN->init(net, n_classes, 1, conf_thresh); //read images std::ifstream all_labels(labels_path); diff --git a/include/tkDNN/CenternetDetection.h b/include/tkDNN/CenternetDetection.h index 227cb78..3c8cfbb 100644 --- a/include/tkDNN/CenternetDetection.h +++ b/include/tkDNN/CenternetDetection.h @@ -73,7 +73,7 @@ public: CenternetDetection() {}; ~CenternetDetection() {}; - bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1); + 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/DetectionNN.h b/include/tkDNN/DetectionNN.h index 030cf8f..ba42834 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -84,7 +84,7 @@ class DetectionNN { * @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, const int n_batches=1) = 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. diff --git a/include/tkDNN/MobilenetDetection.h b/include/tkDNN/MobilenetDetection.h index cabd7eb..9a5fedc 100644 --- a/include/tkDNN/MobilenetDetection.h +++ b/include/tkDNN/MobilenetDetection.h @@ -65,7 +65,7 @@ public: MobilenetDetection() {}; ~MobilenetDetection() {}; - bool init(const std::string& tensor_path, const int n_classes, const int n_batches=1); + 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/Yolo3Detection.h b/include/tkDNN/Yolo3Detection.h index 6d38514..100a720 100644 --- a/include/tkDNN/Yolo3Detection.h +++ b/include/tkDNN/Yolo3Detection.h @@ -24,7 +24,7 @@ public: Yolo3Detection() {}; ~Yolo3Detection() {}; - bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1); + 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/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index 9d8df38..394e24a 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -3,11 +3,12 @@ namespace tk { namespace dnn { -bool CenternetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches){ +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; diff --git a/src/MobilenetDetection.cpp b/src/MobilenetDetection.cpp index c905fea..3c54e28 100644 --- a/src/MobilenetDetection.cpp +++ b/src/MobilenetDetection.cpp @@ -126,12 +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, const int n_batches){ +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]; diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index 606c6d1..e9b0064 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -3,13 +3,14 @@ namespace tk { namespace dnn { -bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, const int n_batches) { +bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh) { //convert network to tensorRT std::cout<<(tensor_path).c_str()<<"\n"; netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str() ); nBatches = n_batches; + confThreshold = conf_thresh; tk::dnn::dataDim_t idim = netRT->input_dim; idim.n = nBatches; @@ -109,10 +110,10 @@ void Yolo3Detection::postprocess(const int bi, const bool mAP){ detected.clear(); for(int j=0; j Date: Thu, 6 Aug 2020 11:05:26 +0200 Subject: [PATCH 70/78] Update README.md --- README.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d9b5755..ea55785 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ M. Verucchi, G. Brilli, D. Sapienza, M. Verasani, M. Arena, F. Gatti, A. Capoton "A Systematic Assessment of Embedded Neural Networks for Object Detection", in IEEE International Conference on Emerging Technologies and Factory Automation (2020) ``` -## Results +## FPS Results Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimesion 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 ); @@ -40,6 +40,20 @@ Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimesio | 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) From df5443e017f9390b3f282a5c18ecf335ffafc5f8 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Thu, 6 Aug 2020 15:53:57 +0200 Subject: [PATCH 71/78] Fix boxes also for Centernet Signed-off-by: Micaela Verucchi --- src/CenternetDetection.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index 394e24a..46757f4 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -372,10 +372,10 @@ void CenternetDetection::postprocess(const int bi, const bool mAP){ // std::cout<<"th: "< Date: Fri, 11 Sep 2020 09:13:59 +0200 Subject: [PATCH 72/78] Fix typos (#107) Signed-off-by: micaela --- README.md | 14 +++++++------- include/tkDNN/DetectionNN.h | 8 ++++---- include/tkDNN/ImuOdom.h | 4 ++-- include/tkDNN/Layer.h | 20 ++++++++++---------- include/tkDNN/Network.h | 8 ++++---- include/tkDNN/NetworkRT.h | 2 +- include/tkDNN/evaluation.h | 8 ++++---- include/tkDNN/pluginsRT/DeformableConvRT.h | 2 +- include/tkDNN/test.h | 2 +- src/DarknetParser.cpp | 2 +- src/DeformConv2d.cpp | 2 +- src/Dense.cpp | 2 +- src/LSTM.cpp | 10 +++++----- src/LayerWgs.cpp | 2 +- src/MulAdd.cpp | 2 +- src/NetworkRT.cpp | 2 +- src/Region.cpp | 2 +- src/Shortcut.cpp | 2 +- src/evaluation.cpp | 6 +++--- 19 files changed, 50 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index ea55785..f17f75e 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ M. Verucchi, G. Brilli, D. Sapienza, M. Verasani, M. Arena, F. Gatti, A. Capoton ``` ## FPS Results -Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimesion as the input size, on +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 ); * Tx2, Jetpack 4.2 (CUDA 10.0, CUDNN 7.3.1, tensorrt 5.0.6 ); @@ -169,7 +169,7 @@ tkDNN implement and easy parser for darknet cfg files, a network can be converte tk::dnn::Network *net = tk::dnn::darknetParser("yolov4.cfg", "yolov4/layers", "coco.names"); net->print(); ``` -All models from darknet are now parsed directly from cfg, you still need to export the weights with the descripted tools in the previus section. +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 @@ -203,7 +203,7 @@ cmake .. -DDEBUG=True make ``` -Once you have succesfully created your rt file, run the demo: +Once you have successfully created your rt file, run the demo: ``` ./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y ``` @@ -247,7 +247,7 @@ You should provide image_list.txt and label_list.txt, using training images. How ``` bash scripts/download_validation.sh COCO ``` -to automatically download COCO2017 validation (inside demo folder) and create those needed file. Use BDD insted of COCO to download BDD validation. +to automatically download COCO2017 validation (inside demo folder) and create those needed file. Use BDD instead of COCO to download BDD validation. Then a complete example using yolo3 and COCO dataset would be: ``` @@ -269,8 +269,8 @@ N.B. export TKDNN_BATCHSIZE=2 # build tensorRT files ``` -This will create a TensorRT file with the desidered **max** batch size. -The test will still run with a batch of 1, but the created tensorRT can manage the desidered batch size. +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. @@ -316,7 +316,7 @@ 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 subit the results to [CodaLab COCO detection challenge](https://competitions.codalab.org/competitions/20794#participate). +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 diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index ba42834..0498d41 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -76,10 +76,10 @@ 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. @@ -141,9 +141,9 @@ class DetectionNN { } /** - * Method to draw boundixg boxes and labels on a frame. + * Method to draw bounding boxes and labels on a frame. * - * @param frames orginal frame to draw bounding box on. + * @param frames original frame to draw bounding box on. */ void draw(std::vector& frames) { tk::dnn::box b; diff --git a/include/tkDNN/ImuOdom.h b/include/tkDNN/ImuOdom.h index 58def96..6d8d4cb 100644 --- a/include/tkDNN/ImuOdom.h +++ b/include/tkDNN/ImuOdom.h @@ -44,7 +44,7 @@ class ImuOdom { virtual ~ImuOdom() {} /** - * Method used for inizialize the class + * Method used for initialize the class * * @return Success of the initialization */ @@ -141,7 +141,7 @@ class ImuOdom { //odomPOS = odomPOS + deltaP.cast(); // V2 odomROT = odomROT * q.normalized().toRotationMatrix(); - // compute euler + // compute Euler auto newEULER = odomROT.eulerAngles(0, 1, 2); for(int i=0; i<3; i++) { while( fabs(newEULER(i) - odomEULER(i)) > M_PI_2 ) { diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index f2ec56d..790a431 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -171,7 +171,7 @@ public: /** - Input layer (it doesnt need weigths) + Input layer (it doesn't need weights) */ class Input : public Layer { @@ -207,7 +207,7 @@ public: /** - Avaible activation functions + Available activation functions */ typedef enum { ACTIVATION_ELU = 100, @@ -216,7 +216,7 @@ typedef enum { } tkdnnActivationMode_t; /** - Activation layer (it doesnt need weigths) + Activation layer (it doesn't need weights) */ class Activation : public Layer { @@ -318,9 +318,9 @@ public: virtual dnnType* infer(dataDim_t &dim, dnnType* srcData); const bool bidirectional = true; /**> 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: @@ -367,7 +367,7 @@ public: /** - Deformable Convolutionl 2d layer + Deformable Convolutional 2d layer */ class DeformConv2d : public LayerWgs { @@ -449,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, @@ -460,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 { @@ -526,7 +526,7 @@ public: /** Reorg layer - Mantain same dimension but change C*H*W distribution + Maintains same dimension but change C*H*W distribution */ class Reorg : public Layer { @@ -559,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 { diff --git a/include/tkDNN/Network.h b/include/tkDNN/Network.h index 2d95215..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 { @@ -43,7 +43,7 @@ public: 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 66b4f3d..4c6c816 100644 --- a/include/tkDNN/NetworkRT.h +++ b/include/tkDNN/NetworkRT.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/evaluation.h b/include/tkDNN/evaluation.h index 8907d9d..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,7 +101,7 @@ 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, 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; b input_bins, std::vector } if(output_bins.size() != outputs.size()) { std::cout< netLayers; std::ifstream if_cfg(cfg_file); diff --git a/src/DeformConv2d.cpp b/src/DeformConv2d.cpp index b161a22..dbb71e1 100644 --- a/src/DeformConv2d.cpp +++ b/src/DeformConv2d.cpp @@ -95,7 +95,7 @@ dnnType* DeformConv2d::infer(dataDim_t &dim, dnnType* srcData) { // split conv2d outputs into offset and mask checkCuda(cudaMemcpy(offset, output_conv, 2*chunk_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice)); checkCuda(cudaMemcpy(mask, output_conv + 2*chunk_dim, chunk_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice)); - // kernel sigmoide + // kernel sigmoid activationSIGMOIDForward(mask, mask, chunk_dim); // deformable convolution diff --git a/src/Dense.cpp b/src/Dense.cpp index b6a9af2..4371d06 100644 --- a/src/Dense.cpp +++ b/src/Dense.cpp @@ -37,7 +37,7 @@ dnnType* Dense::infer(dataDim_t &dim, dnnType* srcData) { // place bias into dstData checkCuda( cudaMemcpy(dstData, bias_d, dim_y*sizeof(dnnType), cudaMemcpyDeviceToDevice) ); - //do matrix moltiplication + //do matrix multiplication checkERROR( cublasSgemv(net->cublasHandle, CUBLAS_OP_T, dim_x, dim_y, &alpha, diff --git a/src/LSTM.cpp b/src/LSTM.cpp index 511fbee..7b87711 100644 --- a/src/LSTM.cpp +++ b/src/LSTM.cpp @@ -133,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; @@ -254,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 @@ -281,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 @@ -289,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 @@ -307,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/LayerWgs.cpp b/src/LayerWgs.cpp index 4afb7cc..a761327 100644 --- a/src/LayerWgs.cpp +++ b/src/LayerWgs.cpp @@ -105,7 +105,7 @@ 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); diff --git a/src/MulAdd.cpp b/src/MulAdd.cpp index 0c2a962..25cec8d 100644 --- a/src/MulAdd.cpp +++ b/src/MulAdd.cpp @@ -12,7 +12,7 @@ MulAdd::MulAdd(Network *net, dnnType mul, dnnType add) : Layer(net) { int size = input_dim.tot(); - // create a vector with all value setted to add + // create a vector with all value set to add dnnType *add_vector_h = new dnnType[size]; for(int i=0; igetBindingIndex("data"); buf_output_idx = engineRT->getBindingIndex("out"); - std::cout<<"input idex = "< output index = "< output index = "<getBindingDimensions(buf_input_idx); diff --git a/src/Region.cpp b/src/Region.cpp index 65bb786..7c26208 100644 --- a/src/Region.cpp +++ b/src/Region.cpp @@ -63,7 +63,7 @@ dnnType* Region::infer(dataDim_t &dim, dnnType* srcData) { } -/* Intepret class */ +/* Interpret class */ RegionInterpret::RegionInterpret(dataDim_t input_dim, dataDim_t output_dim, int classes, int coords, int num, float thresh, std::string fname_weights) { diff --git a/src/Shortcut.cpp b/src/Shortcut.cpp index 78a2f23..2c7a4f4 100644 --- a/src/Shortcut.cpp +++ b/src/Shortcut.cpp @@ -13,7 +13,7 @@ Shortcut::Shortcut(Network *net, Layer *backLayer) : Layer(net) { if( /*backLayer->output_dim.c != input_dim.c ||*/ backLayer->output_dim.w != input_dim.w || backLayer->output_dim.h != input_dim.h ) - FatalError("Shortcut dim missmatch"); + FatalError("Shortcut dim mismatch"); } Shortcut::~Shortcut() { diff --git a/src/evaluation.cpp b/src/evaluation.cpp index 58c951d..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 Date: Tue, 15 Sep 2020 10:50:24 +0200 Subject: [PATCH 73/78] Update README with Xavier NX FPS results Signed-off-by: Micaela Verucchi --- README.md | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index f17f75e..54b8140 100644 --- a/README.md +++ b/README.md @@ -18,27 +18,32 @@ M. Verucchi, G. Brilli, D. Sapienza, M. Verasani, M. Arena, F. Gatti, A. Capoton 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 | -| 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 | - | - | +| 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 | 11.49 | 13.79 | 25.26 | 35.51 | 33.77 | 45.66 | +| Xavier NX | yolo4 416 | 8.38 | 9.65 | 18.72 | 22.97 | 23.71 | 29.28 | +| Xavier NX | yolo4 512 | 7.03 | 7.57 | 13.50 | 15.43 | 17.95 | 19.70 | +| Xavier NX | yolo4 608 | 4.49 | 4.56 | 10.10 | 11.02 | 13.09 | 14.04 | +| 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 From d3372aad31d27d68593209f13e7c189752ec6e42 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Tue, 15 Sep 2020 14:09:02 +0200 Subject: [PATCH 74/78] Update README with Xavier NX FPS results 15W4Core Signed-off-by: Micaela Verucchi --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 54b8140..70ddd26 100644 --- a/README.md +++ b/README.md @@ -32,10 +32,10 @@ Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimensi | 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 | 11.49 | 13.79 | 25.26 | 35.51 | 33.77 | 45.66 | -| Xavier NX | yolo4 416 | 8.38 | 9.65 | 18.72 | 22.97 | 23.71 | 29.28 | -| Xavier NX | yolo4 512 | 7.03 | 7.57 | 13.50 | 15.43 | 17.95 | 19.70 | -| Xavier NX | yolo4 608 | 4.49 | 4.56 | 10.10 | 11.02 | 13.09 | 14.04 | +| 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 | - | - | From a0e7f05a50e5bc639a3c843139c39884d2c5a7fc Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Sat, 10 Oct 2020 13:03:01 +0200 Subject: [PATCH 75/78] Update README.md --- README.md | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 70ddd26..cdfa25b 100644 --- a/README.md +++ b/README.md @@ -3,15 +3,18 @@ tkDNN is a Deep Neural Network library built with cuDNN and tensorRT primitives, 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 one of the following papers. For use in commercial solutions, write at gattifrancesco@hotmail.it and micaela.verucchi@unimore.it or refer to https://hipert.unimore.it/ . +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/ . ``` -Accepted paper @ IRC 2020, will soon be published. -M. Verucchi, L. Bartoli, F. Bagni, F. Gatti, P. Burgio and M. Bertogna, "Real-Time clustering and LiDAR-camera fusion on embedded platforms for self-driving cars", in proceedings in IEEE Robotic Computing (2020) - -Accepted paper @ ETFA 2020, will soon be published. -M. Verucchi, G. Brilli, D. Sapienza, M. Verasani, M. Arena, F. Gatti, A. Capotondi, R. Cavicchioli, M. Bertogna, M. Solieri -"A Systematic Assessment of Embedded Neural Networks for Object Detection", in IEEE International Conference on Emerging Technologies and Factory Automation (2020) +@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 From 86478f9384eef13d68a9406ee12fbcb4df6ab892 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Fri, 23 Oct 2020 11:40:55 +0200 Subject: [PATCH 76/78] Add yolo4_mmr test Signed-off-by: Micaela Verucchi --- tests/darknet/cfg/yolo4_mmr.cfg | 1158 +++++++++++++++++++++++++++++++ tests/darknet/names/mmr.names | 4 + tests/darknet/yolo4_mmr.cpp | 34 + 3 files changed, 1196 insertions(+) create mode 100644 tests/darknet/cfg/yolo4_mmr.cfg create mode 100644 tests/darknet/names/mmr.names create mode 100644 tests/darknet/yolo4_mmr.cpp 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/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/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; +} From 702791e41ac302ed0396034cf80d6d76303ac20a Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 23 Nov 2020 11:25:52 +0100 Subject: [PATCH 77/78] Add support for yolov4x-mish. Changes: - add parameters nms_kind, nms_thresh, new_coords to yolo layer and darknet parser - added diou nms, new method to compute the BBs - created test for yolov4x-mish called yolo4x Tested, all tests work. Problem to solve: little loss in mAP of yolo4x Signed-off-by: Micaela Verucchi --- include/tkDNN/DarknetParser.h | 3 + include/tkDNN/Layer.h | 14 +- include/tkDNN/pluginsRT/YoloRT.h | 20 +- scripts/test_all_tests.sh | 1 + src/DarknetParser.cpp | 14 +- src/NetworkRT.cpp | 12 +- src/Yolo.cpp | 68 +- src/Yolo3Detection.cpp | 7 +- tests/darknet/cfg/yolo4x.cfg | 1427 ++++++++++++++++++++++++++++++ tests/darknet/yolo4x.cpp | 36 + 10 files changed, 1571 insertions(+), 31 deletions(-) create mode 100644 tests/darknet/cfg/yolo4x.cfg create mode 100644 tests/darknet/yolo4x.cpp diff --git a/include/tkDNN/DarknetParser.h b/include/tkDNN/DarknetParser.h index 29d1e8e..089c4d6 100644 --- a/include/tkDNN/DarknetParser.h +++ b/include/tkDNN/DarknetParser.h @@ -24,7 +24,10 @@ namespace tk { namespace dnn { 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"; diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index 790a431..25c4565 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -610,24 +610,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 = 8192; + 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/pluginsRT/YoloRT.h b/include/tkDNN/pluginsRT/YoloRT.h index f8e596c..9af8587 100644 --- a/include/tkDNN/pluginsRT/YoloRT.h +++ b/include/tkDNN/pluginsRT/YoloRT.h @@ -8,12 +8,15 @@ class YoloRT : public IPlugin { public: - YoloRT(int classes, int num, tk::dnn::Yolo *yolo = nullptr, int n_masks=3, float scale_xy=1) { + YoloRT(int classes, int num, tk::dnn::Yolo *yolo = nullptr, int n_masks=3, float scale_xy=1, float nms_thresh=0.45, int nms_kind=0, int new_coords=0) { this->classes = 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/scripts/test_all_tests.sh b/scripts/test_all_tests.sh index 770aa22..af04aff 100644 --- a/scripts/test_all_tests.sh +++ b/scripts/test_all_tests.sh @@ -73,6 +73,7 @@ do print_output $? imuodom test_net yolo4 + test_net yolo4x test_net yolo4_berkeley test_net yolo4tiny test_net yolo3 diff --git a/src/DarknetParser.cpp b/src/DarknetParser.cpp index 7d7d989..7b5410c 100644 --- a/src/DarknetParser.cpp +++ b/src/DarknetParser.cpp @@ -37,7 +37,10 @@ namespace tk { namespace dnn { std::string name,value; if(!divideNameAndValue(line, name, value)) return false; - if(name.find("width") != std::string::npos) + + 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); @@ -79,6 +82,13 @@ namespace tk { namespace dnn { 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 "<classesNames = names; diff --git a/src/NetworkRT.cpp b/src/NetworkRT.cpp index 9d38440..501ade4 100644 --- a/src/NetworkRT.cpp +++ b/src/NetworkRT.cpp @@ -529,7 +529,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Yolo *l) { //std::cout<<"convert Yolo\n"; //std::cout<<"New plugin YOLO\n"; - IPlugin *plugin = new YoloRT(l->classes, l->num, l, l->n_masks, l->scaleXY); + IPlugin *plugin = new YoloRT(l->classes, l->num, l, l->n_masks, l->scaleXY, l->nms_thresh, l->nsm_kind, l->new_coords); IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin); checkNULL(lRT); return lRT; @@ -739,12 +739,16 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa if(name.find("Yolo") == 0) { YoloRT *r = new YoloRT(readBUF(buf), //classes readBUF(buf), //num - nullptr, - readBUF(buf)); //n_masks + nullptr, //yolo + readBUF(buf), //n_masks + readBUF(buf), //scale_xy + readBUF(buf), //nms_thresh + readBUF(buf), //nms_kind + readBUF(buf) //new_coords + ); r->c = readBUF(buf); r->h = readBUF(buf); r->w = readBUF(buf); - r->scaleXY = readBUF(buf); for(int i=0; in_masks; i++) r->mask[i] = readBUF(buf); for(int i=0; in_masks*2*r->num; i++) diff --git a/src/Yolo.cpp b/src/Yolo.cpp index a4416be..9737e74 100644 --- a/src/Yolo.cpp +++ b/src/Yolo.cpp @@ -11,7 +11,7 @@ namespace tk { namespace dnn { -Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_masks, float scale_xy) : +Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_masks, float scale_xy, double nms_thresh, nmsKind_t nsm_kind, int new_coords) : Layer(net) { this->final = true; @@ -19,6 +19,9 @@ Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_ this->num = num; this->n_masks = n_masks; this->scaleXY = scale_xy; + this->nms_thresh = nms_thresh; + this->nsm_kind = nsm_kind; + this->new_coords = new_coords; // load anchors if(fname_weights != "") { @@ -59,12 +62,21 @@ int entry_index(int batch, int location, int entry, entry*input_dim.w*input_dim.h + loc; } -Yolo::box get_yolo_box(float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, int stride) { +Yolo::box get_yolo_box(float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, int stride, int new_coords) { Yolo::box b; - b.x = (i + x[index + 0*stride]) / lw; - b.y = (j + x[index + 1*stride]) / lh; - b.w = exp(x[index + 2*stride]) * biases[2*n] / w; - b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h; + + if(new_coords == 0){ + b.x = (i + x[index + 0*stride]) / lw; + b.y = (j + x[index + 1*stride]) / lh; + b.w = exp(x[index + 2*stride]) * biases[2*n] / w; + b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h; + } + else{ + b.x = (i + x[index + 0 * stride] * 2 - 0.5) / lw; + b.y = (j + x[index + 1 * stride] * 2 - 0.5) / lh; + b.w = x[index + 2 * stride] * x[index + 2 * stride] * 4 * biases[2 * n] / w; + b.h = x[index + 3 * stride] * x[index + 3 * stride] * 4 * biases[2 * n + 1] / h; + } return b; } @@ -75,7 +87,10 @@ dnnType* Yolo::infer(dataDim_t &dim, dnnType* srcData) { for (int b = 0; b < dim.n; ++b){ for(int n = 0; n < n_masks; ++n){ int index = entry_index(b, n*dim.w*dim.h, 0, classes, input_dim, output_dim); - activationLOGISTICForward(srcData + index, dstData + index, 2*dim.w*dim.h); + if (new_coords == 1) + activationLOGISTICForward(srcData + index, dstData + index, 4*dim.w*dim.h); + else + activationLOGISTICForward(srcData + index, dstData + index, 2*dim.w*dim.h); if (this->scaleXY != 1) scalAdd(dstData + index, 2 * dim.w*dim.h, this->scaleXY, -0.5*(this->scaleXY - 1), 1); @@ -116,7 +131,7 @@ void correct_yolo_boxes(Yolo::detection *dets, int n, int w, int h, int netw, in } } -int Yolo::computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh) { +int Yolo::computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh, int new_coords) { if(predictions == nullptr) predictions = new dnnType[output_dim.tot()]; @@ -140,7 +155,7 @@ int Yolo::computeDetections(Yolo::detection *dets, int &ndets, int netw, int net if(objectness <= thresh) continue; int box_index = entry_index(0, n*lw*lh + i, 0, classes, input_dim, output_dim); - dets[count].bbox = get_yolo_box(predictions, bias_h, mask_h[n], box_index, col, row, lw, lh, netw, neth, lw*lh); + dets[count].bbox = get_yolo_box(predictions, bias_h, mask_h[n], box_index, col, row, lw, lh, netw, neth, lw*lh, new_coords); dets[count].objectness = objectness; dets[count].classes = classes; for(j = 0; j < classes; ++j){ @@ -193,6 +208,32 @@ float yolo_box_iou(Yolo::box a, Yolo::box b) return yolo_box_intersection(a, b)/yolo_box_union(a, b); } +void box_c(const Yolo::box a, const Yolo::box b, float& top, float& bot, float& left, float& right) { + top = std::min(a.y - a.h / 2, b.y - b.h / 2); + bot = std::max(a.y + a.h / 2, b.y + b.h / 2); + left = std::min(a.x - a.w / 2, b.x - b.w / 2); + right = std::max(a.x + a.w / 2, b.x + b.w / 2); +} + +// https://github.com/Zzh-tju/DIoU-darknet +// https://arxiv.org/abs/1911.08287 +float yolo_box_diou(const Yolo::box a, const Yolo::box b, const float nms_thresh=0.6) +{ + float top, bot, left, right; + box_c(a, b, top, bot, left, right); + float w = right - left; + float h = bot - top; + float c = w * w + h * h; + float iou = yolo_box_iou(a, b); + if (c == 0) + return iou; + + float d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); + float u = pow(d / c, nms_thresh); + float diou_term = u; + return iou - diou_term; +} + int yolo_nms_comparator(const void *pa, const void *pb) { Yolo::detection a = *(Yolo::detection *)pa; @@ -219,8 +260,7 @@ Yolo::detection *Yolo::allocateDetections(int nboxes, int classes) { return dets; } -void Yolo::mergeDetections(Yolo::detection *dets, int ndets, int classes) { - double nms_thresh = 0.45; +void Yolo::mergeDetections(Yolo::detection *dets, int ndets, int classes, double nms_thresh, nmsKind_t nsm_kind) { int total = ndets; int i, j, k; @@ -246,13 +286,13 @@ void Yolo::mergeDetections(Yolo::detection *dets, int ndets, int classes) { box a = dets[i].bbox; for(j = i+1; j < total; ++j){ box b = dets[j].bbox; - if (yolo_box_iou(a, b) > nms_thresh){ + if (nsm_kind == GREEDY_NMS && yolo_box_iou(a, b) > nms_thresh) + dets[j].prob[k] = 0; + else if (nsm_kind == DIOU_NMS && yolo_box_diou(a, b, nms_thresh) > nms_thresh) dets[j].prob[k] = 0; - } } } } - } }} diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index e9b0064..b94eea9 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -32,6 +32,9 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, c memcpy(yolo[i]->bias_h, yRT->bias, sizeof(dnnType)*num*nMasks*2); yolo[i]->input_dim = yolo[i]->output_dim = tk::dnn::dataDim_t(1, yRT->c, yRT->h, yRT->w); yolo[i]->classesNames = yRT->classesNames; + yolo[i]->nms_thresh = yRT->nms_thresh; + yolo[i]->nsm_kind = (tk::dnn::Yolo::nmsKind_t) yRT->nms_kind; + yolo[i]->new_coords = yRT->new_coords; } dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes); @@ -102,9 +105,9 @@ void Yolo3Detection::postprocess(const int bi, const bool mAP){ 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(); 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/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; +} From b8855b9599e52a51b371e99255063cd6f00fecd7 Mon Sep 17 00:00:00 2001 From: Micaela Verucchi Date: Mon, 23 Nov 2020 11:34:06 +0100 Subject: [PATCH 78/78] Update README Signed-off-by: Micaela Verucchi --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cdfa25b..84e0037 100644 --- a/README.md +++ b/README.md @@ -352,7 +352,8 @@ This demo also creates a json file named ```net_name_COCO_res.json``` containing | 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 | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/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 @@ -365,3 +366,4 @@ This demo also creates a json file named ```net_name_COCO_res.json``` containing 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)