Merge branch 'tree' into ipmslam

This commit is contained in:
Francesco Gatti
2020-05-03 15:58:43 +02:00
24 changed files with 4531 additions and 68 deletions
+9
View File
@@ -113,9 +113,15 @@ 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)
@@ -125,6 +131,9 @@ 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)
+335 -17
View File
@@ -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.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 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.
<signature of Ty Coon>, 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.
+38 -11
View File
@@ -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)
@@ -69,10 +72,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
@@ -114,9 +117,9 @@ python run_ssd_live_demo.py mb2-ssd-lite <pth-model-fil> <labels-file>
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 +139,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 +156,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,16 +169,38 @@ 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
This will test the network with random input and check if the output of each batch is the same.
```
./test_rtinference <network-rt-file> <number-of-batches>
# <number-of-batches> should be less or equal to the max batch size of the <network-rt-file>
# 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
To compute mAP, precision, recall and f1score, run the map_demo.
A validation set is needed. To download COCO_val2017 run (form the root folder):
A validation set is needed.
To download COCO_val2017 (80 classes) run (form the root folder):
```
bash scripts/download_validation.sh
bash scripts/download_validation.sh COCO
```
To download Berkeley_val (10 classes) run (form the root folder):
```
bash scripts/download_validation.sh BDD
```
To compute the map, the following parameters are needed:
```
./map_demo <network rt> <network type [y|c|m]> <labels file path> <config file path>
@@ -204,7 +229,7 @@ cd build
| yolo_tiny | YOLO v2 tiny<sup>1</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/m3orfJr8pGrN5mQ/download) |
| yolo_voc | YOLO v2<sup>1</sup> | [VOC ](http://host.robots.ox.ac.uk/pascal/VOC/) | 21 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/DJC5Fi2pEjfNDP9/download) |
| yolo3 | YOLO v3<sup>2</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download) |
| yolo3_512 | YOLO v3<sup>2</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/e7HfScx77JEHeYb/download) |
| yolo3_512 | YOLO v3<sup>2</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/RGecMeGLD4cXEWL/download) |
| yolo3_berkeley | YOLO v3<sup>2</sup> | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 320x544 | [weights](https://cloud.hipert.unimore.it/s/o5cHa4AjTKS64oD/download) |
| yolo3_coco4 | YOLO v3<sup>2</sup> | [COCO 2014](http://cocodataset.org/) | 4 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/o27NDzSAartbyc4/download) |
| yolo3_flir | YOLO v3<sup>2</sup> | [FREE FLIR](https://www.flir.com/oem/adas/adas-dataset-form/) | 3 | 320x544 | [weights](https://cloud.hipert.unimore.it/s/62DECncmF6bMMiH/download) |
@@ -217,6 +242,7 @@ cd build
| resnet101 | Resnet 101<sup>6</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 224x224 | weights |
| resnet101_cnet | Centernet (Resnet101 backend)<sup>4</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/5BTjHMWBcJk8g3i/download) |
| csresnext50-panet-spp | Cross Stage Partial Network <sup>7</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/Kcs4xBozwY4wFx8/download) |
| yolo4 | Yolov4 <sup>8</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) |
## References
@@ -228,3 +254,4 @@ cd build
5. Sandler, Mark, et al. "Mobilenetv2: Inverted residuals and linear bottlenecks." Proceedings of the IEEE conference on computer vision and pattern recognition. 2018.
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).
+14 -3
View File
@@ -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;
}
@@ -136,8 +137,18 @@ class ImuOdom {
q.x() = deltaQ(1);
q.y() = deltaQ(2);
q.z() = deltaQ(3);
odomPOS = odomPOS + odomROT*deltaP.cast<double>();
odomPOS = odomPOS + deltaP.cast<double>();
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<<newEULER(i)<<" "<<odomEULER(i)<<"\n";
}
}
odomEULER = newEULER;
// compose tf
tf.matrix().block(0, 0, 3, 3) = odomROT.cast<float>();
+8 -2
View File
@@ -18,6 +18,7 @@ enum layerType_t {
LAYER_ACTIVATION,
LAYER_ACTIVATION_CRELU,
LAYER_ACTIVATION_LEAKY,
LAYER_ACTIVATION_MISH,
LAYER_FLATTEN,
LAYER_RESHAPE,
LAYER_MULADD,
@@ -66,6 +67,7 @@ public:
case LAYER_ACTIVATION: return "Activation";
case LAYER_ACTIVATION_CRELU: return "ActivationCReLU";
case LAYER_ACTIVATION_LEAKY: return "ActivationLeaky";
case LAYER_ACTIVATION_MISH: return "ActivationMish";
case LAYER_FLATTEN: return "Flatten";
case LAYER_RESHAPE: return "Reshape";
case LAYER_MULADD: return "MulAdd";
@@ -168,7 +170,8 @@ public:
*/
typedef enum {
ACTIVATION_ELU = 100,
ACTIVATION_LEAKY = 101
ACTIVATION_LEAKY = 101,
ACTIVATION_MISH = 102
} tkdnnActivationMode_t;
/**
@@ -187,6 +190,8 @@ public:
return LAYER_ACTIVATION_CRELU;
else if (act_mode == ACTIVATION_LEAKY)
return LAYER_ACTIVATION_LEAKY;
else if (act_mode == ACTIVATION_MISH)
return LAYER_ACTIVATION_MISH;
else
return LAYER_ACTIVATION;
};
@@ -561,13 +566,14 @@ public:
int sort_class;
};
Yolo(Network *net, int classes, int num, std::string fname_weights, int n_masks=3);
Yolo(Network *net, int classes, int num, std::string fname_weights,int n_masks=3, float scale_xy=1);
virtual ~Yolo();
virtual layerType_t getLayerType() { return LAYER_YOLO; };
int classes, num, n_masks;
dnnType *mask_h, *mask_d; //anchors
dnnType *bias_h, *bias_d; //anchors
float scaleXY;
std::vector<std::string> classesNames;
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
+1
View File
@@ -25,6 +25,7 @@ template<typename T> T readBUF(const char*& buffer)
using namespace nvinfer1;
#include "pluginsRT/ActivationLeakyRT.h"
#include "pluginsRT/ActivationReLUCeilingRT.h"
#include "pluginsRT/ActivationMishRT.h"
#include "pluginsRT/ReorgRT.h"
#include "pluginsRT/RegionRT.h"
//#include "pluginsRT/RouteRT.h"
+3
View File
@@ -8,6 +8,7 @@ void activationLEAKYForward(dnnType *srcData, dnnType *dstData, int size, cudaSt
void activationReLUCeilingForward(dnnType *srcData, dnnType *dstData, int size, const float ceiling, cudaStream_t stream = cudaStream_t(0));
void activationLOGISTICForward(dnnType *srcData, dnnType *dstData, int size, cudaStream_t stream = cudaStream_t(0));
void activationSIGMOIDForward(dnnType *srcData, dnnType *dstData, int size, cudaStream_t stream = cudaStream_t(0));
void activationMishForward(dnnType* srcData, dnnType* dstData, int size, cudaStream_t stream= cudaStream_t(0));
void fill(dnnType *data, int size, dnnType val, cudaStream_t stream = cudaStream_t(0));
@@ -45,4 +46,6 @@ void dcnV2CudaForward(cublasStatus_t stat, cublasHandle_t handle,
const int in_n, const int in_c, const int in_h, const int in_w,
const int out_n, const int out_c, const int out_h, const int out_w,
const int dst_dim, cudaStream_t stream = cudaStream_t(0));
void scalAdd(dnnType* dstData, int size, float alpha, float beta, int inc, cudaStream_t stream = cudaStream_t(0));
#endif //KERNELS_H
@@ -0,0 +1,60 @@
#include<cassert>
#include "../kernels.h"
class ActivationMishRT : public IPlugin {
public:
ActivationMishRT() {
}
~ActivationMishRT(){
}
int getNbOutputs() const override {
return 1;
}
Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override {
return inputs[0];
}
void configure(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, int maxBatchSize) override {
size = 1;
for(int i=0; i<outputDims[0].nbDims; i++)
size *= outputDims[0].d[i];
}
int initialize() override {
return 0;
}
virtual void terminate() override {
}
virtual size_t getWorkspaceSize(int maxBatchSize) const override {
return 0;
}
virtual int enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream) override {
activationMishForward((dnnType*)reinterpret_cast<const dnnType*>(inputs[0]),
reinterpret_cast<dnnType*>(outputs[0]), batchSize*size, stream);
return 0;
}
virtual size_t getSerializationSize() override {
return 1*sizeof(int);
}
virtual void serialize(void* buffer) override {
char *buf = reinterpret_cast<char*>(buffer);
tk::dnn::writeBUF(buf, size);
}
int size;
};
+7 -2
View File
@@ -8,11 +8,12 @@ class YoloRT : public IPlugin {
public:
YoloRT(int classes, int num, tk::dnn::Yolo *yolo = nullptr, int n_masks=3) {
YoloRT(int classes, int num, tk::dnn::Yolo *yolo = nullptr, int n_masks=3, float scale_xy=1) {
this->classes = classes;
this->num = num;
this->n_masks = n_masks;
this->scaleXY = scale_xy;
mask = new dnnType[n_masks];
bias = new dnnType[num*n_masks*2];
@@ -64,6 +65,8 @@ public:
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 (this->scaleXY != 1) scalAdd(dstData + index, 2 * w*h, this->scaleXY, -0.5*(this->scaleXY - 1), 1);
index = entry_index(b, n*w*h, 4);
activationLOGISTICForward(srcData + index, dstData + index, (1+classes)*w*h, stream);
@@ -76,7 +79,7 @@ public:
virtual size_t getSerializationSize() override {
return 6*sizeof(int) + n_masks*sizeof(dnnType) + num*n_masks*2*sizeof(dnnType) + YOLORT_CLASSNAME_W*classes*sizeof(char);
return 6*sizeof(int) + 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,6 +90,7 @@ public:
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<n_masks; i++)
tk::dnn::writeBUF(buf, mask[i]);
for(int i=0; i<n_masks*2*num; i++)
@@ -104,6 +108,7 @@ public:
int c, h, w;
int classes, num, n_masks;
float scaleXY;
std::vector<std::string> classesNames;
dnnType *mask;
+24 -6
View File
@@ -1,8 +1,26 @@
#!/bin/bash
cd demo
wget https://cloud.hipert.unimore.it/s/LNxBDk4wzqXPL8c/download -O COCO_val2017.zip
unzip -d COCO_val2017 COCO_val2017.zip
rm COCO_val2017.zip
cd COCO_val2017/
realpath labels/* > all_labels.txt
function elaborate_testset {
wget $1 -O $2.zip
unzip -d $2 $2.zip
rm $2.zip
cd $2/
realpath labels/* > all_labels.txt
realpath images/* > all_images.txt
cd ..
}
cd demo
for valset in $@
do
if [ $valset = "COCO" ]; then
echo "Downloading $valset validation set in demo"
elaborate_testset "https://cloud.hipert.unimore.it/s/LNxBDk4wzqXPL8c/download" "COCO_val2017"
elif [ $valset = "BDD" ]; then
echo "Downloading $valset validation set in demo"
elaborate_testset "https://cloud.hipert.unimore.it/s/bikqk3FzCq2tg4D/download" "BDD100K_val"
fi
done
+2 -1
View File
@@ -71,6 +71,7 @@ do
./test_imuodom &>> $out_file
print_output $? imuodom
test_net yolo4
test_net resnet101_cnet
test_net yolo3
test_net yolo3_flir
@@ -87,7 +88,7 @@ do
test_net yolo_voc
test_net dla34_cnet
test_net yolo3_coco4
done
echo "If errors occured, check logfile $out_file"
+4
View File
@@ -48,6 +48,10 @@ dnnType* Activation::infer(dataDim_t &dim, dnnType* srcData) {
if(act_mode == ACTIVATION_LEAKY) {
activationLEAKYForward(srcData, dstData, dim.tot());
}
else if(act_mode == ACTIVATION_MISH) {
activationMishForward(srcData, dstData, dim.tot());
} else {
dnnType alpha = dnnType(1);
dnnType beta = dnnType(0);
+7 -2
View File
@@ -172,7 +172,12 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe
colors[c] = cv::Scalar(int(255.0 * b), int(255.0 * g), int(255.0 * r));
}
if(classes == 21){
if(classes == 11){ //BDD
const char *classes_names_[] = {
"person","car","truck","bus","motor","bike","rider","traffic light","traffic sign","train"};
classesNames = std::vector<std::string>(classes_names_, std::end(classes_names_));
}
else if(classes == 21){ //VOC
const char *classes_names_[] = {
"aeroplane", "bicycle", "bird", "boat", "bottle", "bus",
"car", "cat", "chair", "cow", "diningtable", "dog", "horse", "motorbike",
@@ -180,7 +185,7 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe
classesNames = std::vector<std::string>(classes_names_, std::end(classes_names_));
}
else if (classes == 81){
else if (classes == 81){ //COCO
const char *classes_names_[] = {
"person" , "bicycle" , "car" , "motorbike" , "aeroplane" , "bus" ,
"train" , "truck" , "boat" , "traffic light" , "fire hydrant" , "stop sign" ,
+16 -3
View File
@@ -225,7 +225,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Layer *l) {
return convert_layer(input, (Conv2d*) l);
if(type == LAYER_POOLING)
return convert_layer(input, (Pooling*) l);
if(type == LAYER_ACTIVATION || type == LAYER_ACTIVATION_CRELU || type == LAYER_ACTIVATION_LEAKY)
if(type == LAYER_ACTIVATION || type == LAYER_ACTIVATION_CRELU || type == LAYER_ACTIVATION_LEAKY || type == LAYER_ACTIVATION_MISH)
return convert_layer(input, (Activation*) l);
if(type == LAYER_SOFTMAX)
return convert_layer(input, (Softmax*) l);
@@ -413,7 +413,14 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Activation *l) {
IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin);
checkNULL(lRT);
return lRT;
} else {
}
else if(l->act_mode == ACTIVATION_MISH) {
IPlugin *plugin = new ActivationMishRT();
IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin);
checkNULL(lRT);
return lRT;
}
else {
FatalError("this Activation mode is not yet implemented");
return NULL;
}
@@ -518,7 +525,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);
IPlugin *plugin = new YoloRT(l->classes, l->num, l, l->n_masks, l->scaleXY);
IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin);
checkNULL(lRT);
return lRT;
@@ -637,6 +644,11 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
a->size = readBUF<int>(buf);
return a;
}
if(name.find("ActivationMish") == 0) {
ActivationMishRT *a = new ActivationMishRT();
a->size = readBUF<int>(buf);
return a;
}
if(name.find("ActivationCReLU") == 0) {
ActivationReLUCeiling *a = new ActivationReLUCeiling(readBUF<float>(buf));
a->size = readBUF<int>(buf);
@@ -728,6 +740,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
r->c = readBUF<int>(buf);
r->h = readBUF<int>(buf);
r->w = readBUF<int>(buf);
r->scaleXY = readBUF<float>(buf);
for(int i=0; i<r->n_masks; i++)
r->mask[i] = readBUF<dnnType>(buf);
for(int i=0; i<r->n_masks*2*r->num; i++)
+4 -1
View File
@@ -11,12 +11,13 @@
namespace tk { namespace dnn {
Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_masks) :
Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_masks, float scale_xy) :
Layer(net) {
this->classes = classes;
this->num = num;
this->n_masks = n_masks;
this->scaleXY = scale_xy;
// load anchors
if(fname_weights != "") {
@@ -74,6 +75,8 @@ dnnType* Yolo::infer(dataDim_t &dim, dnnType* srcData) {
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 (this->scaleXY != 1) scalAdd(dstData + index, 2 * dim.w*dim.h, this->scaleXY, -0.5*(this->scaleXY - 1), 1);
index = entry_index(b, n*dim.w*dim.h, 4, classes, input_dim, output_dim);
activationLOGISTICForward(srcData + index, dstData + index, (1+classes)*dim.w*dim.h);
+31
View File
@@ -0,0 +1,31 @@
#include "kernels.h"
#include <math.h>
#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) {
if (x > threshold) return x; // too large
else if (x < -threshold) return expf(x); // too small
return logf(expf(x) + 1);
}
// 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));
}
/**
Mish activation function
*/
void activationMishForward(dnnType* srcData, dnnType* dstData, int size, cudaStream_t stream)
{
int blocks = (size+255)/256;
int threads = 256;
activation_mish<<<blocks, threads, 0, stream>>>(srcData, dstData, size);
}
+16
View File
@@ -0,0 +1,16 @@
#include "kernels.h"
#include <math.h>
__global__ void scal_add_kernel(dnnType* dstData, int size, float alpha, float beta, int inc)
{
int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
if (i < size) dstData[i*inc] = dstData[i*inc] * alpha + beta;
}
void scalAdd(dnnType* dstData, int size, float alpha, float beta, int inc, cudaStream_t stream)
{
int blocks = (size+255)/256;
int threads = 256;
scal_add_kernel<<<blocks, threads, 0, stream>>>(dstData, size, alpha, beta, inc);
}
@@ -0,0 +1,554 @@
#include <iostream>
#include <vector>
#include "tkdnn.h"
int main()
{
// Network layout
tk::dnn::dataDim_t dim(1, 3, 320, 544, 1);
tk::dnn::Network net(dim);
// create bdd-csresnext50-panet-spp model
std::string bin_path = "bdd-csresnext50-panet-spp";
int classes = 10;
tk::dnn::Yolo *yolo[3];
std::string input_bin = bin_path + "/layers/input.bin";
std::string output_bin = bin_path + "/debug/layer137_out.bin";
std::vector<std::string> output_bins = {
bin_path + "/debug/layer115_out.bin",
bin_path + "/debug/layer126_out.bin",
bin_path + "/debug/layer137_out.bin"};
std::string c0_bin = bin_path + "/layers/c0.bin";
std::string c2_bin = bin_path + "/layers/c2.bin";
std::string c4_bin = bin_path + "/layers/c4.bin";
std::string c5_bin = bin_path + "/layers/c5.bin";
std::string c6_bin = bin_path + "/layers/c6.bin";
std::string c7_bin = bin_path + "/layers/c7.bin";
std::string c9_bin = bin_path + "/layers/c9.bin";
std::string c10_bin = bin_path + "/layers/c10.bin";
std::string c11_bin = bin_path + "/layers/c11.bin";
std::string c13_bin = bin_path + "/layers/c13.bin";
std::string c14_bin = bin_path + "/layers/c14.bin";
std::string c15_bin = bin_path + "/layers/c15.bin";
std::string c17_bin = bin_path + "/layers/c17.bin";
std::string c19_bin = bin_path + "/layers/c19.bin";
std::string c20_bin = bin_path + "/layers/c20.bin";
std::string c21_bin = bin_path + "/layers/c21.bin";
std::string c23_bin = bin_path + "/layers/c23.bin";
std::string c24_bin = bin_path + "/layers/c24.bin";
std::string c25_bin = bin_path + "/layers/c25.bin";
std::string c26_bin = bin_path + "/layers/c26.bin";
std::string c28_bin = bin_path + "/layers/c28.bin";
std::string c29_bin = bin_path + "/layers/c29.bin";
std::string c30_bin = bin_path + "/layers/c30.bin";
std::string c32_bin = bin_path + "/layers/c32.bin";
std::string c33_bin = bin_path + "/layers/c33.bin";
std::string c34_bin = bin_path + "/layers/c34.bin";
std::string c36_bin = bin_path + "/layers/c36.bin";
std::string c38_bin = bin_path + "/layers/c38.bin";
std::string c39_bin = bin_path + "/layers/c39.bin";
std::string c40_bin = bin_path + "/layers/c40.bin";
std::string c42_bin = bin_path + "/layers/c42.bin";
std::string c43_bin = bin_path + "/layers/c43.bin";
std::string c44_bin = bin_path + "/layers/c44.bin";
std::string c45_bin = bin_path + "/layers/c45.bin";
std::string c47_bin = bin_path + "/layers/c47.bin";
std::string c48_bin = bin_path + "/layers/c48.bin";
std::string c49_bin = bin_path + "/layers/c49.bin";
std::string c51_bin = bin_path + "/layers/c51.bin";
std::string c52_bin = bin_path + "/layers/c52.bin";
std::string c53_bin = bin_path + "/layers/c53.bin";
std::string c55_bin = bin_path + "/layers/c55.bin";
std::string c56_bin = bin_path + "/layers/c56.bin";
std::string c57_bin = bin_path + "/layers/c57.bin";
std::string c59_bin = bin_path + "/layers/c59.bin";
std::string c60_bin = bin_path + "/layers/c60.bin";
std::string c61_bin = bin_path + "/layers/c61.bin";
std::string c63_bin = bin_path + "/layers/c63.bin";
std::string c65_bin = bin_path + "/layers/c65.bin";
std::string c66_bin = bin_path + "/layers/c66.bin";
std::string c67_bin = bin_path + "/layers/c67.bin";
std::string c69_bin = bin_path + "/layers/c69.bin";
std::string c70_bin = bin_path + "/layers/c70.bin";
std::string c71_bin = bin_path + "/layers/c71.bin";
std::string c72_bin = bin_path + "/layers/c72.bin";
std::string c74_bin = bin_path + "/layers/c74.bin";
std::string c75_bin = bin_path + "/layers/c75.bin";
std::string c76_bin = bin_path + "/layers/c76.bin";
std::string c78_bin = bin_path + "/layers/c78.bin";
std::string c80_bin = bin_path + "/layers/c80.bin";
std::string c81_bin = bin_path + "/layers/c81.bin";
std::string c82_bin = bin_path + "/layers/c82.bin";
std::string c83_bin = bin_path + "/layers/c83.bin";
std::string c90_bin = bin_path + "/layers/c90.bin";
std::string c91_bin = bin_path + "/layers/c91.bin";
std::string c92_bin = bin_path + "/layers/c92.bin";
std::string c93_bin = bin_path + "/layers/c93.bin";
std::string c96_bin = bin_path + "/layers/c96.bin";
std::string c98_bin = bin_path + "/layers/c98.bin";
std::string c99_bin = bin_path + "/layers/c99.bin";
std::string c100_bin = bin_path + "/layers/c100.bin";
std::string c101_bin = bin_path + "/layers/c101.bin";
std::string c102_bin = bin_path + "/layers/c102.bin";
std::string c103_bin = bin_path + "/layers/c103.bin";
std::string c106_bin = bin_path + "/layers/c106.bin";
std::string c108_bin = bin_path + "/layers/c108.bin";
std::string c109_bin = bin_path + "/layers/c109.bin";
std::string c110_bin = bin_path + "/layers/c110.bin";
std::string c111_bin = bin_path + "/layers/c111.bin";
std::string c112_bin = bin_path + "/layers/c112.bin";
std::string c113_bin = bin_path + "/layers/c113.bin";
std::string c114_bin = bin_path + "/layers/c114.bin";
std::string c117_bin = bin_path + "/layers/c117.bin";
std::string c119_bin = bin_path + "/layers/c119.bin";
std::string c120_bin = bin_path + "/layers/c120.bin";
std::string c121_bin = bin_path + "/layers/c121.bin";
std::string c122_bin = bin_path + "/layers/c122.bin";
std::string c123_bin = bin_path + "/layers/c123.bin";
std::string c124_bin = bin_path + "/layers/c124.bin";
std::string c125_bin = bin_path + "/layers/c125.bin";
std::string c128_bin = bin_path + "/layers/c128.bin";
std::string c130_bin = bin_path + "/layers/c130.bin";
std::string c131_bin = bin_path + "/layers/c131.bin";
std::string c132_bin = bin_path + "/layers/c132.bin";
std::string c133_bin = bin_path + "/layers/c133.bin";
std::string c134_bin = bin_path + "/layers/c134.bin";
std::string c135_bin = bin_path + "/layers/c135.bin";
std::string c136_bin = bin_path + "/layers/c136.bin";
std::string g115_bin = bin_path + "/layers/g115.bin";
std::string g126_bin = bin_path + "/layers/g126.bin";
std::string g137_bin = bin_path + "/layers/g137.bin";
// downloadWeightsifDoNotExist(input_bin, bin_path, "https://cloud.hipert.unimore.it/s//download");
tk::dnn::Conv2d c0(&net, 64, 7, 7, 2, 2, 3, 3, c0_bin, true);
tk::dnn::Activation a0(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Pooling p1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
tk::dnn::Conv2d c2(&net, 128, 1, 1, 1, 1, 0, 0, c2_bin, true);
tk::dnn::Activation a2(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r3_layers[1] = {&p1};
tk::dnn::Route r3(&net, r3_layers, 1);
tk::dnn::Conv2d c4(&net, 64, 1, 1, 1, 1, 0, 0, c4_bin, true);
tk::dnn::Activation a4(&net, tk::dnn::ACTIVATION_LEAKY);
// //1-1
tk::dnn::Conv2d c5(&net, 128, 1, 1, 1, 1, 0, 0, c5_bin, true);
tk::dnn::Activation a5(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c6(&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true, false, 32, false);
tk::dnn::Activation a6(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c7(&net, 128, 1, 1, 1, 1, 0, 0, c7_bin, true);
tk::dnn::Shortcut s8(&net, &a4);
tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY);
//1-2
tk::dnn::Conv2d c9(&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true);
tk::dnn::Activation a9(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c10(&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true, false, 32);
tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c11(&net, 128, 1, 1, 1, 1, 0, 0, c11_bin, true);
tk::dnn::Shortcut s12(&net, &a8);
tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY);
//1-3
tk::dnn::Conv2d c13(&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true);
tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c14(&net, 128, 3, 3, 1, 1, 1, 1, c14_bin, true, false, 32);
tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c15(&net, 128, 1, 1, 1, 1, 0, 0, c15_bin, true);
tk::dnn::Shortcut s16(&net, &a12);
tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_LEAKY);
// //1-T
tk::dnn::Conv2d c17(&net, 128, 1, 1, 1, 1, 0, 0, c17_bin, true);
tk::dnn::Activation a17(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r18_layers[2] = {&a17, &a2};
tk::dnn::Route r18(&net, r18_layers, 2);
tk::dnn::Conv2d c19(&net, 256, 1, 1, 1, 1, 0, 0, c19_bin, true);
tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c20(&net, 256, 3, 3, 2, 2, 1, 1, c20_bin, true, false, 32);
tk::dnn::Activation a20(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c21(&net, 256, 1, 1, 1, 1, 0, 0, c21_bin, true);
tk::dnn::Layer *r22_layers[2] = {&a20};
tk::dnn::Route r22(&net, r22_layers, 1);
tk::dnn::Conv2d c23(&net, 256, 1, 1, 1, 1, 0, 0, c23_bin, true);
//2-1
tk::dnn::Conv2d c24(&net, 256, 1, 1, 1, 1, 0, 0, c24_bin, true);
tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c25(&net, 256, 3, 3, 1, 1, 1, 1, c25_bin, true, false, 32);
tk::dnn::Activation a25(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c26(&net, 256, 1, 1, 1, 1, 0, 0, c26_bin, true);
tk::dnn::Shortcut s27(&net, &c23);
tk::dnn::Activation a27(&net, tk::dnn::ACTIVATION_LEAKY);
//2-2
tk::dnn::Conv2d c28(&net, 256, 1, 1, 1, 1, 0, 0, c28_bin, true);
tk::dnn::Activation a28(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c29(&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true, false, 32);
tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c30(&net, 256, 1, 1, 1, 1, 0, 0, c30_bin, true);
tk::dnn::Shortcut s31(&net, &a27);
tk::dnn::Activation a31(&net, tk::dnn::ACTIVATION_LEAKY);
//2-3
tk::dnn::Conv2d c32(&net, 256, 1, 1, 1, 1, 0, 0, c32_bin, true);
tk::dnn::Activation a32(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c33(&net, 256, 3, 3, 1, 1, 1, 1, c33_bin, true, false, 32);
tk::dnn::Activation a33(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c34(&net, 256, 1, 1, 1, 1, 0, 0, c34_bin, true);
tk::dnn::Shortcut s35(&net, &a31);
tk::dnn::Activation a35(&net, tk::dnn::ACTIVATION_LEAKY);
// //2-T
tk::dnn::Conv2d c36(&net, 256, 1, 1, 1, 1, 0, 0, c36_bin, true);
tk::dnn::Activation a36(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r37_layers[2] = {&a36, &c21};
tk::dnn::Route r37(&net, r37_layers, 2);
tk::dnn::Conv2d c38(&net, 512, 1, 1, 1, 1, 0, 0, c38_bin, true);
tk::dnn::Activation a38(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c39(&net, 512, 3, 3, 2, 2, 1, 1, c39_bin, true, false, 32);
tk::dnn::Activation a39(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c40(&net, 512, 1, 1, 1, 1, 0, 0, c40_bin, true);
tk::dnn::Layer *r41_layers[2] = {&a39};
tk::dnn::Route r41(&net, r41_layers, 1);
tk::dnn::Conv2d c42(&net, 512, 1, 1, 1, 1, 0, 0, c42_bin, true);
//3-1
tk::dnn::Conv2d c43(&net, 512, 1, 1, 1, 1, 0, 0, c43_bin, true);
tk::dnn::Activation a43(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c44(&net, 512, 3, 3, 1, 1, 1, 1, c44_bin, true, false, 32);
tk::dnn::Activation a44(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c45(&net, 512, 1, 1, 1, 1, 0, 0, c45_bin, true);
tk::dnn::Shortcut s46(&net, &c42);
tk::dnn::Activation a46(&net, tk::dnn::ACTIVATION_LEAKY);
//3-2
tk::dnn::Conv2d c47(&net, 512, 1, 1, 1, 1, 0, 0, c47_bin, true);
tk::dnn::Activation a47(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c48(&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true, false, 32);
tk::dnn::Activation a48(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c49(&net, 512, 1, 1, 1, 1, 0, 0, c49_bin, true);
tk::dnn::Shortcut s50(&net, &a46);
tk::dnn::Activation a50(&net, tk::dnn::ACTIVATION_LEAKY);
//3-3
tk::dnn::Conv2d c51(&net, 512, 1, 1, 1, 1, 0, 0, c51_bin, true);
tk::dnn::Activation a51(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c52(&net, 512, 3, 3, 1, 1, 1, 1, c52_bin, true, false, 32);
tk::dnn::Activation a52(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c53(&net, 512, 1, 1, 1, 1, 0, 0, c53_bin, true);
tk::dnn::Shortcut s54(&net, &a50);
tk::dnn::Activation a54(&net, tk::dnn::ACTIVATION_LEAKY);
//3-4
tk::dnn::Conv2d c55(&net, 512, 1, 1, 1, 1, 0, 0, c55_bin, true);
tk::dnn::Activation a55(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c56(&net, 512, 3, 3, 1, 1, 1, 1, c56_bin, true, false, 32);
tk::dnn::Activation a56(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c57(&net, 512, 1, 1, 1, 1, 0, 0, c57_bin, true);
tk::dnn::Shortcut s58(&net, &a54);
tk::dnn::Activation a58(&net, tk::dnn::ACTIVATION_LEAKY);
//3-5
tk::dnn::Conv2d c59(&net, 512, 1, 1, 1, 1, 0, 0, c59_bin, true);
tk::dnn::Activation a59(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c60(&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true, false, 32);
tk::dnn::Activation a60(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c61(&net, 512, 1, 1, 1, 1, 0, 0, c61_bin, true);
tk::dnn::Shortcut s62(&net, &a58);
tk::dnn::Activation a62(&net, tk::dnn::ACTIVATION_LEAKY);
//3-T
tk::dnn::Conv2d c63(&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true);
tk::dnn::Activation a63(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r64_layers[2] = {&a63, &c40};
tk::dnn::Route r64(&net, r64_layers, 2);
tk::dnn::Conv2d c65(&net, 1024, 1, 1, 1, 1, 0, 0, c65_bin, true);
tk::dnn::Activation a65(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c66(&net, 1024, 3, 3, 2, 2, 1, 1, c66_bin, true, false, 32);
tk::dnn::Activation a66(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c67(&net, 1024, 1, 1, 1, 1, 0, 0, c67_bin, true);
tk::dnn::Activation a67(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r68_layers[2] = {&a66};
tk::dnn::Route r68(&net, r68_layers, 1);
tk::dnn::Conv2d c69(&net, 1024, 1, 1, 1, 1, 0, 0, c69_bin, true);
tk::dnn::Activation a69(&net, tk::dnn::ACTIVATION_LEAKY);
//4-1
tk::dnn::Conv2d c70(&net, 1024, 1, 1, 1, 1, 0, 0, c70_bin, true);
tk::dnn::Activation a70(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c71(&net, 1024, 3, 3, 1, 1, 1, 1, c71_bin, true, false, 32);
tk::dnn::Activation a71(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c72(&net, 1024, 1, 1, 1, 1, 0, 0, c72_bin, true);
tk::dnn::Shortcut s73(&net, &a69);
tk::dnn::Activation a73(&net, tk::dnn::ACTIVATION_LEAKY);
//4-2
tk::dnn::Conv2d c74(&net, 1024, 1, 1, 1, 1, 0, 0, c74_bin, true);
tk::dnn::Activation a74(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c75(&net, 1024, 3, 3, 1, 1, 1, 1, c75_bin, true, false, 32);
tk::dnn::Activation a75(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c76(&net, 1024, 1, 1, 1, 1, 0, 0, c76_bin, true);
tk::dnn::Shortcut s77(&net, &a73);
tk::dnn::Activation a77(&net, tk::dnn::ACTIVATION_LEAKY);
//4-T
tk::dnn::Conv2d c78(&net, 1024, 1, 1, 1, 1, 0, 0, c78_bin, true);
tk::dnn::Activation a78(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r79_layers[2] = {&a78, &a67};
tk::dnn::Route r79(&net, r79_layers, 2);
tk::dnn::Conv2d c80(&net, 2048, 1, 1, 1, 1, 0, 0, c80_bin, true);
tk::dnn::Activation a80(&net, tk::dnn::ACTIVATION_LEAKY);
// ////////////////////
tk::dnn::Conv2d c81(&net, 512, 1, 1, 1, 1, 0, 0, c81_bin, true);
tk::dnn::Activation a81(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c82(&net, 1024, 3, 3, 1, 1, 1, 1, c82_bin, true);
tk::dnn::Activation a82(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c83(&net, 512, 1, 1, 1, 1, 0, 0, c83_bin, true);
tk::dnn::Activation a83(&net, tk::dnn::ACTIVATION_LEAKY);
//SPP
tk::dnn::Pooling p84(&net, 5, 5, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE);
tk::dnn::Layer *r85_layers[1] = {&a83};
tk::dnn::Route r85(&net, r85_layers, 1);
tk::dnn::Pooling p86(&net, 9, 9, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE);
tk::dnn::Layer *r87_layers[1] = {&a83};
tk::dnn::Route r87(&net, r87_layers, 1);
tk::dnn::Pooling p88(&net, 13, 13, 1, 1, 12, 12, tk::dnn::POOLING_MAX_FIXEDSIZE);
tk::dnn::Layer *r89_layers[4] = {&p88, &p86, &p84, &a83};
tk::dnn::Route r89(&net, r89_layers, 4);
//END SPP
tk::dnn::Conv2d c90(&net, 512, 1, 1, 1, 1, 0, 0, c90_bin, true);
tk::dnn::Activation a90(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c91(&net, 1024, 3, 3, 1, 1, 1, 1, c91_bin, true);
tk::dnn::Activation a91(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c92(&net, 512, 1, 1, 1, 1, 0, 0, c92_bin, true);
tk::dnn::Activation a92(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c93(&net, 256, 1, 1, 1, 1, 0, 0, c93_bin, true);
tk::dnn::Activation a93(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Upsample u94(&net, 2);
tk::dnn::Layer *r95_layers[1] = {&a65};
tk::dnn::Route r95(&net, r95_layers, 1);
tk::dnn::Conv2d c96(&net, 256, 1, 1, 1, 1, 0, 0, c96_bin, true);
tk::dnn::Activation a96(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r97_layers[2] = {&a96,&u94};
tk::dnn::Route r97(&net, r97_layers, 2);
tk::dnn::Conv2d c98(&net, 256, 1, 1, 1, 1, 0, 0, c98_bin, true);
tk::dnn::Activation a98(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c99(&net, 512, 3, 3, 1, 1, 1, 1, c99_bin, true);
tk::dnn::Activation a99(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c100(&net, 256, 1, 1, 1, 1, 0, 0, c100_bin, true);
tk::dnn::Activation a100(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c101(&net, 512, 3, 3, 1, 1, 1, 1, c101_bin, true);
tk::dnn::Activation a101(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c102(&net, 256, 1, 1, 1, 1, 0, 0, c102_bin, true);
tk::dnn::Activation a102(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c103(&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true);
tk::dnn::Activation a103(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Upsample u104(&net, 2);
tk::dnn::Layer *r105_layers[1] = {&a38};
tk::dnn::Route r105(&net, r105_layers, 1);
tk::dnn::Conv2d c106(&net, 128, 1, 1, 1, 1, 0, 0, c106_bin, true);
tk::dnn::Activation a106(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r107_layers[2] = {&a106,&u104};
tk::dnn::Route r107(&net, r107_layers, 2);
tk::dnn::Conv2d c108(&net, 128, 1, 1, 1, 1, 0, 0, c108_bin, true);
tk::dnn::Activation a108(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c109(&net, 256, 3, 3, 1, 1, 1, 1, c109_bin, true);
tk::dnn::Activation a109(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c110(&net, 128, 1, 1, 1, 1, 0, 0, c110_bin, true);
tk::dnn::Activation a110(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c111(&net, 256, 3, 3, 1, 1, 1, 1, c111_bin, true);
tk::dnn::Activation a111(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c112(&net, 128, 1, 1, 1, 1, 0, 0, c112_bin, true);
tk::dnn::Activation a112(&net, tk::dnn::ACTIVATION_LEAKY);
// ###########################
tk::dnn::Conv2d c113(&net, 256, 3, 3, 1, 1, 1, 1, c113_bin, true);
tk::dnn::Activation a113(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c114(&net, 45, 1, 1, 1, 1, 0, 0, c114_bin, false);
tk::dnn::Yolo yolo115(&net, classes, 3, g115_bin);
tk::dnn::Layer *r116_layers[1] = {&a112};
tk::dnn::Route r116(&net, r116_layers, 1);
tk::dnn::Conv2d c117(&net, 256, 3, 3, 2, 2, 1, 1, c117_bin, true);
tk::dnn::Activation a117(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r118_layers[2] = {&a117,&a102};
tk::dnn::Route r118(&net, r118_layers, 2);
tk::dnn::Conv2d c119(&net, 256, 1, 1, 1, 1, 0, 0, c119_bin, true);
tk::dnn::Activation a119(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c120(&net, 512, 3, 3, 1, 1, 1, 1, c120_bin, true);
tk::dnn::Activation a120(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c121(&net, 256, 1, 1, 1, 1, 0, 0, c121_bin, true);
tk::dnn::Activation a121(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c122(&net, 512, 3, 3, 1, 1, 1, 1, c122_bin, true);
tk::dnn::Activation a122(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c123(&net, 256, 1, 1, 1, 1, 0, 0, c123_bin, true);
tk::dnn::Activation a123(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c124(&net, 512, 3, 3, 1, 1, 1, 1, c124_bin, true);
tk::dnn::Activation a124(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c125(&net, 45, 1, 1, 1, 1, 0, 0, c125_bin, false);
tk::dnn::Yolo yolo126(&net, classes, 3, g126_bin);
tk::dnn::Layer *r127_layers[1] = {&a123};
tk::dnn::Route r127(&net, r127_layers, 1);
tk::dnn::Conv2d c128(&net, 512, 3, 3, 2, 2, 1, 1, c128_bin, true);
tk::dnn::Activation a128(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Layer *r129_layers[2] = {&a128,&a92};
tk::dnn::Route r129(&net, r129_layers, 2);
tk::dnn::Conv2d c130(&net, 512, 1, 1, 1, 1, 0, 0, c130_bin, true);
tk::dnn::Activation a130(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c131(&net, 1024, 3, 3, 1, 1, 1, 1, c131_bin, true);
tk::dnn::Activation a131(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c132(&net, 512, 1, 1, 1, 1, 0, 0, c132_bin, true);
tk::dnn::Activation a132(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c133(&net, 1024, 3, 3, 1, 1, 1, 1, c133_bin, true);
tk::dnn::Activation a133(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c134(&net, 512, 1, 1, 1, 1, 0, 0, c134_bin, true);
tk::dnn::Activation a134(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c135(&net, 1024, 3, 3, 1, 1, 1, 1, c135_bin, true);
tk::dnn::Activation a135(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Conv2d c136(&net, 45, 1, 1, 1, 1, 0, 0, c136_bin, false);
tk::dnn::Yolo yolo137(&net, classes, 3, g137_bin);
yolo[0] = &yolo115;
yolo[1] = &yolo126;
yolo[2] = &yolo137;
// fill classes names
for (int i = 0; i < 3; i++)
{
yolo[i]->classesNames = {"person","car","truck","bus","motor","bike","rider","traffic light","traffic sign","train"};
}
// Load input
dnnType *data;
dnnType *input_h;
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
//print network model
net.print();
// //convert network to tensorRT
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("bdd-csresnext50-panet-spp"));
// the network have 3 outputs
tk::dnn::dataDim_t out_dim[3];
for (int i = 0; i < 3; i++)
out_dim[i] = yolo[i]->output_dim;
dnnType *cudnn_out[3], *rt_out[3];
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30);
{
dim1.print();
TIMER_START
net.infer(dim1, data);
TIMER_STOP
dim1.print();
}
for (int i = 0; i < 3; i++)
cudnn_out[i] = yolo[i]->dstData;
printCenteredTitle(" compute detections ", '=', 30);
TIMER_START
int ndets = 0;
tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes);
for (int i = 0; i < 3; i++)
yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5);
tk::dnn::Yolo::mergeDetections(dets, ndets, classes);
for (int j = 0; j < ndets; j++)
{
tk::dnn::Yolo::box b = dets[j].bbox;
int x0 = (b.x - b.w / 2.);
int x1 = (b.x + b.w / 2.);
int y0 = (b.y - b.h / 2.);
int y1 = (b.y + b.h / 2.);
int cl = 0;
for (int c = 0; c < classes; ++c)
{
float prob = dets[j].prob[c];
if (prob > 0)
cl = c;
}
std::cout << cl << ": " << x0 << " " << y0 << " " << x1 << " " << y1 << "\n";
}
TIMER_STOP
tk::dnn::dataDim_t dim2 = dim;
printCenteredTitle(" TENSORRT inference ", '=', 30);
{
dim2.print();
TIMER_START
netRT.infer(dim2, data);
TIMER_STOP
dim2.print();
}
for (int i = 0; i < 3; i++)
rt_out[i] = (dnnType *)netRT.buffersRT[i + 1];
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
for (int i = 0; i < 3; i++)
{
printCenteredTitle((std::string(" YOLO ") + std::to_string(i) + " CHECK RESULTS ").c_str(), '=', 30);
dnnType *out, *out_h;
int odim = out_dim[i].tot();
readBinaryFile(output_bins[i], odim, &out_h, &out);
std::cout<<"CUDNN vs correct";
ret_cudnn |= checkResult(odim, cudnn_out[i], out) == 0 ? 0: ERROR_CUDNN;
std::cout<<"TRT vs correct";
ret_tensorrt |= checkResult(odim, rt_out[i], out) == 0 ? 0 : ERROR_TENSORRT;
std::cout<<"CUDNN vs TRT ";
ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
}
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,546 @@
#include <iostream>
#include "tkdnn.h"
const char *output_bin1 = "bdd-mobilenetv2ssd/debug/classification_headers-5.bin";
const char *output_bin2 = "bdd-mobilenetv2ssd/debug/regression_headers-5.bin";
const char *input_bin = "bdd-mobilenetv2ssd/debug/input.bin";
const char *conv0_bin = "bdd-mobilenetv2ssd/layers/base_net-0-0.bin";
const char *inverted_residual1[] = {
"bdd-mobilenetv2ssd/layers/base_net-1-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-1-conv-3.bin"};
const char *inverted_residual2[] = {
"bdd-mobilenetv2ssd/layers/base_net-2-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-2-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-2-conv-6.bin"};
const char *inverted_residual3[] = {
"bdd-mobilenetv2ssd/layers/base_net-3-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-3-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-3-conv-6.bin"};
const char *inverted_residual4[] = {
"bdd-mobilenetv2ssd/layers/base_net-4-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-4-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-4-conv-6.bin"};
const char *inverted_residual5[] = {
"bdd-mobilenetv2ssd/layers/base_net-5-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-5-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-5-conv-6.bin"};
const char *inverted_residual6[] = {
"bdd-mobilenetv2ssd/layers/base_net-6-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-6-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-6-conv-6.bin"};
const char *inverted_residual7[] = {
"bdd-mobilenetv2ssd/layers/base_net-7-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-7-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-7-conv-6.bin"};
const char *inverted_residual8[] = {
"bdd-mobilenetv2ssd/layers/base_net-8-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-8-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-8-conv-6.bin"};
const char *inverted_residual9[] = {
"bdd-mobilenetv2ssd/layers/base_net-9-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-9-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-9-conv-6.bin"};
const char *inverted_residual10[] = {
"bdd-mobilenetv2ssd/layers/base_net-10-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-10-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-10-conv-6.bin"};
const char *inverted_residual11[] = {
"bdd-mobilenetv2ssd/layers/base_net-11-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-11-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-11-conv-6.bin"};
const char *inverted_residual12[] = {
"bdd-mobilenetv2ssd/layers/base_net-12-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-12-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-12-conv-6.bin"};
const char *inverted_residual13[] = {
"bdd-mobilenetv2ssd/layers/base_net-13-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-13-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-13-conv-6.bin"};
const char *inverted_residual14[] = {
"bdd-mobilenetv2ssd/layers/base_net-14-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-14-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-14-conv-6.bin"};
const char *inverted_residual15[] = {
"bdd-mobilenetv2ssd/layers/base_net-15-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-15-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-15-conv-6.bin"};
const char *inverted_residual16[] = {
"bdd-mobilenetv2ssd/layers/base_net-16-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-16-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-16-conv-6.bin"};
const char *inverted_residual17[] = {
"bdd-mobilenetv2ssd/layers/base_net-17-conv-0.bin",
"bdd-mobilenetv2ssd/layers/base_net-17-conv-3.bin",
"bdd-mobilenetv2ssd/layers/base_net-17-conv-6.bin"};
const char *conv18 = "bdd-mobilenetv2ssd/layers/base_net-18-0.bin";
const char *extras0[] = {
"bdd-mobilenetv2ssd/layers/extras-0-conv-0.bin",
"bdd-mobilenetv2ssd/layers/extras-0-conv-3.bin",
"bdd-mobilenetv2ssd/layers/extras-0-conv-6.bin"};
const char *extras1[] = {
"bdd-mobilenetv2ssd/layers/extras-1-conv-0.bin",
"bdd-mobilenetv2ssd/layers/extras-1-conv-3.bin",
"bdd-mobilenetv2ssd/layers/extras-1-conv-6.bin"};
const char *extras2[] = {
"bdd-mobilenetv2ssd/layers/extras-2-conv-0.bin",
"bdd-mobilenetv2ssd/layers/extras-2-conv-3.bin",
"bdd-mobilenetv2ssd/layers/extras-2-conv-6.bin"};
const char *extras3[] = {
"bdd-mobilenetv2ssd/layers/extras-3-conv-0.bin",
"bdd-mobilenetv2ssd/layers/extras-3-conv-3.bin",
"bdd-mobilenetv2ssd/layers/extras-3-conv-6.bin"};
const char *classification_header0[] = {
"bdd-mobilenetv2ssd/layers/classification_headers-0-0.bin",
"bdd-mobilenetv2ssd/layers/classification_headers-0-3.bin"};
const char *classification_header1[] = {
"bdd-mobilenetv2ssd/layers/classification_headers-1-0.bin",
"bdd-mobilenetv2ssd/layers/classification_headers-1-3.bin"};
const char *classification_header2[] = {
"bdd-mobilenetv2ssd/layers/classification_headers-2-0.bin",
"bdd-mobilenetv2ssd/layers/classification_headers-2-3.bin"};
const char *classification_header3[] = {
"bdd-mobilenetv2ssd/layers/classification_headers-3-0.bin",
"bdd-mobilenetv2ssd/layers/classification_headers-3-3.bin"};
const char *classification_header4[] = {
"bdd-mobilenetv2ssd/layers/classification_headers-4-0.bin",
"bdd-mobilenetv2ssd/layers/classification_headers-4-3.bin"};
const char *classification_header5 = "bdd-mobilenetv2ssd/layers/classification_headers-5.bin";
const char *regression_header0[] = {
"bdd-mobilenetv2ssd/layers/regression_headers-0-0.bin",
"bdd-mobilenetv2ssd/layers/regression_headers-0-3.bin"};
const char *regression_header1[] = {
"bdd-mobilenetv2ssd/layers/regression_headers-1-0.bin",
"bdd-mobilenetv2ssd/layers/regression_headers-1-3.bin"};
const char *regression_header2[] = {
"bdd-mobilenetv2ssd/layers/regression_headers-2-0.bin",
"bdd-mobilenetv2ssd/layers/regression_headers-2-3.bin"};
const char *regression_header3[] = {
"bdd-mobilenetv2ssd/layers/regression_headers-3-0.bin",
"bdd-mobilenetv2ssd/layers/regression_headers-3-3.bin"};
const char *regression_header4[] = {
"bdd-mobilenetv2ssd/layers/regression_headers-4-0.bin",
"bdd-mobilenetv2ssd/layers/regression_headers-4-3.bin"};
const char *regression_header5 = "bdd-mobilenetv2ssd/layers/regression_headers-5.bin";
int main()
{
// downloadWeightsifDoNotExist(input_bin, "bdd-mobilenetv2ssd", "https://cloud.hipert.unimore.it/s//download");
int classes = 11;
// Network layout
tk::dnn::dataDim_t dim(1, 3, 300, 300, 1);
tk::dnn::Network net(dim);
tk::dnn::Conv2d conv1(&net, 32, 3, 3, 2, 2, 1, 1, conv0_bin, true);
tk::dnn::Activation relu3(&net, CUDNN_ACTIVATION_RELU);
//Inverted Residual 1
tk::dnn::Conv2d conv2(&net, 32, 3, 3, 1, 1, 1, 1, inverted_residual1[0], true, false, 32);
tk::dnn::Activation relu5(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d conv3(&net, 16, 1, 1, 1, 1, 0, 0, inverted_residual1[1], true);
//Inverted Residual 2
tk::dnn::Conv2d ir_2_conv1(&net, 96, 1, 1, 1, 1, 0, 0, inverted_residual2[0], true);
tk::dnn::Activation relu_2_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_2_conv2(&net, 96, 3, 3, 2, 2, 1, 1, inverted_residual2[1], true, false, 96);
tk::dnn::Activation relu_2_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_2_conv3(&net, 24, 1, 1, 1, 1, 0, 0, inverted_residual2[2], true);
//Inverted Residual 3
tk::dnn::Layer *last = &ir_2_conv3;
tk::dnn::Conv2d ir_3_conv1(&net, 144, 1, 1, 1, 1, 0, 0, inverted_residual3[0], true);
tk::dnn::Activation relu_3_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_3_conv2(&net, 144, 3, 3, 1, 1, 1, 1, inverted_residual3[1], true, false, 144);
tk::dnn::Activation relu_3_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_3_conv3(&net, 24, 1, 1, 1, 1, 0, 0, inverted_residual3[2], true);
tk::dnn::Shortcut s3_0(&net, last);
// //Inverted Residual 4
tk::dnn::Conv2d ir_4_conv1(&net, 144, 1, 1, 1, 1, 0, 0, inverted_residual4[0], true);
tk::dnn::Activation relu_4_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_4_conv2(&net, 144, 3, 3, 2, 2, 1, 1, inverted_residual4[1], true, false, 144);
tk::dnn::Activation relu_4_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_4_conv3(&net, 32, 1, 1, 1, 1, 0, 0, inverted_residual4[2], true);
// // //Inverted Residual 5
last = &ir_4_conv3;
tk::dnn::Conv2d ir_5_conv1(&net, 192, 1, 1, 1, 1, 0, 0, inverted_residual5[0], true);
tk::dnn::Activation relu_5_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_5_conv2(&net, 192, 3, 3, 1, 1, 1, 1, inverted_residual5[1], true, false, 192);
tk::dnn::Activation relu_5_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_5_conv3(&net, 32, 1, 1, 1, 1, 0, 0, inverted_residual5[2], true);
tk::dnn::Shortcut s5_0(&net, last);
// // // //Inverted Residual 6
last = &s5_0;
tk::dnn::Conv2d ir_6_conv1(&net, 192, 1, 1, 1, 1, 0, 0, inverted_residual6[0], true);
tk::dnn::Activation relu_6_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_6_conv2(&net, 192, 3, 3, 1, 1, 1, 1, inverted_residual6[1], true, false, 192);
tk::dnn::Activation relu_6_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_6_conv3(&net, 32, 1, 1, 1, 1, 0, 0, inverted_residual6[2], true);
tk::dnn::Shortcut s6_0(&net, last);
//Inverted Residual 7
tk::dnn::Conv2d ir_7_conv1(&net, 192, 1, 1, 1, 1, 0, 0, inverted_residual7[0], true);
tk::dnn::Activation relu_7_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_7_conv2(&net, 192, 3, 3, 2, 2, 1, 1, inverted_residual7[1], true, false, 192);
tk::dnn::Activation relu_7_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_7_conv3(&net, 64, 1, 1, 1, 1, 0, 0, inverted_residual7[2], true);
// //Inverted Residual 8
last = &ir_7_conv3;
tk::dnn::Conv2d ir_8_conv1(&net, 384, 1, 1, 1, 1, 0, 0, inverted_residual8[0], true);
tk::dnn::Activation relu_8_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_8_conv2(&net, 384, 3, 3, 1, 1, 1, 1, inverted_residual8[1], true, false, 384);
tk::dnn::Activation relu_8_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_8_conv3(&net, 64, 1, 1, 1, 1, 0, 0, inverted_residual8[2], true);
tk::dnn::Shortcut s8_0(&net, last);
//Inverted Residual 9
last = &s8_0;
tk::dnn::Conv2d ir_9_conv1(&net, 384, 1, 1, 1, 1, 0, 0, inverted_residual9[0], true);
tk::dnn::Activation relu_9_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_9_conv2(&net, 384, 3, 3, 1, 1, 1, 1, inverted_residual9[1], true, false, 384);
tk::dnn::Activation relu_9_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_9_conv3(&net, 64, 1, 1, 1, 1, 0, 0, inverted_residual9[2], true);
tk::dnn::Shortcut s9_0(&net, last);
//Inverted Residual 10
last = &s9_0;
tk::dnn::Conv2d ir_10_conv1(&net, 384, 1, 1, 1, 1, 0, 0, inverted_residual10[0], true);
tk::dnn::Activation relu_10_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_10_conv2(&net, 384, 3, 3, 1, 1, 1, 1, inverted_residual10[1], true, false, 384);
tk::dnn::Activation relu_10_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_10_conv3(&net, 64, 1, 1, 1, 1, 0, 0, inverted_residual10[2], true);
tk::dnn::Shortcut s10_0(&net, last);
//Inverted Residual 11
tk::dnn::Conv2d ir_11_conv1(&net, 384, 1, 1, 1, 1, 0, 0, inverted_residual11[0], true);
tk::dnn::Activation relu_11_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_11_conv2(&net, 384, 3, 3, 1, 1, 1, 1, inverted_residual11[1], true, false, 384);
tk::dnn::Activation relu_11_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_11_conv3(&net, 96, 1, 1, 1, 1, 0, 0, inverted_residual11[2], true);
last = &ir_11_conv3;
//Inverted Residual 12
tk::dnn::Conv2d ir_12_conv1(&net, 576, 1, 1, 1, 1, 0, 0, inverted_residual12[0], true);
tk::dnn::Activation relu_12_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_12_conv2(&net, 576, 3, 3, 1, 1, 1, 1, inverted_residual12[1], true, false, 576);
tk::dnn::Activation relu_12_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_12_conv3(&net, 96, 1, 1, 1, 1, 0, 0, inverted_residual12[2], true);
tk::dnn::Shortcut s12_0(&net, last);
last = &s12_0;
//Inverted Residual 13
tk::dnn::Conv2d ir_13_conv1(&net, 576, 1, 1, 1, 1, 0, 0, inverted_residual13[0], true);
tk::dnn::Activation relu_13_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_13_conv2(&net, 576, 3, 3, 1, 1, 1, 1, inverted_residual13[1], true, false, 576);
tk::dnn::Activation relu_13_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_13_conv3(&net, 96, 1, 1, 1, 1, 0, 0, inverted_residual13[2], true);
tk::dnn::Shortcut s13_0(&net, last);
// //Inverted Residual 14
tk::dnn::Conv2d ir_14_conv1(&net, 576, 1, 1, 1, 1, 0, 0, inverted_residual14[0], true);
tk::dnn::Activation relu_14_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_14_conv2(&net, 576, 3, 3, 2, 2, 1, 1, inverted_residual14[1], true, false, 576);
tk::dnn::Activation relu_14_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_14_conv3(&net, 160, 1, 1, 1, 1, 0, 0, inverted_residual14[2], true);
// //Inverted Residual 15
last = &ir_14_conv3;
tk::dnn::Conv2d ir_15_conv1(&net, 960, 1, 1, 1, 1, 0, 0, inverted_residual15[0], true);
tk::dnn::Activation relu_15_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_15_conv2(&net, 960, 3, 3, 1, 1, 1, 1, inverted_residual15[1], true, false, 960);
tk::dnn::Activation relu_15_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_15_conv3(&net, 160, 1, 1, 1, 1, 0, 0, inverted_residual15[2], true);
tk::dnn::Shortcut s15_0(&net, last);
//Inverted Residual 16
last = &s15_0;
tk::dnn::Conv2d ir_16_conv1(&net, 960, 1, 1, 1, 1, 0, 0, inverted_residual16[0], true);
tk::dnn::Activation relu_16_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_16_conv2(&net, 960, 3, 3, 1, 1, 1, 1, inverted_residual16[1], true, false, 960);
tk::dnn::Activation relu_16_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_16_conv3(&net, 160, 1, 1, 1, 1, 0, 0, inverted_residual16[2], true);
tk::dnn::Shortcut s16_0(&net, last);
//Inverted Residual 17
tk::dnn::Conv2d ir_17_conv1(&net, 960, 1, 1, 1, 1, 0, 0, inverted_residual17[0], true);
tk::dnn::Activation relu_17_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_17_conv2(&net, 960, 3, 3, 1, 1, 1, 1, inverted_residual17[1], true, false, 960);
tk::dnn::Activation relu_17_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d ir_17_conv3(&net, 320, 1, 1, 1, 1, 0, 0, inverted_residual17[2], true);
//Conv 18
tk::dnn::Conv2d ir_18_conv1(&net, 1280, 1, 1, 1, 1, 0, 0, conv18, true);
tk::dnn::Activation relu_18_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Layer *header_1[1] = {&relu_18_1};
// //extras Inverted Residual 0
tk::dnn::Conv2d e_0_conv1(&net, 256, 1, 1, 1, 1, 0, 0, extras0[0], true);
tk::dnn::Activation e_relu_0_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d e_0_conv2(&net, 256, 3, 3, 2, 2, 1, 1, extras0[1], true, false, 256);
tk::dnn::Activation e_relu_0_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d e_0_conv3(&net, 512, 1, 1, 1, 1, 0, 0, extras0[2], true);
tk::dnn::Layer *header_2[1] = {&e_0_conv3};
// //extras Inverted Residual 1
tk::dnn::Conv2d e_1_conv1(&net, 128, 1, 1, 1, 1, 0, 0, extras1[0], true);
tk::dnn::Activation e_relu_1_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d e_1_conv2(&net, 128, 3, 3, 2, 2, 1, 1, extras1[1], true, false, 128);
tk::dnn::Activation e_relu_1_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d e_1_conv3(&net, 256, 1, 1, 1, 1, 0, 0, extras1[2], true);
tk::dnn::Layer *header_3[1] = {&e_1_conv3};
//extras Inverted Residual 2
tk::dnn::Conv2d e_2_conv1(&net, 128, 1, 1, 1, 1, 0, 0, extras2[0], true);
tk::dnn::Activation e_relu_2_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d e_2_conv2(&net, 128, 3, 3, 2, 2, 1, 1, extras2[1], true, false, 128);
tk::dnn::Activation e_relu_2_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d e_2_conv3(&net, 256, 1, 1, 1, 1, 0, 0, extras2[2], true);
tk::dnn::Layer *header_4[1] = {&e_2_conv3};
//extras Inverted Residual 3
tk::dnn::Conv2d e_3_conv1(&net, 64, 1, 1, 1, 1, 0, 0, extras3[0], true);
tk::dnn::Activation e_relu_3_1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d e_3_conv2(&net, 64, 3, 3, 2, 2, 1, 1, extras3[1], true, false, 64);
tk::dnn::Activation e_relu_3_2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d e_3_conv3(&net, 64, 1, 1, 1, 1, 0, 0, extras3[2], true);
tk::dnn::Layer *header_5[1] = {&e_3_conv3};
// classification header 0
tk::dnn::Layer *header_0[1] = {&relu_14_1};
tk::dnn::Route rout_ch_0(&net, header_0, 1);
tk::dnn::Conv2d ch_0_conv1(&net, 576, 3, 3, 1, 1, 1, 1, classification_header0[0], true, false, 576, true);
tk::dnn::Activation ch_relu_0_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d ch_0_conv2(&net, 66, 1, 1, 1, 1, 0, 0, classification_header0[1], false);
tk::dnn::Layer *conf0[1] = {&ch_0_conv2};
// // classification header 1
tk::dnn::Route rout_ch_1(&net, header_1, 1);
tk::dnn::Conv2d ch_1_conv1(&net, 1280, 3, 3, 1, 1, 1, 1, classification_header1[0], true, false, 1280, true);
tk::dnn::Activation ch_relu_1_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d ch_1_conv2(&net, 66, 1, 1, 1, 1, 0, 0, classification_header1[1], false);
tk::dnn::Layer *conf1[1] = {&ch_1_conv2};
// //classification header 2
tk::dnn::Route rout_ch_2(&net, header_2, 1);
tk::dnn::Conv2d ch_2_conv1(&net, 512, 3, 3, 1, 1, 1, 1, classification_header2[0], true, false, 512, true);
tk::dnn::Activation ch_relu_2_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d ch_2_conv2(&net, 66, 1, 1, 1, 1, 0, 0, classification_header2[1], false);
tk::dnn::Layer *conf2[1] = {&ch_2_conv2};
// //classification header 3
tk::dnn::Route rout_ch_3(&net, header_3, 1);
tk::dnn::Conv2d ch_3_conv1(&net, 256, 3, 3, 1, 1, 1, 1, classification_header3[0], true, false, 256, true);
tk::dnn::Activation ch_relu_3_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d ch_3_conv2(&net, 66, 1, 1, 1, 1, 0, 0, classification_header3[1], false);
tk::dnn::Layer *conf3[1] = {&ch_3_conv2};
// //classification header 4
tk::dnn::Route rout_ch_4(&net, header_4, 1);
tk::dnn::Conv2d ch_4_conv1(&net, 256, 3, 3, 1, 1, 1, 1, classification_header4[0], true, false, 256, true);
tk::dnn::Activation ch_relu_4_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d ch_4_conv2(&net, 66, 1, 1, 1, 1, 0, 0, classification_header4[1], false);
tk::dnn::Layer *conf4[1] = {&ch_4_conv2};
// //classification header 5
tk::dnn::Route rout_ch_5(&net, header_5, 1);
tk::dnn::Conv2d ch_5_conv(&net, 66, 1, 1, 1, 1, 0, 0, classification_header5, false);
ch_5_conv.setFinal();
tk::dnn::Layer *conf5[1] = {&ch_5_conv};
//regression header 0
tk::dnn::Route rout_rh_0(&net, header_0, 1);
tk::dnn::Conv2d rh_0_conv1(&net, 576, 3, 3, 1, 1, 1, 1, regression_header0[0], true, false, 576, true);
tk::dnn::Activation rh_relu_0_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d rh_0_conv2(&net, 24, 1, 1, 1, 1, 0, 0, regression_header0[1], false);
tk::dnn::Layer *loc0[1] = {&rh_0_conv2};
// //regression header 1
tk::dnn::Route rout_rh_1(&net, header_1, 1);
tk::dnn::Conv2d rh_1_conv1(&net, 1280, 3, 3, 1, 1, 1, 1, regression_header1[0], true, false, 1280, true);
tk::dnn::Activation rh_relu_1_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d rh_1_conv2(&net, 24, 1, 1, 1, 1, 0, 0, regression_header1[1], false);
tk::dnn::Layer *loc1[1] = {&rh_1_conv2};
//regression header 2
tk::dnn::Route rout_rh_2(&net, header_2, 1);
tk::dnn::Conv2d rh_2_conv1(&net, 512, 3, 3, 1, 1, 1, 1, regression_header2[0], true, false, 512, true);
tk::dnn::Activation rh_relu_2_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d rh_2_conv2(&net, 24, 1, 1, 1, 1, 0, 0, regression_header2[1], false);
tk::dnn::Layer *loc2[1] = {&rh_2_conv2};
//regression header 3
tk::dnn::Route rout_rh_3(&net, header_3, 1);
tk::dnn::Conv2d rh_3_conv1(&net, 256, 3, 3, 1, 1, 1, 1, regression_header3[0], true, false, 256, true);
tk::dnn::Activation rh_relu_3_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d rh_3_conv2(&net, 24, 1, 1, 1, 1, 0, 0, regression_header3[1], false);
tk::dnn::Layer *loc3[1] = {&rh_3_conv2};
//regression header 4
tk::dnn::Route rout_rh_4(&net, header_4, 1);
tk::dnn::Conv2d rh_4_conv1(&net, 256, 3, 3, 1, 1, 1, 1, regression_header4[0], true, false, 256, true);
tk::dnn::Activation rh_relu_4_1(&net, CUDNN_ACTIVATION_CLIPPED_RELU, 6);
tk::dnn::Conv2d rh_4_conv2(&net, 24, 1, 1, 1, 1, 0, 0, regression_header4[1], false);
tk::dnn::Layer *loc4[1] = {&rh_4_conv2};
//regression header 5
tk::dnn::Route rout_rh_5(&net, header_5, 1);
tk::dnn::Conv2d rh_5_conv(&net, 24, 1, 1, 1, 1, 0, 0, regression_header5, false);
rh_5_conv.setFinal();
tk::dnn::Layer *loc5[1] = {&rh_5_conv};
last = &rh_5_conv;
//flatten all confidence
tk::dnn::Route r_conf_0(&net, conf0, 1);
tk::dnn::Flatten fl_c_0(&net);
tk::dnn::Route r_conf_1(&net, conf1, 1);
tk::dnn::Flatten fl_c_1(&net);
tk::dnn::Route r_conf_2(&net, conf2, 1);
tk::dnn::Flatten fl_c_2(&net);
tk::dnn::Route r_conf_3(&net, conf3, 1);
tk::dnn::Flatten fl_c_3(&net);
tk::dnn::Route r_conf_4(&net, conf4, 1);
tk::dnn::Flatten fl_c_4(&net);
tk::dnn::Route r_conf_5(&net, conf5, 1);
tk::dnn::Flatten fl_c_5(&net);
// //flatten all locations
tk::dnn::Route r_loc_0(&net, loc0, 1);
tk::dnn::Flatten fl_l_0(&net);
tk::dnn::Route r_loc_1(&net, loc1, 1);
tk::dnn::Flatten fl_l_1(&net);
tk::dnn::Route r_loc_2(&net, loc2, 1);
tk::dnn::Flatten fl_l_2(&net);
tk::dnn::Route r_loc_3(&net, loc3, 1);
tk::dnn::Flatten fl_l_3(&net);
tk::dnn::Route r_loc_4(&net, loc4, 1);
tk::dnn::Flatten fl_l_4(&net);
tk::dnn::Route r_loc_5(&net, loc5, 1);
tk::dnn::Flatten fl_l_5(&net);
// //concat confidence + softmax
tk::dnn::Layer *confidences[6] = {&fl_c_0, &fl_c_1, &fl_c_2, &fl_c_3, &fl_c_4, &fl_c_5};
tk::dnn::Route rout_conf(&net, confidences, 6);
tk::dnn::dataDim_t olddim_c = net.layers[net.num_layers - 1]->output_dim;
tk::dnn::dataDim_t dim_resh(1, olddim_c.c * olddim_c.h * olddim_c.w / classes, classes, 1, 1);
tk::dnn::Reshape reshape_conf1(&net, dim_resh);
tk::dnn::Flatten fl_l_6(&net);
tk::dnn::dataDim_t newdim_c(1, classes, olddim_c.c * olddim_c.h * olddim_c.w / classes, 1, 1);
tk::dnn::Reshape reshape_conf2(&net, newdim_c);
tk::dnn::Softmax sm_1(&net, &newdim_c);
sm_1.setFinal();
// tk::dnn::Flatten fl_l_7(&net);
// tk::dnn::Reshape reshape_conf3(&net,dim_resh, true);
tk::dnn::Layer *conf = &sm_1;
//concat locations
tk::dnn::Layer *locations[6] = {&fl_l_0, &fl_l_1, &fl_l_2, &fl_l_3, &fl_l_4, &fl_l_5};
tk::dnn::Route rout_loc(&net, locations, 6);
tk::dnn::dataDim_t olddim_l = net.layers[net.num_layers - 1]->output_dim;
tk::dnn::dataDim_t newdim_l(1, olddim_l.c * olddim_l.h * olddim_l.w / 4, 1, 4, 1);
tk::dnn::Reshape reshape_loc(&net, newdim_l);
reshape_loc.setFinal();
tk::dnn::Layer *loc = &reshape_loc;
// Load input
dnnType *data;
dnnType *input_h;
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
//printDeviceVector(64, data, true);
//print network model
net.print();
// convert network to tensorRT
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("bdd-mobilenetv2ssd"));
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30);
{
dim1.print();
TIMER_START
net.infer(dim1, data);
TIMER_STOP
dim1.print();
}
dnnType *cudnn_out1 = conf5[0]->dstData;
tk::dnn::dataDim_t out_dim1 = conf5[0]->output_dim;
dnnType *cudnn_out2 = loc5[0]->dstData;
tk::dnn::dataDim_t out_dim2 = loc5[0]->output_dim;
tk::dnn::dataDim_t dim2 = dim;
printCenteredTitle(" TENSORRT inference ", '=', 30);
{
dim2.print();
TIMER_START
netRT.infer(dim2, data);
TIMER_STOP
dim2.print();
}
dnnType *rt_out1 = (dnnType *)netRT.buffersRT[1];
dnnType *rt_out2 = (dnnType *)netRT.buffersRT[2];
dnnType *rt_out3 = (dnnType *)netRT.buffersRT[3];
dnnType *rt_out4 = (dnnType *)netRT.buffersRT[4];
printCenteredTitle(std::string(" RESNET CHECK RESULTS ").c_str(), '=', 30);
dnnType *out1, *out1_h;
int odim1 = out_dim1.tot();
readBinaryFile(output_bin1, odim1, &out1_h, &out1);
dnnType *out2, *out2_h;
int odim2 = out_dim2.tot();
readBinaryFile(output_bin2, odim2, &out2_h, &out2);
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
std::cout << "CUDNN vs correct" << std::endl;
ret_cudnn |= checkResult(odim1, cudnn_out1, out1) == 0 ? 0 : ERROR_CUDNN;
ret_cudnn |= checkResult(odim2, cudnn_out2, out2) == 0 ? 0 : ERROR_CUDNN;
std::cout << "TRT vs correct" << std::endl;
ret_tensorrt |= checkResult(odim1, rt_out1, out1) == 0 ? 0 : ERROR_TENSORRT;
ret_tensorrt |= checkResult(odim2, rt_out2, out2) == 0 ? 0 : ERROR_TENSORRT;
std::cout << "CUDNN vs TRT " << std::endl;
ret_cudnn_tensorrt |= checkResult(odim1, cudnn_out1, rt_out1) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
ret_cudnn_tensorrt |= checkResult(odim2, cudnn_out2, rt_out2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Confidence CUDNN" << std::endl;
printDeviceVector(64, conf->dstData, true);
std::cout << "Locations CUDNN" << std::endl;
printDeviceVector(64, loc->dstData, true);
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "Confidence tensorRT" << std::endl;
printDeviceVector(64, rt_out3, true);
std::cout << "Locations tensorRT" << std::endl;
printDeviceVector(64, rt_out4, true);
std::cout << "---------------------------------------------------" << std::endl;
std::cout << "CUDNN vs TRT " << std::endl;
ret_cudnn_tensorrt |= checkResult(conf->output_dim.tot(), conf->dstData, rt_out3) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
ret_cudnn_tensorrt |= checkResult(loc->output_dim.tot(), loc->dstData, rt_out4) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
}
+8 -16
View File
@@ -7,26 +7,14 @@ 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");
downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/BBSEbEbQbPKxp4s/download");
tk::dnn::ImuOdom ImuNet;
ImuNet.init("imuodom/layers/");
const int N = 10000; //19513;
const int N = 19513;
// Network layout
tk::dnn::dataDim_t dim0(1, 4, 1, 100);
@@ -60,7 +48,9 @@ int main() {
//TIMER_STOP
// log path
path<<ImuNet.odomPOS(0)<<" "<<ImuNet.odomPOS(1)<<" "<< ImuNet.odomPOS(2)<<"\n";
path<<ImuNet.odomPOS(0)<<" "<<ImuNet.odomPOS(1)<<" "<< ImuNet.odomPOS(2)<<" ";
path<<ImuNet.odomEULER(0)<<" "<<ImuNet.odomEULER(1)<<" "<< ImuNet.odomEULER(2)<<"\n";
path.flush();
// Print real test
@@ -77,6 +67,8 @@ int main() {
out1 += ImuNet.odim1.tot();
}
int err = system("cat path.txt | gnuplot -p -e \"set datafile separator ' '; plot '-'\"");
int err = 0;
err = system("cat path.txt | cut -d\" \" -f1,2 | gnuplot -p -e \"set datafile separator ' '; plot '-'\"");
err = system("cat path.txt | cut -d\" \" -f6 | gnuplot -p -e \"set datafile separator ' '; plot '-'\"");
return ret_cudnn;
}
+4 -4
View File
@@ -16,14 +16,14 @@ def bin_write(f, data):
bin = struct.pack(fmt, *data)
f.write(bin)
# USE weight_exporter to generare wgs bins
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()
+666
View File
@@ -0,0 +1,666 @@
#include <iostream>
#include <vector>
#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<std::string> 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;
}
File diff suppressed because it is too large Load Diff