first docker

This commit is contained in:
root
2021-06-04 05:24:13 +00:00
parent 8cc5ebf832
commit 8c2282a6fb
84 changed files with 1486 additions and 19657 deletions
+43 -59
View File
@@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.5)
set(PROJ_NAME tkDNN)
project (tkDNN)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if(UNIX)
####
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wno-deprecated-declarations -Wno-unused-variable ")
endif()
if(WIN32)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "/O2 /FS /EHsc")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
#add extras for baggage
endif(WIN32)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/tkDNN)
@@ -60,66 +63,47 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} ${NVINFER_INCLUDES})
add_library(tkDNN SHARED ${tkdnn_SRC})
target_link_libraries(tkDNN ${tkdnn_LIBS})
####compile
#set(PROJ_NAME BaggageAIApi)
# Path to BaggageAI project folder.
set(BAGGAGEAI_PATH /home/baggageai/files)
# Give a custom name to shared library which is provided by DIMENSIONLESS.
#set(BAGGAGEAI_LIB_NAME libBaggageAI)
# Define C++ level, could be 11 or 17 as well.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
# Define compiler optimization level.
set(CMAKE_CXX_FLAGS "-O3")
# Do print warnings uppon compilation, let's keep our code as clean as possible.
set(CMAKE_CXX_FLAGS "-Wall -Wextra")
# Apply flags.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -DBOOST_LOG_DYN_LINK")
set(Casablanca_LIBRARIES "-lboost_log -lboost_log_setup -lboost_thread -lboost_system -lcrypto -lssl -lcpprest -lpthread")
# Note: We do not recommend using GLOB or GLOB_RECURSE to collect a list of source files from your source tree.
# If no CMakeLists.txt file changes when a source is added or removed then the generated build system cannot know
# when to ask CMake to regenerate.
file(GLOB_RECURSE SOURCE_FILES "main.cpp" "handler.cpp" "src/*.cpp")
add_executable(baggageAPI ${SOURCE_FILES})
set(Casablanca_LIBRARIES "-lboost_log -lboost_log_setup -lboost_thread -lboost_system -lcrypto -lssl -lcpprest -lpthread" )
set(tkdnn_LIBS kernels ${Casablanca_LIBRARIES} ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRARIES} ${OpenCV_LIBS} yaml-cpp)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
# Link BaggageAI library' include folder.
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} ${NVINFER_INCLUDES} ${Casablanca_LIBRARIES} ${CMAKE_CXX_FLAGS})
# Define BaggageAI library' shared library.
#add_library(${BAGGAGEAI_LIB_NAME} SHARED IMPORTED)
# Set a path to BaggageAI library' shared library
#set_property(TARGET ${BAGGAGEAI_LIB_NAME} PROPERTY IMPORTED_LOCATION "${BAGGAGEAI_PATH}/libBaggageAI.so")
# Link all libraries together.
target_link_libraries(baggageAPI ${tkdnn_LIBS})
#static
#add_library(tkDNN_static STATIC ${tkdnn_SRC})
#target_link_libraries(tkDNN_static ${tkdnn_LIBS})
# SMALL NETS
add_executable(test_simple tests/simple/test_simple.cpp)
target_link_libraries(test_simple tkDNN)
add_executable(test_mnist tests/mnist/test_mnist.cpp)
target_link_libraries(test_mnist tkDNN)
add_executable(test_mnistRT tests/mnist/test_mnistRT.cpp)
target_link_libraries(test_mnistRT tkDNN)
add_executable(test_imuodom tests/imuodom/imuodom.cpp)
target_link_libraries(test_imuodom tkDNN)
# DARKNET
file(GLOB darknet_SRC "tests/darknet/*.cpp")
foreach(test_SRC ${darknet_SRC})
get_filename_component(test_NAME "${test_SRC}" NAME_WE)
set(test_NAME test_${test_NAME})
add_executable(${test_NAME} ${test_SRC})
target_link_libraries(${test_NAME} tkDNN)
endforeach()
# MOBILENET
add_executable(test_mobilenetv2ssd tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp)
target_link_libraries(test_mobilenetv2ssd tkDNN)
add_executable(test_bdd-mobilenetv2ssd tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp)
target_link_libraries(test_bdd-mobilenetv2ssd tkDNN)
add_executable(test_mobilenetv2ssd512 tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp)
target_link_libraries(test_mobilenetv2ssd512 tkDNN)
# BACKBONES
add_executable(test_resnet101 tests/backbones/resnet101/resnet101.cpp)
target_link_libraries(test_resnet101 tkDNN)
add_executable(test_dla34 tests/backbones/dla34/dla34.cpp)
target_link_libraries(test_dla34 tkDNN)
# CENTERNET
add_executable(test_resnet101_cnet tests/centernet/resnet101_cnet/resnet101_cnet.cpp)
target_link_libraries(test_resnet101_cnet tkDNN)
add_executable(test_dla34_cnet tests/centernet/dla34_cnet/dla34_cnet.cpp)
target_link_libraries(test_dla34_cnet tkDNN)
# DEMOS
add_executable(test_rtinference tests/test_rtinference/rtinference.cpp)
target_link_libraries(test_rtinference tkDNN)
add_executable(map_demo demo/demo/map.cpp)
target_link_libraries(map_demo tkDNN)
add_executable(demo demo/demo/demo.cpp)
target_link_libraries(demo tkDNN)
#add_executable(demo demo/inf.cpp)
#target_link_libraries(demo tkDNN)
#-------------------------------------------------------------------------------
# Install
-1
View File
@@ -1 +0,0 @@
1)error C2131 @ Yolo3Detection.cpp(97) -> expression doesnt evaluate to a constant caused to read of variable outside its lifetime
-339
View File
@@ -1,339 +0,0 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
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.
Preamble
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.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
tkDNN
Copyright (C) 2017 Francesco Gatti
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<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.
+2 -2
View File
@@ -1,5 +1,5 @@
classes : 80 #number of classes
map_points : 101 #number of recall points (0 for all, 101 for COCO, 11 PascalVOC)
classes : 13 #number of classes
map_points : 0 #number of recall points (0 for all, 101 for COCO, 11 PascalVOC)
map_levels : 10 #number of IoU step for the AP
map_step : 0.05 #step of IoU
IoU_thresh : 0.5 #starting IoU threshold
-7
View File
@@ -1,7 +0,0 @@
classes : 3 #number of classes
map_points : 101 #number of recall points (0 for all, 101 for COCO, 11 PascalVOC)
map_levels : 10 #number of IoU step for the AP
map_step : 0.05 #step of IoU
IoU_thresh : 0.5 #starting IoU threshold
conf_thresh : 0.0 #threshold on the condifence of the bbox
verbose : false #print on screen information
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

-147
View File
@@ -1,147 +0,0 @@
#include <iostream>
#include <signal.h>
#include <stdlib.h> /* srand, rand */
//#include <unistd.h>
#include <mutex>
#include "CenternetDetection.h"
#include "MobilenetDetection.h"
#include "Yolo3Detection.h"
bool gRun;
bool SAVE_RESULT = false;
void sig_handler(int signo) {
std::cout<<"request gateway stop\n";
gRun = false;
}
int main(int argc, char *argv[]) {
std::cout<<"detection\n";
signal(SIGINT, sig_handler);
std::string net = "yolo4tiny_fp32.rt";
if(argc > 1)
net = argv[1];
#ifdef __linux__
std::string input = "../demo/yolo_test.mp4";
#elif _WIN32
std::string input = "..\\..\\..\\demo\\yolo_test.mp4";
#endif
if(argc > 2)
input = argv[2];
char ntype = 'y';
if(argc > 3)
ntype = argv[3][0];
int n_classes = 80;
if(argc > 4)
n_classes = atoi(argv[4]);
int n_batch = 1;
if(argc > 5)
n_batch = atoi(argv[5]);
bool show = true;
if(argc > 6)
show = atoi(argv[6]);
float conf_thresh=0.3;
if(argc > 7)
conf_thresh = atof(argv[7]);
if(n_batch < 1 || n_batch > 64)
FatalError("Batch dim not supported");
if(!show)
SAVE_RESULT = true;
tk::dnn::Yolo3Detection yolo;
tk::dnn::CenternetDetection cnet;
tk::dnn::MobilenetDetection mbnet;
tk::dnn::DetectionNN *detNN;
switch(ntype)
{
case 'y':
detNN = &yolo;
break;
case 'c':
detNN = &cnet;
break;
case 'm':
detNN = &mbnet;
n_classes++;
break;
default:
FatalError("Network type not allowed (3rd parameter)\n");
}
detNN->init(net, n_classes, n_batch, conf_thresh);
gRun = true;
cv::VideoCapture cap(input);
if(!cap.isOpened())
gRun = false;
else
std::cout<<"camera started\n";
cv::VideoWriter resultVideo;
if(SAVE_RESULT) {
int w = cap.get(cv::CAP_PROP_FRAME_WIDTH);
int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h));
}
cv::Mat frame;
if(show)
cv::namedWindow("detection", cv::WINDOW_NORMAL);
std::vector<cv::Mat> batch_frame;
std::vector<cv::Mat> batch_dnn_input;
while(gRun) {
batch_dnn_input.clear();
batch_frame.clear();
for(int bi=0; bi< n_batch; ++bi){
cap >> frame;
if(!frame.data)
break;
batch_frame.push_back(frame);
// this will be resized to the net format
batch_dnn_input.push_back(frame.clone());
}
if(!frame.data)
break;
//inference
detNN->update(batch_dnn_input, n_batch);
detNN->draw(batch_frame);
if(show){
for(int bi=0; bi< n_batch; ++bi){
cv::imshow("detection", batch_frame[bi]);
cv::waitKey(1);
}
}
if(n_batch == 1 && SAVE_RESULT)
resultVideo << frame;
}
std::cout<<"detection end\n";
double mean = 0;
std::cout<<COL_GREENB<<"\n\nTime stats:\n";
std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
for(int i=0; i<detNN->stats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size();
std::cout<<"Avg: "<<mean/n_batch<<" ms\t"<<1000/(mean/n_batch)<<" FPS\n"<<COL_END;
return 0;
}
-238
View File
@@ -1,238 +0,0 @@
#include <iostream>
#include <signal.h>
#include <stdlib.h> /* srand, rand */
#ifdef __linux__
#include <unistd.h>
#endif
#include <mutex>
#include "utils.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "Yolo3Detection.h"
#include "CenternetDetection.h"
#include "MobilenetDetection.h"
#include "evaluation.h"
#include <map>
void convertFilename(std::string &filename,const std::string l_folder, const std::string i_folder, const std::string l_ext,const std::string i_ext)
{
filename.replace(filename.find(l_folder),l_folder.length(),i_folder);
filename.replace(filename.find(l_ext),l_ext.length(),i_ext);
}
int main(int argc, char *argv[])
{
char ntype = 'y';
const char *config_filename = "../demo/config.yaml";
const char * net = "yolo3.rt";
const char * labels_path = "../demo/COCO_val2017/all_labels.txt";
bool show = false;
bool write_dets = false;
bool write_res_on_file = true;
bool write_coco_json = true;
int n_images = 5000;
bool verbose;
int classes, map_points, map_levels;
float map_step, IoU_thresh, conf_thresh;
double vm_total = 0, rss_total = 0;
double vm, rss;
//read args
if(argc > 1)
net = argv[1];
if(argc > 2)
ntype = argv[2][0];
if(argc > 3)
labels_path = argv[3];
if(argc > 4)
config_filename = argv[4];
//check if files needed exist
if(!fileExist(config_filename))
FatalError("Wrong config file path.");
if(!fileExist(net))
FatalError("Wrong net file path.");
if(!fileExist(labels_path))
FatalError("Wrong labels file path.");
//read mAP parameters
tk::dnn::readmAPParams( config_filename, classes, map_points, map_levels, map_step,
IoU_thresh, conf_thresh, verbose);
//extract network name from rt path
std::string net_name;
removePathAndExtension(net, net_name);
std::cout<<"Network: "<<net_name<<std::endl;
//open files (if needed)
std::ofstream times, memory, coco_json;
if(write_coco_json){
coco_json.open(net_name+"_COCO_res.json");
coco_json << "[\n";
}
if(write_res_on_file){
times.open("times_"+net_name+".csv");
memory.open("memory.csv", std::ios_base::app);
memory<<net<<";";
}
// instantiate detector
tk::dnn::Yolo3Detection yolo;
tk::dnn::CenternetDetection cnet;
tk::dnn::MobilenetDetection mbnet;
tk::dnn::DetectionNN *detNN;
int n_classes = classes;
switch(ntype){
case 'y':
detNN = &yolo;
break;
case 'c':
detNN = &cnet;
break;
case 'm':
detNN = &mbnet;
n_classes++;
break;
default:
FatalError("Network type not allowed (3rd parameter)\n");
}
detNN->init(net, n_classes, 1, conf_thresh);
//read images
std::ifstream all_labels(labels_path);
std::string l_filename;
std::vector<tk::dnn::Frame> images;
std::vector<tk::dnn::box> detected_bbox;
std::cout<<"Reading groundtruth and generating detections"<<std::endl;
if(show)
cv::namedWindow("detection", cv::WINDOW_NORMAL);
int images_done;
for (images_done=0 ; std::getline(all_labels, l_filename) && images_done < n_images ; ++images_done) {
std::cout <<COL_ORANGEB<< "Images done:\t" << images_done<< "\n"<<COL_END;
tk::dnn::Frame f;
f.lFilename = l_filename;
f.iFilename = l_filename;
convertFilename(f.iFilename, "labels", "images", ".txt", ".jpg");
// read frame
if(!fileExist(f.iFilename.c_str()))
FatalError("Wrong image file path.");
cv::Mat frame = cv::imread(f.iFilename.c_str(), cv::IMREAD_COLOR);
std::vector<cv::Mat> batch_frames;
batch_frames.push_back(frame);
int height = frame.rows;
int width = frame.cols;
if(!frame.data)
break;
std::vector<cv::Mat> batch_dnn_input;
batch_dnn_input.push_back(frame.clone());
//inference
detected_bbox.clear();
detNN->update(batch_dnn_input,1,write_res_on_file, &times, write_coco_json);
detNN->draw(batch_frames);
detected_bbox = detNN->detected;
if(write_coco_json)
printJsonCOCOFormat(&coco_json, f.iFilename.c_str(), detected_bbox, classes, width, height);
std::ofstream myfile;
if(write_dets)
myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("labels/") + 7));
// save detections labels
for(auto d:detected_bbox){
//convert detected bb in the same format as label
//<x_center>/<image_width> <y_center>/<image_width> <width>/<image_width> <height>/<image_width>
tk::dnn::BoundingBox b;
b.x = (d.x + d.w/2) / width;
b.y = (d.y + d.h/2) / height;
b.w = d.w / width;
b.h = d.h / height;
b.prob = d.prob;
b.cl = d.cl;
f.det.push_back(b);
if(write_dets)
myfile << d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n";
if(show)// draw rectangle for detection
cv::rectangle(batch_frames[0], cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2);
}
if(write_dets)
myfile.close();
// read and save groundtruth labels
if(fileExist(f.lFilename.c_str()))
{
std::ifstream labels(l_filename);
for(std::string line; std::getline(labels, line); ){
std::istringstream in(line);
tk::dnn::BoundingBox b;
in >> b.cl >> b.x >> b.y >> b.w >> b.h;
b.prob = 1;
b.truthFlag = 1;
f.gt.push_back(b);
if(show)// draw rectangle for groundtruth
cv::rectangle(batch_frames[0], cv::Point((b.x-b.w/2)*width, (b.y-b.h/2)*height), cv::Point((b.x+b.w/2)*width,(b.y+b.h/2)*height), cv::Scalar(0, 255, 0), 2);
}
}
images.push_back(f);
if(show){
cv::imshow("detection", batch_frames[0]);
cv::waitKey(0);
}
getMemUsage(vm, rss);
vm_total += vm;
rss_total += rss;
}
if(write_coco_json){
coco_json.seekp (coco_json.tellp() - std::streampos(2));
coco_json << "\n]\n";
coco_json.close();
}
std::cout << "Avg VM[MB]: " << vm_total/images_done/1024.0 << ";Avg RSS[MB]: " << rss_total/images_done/1024.0 << std::endl;
//compute mAP
double AP = tk::dnn::computeMapNIoULevels(images,classes,IoU_thresh,conf_thresh, map_points, map_step, map_levels, verbose, write_res_on_file, net_name);
std::cout<<"mAP "<<IoU_thresh<<":"<<IoU_thresh+map_step*(map_levels-1)<<" = "<<AP<<std::endl;
//compute average precision, recall and f1score
tk::dnn::computeTPFPFN(images,classes,IoU_thresh,conf_thresh, verbose, write_res_on_file, net_name);
if(write_res_on_file){
memory<<vm_total/images_done/1024.0<<";"<<rss_total/images_done/1024.0<<"\n";
times.close();
memory.close();
}
return 0;
}
+130
View File
@@ -0,0 +1,130 @@
#include <iostream>
#include <signal.h>
#include <stdlib.h> /* srand, rand */
#ifdef __linux__
#include <unistd.h>
#endif
#include <mutex>
#include "utils.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "Yolo3Detection.h"
//#include "CenternetDetection.h"
//#include "MobilenetDetection.h"
#include "evaluation.h"
#include <chrono>
#include <cstdint>
#include <iostream>
uint64_t timeSinceEpochMillisec() {
using namespace std::chrono;
return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
}
int baggage() {
std::cout << timeSinceEpochMillisec() << std::endl;
char ntype = 'y';
const char *config_filename = "../demo/config.yaml";
const char * net = "../demo/yolo4_fp32.rt";
const char * img_path = "../demo/demo.jpg";
bool show = false;
bool verbose;
int classes, map_points, map_levels;
float map_step, IoU_thresh, conf_thresh;
//read parameters
tk::dnn::readmAPParams(config_filename, classes, map_points, map_levels, map_step,
IoU_thresh, conf_thresh, verbose);
//extract network name from rt path
std::string net_name;
removePathAndExtension(net, net_name);
std::cout<<"Network: "<<net_name<<std::endl;
//open files (if needed)
std::ofstream times, memory, coco_json;
// instantiate detector
tk::dnn::Yolo3Detection yolo;
// tk::dnn::CenternetDetection cnet;
// tk::dnn::MobilenetDetection mbnet;
tk::dnn::DetectionNN *detNN;
int n_classes = classes;
// float conf_threshold=0.001;
detNN = &yolo;
detNN->init(net, n_classes, 1, conf_thresh);
//read images
// std::ifstream all_labels(labels_path);
std::cout << timeSinceEpochMillisec() << std::endl;
std::string l_filename;
std::vector<tk::dnn::Frame> images;
std::vector<tk::dnn::box> detected_bbox;
std::cout<<"Reading groundtruth and generating detections"<<std::endl;
if(show)
cv::namedWindow("detection", cv::WINDOW_NORMAL);
// int images_done;
// for (images_done=0 ; std::getline(all_labels, l_filename) && images_done < n_images ; ++images_done) {
// std::cout <<COL_ORANGEB<< "Images done:\t" << images_done<< "\n"<<COL_END;
tk::dnn::Frame f;
// f.lFilename = l_filename;
// f.iFilename = l_filename;
//convertFilename(f.iFilename, "labels", "images", ".txt", ".jpg");
// read frame
//if(!fileExist(f.iFilename.c_str()))
// FatalError("Wrong image file path.");
cv::Mat frame = cv::imread(img_path, cv::IMREAD_COLOR);
std::vector<cv::Mat> batch_frames;
batch_frames.push_back(frame);
int height = frame.rows;
int width = frame.cols;
// if(!frame.data)
// break;
std::vector<cv::Mat> batch_dnn_input;
batch_dnn_input.push_back(frame.clone());
std::cout<<"test1"<<"\n";
//inference
detected_bbox.clear();
detNN->update(batch_dnn_input,1);
detNN->draw(batch_frames);
detected_bbox = detNN->detected;
std::cout<<"test2"<<"\n";
// save detections labels
for(auto d:detected_bbox){
//convert detected bb in the same format as label
//<x_center>/<image_width> <y_center>/<image_width> <width>/<image_width> <height>/<image_width>
tk::dnn::BoundingBox b;
b.x = (d.x + d.w/2) / width;
b.y = (d.y + d.h/2) / height;
b.w = d.w / width;
b.h = d.h / height;
b.prob = d.prob;
b.cl = d.cl;
f.det.push_back(b);
std::cout<< d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n";
if(show)// draw rectangle for detection
cv::rectangle(batch_frames[0], cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2);
}
//images.push_back(f);
if(show){
cv::imshow("detection", batch_frames[0]);
cv::waitKey(0);
}
std::cout << timeSinceEpochMillisec() << std::endl;
return 0;
}
Binary file not shown.
+28 -4
View File
@@ -1,7 +1,31 @@
FROM ceccocats/tkdnn:latest
LABEL maintainer "Francesco Gatti"
FROM mohitkhubele95/tkdnn
ARG DEBIAN_FRONTEND=noninteractive
RUN cd && git clone https://github.com/ceccocats/tkDNN.git && cd tkDNN && mkdir build && cd build \
&& cmake .. && make -j12
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository 'deb http://security.ubuntu.com/ubuntu xenial-security main'
RUN apt-get -y update
RUN apt-get -y upgrade
RUN apt-get -y install cmake g++ git sudo vim curl rapidjson-dev awscli zip unzip dpkg libcpprest-dev libboost-dev libboost-all-dev
RUN useradd -ms /bin/bash baggageai && echo "baggageai:baggageai" | chpasswd && adduser baggageai sudo
USER baggageai
WORKDIR /home/baggageai
EXPOSE 8080
#RUN aws s3 cp s3://dim-bai-s3-dev-developer-space/smiths_29_objects/BaggageAI.zip .
RUN mkdir files
#RUN mkdir files/include
#RUN mkdir files/server
#Change path of include and server folder accordingly
#COPY --chown=baggageai:baggageai src/include/ files/include
#COPY --chown=baggageai:baggageai src/server/ files/server
COPY --chown=baggageai:baggageai . files/
#RUN aws s3 cp s3://dim-bai-s3-dev-developer-space/smiths_29_objects/libBaggageAI.so files/
WORKDIR /home/baggageai/files
#RUN chmod 777 run.sh
#ENTRYPOINT ["./run.sh"]
-57
View File
@@ -1,57 +0,0 @@
FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
LABEL maintainer "Francesco Gatti"
ADD nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb /tmp/trt.deb
RUN apt-get update && dpkg -i /tmp/trt.deb && rm /tmp/trt.deb && apt-get update
RUN apt install -y libnvinfer7=7.0.0-1+cuda10.2 libnvinfer-dev=7.0.0-1+cuda10.2
RUN DEBIAN_FRONTEND=noninteractive apt install -y git wget libeigen3-dev libyaml-cpp-dev
RUN cd /tmp && \
wget https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-x86_64.sh && \
chmod +x cmake-3.17.3-Linux-x86_64.sh && \
./cmake-3.17.3-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir --skip-license && \
rm ./cmake-3.17.3-Linux-x86_64.sh
RUN echo "INSTALL OPENCV"
RUN apt-get install -y build-essential \
unzip \
pkg-config \
libjpeg-dev \
libpng-dev \
libtiff-dev \
libavcodec-dev \
libavformat-dev \
libswscale-dev \
libv4l-dev \
libxvidcore-dev \
libx264-dev \
libgtk-3-dev \
libatlas-base-dev \
gfortran \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libdc1394-22-dev \
libavresample-dev
RUN cd && wget https://github.com/opencv/opencv/archive/4.3.0.tar.gz && tar -xf 4.3.0.tar.gz && rm *.tar.gz
RUN cd && wget https://github.com/opencv/opencv_contrib/archive/4.3.0.tar.gz && tar -xf 4.3.0.tar.gz && rm *.tar.gz
RUN cd && \
cd opencv-4.3.0 && mkdir build && cd build && \
cmake -D CMAKE_BUILD_TYPE=RELEASE \
-D CMAKE_INSTALL_PREFIX=/usr/local \
-D INSTALL_PYTHON_EXAMPLES=OFF \
-D INSTALL_C_EXAMPLES=OFF \
-D OPENCV_EXTRA_MODULES_PATH='~/opencv_contrib-4.3.0/modules' \
-D BUILD_EXAMPLES=OFF \
-D WITH_CUDA=ON \
-D CUDA_ARCH_BIN=7.2 \
-D CUDA_ARCH_PTX="" \
-D ENABLE_FAST_MATH=ON \
-D CUDA_FAST_MATH=ON \
-D WITH_CUBLAS=ON \
-D WITH_LIBV4L=ON \
-D WITH_GSTREAMER=ON \
-D WITH_GSTREAMER_0_10=OFF \
-D WITH_TBB=ON \
../ && make -j12 && make install
RUN apt clean
-21
View File
@@ -1,21 +0,0 @@
# Use the prebuilt image
```
# build image
docker build -t tkdnn:build -f Dockerfile .
```
# Build Base Docker image
```
# make nvidia docker working
# follow this guide: https://github.com/NVIDIA/nvidia-docker
# dowload tensorrt
# from: https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.0/7.0.0.11/local_repo/nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb
# build image
docker build -t ceccocats/tkdnn:latest -f Dockerfile.base .
# run image
docker run -ti --gpus all --rm ceccocats/tkdnn:latest bash
```
+191
View File
@@ -0,0 +1,191 @@
#include <iostream>
#include <signal.h>
#include <stdlib.h> /* srand, rand */
#ifdef __linux__
#include <unistd.h>
#endif
#include <mutex>
#include "utils.h"
#include "baggageDetect.hpp"
#include "handler.h"
#include <vector>
#include <random>
#include <climits>
#include <algorithm>
#include <functional>
#include <string>
#include <fstream>
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "Yolo3Detection.h"
//#include "CenternetDetection.h"
//#include "MobilenetDetection.h"
#include "evaluation.h"
#include <chrono>
#include <cstdint>
#include <iostream>
using namespace std;
char ntype = 'y';
const char *config_filename = "../demo/config.yaml";
const char * net = "../demo/yolo4_fp32.rt";
// const char * img_path = "../demo/demo.jpg";
// char * img_path;
bool show = false;
bool verbose;
int classes, map_points, map_levels;
float map_step, IoU_thresh, conf_thresh;
tk::dnn::Yolo3Detection yolo;
// tk::dnn::CenternetDetection cnet;
// tk::dnn::MobilenetDetection mbnet;
tk::dnn::DetectionNN *detNN;
int n_classes = classes;
std::vector<tk::dnn::Frame> images;
std::vector<tk::dnn::box> detected_bbox;
tk::dnn::Frame f;
//read parametersi
handler::handler(utility::string_t url):m_listener(url)
{
m_listener.support(methods::POST, bind(&handler::handle_post, this, placeholders::_1));
}
string name_from_path(string path)
{
return path.substr(path.find_last_of("/\\")+1);
}
void init_bag(){//tk::dnn::readmAPParams(config_filename, classes, map_points, map_levels, map_step,
//IoU_thresh, conf_thresh, verbose);
//extract network name from rt path
std::string net_name;
removePathAndExtension(net, net_name);
std::cout<<"Network: "<<net_name<<std::endl;
//open files (if needed)
//std::ofstream times, memory, coco_json;
int n_classes = classes;
// float conf_threshold=0.001;
detNN = &yolo;
detNN->init(net, n_classes, 1, conf_thresh);
//read images
// std::ifstream all_labels(labels_path);
// std::cout << timeSinceEpochMillisec() << std::endl;
std::string l_filename;
//std::vector<tk::dnn::Frame> images;
//std::vector<tk::dnn::box> detected_bbox;
std::cout<<"Reading groundtruth and generating detections"<<std::endl;
if(show)
cv::namedWindow("detection", cv::WINDOW_NORMAL);
}
// int images_done;
// for (images_done=0 ; std::getline(all_labels, l_filename) && images_done < n_images ; ++images_done) {
// std::cout <<COL_ORANGEB<< "Images done:\t" << images_done<< "\n"<<COL_END;
void handler::handle_post(http_request request){
init_bag();
// const char * img_path=
//tk::dnn::Frame f;
BOOST_LOG_TRIVIAL(info) << "[" << name_from_path(string(__FILE__)) << " " << __LINE__ << "] " << request.to_string();
map<utility::string_t, utility::string_t> http_get_vars = uri::split_query(request.request_uri().query());
map<utility::string_t, utility::string_t>::iterator it = http_get_vars.find("name");
// std::cout<<request<<"\n";
//If 'name' is not in the query.
int len;
if(it == http_get_vars.end())
{
BOOST_LOG_TRIVIAL(error) << "[" << name_from_path(string(__FILE__)) << " " << __LINE__ << "] " << "Image name not passed in query.";
request.reply(status_codes::UnprocessableEntity,"Please pass image name in the query.");
return;
}
std::cout<<http_get_vars["name"]<<"\n";
string image_name = (string)http_get_vars["name"];
string ustring;
//reading binary data and storing it in a pointer
request.extract_vector().then([image_name, &ustring, &len](vector<unsigned char> v) {
ustring = {v.begin(),v.end()};
len = ustring.size();
}).wait();
BOOST_LOG_TRIVIAL(info) << "[" << name_from_path(string(__FILE__)) << " " << __LINE__ << "] " << "Detection Started";
// img_path=(unsigned char *)ustring.c_str();
//reading binary data and storing it in a pointer
// std::string body = request.extract_string().get();
//string img_data= (string)http_get_vars[:];
std::cout<<ustring<<"hi\n";
cv::Mat frame = cv::imread(ustring, cv::IMREAD_COLOR);
// cv::Mat frame=cv::imdecode((unsigned char *)ustring.c_str())
std::vector<cv::Mat> batch_frames;
batch_frames.push_back(frame);
int height = frame.rows;
int width = frame.cols;
// if(!frame.data)
// break;
std::vector<cv::Mat> batch_dnn_input;
batch_dnn_input.push_back(frame.clone());
std::cout<<"test1"<<"\n";
//inference
detected_bbox.clear();
detNN->update(batch_dnn_input,1);
detNN->draw(batch_frames);
detected_bbox = detNN->detected;
std::cout<<"test2"<<"\n";
try{
json::value response;
vector<json::value> jsonArray;
// save detections labels
for(auto d:detected_bbox){
//convert detected bb in the same format as label
//<x_center>/<image_width> <y_center>/<image_width> <width>/<image_width> <height>/<image_width>
tk::dnn::BoundingBox b;
b.x = (d.x + d.w/2) / width;
b.y = (d.y + d.h/2) / height;
b.w = d.w / width;
b.h = d.h / height;
b.prob = d.prob;
b.cl = d.cl;
//f.det.push_back(b);
json::value detection;
detection["label"] = json::value::number(b.cl);
detection["x"] = json::value::number(b.x);
detection["y"] = json::value::number(b.y);
detection["w"] = json::value::number(b.w);
detection["h"] = json::value::number(b.h);
detection["prob"] = json::value::number(b.prob);
jsonArray.push_back(detection);
std::cout<< d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n";
if(show)// draw rectangle for detection
cv::rectangle(batch_frames[0], cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2);
}
//images.push_back(f);
if(show){
cv::imshow("detection", batch_frames[0]);
cv::waitKey(0);
}
response["detections"] = json::value::array(jsonArray); //JSON Response
request.reply(status_codes::OK,response.serialize());
// free(detectboxes);
BOOST_LOG_TRIVIAL(info) << "[" << name_from_path(string(__FILE__)) << " " << __LINE__ << "] " << "Detection Completed and Response sent";
}
catch (exception const& e) {
BOOST_LOG_TRIVIAL(error) << "[" << name_from_path(string(__FILE__)) << " " << __LINE__ << "] " << e.what();
request.reply(status_codes::BadRequest, e.what());
}
// std::cout << timeSinceEpochMillisec() << std::endl;
return ;
}
+59
View File
@@ -0,0 +1,59 @@
#ifdef OS_WIN
#pragma once
#ifdef LIB_EXPORTS
#define LIB_API __declspec(dllexport)
#else
#define LIB_API __declspec(dllimport)
#endif
#endif
#include <iostream>
#include <vector>
#include <string>
#ifdef OPENCV
#include <opencv2/opencv.hpp>
#include <opencv2/core/types_c.h>
using namespace cv;
#endif
using namespace std;
struct baggagedetector {
int x,y,w,h,size;
char *label;
float prob;
};
#ifdef __cplusplus
class baggageAI
{
//std::shared_ptr<void> detector_gpu_ptr;
public:
//static LIB_API image_t image_load(std::string image_filename);
#ifdef OS_WIN
LIB_API baggageAI();
//LIB_API ~baggageAI();
LIB_API baggagedetector * baggageDetections(char *input);
LIB_API baggagedetector * baggageDetections(unsigned char *input, int len, int antiLog, int gray);
#ifdef OPENCV
LIB_API baggagedetector * baggageDetections(Mat m);
#endif
#else
baggageAI();
//LIB_API ~baggageAI();
baggagedetector * baggageDetections(char *input);
baggagedetector * baggageDetections(unsigned char *input, int len,int antiLog, int gray);
#ifdef OPENCV
baggagedetector * baggageDetections(Mat m);
#endif
#endif
};
#endif
+852
View File
@@ -0,0 +1,852 @@
#ifndef DIMENSIONLESS_API
#define DIMENSIONLESS_API
#if defined(_MSC_VER) && _MSC_VER < 1900
#define inline __inline
#endif
#if defined(DEBUG) && !defined(_CRTDBG_MAP_ALLOC)
#define _CRTDBG_MAP_ALLOC
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <assert.h>
#include <pthread.h>
#ifndef LIB_API
#ifdef LIB_EXPORTS
#if defined(_MSC_VER)
#define LIB_API __declspec(dllexport)
#else
#define LIB_API __attribute__((visibility("default")))
#endif
#else
#if defined(_MSC_VER)
#define LIB_API
#else
#define LIB_API
#endif
#endif
#endif
#define SECRET_NUM -1234
#ifdef GPU
#include "cuda_runtime.h"
#include "curand.h"
#include "cublas_v2.h"
#ifdef CUDNN
#include "cudnn.h"
#endif
#endif
#ifdef __cplusplus
extern "C" {
#endif
struct network;
typedef struct network network;
struct network_state;
typedef struct network_state network_state;
struct layer;
typedef struct layer layer;
struct image;
typedef struct image image;
struct detection;
typedef struct detection detection;
struct load_args;
typedef struct load_args load_args;
struct data;
typedef struct data data;
struct metadata;
typedef struct metadata metadata;
struct tree;
typedef struct tree tree;
extern int gpu_index;
// option_list.h
typedef struct metadata {
int classes;
char **names;
} metadata;
// tree.h
typedef struct tree {
int *leaf;
int n;
int *parent;
int *child;
int *group;
char **name;
int groups;
int *group_size;
int *group_offset;
} tree;
// activations.h
typedef enum {
LOGISTIC, RELU, RELIE, LINEAR, RAMP, TANH, PLSE, LEAKY, ELU, LOGGY, STAIR, HARDTAN, LHTAN, SELU
}ACTIVATION;
// image.h
typedef enum{
PNG, BMP, TGA, JPG
} IMTYPE;
// activations.h
typedef enum{
MULT, ADD, SUB, DIV
} BINARY_ACTIVATION;
// layer.h
typedef enum {
CONVOLUTIONAL,
DECONVOLUTIONAL,
CONNECTED,
MAXPOOL,
SOFTMAX,
DETECTION,
DROPOUT,
CROP,
ROUTE,
COST,
NORMALIZATION,
AVGPOOL,
LOCAL,
SHORTCUT,
ACTIVE,
RNN,
GRU,
LSTM,
CONV_LSTM,
CRNN,
BATCHNORM,
NETWORK,
XNOR,
REGION,
BAGGAGEAI,
ISEG,
REORG,
REORG_OLD,
UPSAMPLE,
LOGXENT,
L2NORM,
BLANK
} LAYER_TYPE;
// layer.h
typedef enum{
SSE, MASKED, L1, SEG, SMOOTH,WGAN
} COST_TYPE;
// layer.h
typedef struct update_args {
int batch;
float learning_rate;
float momentum;
float decay;
int adam;
float B1;
float B2;
float eps;
int t;
} update_args;
// layer.h
struct layer {
LAYER_TYPE type;
ACTIVATION activation;
COST_TYPE cost_type;
void(*forward) (struct layer, struct network_state);
void(*backward) (struct layer, struct network_state);
void(*update) (struct layer, int, float, float, float);
void(*forward_gpu) (struct layer, struct network_state);
void(*backward_gpu) (struct layer, struct network_state);
void(*update_gpu) (struct layer, int, float, float, float);
int batch_normalize;
int shortcut;
int batch;
int forced;
int flipped;
int inputs;
int outputs;
int nweights;
int nbiases;
int extra;
int truths;
int h, w, c;
int out_h, out_w, out_c;
int n;
int max_boxes;
int groups;
int size;
int side;
int stride;
int reverse;
int flatten;
int spatial;
int pad;
int sqrt;
int flip;
int index;
int binary;
int xnor;
int peephole;
int use_bin_output;
int steps;
int state_constrain;
int hidden;
int truth;
float smooth;
float dot;
float angle;
float jitter;
float saturation;
float exposure;
float shift;
float ratio;
float learning_rate_scale;
float clip;
int focal_loss;
int noloss;
int softmax;
int classes;
int coords;
int background;
int rescore;
int objectness;
int does_cost;
int joint;
int noadjust;
int reorg;
int log;
int tanh;
int *mask;
int total;
float bflops;
int adam;
float B1;
float B2;
float eps;
int t;
float alpha;
float beta;
float kappa;
float coord_scale;
float object_scale;
float noobject_scale;
float mask_scale;
float class_scale;
int bias_match;
int random;
float ignore_thresh;
float truth_thresh;
float thresh;
float focus;
int classfix;
int absolute;
int onlyforward;
int stopbackward;
int dontload;
int dontsave;
int dontloadscales;
int numload;
float temperature;
float probability;
float scale;
char * cweights;
int * indexes;
int * input_layers;
int * input_sizes;
int * map;
int * counts;
float ** sums;
float * rand;
float * cost;
float * state;
float * prev_state;
float * forgot_state;
float * forgot_delta;
float * state_delta;
float * combine_cpu;
float * combine_delta_cpu;
float *concat;
float *concat_delta;
float *binary_weights;
float *biases;
float *bias_updates;
float *scales;
float *scale_updates;
float *weights;
float *weight_updates;
char *align_bit_weights_gpu;
float *mean_arr_gpu;
float *align_workspace_gpu;
float *transposed_align_workspace_gpu;
int align_workspace_size;
char *align_bit_weights;
float *mean_arr;
int align_bit_weights_size;
int lda_align;
int new_lda;
int bit_align;
float *col_image;
float * delta;
float * output;
int delta_pinned;
int output_pinned;
float * loss;
float * squared;
float * norms;
float * spatial_mean;
float * mean;
float * variance;
float * mean_delta;
float * variance_delta;
float * rolling_mean;
float * rolling_variance;
float * x;
float * x_norm;
float * m;
float * v;
float * bias_m;
float * bias_v;
float * scale_m;
float * scale_v;
float *z_cpu;
float *r_cpu;
float *h_cpu;
float *stored_h_cpu;
float * prev_state_cpu;
float *temp_cpu;
float *temp2_cpu;
float *temp3_cpu;
float *dh_cpu;
float *hh_cpu;
float *prev_cell_cpu;
float *cell_cpu;
float *f_cpu;
float *i_cpu;
float *g_cpu;
float *o_cpu;
float *c_cpu;
float *stored_c_cpu;
float *dc_cpu;
float *binary_input;
uint32_t *bin_re_packed_input;
char *t_bit_input;
struct layer *input_layer;
struct layer *self_layer;
struct layer *output_layer;
struct layer *reset_layer;
struct layer *update_layer;
struct layer *state_layer;
struct layer *input_gate_layer;
struct layer *state_gate_layer;
struct layer *input_save_layer;
struct layer *state_save_layer;
struct layer *input_state_layer;
struct layer *state_state_layer;
struct layer *input_z_layer;
struct layer *state_z_layer;
struct layer *input_r_layer;
struct layer *state_r_layer;
struct layer *input_h_layer;
struct layer *state_h_layer;
struct layer *wz;
struct layer *uz;
struct layer *wr;
struct layer *ur;
struct layer *wh;
struct layer *uh;
struct layer *uo;
struct layer *wo;
struct layer *vo;
struct layer *uf;
struct layer *wf;
struct layer *vf;
struct layer *ui;
struct layer *wi;
struct layer *vi;
struct layer *ug;
struct layer *wg;
tree *softmax_tree;
size_t workspace_size;
#ifdef GPU
int *indexes_gpu;
float *z_gpu;
float *r_gpu;
float *h_gpu;
float *stored_h_gpu;
float *temp_gpu;
float *temp2_gpu;
float *temp3_gpu;
float *dh_gpu;
float *hh_gpu;
float *prev_cell_gpu;
float *prev_state_gpu;
float *last_prev_state_gpu;
float *last_prev_cell_gpu;
float *cell_gpu;
float *f_gpu;
float *i_gpu;
float *g_gpu;
float *o_gpu;
float *c_gpu;
float *stored_c_gpu;
float *dc_gpu;
// adam
float *m_gpu;
float *v_gpu;
float *bias_m_gpu;
float *scale_m_gpu;
float *bias_v_gpu;
float *scale_v_gpu;
float * combine_gpu;
float * combine_delta_gpu;
float * forgot_state_gpu;
float * forgot_delta_gpu;
float * state_gpu;
float * state_delta_gpu;
float * gate_gpu;
float * gate_delta_gpu;
float * save_gpu;
float * save_delta_gpu;
float * concat_gpu;
float * concat_delta_gpu;
float *binary_input_gpu;
float *binary_weights_gpu;
float *bin_conv_shortcut_in_gpu;
float *bin_conv_shortcut_out_gpu;
float * mean_gpu;
float * variance_gpu;
float * rolling_mean_gpu;
float * rolling_variance_gpu;
float * variance_delta_gpu;
float * mean_delta_gpu;
float * col_image_gpu;
float * x_gpu;
float * x_norm_gpu;
float * weights_gpu;
float * weight_updates_gpu;
float * weight_change_gpu;
float * weights_gpu16;
float * weight_updates_gpu16;
float * biases_gpu;
float * bias_updates_gpu;
float * bias_change_gpu;
float * scales_gpu;
float * scale_updates_gpu;
float * scale_change_gpu;
float * output_gpu;
float * loss_gpu;
float * delta_gpu;
float * rand_gpu;
float * squared_gpu;
float * norms_gpu;
#ifdef CUDNN
cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc;
cudnnTensorDescriptor_t srcTensorDesc16, dstTensorDesc16;
cudnnTensorDescriptor_t dsrcTensorDesc, ddstTensorDesc;
cudnnTensorDescriptor_t dsrcTensorDesc16, ddstTensorDesc16;
cudnnTensorDescriptor_t normTensorDesc, normDstTensorDesc, normDstTensorDescF16;
cudnnFilterDescriptor_t weightDesc, weightDesc16;
cudnnFilterDescriptor_t dweightDesc, dweightDesc16;
cudnnConvolutionDescriptor_t convDesc;
cudnnConvolutionFwdAlgo_t fw_algo, fw_algo16;
cudnnConvolutionBwdDataAlgo_t bd_algo, bd_algo16;
cudnnConvolutionBwdFilterAlgo_t bf_algo, bf_algo16;
cudnnPoolingDescriptor_t poolingDesc;
#endif // CUDNN
#endif // GPU
};
// network.h
typedef enum {
CONSTANT, STEP, EXP, POLY, STEPS, SIG, RANDOM, SGDR
} learning_rate_policy;
// network.h
typedef struct network {
int n;
int batch;
uint64_t *seen;
int *t;
float epoch;
int subdivisions;
layer *layers;
float *output;
learning_rate_policy policy;
float learning_rate;
float learning_rate_min;
float learning_rate_max;
int batches_per_cycle;
int batches_cycle_mult;
float momentum;
float decay;
float gamma;
float scale;
float power;
int time_steps;
int step;
int max_batches;
float *seq_scales;
float *scales;
int *steps;
int num_steps;
int burn_in;
int cudnn_half;
float *pre_allocated_ptr;
int adam;
float B1;
float B2;
float eps;
int inputs;
int outputs;
int truths;
int notruth;
int h, w, c;
int max_crop;
int min_crop;
float max_ratio;
float min_ratio;
int center;
int flip; // horizontal flip 50% probability augmentaiont for classifier training (default = 1)
int blur;
float angle;
float aspect;
float exposure;
float saturation;
float hue;
int random;
int track;
int augment_speed;
int sequential_subdivisions;
int init_sequential_subdivisions;
int current_subdivision;
int try_fix_nan;
int gpu_index;
tree *hierarchy;
float *input;
float *truth;
float *delta;
float *workspace;
int train;
int index;
float *cost;
float clip;
#ifdef GPU
//float *input_gpu;
//float *truth_gpu;
float *delta_gpu;
float *output_gpu;
float *input_state_gpu;
float *input_pinned_cpu;
int input_pinned_cpu_flag;
float **input_gpu;
float **truth_gpu;
float **input16_gpu;
float **output16_gpu;
size_t *max_input16_size;
size_t *max_output16_size;
int wait_stream;
#endif
} network;
// network.h
typedef struct network_state {
float *truth;
float *input;
float *delta;
float *workspace;
int train;
int index;
network net;
} network_state;
//typedef struct {
// int w;
// int h;
// float scale;
// float rad;
// float dx;
// float dy;
// float aspect;
//} augment_args;
// image.h
typedef struct image {
int w;
int h;
int c;
float *data;
} image;
//typedef struct {
// int w;
// int h;
// int c;
// float *data;
//} image;
// box.h
typedef struct box {
float x, y, w, h;
} box;
// box.h
typedef struct detection{
box bbox;
int classes;
float *prob;
float *mask;
float objectness;
int sort_class;
} detection;
// matrix.h
typedef struct matrix {
int rows, cols;
float **vals;
} matrix;
// data.h
typedef struct data {
int w, h;
matrix X;
matrix y;
int shallow;
int *num_boxes;
box **boxes;
} data;
// data.h
typedef enum {
CLASSIFICATION_DATA, DETECTION_DATA, CAPTCHA_DATA, REGION_DATA, IMAGE_DATA, COMPARE_DATA, WRITING_DATA, SWAG_DATA, TAG_DATA, OLD_CLASSIFICATION_DATA, STUDY_DATA, DET_DATA, SUPER_DATA, LETTERBOX_DATA, REGRESSION_DATA, SEGMENTATION_DATA, INSTANCE_DATA, ISEG_DATA
} data_type;
// data.h
typedef struct load_args {
int threads;
char **paths;
char *path;
int n;
int m;
char **labels;
int h;
int w;
int c; // color depth
int out_w;
int out_h;
int nh;
int nw;
int num_boxes;
int min, max, size;
int classes;
int background;
int scale;
int center;
int coords;
int mini_batch;
int track;
int augment_speed;
int show_imgs;
float jitter;
int flip;
int blur;
float angle;
float aspect;
float saturation;
float exposure;
float hue;
data *d;
image *im;
image *resized;
data_type type;
tree *hierarchy;
} load_args;
// data.h
typedef struct box_label {
int id;
float x, y, w, h;
float left, right, top, bottom;
} box_label;
// list.h
//typedef struct node {
// void *val;
// struct node *next;
// struct node *prev;
//} node;
// list.h
//typedef struct list {
// int size;
// node *front;
// node *back;
//} list;
// -----------------------------------------------------
// parser.c
LIB_API network *load_network(char *cfg, char *weights, int clear);
LIB_API network *load_network_custom(char *cfg, char *weights, int clear, int batch);
LIB_API network *load_network(char *cfg, char *weights, int clear);
// network.c
LIB_API load_args get_base_args(network *net);
// box.h
LIB_API void do_nms_sort(detection *dets, int total, int classes, float thresh);
LIB_API void do_nms_obj(detection *dets, int total, int classes, float thresh);
// network.h
LIB_API float *network_predict(network net, float *input);
LIB_API float *network_predict_ptr(network *net, float *input);
LIB_API detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num, int letter);
LIB_API void free_detections(detection *dets, int n);
LIB_API void fuse_conv_batchnorm(network net);
LIB_API void calculate_binary_weights(network net);
LIB_API char *detection_to_json(detection *dets, int nboxes, int classes, char **names, long long int frame_id, char *filename);
LIB_API layer* get_network_layer(network* net, int i);
//LIB_API detection *get_network_boxes(network *net, int w, int h, float thresh, float hier, int *map, int relative, int *num, int letter);
LIB_API detection *make_network_boxes(network *net, float thresh, int *num);
LIB_API void reset_rnn(network *net);
LIB_API float *network_predict_image(network *net, image im);
LIB_API float validate_detector_map(char *datacfg, char *cfgfile, char *weightfile, float thresh_calc_avg_iou, const float iou_thresh, const int map_points, network *existing_net);
LIB_API void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, int ngpus, int clear, int dont_show, int calc_map, int mjpeg_port, int show_imgs);
LIB_API void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filename, float thresh,
float hier_thresh, int dont_show, int ext_output, int save_labels, char *outfile, int letter_box);
LIB_API int network_width(network *net);
LIB_API int network_height(network *net);
LIB_API void optimize_picture(network *net, image orig, int max_layer, float scale, float rate, float thresh, int norm);
// image.h
LIB_API image resize_image(image im, int w, int h);
LIB_API void copy_image_from_bytes(image im, char *pdata);
LIB_API image letterbox_image(image im, int w, int h);
LIB_API void rgbgr_image(image im);
LIB_API image make_image(int w, int h, int c);
LIB_API image load_image_color(char *filename, int w, int h);
LIB_API void free_image(image m);
// layer.h
LIB_API void free_layer(layer);
// data.c
LIB_API void free_data(data d);
LIB_API pthread_t load_data(load_args args);
LIB_API pthread_t load_data_in_thread(load_args args);
// dark_cuda.h
LIB_API void cuda_pull_array(float *x_gpu, float *x, size_t n);
LIB_API void cuda_pull_array_async(float *x_gpu, float *x, size_t n);
LIB_API void cuda_set_device(int n);
LIB_API void *cuda_get_context();
// utils.h
LIB_API void free_ptrs(void **ptrs, int n);
LIB_API void top_k(float *a, int n, int k, int *index);
// tree.h
LIB_API tree *read_tree(char *filename);
// option_list.h
LIB_API metadata get_metadata(char *file);
// http_stream.h
LIB_API void delete_json_sender();
LIB_API void send_json_custom(char const* send_buf, int port, int timeout);
LIB_API double get_time_point();
void start_timer();
void stop_timer();
double get_time();
void stop_timer_and_show();
void stop_timer_and_show_name(char *name);
void show_total_time();
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // DIMENSIONLESS_API
+28
View File
@@ -0,0 +1,28 @@
#ifndef HANDLER_H
#define HANDLER_H
#include <iostream>
#include "stdafx.h"
using namespace std;
using namespace web;
using namespace http;
using namespace utility;
using namespace http::experimental::listener;
class handler
{
public:
handler(utility::string_t url);
pplx::task<void>open(){return m_listener.open();}
pplx::task<void>close(){return m_listener.close();}
protected:
private:
void handle_post(http_request message);
http_listener m_listener;
};
#endif // HANDLER_H
+43
View File
@@ -0,0 +1,43 @@
#ifndef STDAFX_H_INCLUDED
#define STDAFX_H_INCLUDED
#define BOOST_LOG_DYN_LINK 1
#pragma once
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <fstream>
#include <random>
#ifdef _WIN32
#define NOMINMAX
#include <Windows.h>
#else
# include <sys/time.h>
#endif
#include "cpprest/json.h"
#include "cpprest/http_listener.h"
#include "cpprest/uri.h"
#include "cpprest/asyncrt_utils.h"
#include "cpprest/json.h"
#include "cpprest/filestream.h"
#include "cpprest/containerstream.h"
#include "cpprest/producerconsumerstream.h"
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/asio/ip/host_name.hpp>
#pragma warning ( push )
#pragma warning ( disable : 4457 )
#pragma warning ( pop )
#include <locale>
#include <ctime>
#endif // STDAFX_H_INCLUDED
+87
View File
@@ -0,0 +1,87 @@
#include <iostream>
#include "stdafx.h"
#include "handler.h"
using namespace std;
using namespace web;
using namespace http;
using namespace utility;
using namespace http::experimental::listener;
namespace logging = boost::log;
namespace keywords = boost::log::keywords;
std::unique_ptr<handler> g_httpHandler;
string get_file_name(string path)
{
return path.substr(path.find_last_of("/\\")+1);
}
void init_logging()
{
logging::register_simple_formatter_factory<logging::trivial::severity_level, char>("Severity");
auto host_name = boost::asio::ip::host_name();
string logFileName = "server_" + string(host_name) + ".log";
logging::add_file_log(
keywords::file_name = "/home/baggageai/log/"+logFileName,
keywords::format = "BAI-[%LineID%] [%TimeStamp%] [%Severity%] %Message%",
keywords::auto_flush = true
);
logging::core::get()->set_filter
(
logging::trivial::severity >= logging::trivial::info
);
logging::add_common_attributes();
}
void on_initialize(const string_t& address)
{
uri_builder uri(address);
try
{
auto addr = uri.to_uri().to_string();
g_httpHandler = std::unique_ptr<handler>(new handler(addr));
g_httpHandler->open().wait();
BOOST_LOG_TRIVIAL(info) << "[" << get_file_name(string(__FILE__)) << " " << __LINE__ << "] " << "Listening for requests at: "+ string(addr);
while(true);
}
catch (exception const& e)
{
BOOST_LOG_TRIVIAL(error) << "[" << get_file_name(string(__FILE__)) << " " << __LINE__ << "] " << e.what();
wcout << e.what() << endl;
}
}
void on_shutdown()
{
g_httpHandler->close().wait();
return;
}
#ifdef _WIN32
int wmain(int argc, wchar_t *argv[])
#else
int main(int argc, char *argv[])
#endif
{
init_logging();
utility::string_t port = U("8080");
if(argc == 2)
{
port = argv[1];
}
utility::string_t address = U("http://0.0.0.0:");
address.append(port);
on_initialize(address);
return 0;
}
+23
View File
@@ -0,0 +1,23 @@
#!/bin/sh
#Removing build folder of home directory to overcome overwriting issue
if [ -d ~/"build/" ]; then
rm -rf ~/build/
fi
#Removing build folder of the project directory
if [ -d "build/" ]; then
rm -rf build/
fi
mkdir build #build folder will be created and project will be build in that folder. If you want to make a folder with different name, then just change it.
cd build #Name of the folder
#Building commands
#cmake -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - Unix Makefiles" ../
#cmake --build . --target BaggageAIApi -- -j4
#Running DemoApp application
cd ..
build/baggageAPI
-350
View File
@@ -1,350 +0,0 @@
#include <iostream>
#include "tkdnn.h"
const char *input_bin = "dla34/debug/input.bin";
const char *conv1_bin = "dla34/layers/features-init_block-conv1-conv.bin";
const char *conv2_bin = "dla34/layers/features-init_block-conv2-conv.bin";
const char *conv3_bin = "dla34/layers/features-init_block-conv3-conv.bin";
// s - stage, t - tree
const char *s1_t1_conv1_bin = "dla34/layers/features-stage1-tree1-body-conv1-conv.bin";
const char *s1_t1_conv2_bin = "dla34/layers/features-stage1-tree1-body-conv2-conv.bin";
const char *s1_t1_project = "dla34/layers/features-stage1-tree1-project_conv-conv.bin";
const char *s1_t2_conv1_bin = "dla34/layers/features-stage1-tree2-body-conv1-conv.bin";
const char *s1_t2_conv2_bin = "dla34/layers/features-stage1-tree2-body-conv2-conv.bin";
const char *s1_root_conv1_bin = "dla34/layers/features-stage1-root-conv-conv.bin";
const char *s2_t1_t1_conv1_bin = "dla34/layers/features-stage2-tree1-tree1-body-conv1-conv.bin";
const char *s2_t1_t1_conv2_bin = "dla34/layers/features-stage2-tree1-tree1-body-conv2-conv.bin";
const char *s2_t1_t1_project = "dla34/layers/features-stage2-tree1-tree1-project_conv-conv.bin";
const char *s2_t1_t2_conv1_bin = "dla34/layers/features-stage2-tree1-tree2-body-conv1-conv.bin";
const char *s2_t1_t2_conv2_bin = "dla34/layers/features-stage2-tree1-tree2-body-conv2-conv.bin";
const char *s2_t1_root_conv1_bin = "dla34/layers/features-stage2-tree1-root-conv-conv.bin";
const char *s2_t2_t1_conv1_bin = "dla34/layers/features-stage2-tree2-tree1-body-conv1-conv.bin";
const char *s2_t2_t1_conv2_bin = "dla34/layers/features-stage2-tree2-tree1-body-conv2-conv.bin";
const char *s2_t2_t2_conv1_bin = "dla34/layers/features-stage2-tree2-tree2-body-conv1-conv.bin";
const char *s2_t2_t2_conv2_bin = "dla34/layers/features-stage2-tree2-tree2-body-conv2-conv.bin";
const char *s2_t2_root_conv1_bin = "dla34/layers/features-stage2-tree2-root-conv-conv.bin";
const char *s3_t1_t1_conv1_bin = "dla34/layers/features-stage3-tree1-tree1-body-conv1-conv.bin";
const char *s3_t1_t1_conv2_bin = "dla34/layers/features-stage3-tree1-tree1-body-conv2-conv.bin";
const char *s3_t1_t1_project = "dla34/layers/features-stage3-tree1-tree1-project_conv-conv.bin";
const char *s3_t1_t2_conv1_bin = "dla34/layers/features-stage3-tree1-tree2-body-conv1-conv.bin";
const char *s3_t1_t2_conv2_bin = "dla34/layers/features-stage3-tree1-tree2-body-conv2-conv.bin";
const char *s3_t1_root_conv1_bin = "dla34/layers/features-stage3-tree1-root-conv-conv.bin";
const char *s3_t2_t1_conv1_bin = "dla34/layers/features-stage3-tree2-tree1-body-conv1-conv.bin";
const char *s3_t2_t1_conv2_bin = "dla34/layers/features-stage3-tree2-tree1-body-conv2-conv.bin";
const char *s3_t2_t2_conv1_bin = "dla34/layers/features-stage3-tree2-tree2-body-conv1-conv.bin";
const char *s3_t2_t2_conv2_bin = "dla34/layers/features-stage3-tree2-tree2-body-conv2-conv.bin";
const char *s3_t2_root_conv1_bin = "dla34/layers/features-stage3-tree2-root-conv-conv.bin";
const char *s4_t1_conv1_bin = "dla34/layers/features-stage4-tree1-body-conv1-conv.bin";
const char *s4_t1_conv2_bin = "dla34/layers/features-stage4-tree1-body-conv2-conv.bin";
const char *s4_t1_project = "dla34/layers/features-stage4-tree1-project_conv-conv.bin";
const char *s4_t2_conv1_bin = "dla34/layers/features-stage4-tree2-body-conv1-conv.bin";
const char *s4_t2_conv2_bin = "dla34/layers/features-stage4-tree2-body-conv2-conv.bin";
const char *s4_root_conv1_bin = "dla34/layers/features-stage4-root-conv-conv.bin";
//final
const char *fc_bin = "dla34/layers/output.bin";
const char *output_bin = "dla34/debug/output.bin";
int main()
{
// Network layout
tk::dnn::dataDim_t dim(1, 3, 224, 224, 1);
tk::dnn::Network net(dim);
tk::dnn::Layer *last1, *last2, *last3, *last4;
tk::dnn::Conv2d conv1(&net, 16, 7, 7, 1, 1, 3, 3, conv1_bin, true);
tk::dnn::Activation relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d conv2(&net, 16, 3, 3, 1, 1, 1, 1, conv2_bin, true);
tk::dnn::Activation relu2(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d conv3(&net, 32, 3, 3, 2, 2, 1, 1, conv3_bin, true);
tk::dnn::Activation relu3(&net, CUDNN_ACTIVATION_RELU);
last1 = &relu3;
// level 2
// tree 1
tk::dnn::Conv2d s1_t1_conv1(&net, 64, 3, 3, 2, 2, 1, 1, s1_t1_conv1_bin, true);
tk::dnn::Activation s1_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s1_t1_conv2(&net, 64, 3, 3, 1, 1, 1, 1, s1_t1_conv2_bin, true);
last2 = &s1_t1_conv2;
// get the basicblock input and apply maxpool conv2d and relu
tk::dnn::Layer *route_s1_t1_layers[1] = { last1 };
tk::dnn::Route route_s1_t1(&net, route_s1_t1_layers, 1);
// downsample
tk::dnn::Pooling s1_t1_maxpool1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
// project
tk::dnn::Conv2d s1_t1_residual1_conv1(&net, 64, 1, 1, 1, 1, 0, 0, s1_t1_project, true);
tk::dnn::Shortcut s1_t1_s1(&net, last2);
tk::dnn::Activation s1_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s1_t1_relu;
// tree 2
tk::dnn::Conv2d s1_t2_conv1(&net, 64, 3, 3, 1, 1, 1, 1, s1_t2_conv1_bin, true);
tk::dnn::Activation s1_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s1_t2_conv2(&net, 64, 3, 3, 1, 1, 1, 1, s1_t2_conv2_bin, true);
tk::dnn::Shortcut s1_t2_s1(&net, last1);
tk::dnn::Activation s1_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s1_t2_relu;
// root
// join last1 and net in single input 128, 56, 56
tk::dnn::Layer *route_s1_root_layers[2] = { last2, last1 };
tk::dnn::Route route_s1_root(&net, route_s1_root_layers, 2);
tk::dnn::Conv2d s1_root_conv1(&net, 64, 1, 1, 1, 1, 0, 0, s1_root_conv1_bin, true);
tk::dnn::Activation s1_root_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s1_root_relu;
// level 3
// tree 1
// tree 1
tk::dnn::Conv2d s2_t1_t1_conv1(&net, 128, 3, 3, 2, 2, 1, 1, s2_t1_t1_conv1_bin, true);
tk::dnn::Activation s2_t1_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s2_t1_t1_conv2(&net, 128, 3, 3, 1, 1, 1, 1, s2_t1_t1_conv2_bin, true);
last2 = &s2_t1_t1_conv2;
// get the basicblock input and apply maxpool conv2d and relu
tk::dnn::Layer *route_s2_t1_t1_layers[1] = { last1 };
tk::dnn::Route route_s2_t1_t1(&net, route_s2_t1_t1_layers, 1);
// downsample
tk::dnn::Pooling s2_t1_t1_maxpool1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
last4 = &s2_t1_t1_maxpool1;
// project
tk::dnn::Conv2d s2_t1_t1_residual1_conv1(&net, 128, 1, 1, 1, 1, 0, 0, s2_t1_t1_project, true);
tk::dnn::Shortcut s2_t1_t1_s1(&net, last2);
tk::dnn::Activation s2_t1_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s2_t1_t1_relu;
// tree 2
tk::dnn::Conv2d s2_t1_t2_conv1(&net, 128, 3, 3, 1, 1, 1, 1, s2_t1_t2_conv1_bin, true);
tk::dnn::Activation s2_t1_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s2_t1_t2_conv2(&net, 128, 3, 3, 1, 1, 1, 1, s2_t1_t2_conv2_bin, true);
tk::dnn::Shortcut s2_t1_t2_s1(&net, last1);
tk::dnn::Activation s2_t1_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s2_t1_t2_relu;
// root
// join last1 and net in single input 128, 56, 56
tk::dnn::Layer *route_s2_t1_root_layers[2] = { last2, last1 };
tk::dnn::Route route_s2_t1_root(&net, route_s2_t1_root_layers, 2);
tk::dnn::Conv2d s2_t1_root_conv1(&net, 128, 1, 1, 1, 1, 0, 0, s2_t1_root_conv1_bin, true);
tk::dnn::Activation s2_t1_root_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s2_t1_root_relu;
last3 = &s2_t1_root_relu;
// tree 2
// tree 1
tk::dnn::Conv2d s2_t2_t1_conv1(&net, 128, 3, 3, 1, 1, 1, 1, s2_t2_t1_conv1_bin, true);
tk::dnn::Activation s2_t2_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s2_t2_t1_conv2(&net, 128, 3, 3, 1, 1, 1, 1, s2_t2_t1_conv2_bin, true);
tk::dnn::Shortcut s2_t2_t1_s1(&net, last1);
tk::dnn::Activation s2_t2_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s2_t2_t1_relu;
// tree 2
tk::dnn::Conv2d s2_t2_t2_conv1(&net, 128, 3, 3, 1, 1, 1, 1, s2_t2_t2_conv1_bin, true);
tk::dnn::Activation s2_t2_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s2_t2_t2_conv2(&net, 128, 3, 3, 1, 1, 1, 1, s2_t2_t2_conv2_bin, true);
tk::dnn::Shortcut s2_t2_t2_s1(&net, last1);
tk::dnn::Activation s2_t2_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s2_t2_t2_relu;
// root
// join last1 and net in single input 128, 56, 56
tk::dnn::Layer *route_s2_t2_root_layers[4] = { last2, last1, last4, last3};
tk::dnn::Route route_s2_t2_root(&net, route_s2_t2_root_layers, 4);
tk::dnn::Conv2d s2_t2_root_conv1(&net, 128, 1, 1, 1, 1, 0, 0, s2_t2_root_conv1_bin, true);
tk::dnn::Activation s2_t2_root_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s2_t2_root_relu;
// level 4
// tree 1
// tree 1
tk::dnn::Conv2d s3_t1_t1_conv1(&net, 256, 3, 3, 2, 2, 1, 1, s3_t1_t1_conv1_bin, true);
tk::dnn::Activation s3_t1_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s3_t1_t1_conv2(&net, 256, 3, 3, 1, 1, 1, 1, s3_t1_t1_conv2_bin, true);
last2 = &s3_t1_t1_conv2;
// get the basicblock input and apply maxpool conv2d and relu
tk::dnn::Layer *route_s3_t1_t1_layers[1] = { last1 };
tk::dnn::Route route_s3_t1_t1(&net, route_s3_t1_t1_layers, 1);
// downsample
tk::dnn::Pooling s3_t1_t1_maxpool1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
last4 = &s3_t1_t1_maxpool1;
// project
tk::dnn::Conv2d s3_t1_t1_residual1_conv1(&net, 256, 1, 1, 1, 1, 0, 0, s3_t1_t1_project, true);
tk::dnn::Shortcut s3_t1_t1_s1(&net, last2);
tk::dnn::Activation s3_t1_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s3_t1_t1_relu;
// tree 2
tk::dnn::Conv2d s3_t1_t2_conv1(&net, 256, 3, 3, 1, 1, 1, 1, s3_t1_t2_conv1_bin, true);
tk::dnn::Activation s3_t1_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s3_t1_t2_conv2(&net, 256, 3, 3, 1, 1, 1, 1, s3_t1_t2_conv2_bin, true);
tk::dnn::Shortcut s3_t1_t2_s1(&net, last1);
tk::dnn::Activation s3_t1_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s3_t1_t2_relu;
// root
// join last1 and net in single input 256, 56, 56
tk::dnn::Layer *route_s3_t1_root_layers[2] = { last2, last1 };
tk::dnn::Route route_s3_t1_root(&net, route_s3_t1_root_layers, 2);
tk::dnn::Conv2d s3_t1_root_conv1(&net, 256, 1, 1, 1, 1, 0, 0, s3_t1_root_conv1_bin, true);
tk::dnn::Activation s3_t1_root_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s3_t1_root_relu;
last3 = &s3_t1_root_relu;
// tree 2
// tree 1
tk::dnn::Conv2d s3_t2_t1_conv1(&net, 256, 3, 3, 1, 1, 1, 1, s3_t2_t1_conv1_bin, true);
tk::dnn::Activation s3_t2_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s3_t2_t1_conv2(&net, 256, 3, 3, 1, 1, 1, 1, s3_t2_t1_conv2_bin, true);
tk::dnn::Shortcut s3_t2_t1_s1(&net, last1);
tk::dnn::Activation s3_t2_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s3_t2_t1_relu;
// tree 2
tk::dnn::Conv2d s3_t2_t2_conv1(&net, 256, 3, 3, 1, 1, 1, 1, s3_t2_t2_conv1_bin, true);
tk::dnn::Activation s3_t2_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s3_t2_t2_conv2(&net, 256, 3, 3, 1, 1, 1, 1, s3_t2_t2_conv2_bin, true);
tk::dnn::Shortcut s3_t2_t2_s1(&net, last1);
tk::dnn::Activation s3_t2_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s3_t2_t2_relu;
// root
// join last1 and net in single input 256, 56, 56
tk::dnn::Layer *route_s3_t2_root_layers[4] = { last2, last1, last4, last3};
tk::dnn::Route route_s3_t2_root(&net, route_s3_t2_root_layers, 4);
tk::dnn::Conv2d s3_t2_root_conv1(&net, 256, 1, 1, 1, 1, 0, 0, s3_t2_root_conv1_bin, true);
tk::dnn::Activation s3_t2_root_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s3_t2_root_relu;
// level 4
// tree 1
tk::dnn::Conv2d s4_t1_conv1(&net, 512, 3, 3, 2, 2, 1, 1, s4_t1_conv1_bin, true);
tk::dnn::Activation s4_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s4_t1_conv2(&net, 512, 3, 3, 1, 1, 1, 1, s4_t1_conv2_bin, true);
last2 = &s4_t1_conv2;
// get the basicblock input and apply maxpool conv2d and relu
tk::dnn::Layer *route_s4_t1_layers[1] = { last1 };
tk::dnn::Route route_s4_t1(&net, route_s4_t1_layers, 1);
// downsample
tk::dnn::Pooling s4_t1_maxpool1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
last4 = &s4_t1_maxpool1;
// project
tk::dnn::Conv2d s4_t1_residual1_conv1(&net, 512, 1, 1, 1, 1, 0, 0, s4_t1_project, true);
tk::dnn::Shortcut s4_t1_s1(&net, last2);
tk::dnn::Activation s4_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s4_t1_relu;
// tree 2
tk::dnn::Conv2d s4_t2_conv1(&net, 512, 3, 3, 1, 1, 1, 1, s4_t2_conv1_bin, true);
tk::dnn::Activation s4_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s4_t2_conv2(&net, 512, 3, 3, 1, 1, 1, 1, s4_t2_conv2_bin, true);
tk::dnn::Shortcut s4_t2_s1(&net, last1);
tk::dnn::Activation s4_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s4_t2_relu;
// root
// join last1 and net in single input 128, 56, 56
tk::dnn::Layer *route_s4_root_layers[3] = { last2, last1, last4 };
tk::dnn::Route route_s4_root(&net, route_s4_root_layers, 3);
tk::dnn::Conv2d s4_root_conv1(&net, 512, 1, 1, 1, 1, 0, 0, s4_root_conv1_bin, true);
tk::dnn::Activation s4_root_relu(&net, CUDNN_ACTIVATION_RELU);
//final
tk::dnn::Pooling avgpool(&net, 7, 7, 7, 7, 0, 0, tk::dnn::POOLING_AVERAGE);
tk::dnn::Dense fc(&net, 1000, fc_bin);
// 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("dla34"));
tk::dnn::dataDim_t out_dim;
out_dim = net.layers[net.num_layers-1]->output_dim;
dnnType *cudnn_out, *rt_out;
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30);
{
dim1.print();
TKDNN_TSTART
net.infer(dim1, data);
TKDNN_TSTOP
dim1.print();
}
cudnn_out = net.layers[net.num_layers-1]->dstData;
// printDeviceVector(64, cudnn_out, true);
tk::dnn::dataDim_t dim2 = dim;
printCenteredTitle(" TENSORRT inference ", '=', 30);
{
dim2.print();
TKDNN_TSTART
netRT.infer(dim2, data);
TKDNN_TSTOP
dim2.print();
}
rt_out = (dnnType *)netRT.buffersRT[1];
printCenteredTitle(std::string(" RESNET CHECK RESULTS ").c_str(), '=', 30);
dnnType *out, *out_h;
int odim = out_dim.tot();
readBinaryFile(output_bin, odim, &out_h, &out);
std::cout<<"CUDNN vs correct";
int ret_cudnn = checkResult(odim, cudnn_out, out) == 0 ? 0: ERROR_CUDNN;
std::cout<<"TRT vs correct";
int ret_tensorrt = checkResult(odim, rt_out, out) == 0 ? 0 : ERROR_TENSORRT;
std::cout<<"CUDNN vs TRT ";
int ret_cudnn_tensorrt = checkResult(odim, cudnn_out, rt_out) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
}
@@ -1,162 +0,0 @@
import torch
import urllib
from PIL import Image
from torchvision import transforms
import numpy as np
import struct
import os
from pytorchcv.model_provider import get_model as ptcv_get_model
from torch.autograd import Variable
from torchsummary import summary
import torch.nn as nn
from torch.jit import trace
def create_folders():
if not os.path.exists('debug'):
os.makedirs('debug')
if not os.path.exists('layers'):
os.makedirs('layers')
def bin_write(f, data):
data =data.flatten()
fmt = 'f'*len(data)
bin = struct.pack(fmt, *data)
f.write(bin)
def hook(module, input, output):
setattr(module, "_value_hook", output)
def load_ex_image(model):
# Download an example image from the pytorch website
url, filename = (
"https://github.com/pytorch/hub/raw/master/dog.jpg", "dog.jpg")
try:
urllib.URLopener().retrieve(url, filename)
except:
urllib.request.urlretrieve(url, filename)
# sample execution (requires torchvision)
input_image = Image.open(filename)
print("input_image: ",input_image.size)
preprocess = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[
0.229, 0.224, 0.225]),
])
input_tensor = preprocess(input_image)
print("input_tensor: ",input_tensor.shape)
# create a mini-batch as expected by the model
input_batch = input_tensor.unsqueeze(0)
# move the input and model to GPU for speed if available
if torch.cuda.is_available():
input_batch = input_batch.to('cuda')
model.to('cuda')
return model, input_batch
def exp_input(model, input_batch):
# Export the input batch
model(input_batch)
i = input_batch.cpu().data.numpy()
i = np.array(i, dtype=np.float32)
i.tofile("debug/input.bin", format="f")
print("input: ", i.shape)
def print_wb_output(model):
f = None
for n, m in model.named_modules():
m.eval()
if 'DLAResBlock' in str(m.type):
continue
in_output = m._value_hook
o = in_output.data.numpy()
o = np.array(o, dtype=np.float32)
t = '-'.join(n.split('.'))
o.tofile("debug/" + t + ".bin", format="f")
print('------- ', n, ' ------')
print("debug ",o.shape)
if not(' of Conv2d' in str(m.type) or ' of Linear' in str(m.type) or ' of BatchNorm2d' in str(m.type)):
continue
if ' of Conv2d' in str(m.type) or ' of Linear' in str(m.type):
file_name = "layers/" + t + ".bin"
print("open file: ", file_name)
f = open(file_name, mode='wb')
w = np.array([])
b = np.array([])
if 'weight' in m._parameters and m._parameters['weight'] is not None:
w = m._parameters['weight'].data.numpy()
w = np.array(w, dtype=np.float32)
print (" weights shape:", np.shape(w))
if 'bias' in m._parameters and m._parameters['bias'] is not None:
b = m._parameters['bias'].data.numpy()
b = np.array(b, dtype=np.float32)
print (" bias shape:", np.shape(b))
if 'BatchNorm2d' in str(m.type):
b = m._parameters['bias'].data.numpy()
b = np.array(b, dtype=np.float32)
s = m._parameters['weight'].data.numpy()
s = np.array(s, dtype=np.float32)
rm = m.running_mean.data.numpy()
rm = np.array(rm, dtype=np.float32)
rv = m.running_var.data.numpy()
rv = np.array(rv, dtype=np.float32)
bin_write(f,b)
bin_write(f,s)
bin_write(f,rm)
bin_write(f,rv)
print (" b shape:", np.shape(b))
print (" s shape:", np.shape(s))
print (" rm shape:", np.shape(rm))
print (" rv shape:", np.shape(rv))
else:
bin_write(f,w)
if b.size > 0 and b is not None:
bin_write(f,b)
if ' of BatchNorm2d' in str(m.type) or ' of Linear' in str(m.type):
f.close()
print("close file")
f = None
if __name__ == '__main__':
model = ptcv_get_model("dla34", pretrained=True)
model.eval()
# load an example image and load it on model
model, input_batch = load_ex_image(model)
model.eval()
with torch.no_grad():
output = model(input_batch)
# create folders debug and layers if do not exist
create_folders()
# add output attribute to the layers
for n, m in model.named_modules():
m.register_forward_hook(hook)
# export input bin
exp_input(model, input_batch)
print_wb_output(model)
with open("dla34.txt", 'w') as f:
for item in list(model.children()):
f.write("%s\n" % item)
summary(model, (3, 224, 224))
# print(trace(model, input_batch))
-60
View File
@@ -1,60 +0,0 @@
name: dla34
channels:
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- _pytorch_select=0.2=gpu_0
- blas=1.0=mkl
- ca-certificates=2019.10.16=0
- certifi=2019.9.11=py36_0
- cffi=1.13.1=py36h2e261b9_0
- cudatoolkit=10.0.130=0
- cudnn=7.6.0=cuda10.0_0
- freetype=2.9.1=h8a8886c_1
- intel-openmp=2019.4=243
- jpeg=9b=h024ee3a_2
- libedit=3.1.20181209=hc058e9b_0
- libffi=3.2.1=hd88cf55_4
- libgcc-ng=9.1.0=hdf63c60_0
- libgfortran-ng=7.3.0=hdf63c60_0
- libpng=1.6.37=hbc83047_0
- libstdcxx-ng=9.1.0=hdf63c60_0
- libtiff=4.0.10=h2733197_2
- mkl=2019.4=243
- mkl-service=2.3.0=py36he904b0f_0
- mkl_fft=1.0.14=py36ha843d7b_0
- mkl_random=1.1.0=py36hd6b4f25_0
- ncurses=6.1=he6710b0_1
- ninja=1.9.0=py36hfd86e86_0
- numpy=1.17.2=py36haad9e8e_0
- numpy-base=1.17.2=py36hde5b4d6_0
- olefile=0.46=py36_0
- openssl=1.1.1d=h7b6447c_3
- pillow=6.2.0=py36h34e0f95_0
- pip=19.3.1=py36_0
- pycparser=2.19=py36_0
- python=3.6.9=h265db76_0
- readline=7.0=h7b6447c_5
- setuptools=41.6.0=py36_0
- six=1.12.0=py36_0
- sqlite=3.30.1=h7b6447c_0
- tk=8.6.8=hbc83047_0
- wheel=0.33.6=py36_0
- xz=5.2.4=h14c3975_4
- zlib=1.2.11=h7b6447c_3
- zstd=1.3.7=h0b5b093_0
- pip:
- chardet==3.0.4
- decorator==4.4.1
- idna==2.8
- lxml==4.4.2
- networkx==2.4
- nltk==3.4.5
- pytorchcv==0.0.55
- requests==2.22.0
- summary==0.2.0
- torch==1.3.0
- torchsummary==1.5.1
- torchvision==0.4.1
- urllib3==1.25.8
@@ -1,56 +0,0 @@
name: resnet101
channels:
- defaults
dependencies:
- _libgcc_mutex=0.1=main
- _pytorch_select=0.2=gpu_0
- blas=1.0=mkl
- ca-certificates=2019.10.16=0
- certifi=2019.9.11=py36_0
- cffi=1.13.1=py36h2e261b9_0
- cudatoolkit=10.0.130=0
- cudnn=7.6.0=cuda10.0_0
- freetype=2.9.1=h8a8886c_1
- intel-openmp=2019.4=243
- jpeg=9b=h024ee3a_2
- libedit=3.1.20181209=hc058e9b_0
- libffi=3.2.1=hd88cf55_4
- libgcc-ng=9.1.0=hdf63c60_0
- libgfortran-ng=7.3.0=hdf63c60_0
- libpng=1.6.37=hbc83047_0
- libstdcxx-ng=9.1.0=hdf63c60_0
- libtiff=4.0.10=h2733197_2
- mkl=2019.4=243
- mkl-service=2.3.0=py36he904b0f_0
- mkl_fft=1.0.14=py36ha843d7b_0
- mkl_random=1.1.0=py36hd6b4f25_0
- ncurses=6.1=he6710b0_1
- ninja=1.9.0=py36hfd86e86_0
- numpy=1.17.2=py36haad9e8e_0
- numpy-base=1.17.2=py36hde5b4d6_0
- olefile=0.46=py36_0
- openssl=1.1.1d=h7b6447c_3
- pillow=6.2.0=py36h34e0f95_0
- pip=19.3.1=py36_0
- pycparser=2.19=py36_0
- python=3.6.9=h265db76_0
- pytorch=1.2.0=cuda100py36h938c94c_0
- readline=7.0=h7b6447c_5
- setuptools=41.6.0=py36_0
- six=1.12.0=py36_0
- sqlite=3.30.1=h7b6447c_0
- tk=8.6.8=hbc83047_0
- wheel=0.33.6=py36_0
- xz=5.2.4=h14c3975_4
- zlib=1.2.11=h7b6447c_3
- zstd=1.3.7=h0b5b093_0
- pip:
- chardet==3.0.4
- idna==2.8
- pytorchcv==0.0.55
- requests==2.22.0
- torch==1.3.0
- torchsummary==1.5.1
- torchvision==0.4.1
- urllib3==1.25.8
-338
View File
@@ -1,338 +0,0 @@
#include <iostream>
#include "tkdnn.h"
const char *input_bin = "resnet101/debug/input.bin";
const char *conv1_bin = "resnet101/layers/conv1.bin";
//layer1
const char *layer1_bin[]={
"resnet101/layers/layer1-0-conv1.bin",
"resnet101/layers/layer1-0-conv2.bin",
"resnet101/layers/layer1-0-conv3.bin",
"resnet101/layers/layer1-0-downsample-0.bin",
"resnet101/layers/layer1-1-conv1.bin",
"resnet101/layers/layer1-1-conv2.bin",
"resnet101/layers/layer1-1-conv3.bin",
"resnet101/layers/layer1-2-conv1.bin",
"resnet101/layers/layer1-2-conv2.bin",
"resnet101/layers/layer1-2-conv3.bin"};
//layer2
const char *layer2_bin[]={
"resnet101/layers/layer2-0-conv1.bin",
"resnet101/layers/layer2-0-conv2.bin",
"resnet101/layers/layer2-0-conv3.bin",
"resnet101/layers/layer2-0-downsample-0.bin",
"resnet101/layers/layer2-1-conv1.bin",
"resnet101/layers/layer2-1-conv2.bin",
"resnet101/layers/layer2-1-conv3.bin",
"resnet101/layers/layer2-2-conv1.bin",
"resnet101/layers/layer2-2-conv2.bin",
"resnet101/layers/layer2-2-conv3.bin",
"resnet101/layers/layer2-3-conv1.bin",
"resnet101/layers/layer2-3-conv2.bin",
"resnet101/layers/layer2-3-conv3.bin"
};
//layer3
const char *layer3_bin[]={
"resnet101/layers/layer3-0-conv1.bin",
"resnet101/layers/layer3-0-conv2.bin",
"resnet101/layers/layer3-0-conv3.bin",
"resnet101/layers/layer3-0-downsample-0.bin",
"resnet101/layers/layer3-1-conv1.bin",
"resnet101/layers/layer3-1-conv2.bin",
"resnet101/layers/layer3-1-conv3.bin",
"resnet101/layers/layer3-2-conv1.bin",
"resnet101/layers/layer3-2-conv2.bin",
"resnet101/layers/layer3-2-conv3.bin",
"resnet101/layers/layer3-3-conv1.bin",
"resnet101/layers/layer3-3-conv2.bin",
"resnet101/layers/layer3-3-conv3.bin",
"resnet101/layers/layer3-4-conv1.bin",
"resnet101/layers/layer3-4-conv2.bin",
"resnet101/layers/layer3-4-conv3.bin",
"resnet101/layers/layer3-5-conv1.bin",
"resnet101/layers/layer3-5-conv2.bin",
"resnet101/layers/layer3-5-conv3.bin",
"resnet101/layers/layer3-6-conv1.bin",
"resnet101/layers/layer3-6-conv2.bin",
"resnet101/layers/layer3-6-conv3.bin",
"resnet101/layers/layer3-7-conv1.bin",
"resnet101/layers/layer3-7-conv2.bin",
"resnet101/layers/layer3-7-conv3.bin",
"resnet101/layers/layer3-8-conv1.bin",
"resnet101/layers/layer3-8-conv2.bin",
"resnet101/layers/layer3-8-conv3.bin",
"resnet101/layers/layer3-9-conv1.bin",
"resnet101/layers/layer3-9-conv2.bin",
"resnet101/layers/layer3-9-conv3.bin",
"resnet101/layers/layer3-10-conv1.bin",
"resnet101/layers/layer3-10-conv2.bin",
"resnet101/layers/layer3-10-conv3.bin",
"resnet101/layers/layer3-11-conv1.bin",
"resnet101/layers/layer3-11-conv2.bin",
"resnet101/layers/layer3-11-conv3.bin",
"resnet101/layers/layer3-12-conv1.bin",
"resnet101/layers/layer3-12-conv2.bin",
"resnet101/layers/layer3-12-conv3.bin",
"resnet101/layers/layer3-13-conv1.bin",
"resnet101/layers/layer3-13-conv2.bin",
"resnet101/layers/layer3-13-conv3.bin",
"resnet101/layers/layer3-14-conv1.bin",
"resnet101/layers/layer3-14-conv2.bin",
"resnet101/layers/layer3-14-conv3.bin",
"resnet101/layers/layer3-15-conv1.bin",
"resnet101/layers/layer3-15-conv2.bin",
"resnet101/layers/layer3-15-conv3.bin",
"resnet101/layers/layer3-16-conv1.bin",
"resnet101/layers/layer3-16-conv2.bin",
"resnet101/layers/layer3-16-conv3.bin",
"resnet101/layers/layer3-17-conv1.bin",
"resnet101/layers/layer3-17-conv2.bin",
"resnet101/layers/layer3-17-conv3.bin",
"resnet101/layers/layer3-18-conv1.bin",
"resnet101/layers/layer3-18-conv2.bin",
"resnet101/layers/layer3-18-conv3.bin",
"resnet101/layers/layer3-19-conv1.bin",
"resnet101/layers/layer3-19-conv2.bin",
"resnet101/layers/layer3-19-conv3.bin",
"resnet101/layers/layer3-20-conv1.bin",
"resnet101/layers/layer3-20-conv2.bin",
"resnet101/layers/layer3-20-conv3.bin",
"resnet101/layers/layer3-21-conv1.bin",
"resnet101/layers/layer3-21-conv2.bin",
"resnet101/layers/layer3-21-conv3.bin",
"resnet101/layers/layer3-22-conv1.bin",
"resnet101/layers/layer3-22-conv2.bin",
"resnet101/layers/layer3-22-conv3.bin"};
//layer4
const char *layer4_bin[]={
"resnet101/layers/layer4-0-conv1.bin",
"resnet101/layers/layer4-0-conv2.bin",
"resnet101/layers/layer4-0-conv3.bin",
"resnet101/layers/layer4-0-downsample-0.bin",
"resnet101/layers/layer4-1-conv1.bin",
"resnet101/layers/layer4-1-conv2.bin",
"resnet101/layers/layer4-1-conv3.bin",
"resnet101/layers/layer4-2-conv1.bin",
"resnet101/layers/layer4-2-conv2.bin",
"resnet101/layers/layer4-2-conv3.bin"};
//final
const char *fc_bin = "resnet101/layers/fc.bin";
const char *output_bin = "resnet101/debug/fc.bin";
int main()
{
// Network layout
tk::dnn::dataDim_t dim(1, 3, 224, 224, 1);
tk::dnn::Network net(dim);
tk::dnn::Conv2d conv1(&net, 64, 7, 7, 2, 2, 3, 3, conv1_bin, true);
tk::dnn::Activation relu3(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Pooling maxpool4(&net, 3, 3, 2, 2, 1, 1, tk::dnn::POOLING_MAX);
//layer 1
int id_layer1_bin = 0;
tk::dnn::Layer *last = &maxpool4;
for(int i=0; i<3;i++)
{
tk::dnn::Conv2d *layer1_0_conv1 = new tk::dnn::Conv2d(&net, 64, 1, 1, 1, 1, 0, 0, layer1_bin[id_layer1_bin++], true);
tk::dnn::Activation *relu1_0_1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv2 = new tk::dnn::Conv2d(&net, 64, 3, 3, 1, 1, 1, 1, layer1_bin[id_layer1_bin++], true);
tk::dnn::Activation *relu1_0_2 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv3 = new tk::dnn::Conv2d(&net, 256, 1, 1, 1, 1, 0, 0, layer1_bin[id_layer1_bin++], true);
if(i==0) {
tk::dnn::Layer *route_1_0_layers[1] = { last };
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *layer1_0_downsample_0 = new tk::dnn::Conv2d(&net, 256, 1, 1, 1, 1, 0, 0, layer1_bin[id_layer1_bin++], true);
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, layer1_0_conv3);
} else {
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, last);
}
tk::dnn::Activation *layer1_0_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
last = layer1_0_relu;
}
// tk::dnn::Activation *last_activation = (tk::dnn::Activation *) net.layers[net.num_layers-1];
// layer 2
int id_layer2_bin = 0;
for(int i=0; i<4;i++)
{
tk::dnn::Conv2d *layer1_0_conv1 = new tk::dnn::Conv2d(&net, 128, 1, 1, 1, 1, 0, 0, layer2_bin[id_layer2_bin++], true);
tk::dnn::Activation *relu1_0_1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv2;
if(i==0)
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 128, 3, 3, 2, 2, 1, 1, layer2_bin[id_layer2_bin++], true);
else
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 128, 3, 3, 1, 1, 1, 1, layer2_bin[id_layer2_bin++], true);
tk::dnn::Activation *relu1_0_2 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv3 = new tk::dnn::Conv2d(&net, 512, 1, 1, 1, 1, 0, 0, layer2_bin[id_layer2_bin++], true);
if(i==0)
{
tk::dnn::Layer *route_1_0_layers[1] = { last };
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *layer1_0_downsample_0 = new tk::dnn::Conv2d(&net, 512, 1, 1, 2, 2, 0, 0, layer2_bin[id_layer2_bin++], true);
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, layer1_0_conv3);
}
else
{
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, last);
}
tk::dnn::Activation *layer1_0_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
last = layer1_0_relu;
}
// layer 3
int id_layer3_bin = 0;
for(int i=0; i<23;i++)
{
tk::dnn::Conv2d *layer1_0_conv1 = new tk::dnn::Conv2d(&net, 256, 1, 1, 1, 1, 0, 0, layer3_bin[id_layer3_bin++], true);
tk::dnn::Activation *relu1_0_1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv2;
if(i==0)
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 256, 3, 3, 2, 2, 1, 1, layer3_bin[id_layer3_bin++], true);
else
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 256, 3, 3, 1, 1, 1, 1, layer3_bin[id_layer3_bin++], true);
tk::dnn::Activation *relu1_0_2 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv3 = new tk::dnn::Conv2d(&net, 1024, 1, 1, 1, 1, 0, 0, layer3_bin[id_layer3_bin++], true);
if(i==0)
{
tk::dnn::Layer *route_1_0_layers[1] = { last };
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *layer1_0_downsample_0 = new tk::dnn::Conv2d(&net, 1024, 1, 1, 2, 2, 0, 0, layer3_bin[id_layer3_bin++], true);
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, layer1_0_conv3);
}
else
{
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, last);
}
tk::dnn::Activation *layer1_0_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
last = layer1_0_relu;
}
// layer 4
int id_layer4_bin = 0;
for(int i=0; i<3;i++)
{
tk::dnn::Conv2d *layer1_0_conv1 = new tk::dnn::Conv2d(&net, 512, 1, 1, 1, 1, 0, 0, layer4_bin[id_layer4_bin++], true);
tk::dnn::Activation *relu1_0_1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv2;
if(i==0)
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 512, 3, 3, 2, 2, 1, 1, layer4_bin[id_layer4_bin++], true);
else
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 512, 3, 3, 1, 1, 1, 1, layer4_bin[id_layer4_bin++], true);
tk::dnn::Activation *relu1_0_2 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv3 = new tk::dnn::Conv2d(&net, 2048, 1, 1, 1, 1, 0, 0, layer4_bin[id_layer4_bin++], true);
if(i==0)
{
tk::dnn::Layer *route_1_0_layers[1] = { last };
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *layer1_0_downsample_0 = new tk::dnn::Conv2d(&net, 2048, 1, 1, 2, 2, 0, 0, layer4_bin[id_layer4_bin++], true);
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, layer1_0_conv3);
}
else
{
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, last);
}
tk::dnn::Activation *layer1_0_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
last = layer1_0_relu;
}
//final
tk::dnn::Pooling avgpool(&net, 7, 7, 7, 7, 0, 0, tk::dnn::POOLING_AVERAGE);
tk::dnn::Dense fc(&net, 1000, fc_bin);
// 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("resnet101"));
tk::dnn::dataDim_t out_dim;
out_dim = net.layers[net.num_layers-1]->output_dim;
dnnType *cudnn_out, *rt_out;
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30);
{
dim1.print();
TKDNN_TSTART
net.infer(dim1, data);
TKDNN_TSTOP
dim1.print();
}
cudnn_out = net.layers[net.num_layers-1]->dstData;
//printDeviceVector(64, cudnn_out, true);
tk::dnn::dataDim_t dim2 = dim;
printCenteredTitle(" TENSORRT inference ", '=', 30);
{
dim2.print();
TKDNN_TSTART
netRT.infer(dim2, data);
TKDNN_TSTOP
dim2.print();
}
rt_out = (dnnType *)netRT.buffersRT[1];
printCenteredTitle(std::string(" RESNET CHECK RESULTS ").c_str(), '=', 30);
dnnType *out, *out_h;
int odim = out_dim.tot();
readBinaryFile(output_bin, odim, &out_h, &out);
std::cout<<"CUDNN vs correct";
int ret_cudnn = checkResult(odim, cudnn_out, out) == 0 ? 0: ERROR_CUDNN;
std::cout<<"TRT vs correct";
int ret_tensorrt = checkResult(odim, rt_out, out) == 0 ? 0 : ERROR_TENSORRT;
std::cout<<"CUDNN vs TRT ";
int ret_cudnn_tensorrt = checkResult(odim, cudnn_out, rt_out) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
}
@@ -1,162 +0,0 @@
import torch
import urllib
from PIL import Image
from torchvision import transforms
import numpy as np
import struct
import os
from pytorchcv.model_provider import get_model as ptcv_get_model
from torch.autograd import Variable
from torchsummary import summary
import torch.nn as nn
from torch.jit import trace
def create_folders():
if not os.path.exists('debug'):
os.makedirs('debug')
if not os.path.exists('layers'):
os.makedirs('layers')
def bin_write(f, data):
data =data.flatten()
fmt = 'f'*len(data)
bin = struct.pack(fmt, *data)
f.write(bin)
def hook(module, input, output):
setattr(module, "_value_hook", output)
def load_ex_image(model):
# Download an example image from the pytorch website
url, filename = (
"https://github.com/pytorch/hub/raw/master/dog.jpg", "dog.jpg")
try:
urllib.URLopener().retrieve(url, filename)
except:
urllib.request.urlretrieve(url, filename)
# sample execution (requires torchvision)
input_image = Image.open(filename)
print("input_image: ",input_image.size)
preprocess = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[
0.229, 0.224, 0.225]),
])
input_tensor = preprocess(input_image)
print("input_tensor: ",input_tensor.shape)
# create a mini-batch as expected by the model
input_batch = input_tensor.unsqueeze(0)
# move the input and model to GPU for speed if available
if torch.cuda.is_available():
input_batch = input_batch.to('cuda')
model.to('cuda')
return model, input_batch
def exp_input(model, input_batch):
# Export the input batch
model(input_batch)
i = input_batch.cpu().data.numpy()
i = np.array(i, dtype=np.float32)
i.tofile("debug/input.bin", format="f")
print("input: ", i.shape)
def print_wb_output(model):
f = None
for n, m in model.named_modules():
in_output = m._value_hook
o = in_output.data.numpy()
o = np.array(o, dtype=np.float32)
t = '-'.join(n.split('.'))
o.tofile("debug/" + t + ".bin", format="f")
print('------- ', n, ' ------')
print("debug ",o.shape)
if not(' of Conv2d' in str(m.type) or ' of Linear' in str(m.type) or ' of BatchNorm2d' in str(m.type)):
continue
if ' of Conv2d' in str(m.type) or ' of Linear' in str(m.type):
file_name = "layers/" + t + ".bin"
print("open file: ", file_name)
f = open(file_name, mode='wb')
w = np.array([])
b = np.array([])
if 'weight' in m._parameters and m._parameters['weight'] is not None:
w = m._parameters['weight'].data.numpy()
w = np.array(w, dtype=np.float32)
print (" weights shape:", np.shape(w))
if 'bias' in m._parameters and m._parameters['bias'] is not None:
b = m._parameters['bias'].data.numpy()
b = np.array(b, dtype=np.float32)
print (" bias shape:", np.shape(b))
if 'BatchNorm2d' in str(m.type):
b = m._parameters['bias'].data.numpy()
b = np.array(b, dtype=np.float32)
s = m._parameters['weight'].data.numpy()
s = np.array(s, dtype=np.float32)
rm = m.running_mean.data.numpy()
rm = np.array(rm, dtype=np.float32)
rv = m.running_var.data.numpy()
rv = np.array(rv, dtype=np.float32)
bin_write(f,b)
bin_write(f,s)
bin_write(f,rm)
bin_write(f,rv)
print (" b shape:", np.shape(b))
print (" s shape:", np.shape(s))
print (" rm shape:", np.shape(rm))
print (" rv shape:", np.shape(rv))
else:
bin_write(f,w)
if b.size > 0:
bin_write(f,b)
if ' of BatchNorm2d' in str(m.type) or ' of Linear' in str(m.type):
f.close()
print("close file")
f = None
if __name__ == '__main__':
model = torch.hub.load('pytorch/vision', 'resnet101', pretrained=True)
model.eval()
# load an example image and load it on model
model, input_batch = load_ex_image(model)
model.eval()
with torch.no_grad():
output = model(input_batch)
# create folders debug and layers if do not exist
create_folders()
# add output attribute to the layers
for n, m in model.named_modules():
m.register_forward_hook(hook)
# export input bin
exp_input(model, input_batch)
print_wb_output(model)
with open("resnet101.txt", 'w') as f:
for item in list(model.children()):
f.write("%s\n" % item)
summary(model, (3, 224, 224))
# print(trace(model, input_batch))
-532
View File
@@ -1,532 +0,0 @@
#include <iostream>
#include "tkdnn.h"
const char *input_bin = "dla34_cnet/debug/input.bin";
const char *conv1_bin = "dla34_cnet/layers/base-base_layer-0.bin";
const char *conv2_bin = "dla34_cnet/layers/base-level0-0.bin";
const char *conv3_bin = "dla34_cnet/layers/base-level1-0.bin";
// s - stage, t - tree
const char *s1_t1_conv1_bin = "dla34_cnet/layers/base-level2-tree1-conv1.bin";
const char *s1_t1_conv2_bin = "dla34_cnet/layers/base-level2-tree1-conv2.bin";
const char *s1_t1_project = "dla34_cnet/layers/base-level2-project-0.bin";
const char *s1_t2_conv1_bin = "dla34_cnet/layers/base-level2-tree2-conv1.bin";
const char *s1_t2_conv2_bin = "dla34_cnet/layers/base-level2-tree2-conv2.bin";
const char *s1_root_conv1_bin = "dla34_cnet/layers/base-level2-root-conv.bin";
const char *s2_t1_t1_conv1_bin = "dla34_cnet/layers/base-level3-tree1-tree1-conv1.bin";
const char *s2_t1_t1_conv2_bin = "dla34_cnet/layers/base-level3-tree1-tree1-conv2.bin";
const char *s2_t1_t1_project = "dla34_cnet/layers/base-level3-tree1-project-0.bin";
const char *s2_t1_t2_conv1_bin = "dla34_cnet/layers/base-level3-tree1-tree2-conv1.bin";
const char *s2_t1_t2_conv2_bin = "dla34_cnet/layers/base-level3-tree1-tree2-conv2.bin";
const char *s2_t1_root_conv1_bin = "dla34_cnet/layers/base-level3-tree1-root-conv.bin";
const char *s2_t2_t1_conv1_bin = "dla34_cnet/layers/base-level3-tree2-tree1-conv1.bin";
const char *s2_t2_t1_conv2_bin = "dla34_cnet/layers/base-level3-tree2-tree1-conv2.bin";
const char *s2_t2_t2_conv1_bin = "dla34_cnet/layers/base-level3-tree2-tree2-conv1.bin";
const char *s2_t2_t2_conv2_bin = "dla34_cnet/layers/base-level3-tree2-tree2-conv2.bin";
const char *s2_t2_root_conv1_bin = "dla34_cnet/layers/base-level3-tree2-root-conv.bin";
const char *s3_t1_t1_conv1_bin = "dla34_cnet/layers/base-level4-tree1-tree1-conv1.bin";
const char *s3_t1_t1_conv2_bin = "dla34_cnet/layers/base-level4-tree1-tree1-conv2.bin";
const char *s3_t1_t1_project = "dla34_cnet/layers/base-level4-tree1-project-0.bin";
const char *s3_t1_t2_conv1_bin = "dla34_cnet/layers/base-level4-tree1-tree2-conv1.bin";
const char *s3_t1_t2_conv2_bin = "dla34_cnet/layers/base-level4-tree1-tree2-conv2.bin";
const char *s3_t1_root_conv1_bin = "dla34_cnet/layers/base-level4-tree1-root-conv.bin";
const char *s3_t2_t1_conv1_bin = "dla34_cnet/layers/base-level4-tree2-tree1-conv1.bin";
const char *s3_t2_t1_conv2_bin = "dla34_cnet/layers/base-level4-tree2-tree1-conv2.bin";
const char *s3_t2_t2_conv1_bin = "dla34_cnet/layers/base-level4-tree2-tree2-conv1.bin";
const char *s3_t2_t2_conv2_bin = "dla34_cnet/layers/base-level4-tree2-tree2-conv2.bin";
const char *s3_t2_root_conv1_bin = "dla34_cnet/layers/base-level4-tree2-root-conv.bin";
const char *s4_t1_conv1_bin = "dla34_cnet/layers/base-level5-tree1-conv1.bin";
const char *s4_t1_conv2_bin = "dla34_cnet/layers/base-level5-tree1-conv2.bin";
const char *s4_t1_project = "dla34_cnet/layers/base-level5-project-0.bin";
const char *s4_t2_conv1_bin = "dla34_cnet/layers/base-level5-tree2-conv1.bin";
const char *s4_t2_conv2_bin = "dla34_cnet/layers/base-level5-tree2-conv2.bin";
const char *s4_root_conv1_bin = "dla34_cnet/layers/base-level5-root-conv.bin";
//final
// const char *fc_bin = "dla34_cnet/layers/output.bin";
const char *ida_0_p_1_dcn_bin = "dla34_cnet/layers/dla_up-ida_0-proj_1-conv.bin";
const char *ida_0_p_1_conv_bin = "dla34_cnet/layers/dla_up-ida_0-proj_1-conv-conv_offset_mask.bin";
const char *ida_0_up_1_deconv_bin = "dla34_cnet/layers/dla_up-ida_0-up_1.bin";
const char *ida_0_n_1_dcn_bin = "dla34_cnet/layers/dla_up-ida_0-node_1-conv.bin";
const char *ida_0_n_1_conv_bin = "dla34_cnet/layers/dla_up-ida_0-node_1-conv-conv_offset_mask.bin";
const char *ida_1_p_1_dcn_bin = "dla34_cnet/layers/dla_up-ida_1-proj_1-conv.bin";
const char *ida_1_p_1_conv_bin = "dla34_cnet/layers/dla_up-ida_1-proj_1-conv-conv_offset_mask.bin";
const char *ida_1_up_1_deconv_bin = "dla34_cnet/layers/dla_up-ida_1-up_1.bin";
const char *ida_1_n_1_dcn_bin = "dla34_cnet/layers/dla_up-ida_1-node_1-conv.bin";
const char *ida_1_n_1_conv_bin = "dla34_cnet/layers/dla_up-ida_1-node_1-conv-conv_offset_mask.bin";
const char *ida_1_p_2_dcn_bin = "dla34_cnet/layers/dla_up-ida_1-proj_2-conv.bin";
const char *ida_1_p_2_conv_bin = "dla34_cnet/layers/dla_up-ida_1-proj_2-conv-conv_offset_mask.bin";
const char *ida_1_up_2_deconv_bin = "dla34_cnet/layers/dla_up-ida_1-up_2.bin";
const char *ida_1_n_2_dcn_bin = "dla34_cnet/layers/dla_up-ida_1-node_2-conv.bin";
const char *ida_1_n_2_conv_bin = "dla34_cnet/layers/dla_up-ida_1-node_2-conv-conv_offset_mask.bin";
const char *ida_2_p_1_dcn_bin = "dla34_cnet/layers/dla_up-ida_2-proj_1-conv.bin";
const char *ida_2_p_1_conv_bin = "dla34_cnet/layers/dla_up-ida_2-proj_1-conv-conv_offset_mask.bin";
const char *ida_2_up_1_deconv_bin = "dla34_cnet/layers/dla_up-ida_2-up_1.bin";
const char *ida_2_n_1_dcn_bin = "dla34_cnet/layers/dla_up-ida_2-node_1-conv.bin";
const char *ida_2_n_1_conv_bin = "dla34_cnet/layers/dla_up-ida_2-node_1-conv-conv_offset_mask.bin";
const char *ida_2_p_2_dcn_bin = "dla34_cnet/layers/dla_up-ida_2-proj_2-conv.bin";
const char *ida_2_p_2_conv_bin = "dla34_cnet/layers/dla_up-ida_2-proj_2-conv-conv_offset_mask.bin";
const char *ida_2_up_2_deconv_bin = "dla34_cnet/layers/dla_up-ida_2-up_2.bin";
const char *ida_2_n_2_dcn_bin = "dla34_cnet/layers/dla_up-ida_2-node_2-conv.bin";
const char *ida_2_n_2_conv_bin = "dla34_cnet/layers/dla_up-ida_2-node_2-conv-conv_offset_mask.bin";
const char *ida_2_p_3_dcn_bin = "dla34_cnet/layers/dla_up-ida_2-proj_3-conv.bin";
const char *ida_2_p_3_conv_bin = "dla34_cnet/layers/dla_up-ida_2-proj_3-conv-conv_offset_mask.bin";
const char *ida_2_up_3_deconv_bin = "dla34_cnet/layers/dla_up-ida_2-up_3.bin";
const char *ida_2_n_3_dcn_bin = "dla34_cnet/layers/dla_up-ida_2-node_3-conv.bin";
const char *ida_2_n_3_conv_bin = "dla34_cnet/layers/dla_up-ida_2-node_3-conv-conv_offset_mask.bin";
const char *ida_up_p_1_dcn_bin = "dla34_cnet/layers/ida_up-proj_1-conv.bin";
const char *ida_up_p_1_conv_bin = "dla34_cnet/layers/ida_up-proj_1-conv-conv_offset_mask.bin";
const char *ida_up_up_1_deconv_bin = "dla34_cnet/layers/ida_up-up_1.bin";
const char *ida_up_n_1_dcn_bin = "dla34_cnet/layers/ida_up-node_1-conv.bin";
const char *ida_up_n_1_conv_bin = "dla34_cnet/layers/ida_up-node_1-conv-conv_offset_mask.bin";
const char *ida_up_p_2_dcn_bin = "dla34_cnet/layers/ida_up-proj_2-conv.bin";
const char *ida_up_p_2_conv_bin = "dla34_cnet/layers/ida_up-proj_2-conv-conv_offset_mask.bin";
const char *ida_up_up_2_deconv_bin = "dla34_cnet/layers/ida_up-up_2.bin";
const char *ida_up_n_2_dcn_bin = "dla34_cnet/layers/ida_up-node_2-conv.bin";
const char *ida_up_n_2_conv_bin = "dla34_cnet/layers/ida_up-node_2-conv-conv_offset_mask.bin";
const char *hm_conv1_bin = "dla34_cnet/layers/hm-0.bin";
const char *hm_conv2_bin = "dla34_cnet/layers/hm-2.bin";
const char *wh_conv1_bin = "dla34_cnet/layers/wh-0.bin";
const char *wh_conv2_bin = "dla34_cnet/layers/wh-2.bin";
const char *reg_conv1_bin = "dla34_cnet/layers/reg-0.bin";
const char *reg_conv2_bin = "dla34_cnet/layers/reg-2.bin";
const char *output_bin[]={
"dla34_cnet/debug/hm.bin",
"dla34_cnet/debug/wh.bin",
"dla34_cnet/debug/reg.bin"};
int main()
{
downloadWeightsifDoNotExist(input_bin, "dla34_cnet", "https://cloud.hipert.unimore.it/s/KRZBbCQsKAtQwpZ/download");
// Network layout
tk::dnn::dataDim_t dim(1, 3, 512, 512, 1);
tk::dnn::Network net(dim);
tk::dnn::Layer *last1, *last2, *last3, *last4;
tk::dnn::Layer *base1, *base2, *base3, *base4, *base5, *base6, *ida1, *ida2_1, *ida2_2, *ida3_1, *ida3_2, *ida3_3, *idaup_1, *idaup_2;
tk::dnn::Conv2d conv1(&net, 16, 7, 7, 1, 1, 3, 3, conv1_bin, true);
tk::dnn::Activation relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d conv2(&net, 16, 3, 3, 1, 1, 1, 1, conv2_bin, true);
tk::dnn::Activation relu2(&net, CUDNN_ACTIVATION_RELU);
base1 = &relu2;
tk::dnn::Conv2d conv3(&net, 32, 3, 3, 2, 2, 1, 1, conv3_bin, true);
tk::dnn::Activation relu3(&net, CUDNN_ACTIVATION_RELU);
base2 = &relu3;
// level 2
// tree 1
tk::dnn::Conv2d s1_t1_conv1(&net, 64, 3, 3, 2, 2, 1, 1, s1_t1_conv1_bin, true);
tk::dnn::Activation s1_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s1_t1_conv2(&net, 64, 3, 3, 1, 1, 1, 1, s1_t1_conv2_bin, true);
last2 = &s1_t1_conv2;
// get the basicblock input and apply maxpool conv2d and relu
tk::dnn::Layer *route_s1_t1_layers[1] = { base2 };
tk::dnn::Route route_s1_t1(&net, route_s1_t1_layers, 1);
// downsample
tk::dnn::Pooling s1_t1_maxpool1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
// project
tk::dnn::Conv2d s1_t1_residual1_conv1(&net, 64, 1, 1, 1, 1, 0, 0, s1_t1_project, true);
tk::dnn::Shortcut s1_t1_s1(&net, last2);
tk::dnn::Activation s1_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s1_t1_relu;
// tree 2
tk::dnn::Conv2d s1_t2_conv1(&net, 64, 3, 3, 1, 1, 1, 1, s1_t2_conv1_bin, true);
tk::dnn::Activation s1_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s1_t2_conv2(&net, 64, 3, 3, 1, 1, 1, 1, s1_t2_conv2_bin, true);
tk::dnn::Shortcut s1_t2_s1(&net, last1);
tk::dnn::Activation s1_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s1_t2_relu;
// root
// join last1 and net in single input 128, 56, 56
tk::dnn::Layer *route_s1_root_layers[2] = { last2, last1 };
tk::dnn::Route route_s1_root(&net, route_s1_root_layers, 2);
tk::dnn::Conv2d s1_root_conv1(&net, 64, 1, 1, 1, 1, 0, 0, s1_root_conv1_bin, true);
tk::dnn::Activation s1_root_relu(&net, CUDNN_ACTIVATION_RELU);
base3 = &s1_root_relu;
// level 3
// tree 1
// tree 1
tk::dnn::Conv2d s2_t1_t1_conv1(&net, 128, 3, 3, 2, 2, 1, 1, s2_t1_t1_conv1_bin, true);
tk::dnn::Activation s2_t1_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s2_t1_t1_conv2(&net, 128, 3, 3, 1, 1, 1, 1, s2_t1_t1_conv2_bin, true);
last2 = &s2_t1_t1_conv2;
// get the basicblock input and apply maxpool conv2d and relu
tk::dnn::Layer *route_s2_t1_t1_layers[1] = { base3 };
tk::dnn::Route route_s2_t1_t1(&net, route_s2_t1_t1_layers, 1);
// downsample
tk::dnn::Pooling s2_t1_t1_maxpool1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
last4 = &s2_t1_t1_maxpool1;
// project
tk::dnn::Conv2d s2_t1_t1_residual1_conv1(&net, 128, 1, 1, 1, 1, 0, 0, s2_t1_t1_project, true);
tk::dnn::Shortcut s2_t1_t1_s1(&net, last2);
tk::dnn::Activation s2_t1_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s2_t1_t1_relu;
// tree 2
tk::dnn::Conv2d s2_t1_t2_conv1(&net, 128, 3, 3, 1, 1, 1, 1, s2_t1_t2_conv1_bin, true);
tk::dnn::Activation s2_t1_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s2_t1_t2_conv2(&net, 128, 3, 3, 1, 1, 1, 1, s2_t1_t2_conv2_bin, true);
tk::dnn::Shortcut s2_t1_t2_s1(&net, last1);
tk::dnn::Activation s2_t1_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s2_t1_t2_relu;
// root
// join last1 and net in single input 128, 56, 56
tk::dnn::Layer *route_s2_t1_root_layers[2] = { last2, last1 };
tk::dnn::Route route_s2_t1_root(&net, route_s2_t1_root_layers, 2);
tk::dnn::Conv2d s2_t1_root_conv1(&net, 128, 1, 1, 1, 1, 0, 0, s2_t1_root_conv1_bin, true);
tk::dnn::Activation s2_t1_root_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s2_t1_root_relu;
last3 = &s2_t1_root_relu;
// tree 2
// tree 1
tk::dnn::Conv2d s2_t2_t1_conv1(&net, 128, 3, 3, 1, 1, 1, 1, s2_t2_t1_conv1_bin, true);
tk::dnn::Activation s2_t2_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s2_t2_t1_conv2(&net, 128, 3, 3, 1, 1, 1, 1, s2_t2_t1_conv2_bin, true);
tk::dnn::Shortcut s2_t2_t1_s1(&net, last1);
tk::dnn::Activation s2_t2_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s2_t2_t1_relu;
// tree 2
tk::dnn::Conv2d s2_t2_t2_conv1(&net, 128, 3, 3, 1, 1, 1, 1, s2_t2_t2_conv1_bin, true);
tk::dnn::Activation s2_t2_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s2_t2_t2_conv2(&net, 128, 3, 3, 1, 1, 1, 1, s2_t2_t2_conv2_bin, true);
tk::dnn::Shortcut s2_t2_t2_s1(&net, last1);
tk::dnn::Activation s2_t2_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s2_t2_t2_relu;
// root
// join last1 and net in single input 128, 56, 56
tk::dnn::Layer *route_s2_t2_root_layers[4] = { last2, last1, last4, last3};
tk::dnn::Route route_s2_t2_root(&net, route_s2_t2_root_layers, 4);
tk::dnn::Conv2d s2_t2_root_conv1(&net, 128, 1, 1, 1, 1, 0, 0, s2_t2_root_conv1_bin, true);
tk::dnn::Activation s2_t2_root_relu(&net, CUDNN_ACTIVATION_RELU);
base4 = &s2_t2_root_relu;
// level 4
// tree 1
// tree 1
tk::dnn::Conv2d s3_t1_t1_conv1(&net, 256, 3, 3, 2, 2, 1, 1, s3_t1_t1_conv1_bin, true);
tk::dnn::Activation s3_t1_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s3_t1_t1_conv2(&net, 256, 3, 3, 1, 1, 1, 1, s3_t1_t1_conv2_bin, true);
last2 = &s3_t1_t1_conv2;
// get the basicblock input and apply maxpool conv2d and relu
tk::dnn::Layer *route_s3_t1_t1_layers[1] = { base4 };
tk::dnn::Route route_s3_t1_t1(&net, route_s3_t1_t1_layers, 1);
// downsample
tk::dnn::Pooling s3_t1_t1_maxpool1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
last4 = &s3_t1_t1_maxpool1;
// project
tk::dnn::Conv2d s3_t1_t1_residual1_conv1(&net, 256, 1, 1, 1, 1, 0, 0, s3_t1_t1_project, true);
tk::dnn::Shortcut s3_t1_t1_s1(&net, last2);
tk::dnn::Activation s3_t1_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s3_t1_t1_relu;
// tree 2
tk::dnn::Conv2d s3_t1_t2_conv1(&net, 256, 3, 3, 1, 1, 1, 1, s3_t1_t2_conv1_bin, true);
tk::dnn::Activation s3_t1_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s3_t1_t2_conv2(&net, 256, 3, 3, 1, 1, 1, 1, s3_t1_t2_conv2_bin, true);
tk::dnn::Shortcut s3_t1_t2_s1(&net, last1);
tk::dnn::Activation s3_t1_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s3_t1_t2_relu;
// root
// join last1 and net in single input 256, 56, 56
tk::dnn::Layer *route_s3_t1_root_layers[2] = { last2, last1 };
tk::dnn::Route route_s3_t1_root(&net, route_s3_t1_root_layers, 2);
tk::dnn::Conv2d s3_t1_root_conv1(&net, 256, 1, 1, 1, 1, 0, 0, s3_t1_root_conv1_bin, true);
tk::dnn::Activation s3_t1_root_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s3_t1_root_relu;
last3 = &s3_t1_root_relu;
// tree 2
// tree 1
tk::dnn::Conv2d s3_t2_t1_conv1(&net, 256, 3, 3, 1, 1, 1, 1, s3_t2_t1_conv1_bin, true);
tk::dnn::Activation s3_t2_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s3_t2_t1_conv2(&net, 256, 3, 3, 1, 1, 1, 1, s3_t2_t1_conv2_bin, true);
tk::dnn::Shortcut s3_t2_t1_s1(&net, last1);
tk::dnn::Activation s3_t2_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s3_t2_t1_relu;
// tree 2
tk::dnn::Conv2d s3_t2_t2_conv1(&net, 256, 3, 3, 1, 1, 1, 1, s3_t2_t2_conv1_bin, true);
tk::dnn::Activation s3_t2_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s3_t2_t2_conv2(&net, 256, 3, 3, 1, 1, 1, 1, s3_t2_t2_conv2_bin, true);
tk::dnn::Shortcut s3_t2_t2_s1(&net, last1);
tk::dnn::Activation s3_t2_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s3_t2_t2_relu;
// root
// join last1 and net in single input 256, 56, 56
tk::dnn::Layer *route_s3_t2_root_layers[4] = { last2, last1, last4, last3};
tk::dnn::Route route_s3_t2_root(&net, route_s3_t2_root_layers, 4);
tk::dnn::Conv2d s3_t2_root_conv1(&net, 256, 1, 1, 1, 1, 0, 0, s3_t2_root_conv1_bin, true);
tk::dnn::Activation s3_t2_root_relu(&net, CUDNN_ACTIVATION_RELU);
base5 = &s3_t2_root_relu;
// level 5
// tree 1
tk::dnn::Conv2d s4_t1_conv1(&net, 512, 3, 3, 2, 2, 1, 1, s4_t1_conv1_bin, true);
tk::dnn::Activation s4_t1_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s4_t1_conv2(&net, 512, 3, 3, 1, 1, 1, 1, s4_t1_conv2_bin, true);
last2 = &s4_t1_conv2;
// get the basicblock input and apply maxpool conv2d and relu
tk::dnn::Layer *route_s4_t1_layers[1] = { base5 };
tk::dnn::Route route_s4_t1(&net, route_s4_t1_layers, 1);
// downsample
tk::dnn::Pooling s4_t1_maxpool1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
last4 = &s4_t1_maxpool1;
// project
tk::dnn::Conv2d s4_t1_residual1_conv1(&net, 512, 1, 1, 1, 1, 0, 0, s4_t1_project, true);
tk::dnn::Shortcut s4_t1_s1(&net, last2);
tk::dnn::Activation s4_t1_relu(&net, CUDNN_ACTIVATION_RELU);
last1 = &s4_t1_relu;
// tree 2
tk::dnn::Conv2d s4_t2_conv1(&net, 512, 3, 3, 1, 1, 1, 1, s4_t2_conv1_bin, true);
tk::dnn::Activation s4_t2_relu1(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d s4_t2_conv2(&net, 512, 3, 3, 1, 1, 1, 1, s4_t2_conv2_bin, true);
tk::dnn::Shortcut s4_t2_s1(&net, last1);
tk::dnn::Activation s4_t2_relu(&net, CUDNN_ACTIVATION_RELU);
last2 = &s4_t2_relu;
// root
// join last1 and net in single input 128, 56, 56
tk::dnn::Layer *route_s4_root_layers[3] = { last2, last1, last4 };
tk::dnn::Route route_s4_root(&net, route_s4_root_layers, 3);
tk::dnn::Conv2d s4_root_conv1(&net, 512, 1, 1, 1, 1, 0, 0, s4_root_conv1_bin, true);
tk::dnn::Activation s4_root_relu(&net, CUDNN_ACTIVATION_RELU);
base6 = &s4_root_relu;
//final
// tk::dnn::Pooling avgpool(&net, 7, 7, 7, 7, 0, 0, tk::dnn::POOLING_AVERAGE);
// tk::dnn::Dense fc(&net, 1000, fc_bin);
//ida 0
tk::dnn::DeformConv2d ida_0_p_1_dcn(&net, 256, 1, 3, 3, 1, 1, 1, 1, ida_0_p_1_dcn_bin, ida_0_p_1_conv_bin, true);
tk::dnn::Activation ida_0_p_1_relu(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d ida_0_up_1_deconv(&net, 256, 4, 4, 2, 2, 1, 1, ida_0_up_1_deconv_bin, false, 256);
tk::dnn::Shortcut ida_0_shortcut(&net, base5);
tk::dnn::DeformConv2d ida_0_n_1_dcn(&net, 256, 1, 3, 3, 1, 1, 1, 1, ida_0_n_1_dcn_bin, ida_0_n_1_conv_bin, true);
tk::dnn::Activation ida_0_n_1_relu(&net, CUDNN_ACTIVATION_RELU);
ida1 = &ida_0_n_1_relu;
//ida1-1
tk::dnn::Layer *route_ida1_layers_1[1] = { base5 };
tk::dnn::Route route_ida1_1(&net, route_ida1_layers_1, 1);
tk::dnn::DeformConv2d ida_1_p_1_dcn(&net, 128, 1, 3, 3, 1, 1, 1, 1, ida_1_p_1_dcn_bin, ida_1_p_1_conv_bin, true);
tk::dnn::Activation ida_1_p_1_relu(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d ida_1_up_1_deconv(&net, 128, 4, 4, 2, 2, 1, 1, ida_1_up_1_deconv_bin, false, 128);
tk::dnn::Shortcut ida_1_shortcut1(&net, base4);
tk::dnn::DeformConv2d ida_1_n_1_dcn(&net, 128, 1, 3, 3, 1, 1, 1, 1, ida_1_n_1_dcn_bin, ida_1_n_1_conv_bin, true);
tk::dnn::Activation ida_1_n_1_relu(&net, CUDNN_ACTIVATION_RELU);
ida2_1 = &ida_1_n_1_relu;
//ida1-2
tk::dnn::Layer *route_ida1_layers_2[1] = { ida1 };
tk::dnn::Route route_ida1_2(&net, route_ida1_layers_2, 1);
tk::dnn::DeformConv2d ida_1_p_2_dcn(&net, 128, 1, 3, 3, 1, 1, 1, 1, ida_1_p_2_dcn_bin, ida_1_p_2_conv_bin, true);
tk::dnn::Activation ida_1_p_2_relu(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d ida_1_up_2_deconv(&net, 128, 4, 4, 2, 2, 1, 1, ida_1_up_2_deconv_bin, false, 128);
tk::dnn::Shortcut ida_1_shortcut2(&net, ida2_1);
tk::dnn::DeformConv2d ida_1_n_2_dcn(&net, 128, 1, 3, 3, 1, 1, 1, 1, ida_1_n_2_dcn_bin, ida_1_n_2_conv_bin, true);
tk::dnn::Activation ida_1_n_2_relu(&net, CUDNN_ACTIVATION_RELU);
ida2_2 = &ida_1_n_2_relu;
//ida2-1
tk::dnn::Layer *route_ida2_layers_1[1] = { base4 };
tk::dnn::Route route_ida2_1(&net, route_ida2_layers_1, 1);
tk::dnn::DeformConv2d ida_2_p_1_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_2_p_1_dcn_bin, ida_2_p_1_conv_bin, true);
tk::dnn::Activation ida_2_p_1_relu(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d ida_2_up_1_deconv(&net, 64, 4, 4, 2, 2, 1, 1, ida_2_up_1_deconv_bin, false, 64);
tk::dnn::Shortcut ida_2_shortcut1(&net, base3);
tk::dnn::DeformConv2d ida_2_n_1_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_2_n_1_dcn_bin, ida_2_n_1_conv_bin, true);
tk::dnn::Activation ida_2_n_1_relu(&net, CUDNN_ACTIVATION_RELU);
ida3_1 = &ida_2_n_1_relu;
//ida2-2
tk::dnn::Layer *route_ida2_layers_2[1] = { ida2_1 };
tk::dnn::Route route_ida2_2(&net, route_ida2_layers_2, 1);
tk::dnn::DeformConv2d ida_2_p_2_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_2_p_2_dcn_bin, ida_2_p_2_conv_bin, true);
tk::dnn::Activation ida_2_p_2_relu(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d ida_2_up_2_deconv(&net, 64, 4, 4, 2, 2, 1, 1, ida_2_up_2_deconv_bin, false, 64);
tk::dnn::Shortcut ida_2_shortcut2(&net, ida3_1);
tk::dnn::DeformConv2d ida_2_n_2_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_2_n_2_dcn_bin, ida_2_n_2_conv_bin, true);
tk::dnn::Activation ida_2_n_2_relu(&net, CUDNN_ACTIVATION_RELU);
ida3_2 = &ida_2_n_2_relu;
//ida2-3
tk::dnn::Layer *route_ida2_layers_3[1] = { ida2_2 };
tk::dnn::Route route_ida2_3(&net, route_ida2_layers_3, 1);
tk::dnn::DeformConv2d ida_2_p_3_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_2_p_3_dcn_bin, ida_2_p_3_conv_bin, true);
tk::dnn::Activation ida_2_p_3_relu(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d ida_2_up_3_deconv(&net, 64, 4, 4, 2, 2, 1, 1, ida_2_up_3_deconv_bin, false, 64);
tk::dnn::Shortcut ida_2_shortcut3(&net, ida3_2);
tk::dnn::DeformConv2d ida_2_n_3_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_2_n_3_dcn_bin, ida_2_n_3_conv_bin, true);
tk::dnn::Activation ida_2_n_3_relu(&net, CUDNN_ACTIVATION_RELU);
ida3_3 = &ida_2_n_3_relu;
//idaup-1
tk::dnn::Layer *route_idaup_layers_1[1] = { ida2_2 };
tk::dnn::Route route_idaup_1(&net, route_idaup_layers_1, 1);
tk::dnn::DeformConv2d idaup_p_1_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_up_p_1_dcn_bin, ida_up_p_1_conv_bin, true);
tk::dnn::Activation idaup_p_1_relu(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d idaup_up_1_deconv(&net, 64, 4, 4, 2, 2, 1, 1, ida_up_up_1_deconv_bin, false, 64);
tk::dnn::Shortcut idaup_shortcut1(&net, ida3_3);
tk::dnn::DeformConv2d idaup_n_1_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_up_n_1_dcn_bin, ida_up_n_1_conv_bin, true);
tk::dnn::Activation idaup_n_1_relu(&net, CUDNN_ACTIVATION_RELU);
idaup_1 = &idaup_n_1_relu;
//idaup-2
tk::dnn::Layer *route_idaup_layers_2[1] = { ida1 };
tk::dnn::Route route_idaup_2(&net, route_idaup_layers_2, 1);
tk::dnn::DeformConv2d idaup_p_2_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_up_p_2_dcn_bin, ida_up_p_2_conv_bin, true);
tk::dnn::Activation idaup_p_2_relu(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d idaup_up_2_deconv(&net, 64, 8, 8, 4, 4, 2, 2, ida_up_up_2_deconv_bin, false, 64);
tk::dnn::Shortcut idaup_shortcut2(&net, idaup_1);
tk::dnn::DeformConv2d idaup_n_2_dcn(&net, 64, 1, 3, 3, 1, 1, 1, 1, ida_up_n_2_dcn_bin, ida_up_n_2_conv_bin, true);
tk::dnn::Activation idaup_n_2_relu(&net, CUDNN_ACTIVATION_RELU);
idaup_2 = &idaup_n_2_relu;
tk::dnn::Layer *route_1_0_layers[1] = { idaup_2 };
// hm
tk::dnn::Conv2d *hm_conv1 = new tk::dnn::Conv2d(&net, 256, 3, 3, 1, 1, 1, 1, hm_conv1_bin, false);
tk::dnn::Activation *hm_relu1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *hm = new tk::dnn::Conv2d(&net, 80, 1, 1, 1, 1, 0, 0, hm_conv2_bin, false);
hm->setFinal();
int kernel = 3;
int pad = (kernel - 1)/2;
tk::dnn::Activation *hm_sig = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_SIGMOID);
tk::dnn::Pooling *hmax = new tk::dnn::Pooling(&net, kernel, kernel, 1, 1, pad, pad, tk::dnn::POOLING_MAX);
hmax->setFinal();
// // wh
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *wh_conv1 = new tk::dnn::Conv2d(&net, 256, 3, 3, 1, 1, 1, 1, wh_conv1_bin, false);
tk::dnn::Activation *wh_relu1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *wh = new tk::dnn::Conv2d(&net, 2, 1, 1, 1, 1, 0, 0, wh_conv2_bin, false);
wh->setFinal();
// // reg
tk::dnn::Route *route_2_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *reg_conv1 = new tk::dnn::Conv2d(&net, 256, 3, 3, 1, 1, 1, 1, reg_conv1_bin, false);
tk::dnn::Activation *reg_relu1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *reg = new tk::dnn::Conv2d(&net, 2, 1, 1, 1, 1, 0, 0, reg_conv2_bin, false);
reg->setFinal();
// 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("dla34_cnet"));
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30);
{
dim1.print();
TKDNN_TSTART
net.infer(dim1, data);
TKDNN_TSTOP
dim1.print();
}
tk::dnn::dataDim_t dim2 = dim;
printCenteredTitle(" TENSORRT inference ", '=', 30);
{
dim2.print();
TKDNN_TSTART
netRT.infer(dim2, data);
TKDNN_TSTOP
dim2.print();
}
tk::dnn::Layer *outs[3] = { hm, wh, reg };
int out_count = 1;
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
for(int i=0; i<3; i++) {
printCenteredTitle((std::string(" RESNET CHECK RESULTS ") + std::to_string(i) + " ").c_str(), '=', 30);
outs[i]->output_dim.print();
dnnType *out, *out_h;
int odim = outs[i]->output_dim.tot();
readBinaryFile(output_bin[i], odim, &out_h, &out);
dnnType *cudnn_out, *rt_out;
cudnn_out = outs[i]->dstData;
rt_out = (dnnType *)netRT.buffersRT[i+out_count];
// there is the maxpool. It isn't an output but it is necessary for the process section
if(i==0)
out_count ++;
std::cout<<"CUDNN vs correct";
ret_cudnn |= checkResult(odim, cudnn_out, out) == 0 ? 0: ERROR_CUDNN;
std::cout<<"TRT vs correct";
ret_tensorrt |= checkResult(odim, rt_out, out) == 0 ? 0 : ERROR_TENSORRT;
std::cout<<"CUDNN vs TRT ";
ret_cudnn_tensorrt |= checkResult(odim, cudnn_out, rt_out) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
}
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
}
@@ -1,413 +0,0 @@
#include <iostream>
#include "kernels.h"
#include "Yolo3Detection.h"
#include "tkdnn.h"
#include <vector>
#include <numeric> // std::iota
#include <algorithm> // std::sort
// #include "utils.h"
const char *input_bin = "resnet101_cnet/debug/input.bin";
const char *conv1_bin = "resnet101_cnet/layers/conv1.bin";
//layer1
const char *layer1_bin[]={
"resnet101_cnet/layers/layer1-0-conv1.bin",
"resnet101_cnet/layers/layer1-0-conv2.bin",
"resnet101_cnet/layers/layer1-0-conv3.bin",
"resnet101_cnet/layers/layer1-0-downsample-0.bin",
"resnet101_cnet/layers/layer1-1-conv1.bin",
"resnet101_cnet/layers/layer1-1-conv2.bin",
"resnet101_cnet/layers/layer1-1-conv3.bin",
"resnet101_cnet/layers/layer1-2-conv1.bin",
"resnet101_cnet/layers/layer1-2-conv2.bin",
"resnet101_cnet/layers/layer1-2-conv3.bin"};
//layer2
const char *layer2_bin[]={
"resnet101_cnet/layers/layer2-0-conv1.bin",
"resnet101_cnet/layers/layer2-0-conv2.bin",
"resnet101_cnet/layers/layer2-0-conv3.bin",
"resnet101_cnet/layers/layer2-0-downsample-0.bin",
"resnet101_cnet/layers/layer2-1-conv1.bin",
"resnet101_cnet/layers/layer2-1-conv2.bin",
"resnet101_cnet/layers/layer2-1-conv3.bin",
"resnet101_cnet/layers/layer2-2-conv1.bin",
"resnet101_cnet/layers/layer2-2-conv2.bin",
"resnet101_cnet/layers/layer2-2-conv3.bin",
"resnet101_cnet/layers/layer2-3-conv1.bin",
"resnet101_cnet/layers/layer2-3-conv2.bin",
"resnet101_cnet/layers/layer2-3-conv3.bin"
};
//layer3
const char *layer3_bin[]={
"resnet101_cnet/layers/layer3-0-conv1.bin",
"resnet101_cnet/layers/layer3-0-conv2.bin",
"resnet101_cnet/layers/layer3-0-conv3.bin",
"resnet101_cnet/layers/layer3-0-downsample-0.bin",
"resnet101_cnet/layers/layer3-1-conv1.bin",
"resnet101_cnet/layers/layer3-1-conv2.bin",
"resnet101_cnet/layers/layer3-1-conv3.bin",
"resnet101_cnet/layers/layer3-2-conv1.bin",
"resnet101_cnet/layers/layer3-2-conv2.bin",
"resnet101_cnet/layers/layer3-2-conv3.bin",
"resnet101_cnet/layers/layer3-3-conv1.bin",
"resnet101_cnet/layers/layer3-3-conv2.bin",
"resnet101_cnet/layers/layer3-3-conv3.bin",
"resnet101_cnet/layers/layer3-4-conv1.bin",
"resnet101_cnet/layers/layer3-4-conv2.bin",
"resnet101_cnet/layers/layer3-4-conv3.bin",
"resnet101_cnet/layers/layer3-5-conv1.bin",
"resnet101_cnet/layers/layer3-5-conv2.bin",
"resnet101_cnet/layers/layer3-5-conv3.bin",
"resnet101_cnet/layers/layer3-6-conv1.bin",
"resnet101_cnet/layers/layer3-6-conv2.bin",
"resnet101_cnet/layers/layer3-6-conv3.bin",
"resnet101_cnet/layers/layer3-7-conv1.bin",
"resnet101_cnet/layers/layer3-7-conv2.bin",
"resnet101_cnet/layers/layer3-7-conv3.bin",
"resnet101_cnet/layers/layer3-8-conv1.bin",
"resnet101_cnet/layers/layer3-8-conv2.bin",
"resnet101_cnet/layers/layer3-8-conv3.bin",
"resnet101_cnet/layers/layer3-9-conv1.bin",
"resnet101_cnet/layers/layer3-9-conv2.bin",
"resnet101_cnet/layers/layer3-9-conv3.bin",
"resnet101_cnet/layers/layer3-10-conv1.bin",
"resnet101_cnet/layers/layer3-10-conv2.bin",
"resnet101_cnet/layers/layer3-10-conv3.bin",
"resnet101_cnet/layers/layer3-11-conv1.bin",
"resnet101_cnet/layers/layer3-11-conv2.bin",
"resnet101_cnet/layers/layer3-11-conv3.bin",
"resnet101_cnet/layers/layer3-12-conv1.bin",
"resnet101_cnet/layers/layer3-12-conv2.bin",
"resnet101_cnet/layers/layer3-12-conv3.bin",
"resnet101_cnet/layers/layer3-13-conv1.bin",
"resnet101_cnet/layers/layer3-13-conv2.bin",
"resnet101_cnet/layers/layer3-13-conv3.bin",
"resnet101_cnet/layers/layer3-14-conv1.bin",
"resnet101_cnet/layers/layer3-14-conv2.bin",
"resnet101_cnet/layers/layer3-14-conv3.bin",
"resnet101_cnet/layers/layer3-15-conv1.bin",
"resnet101_cnet/layers/layer3-15-conv2.bin",
"resnet101_cnet/layers/layer3-15-conv3.bin",
"resnet101_cnet/layers/layer3-16-conv1.bin",
"resnet101_cnet/layers/layer3-16-conv2.bin",
"resnet101_cnet/layers/layer3-16-conv3.bin",
"resnet101_cnet/layers/layer3-17-conv1.bin",
"resnet101_cnet/layers/layer3-17-conv2.bin",
"resnet101_cnet/layers/layer3-17-conv3.bin",
"resnet101_cnet/layers/layer3-18-conv1.bin",
"resnet101_cnet/layers/layer3-18-conv2.bin",
"resnet101_cnet/layers/layer3-18-conv3.bin",
"resnet101_cnet/layers/layer3-19-conv1.bin",
"resnet101_cnet/layers/layer3-19-conv2.bin",
"resnet101_cnet/layers/layer3-19-conv3.bin",
"resnet101_cnet/layers/layer3-20-conv1.bin",
"resnet101_cnet/layers/layer3-20-conv2.bin",
"resnet101_cnet/layers/layer3-20-conv3.bin",
"resnet101_cnet/layers/layer3-21-conv1.bin",
"resnet101_cnet/layers/layer3-21-conv2.bin",
"resnet101_cnet/layers/layer3-21-conv3.bin",
"resnet101_cnet/layers/layer3-22-conv1.bin",
"resnet101_cnet/layers/layer3-22-conv2.bin",
"resnet101_cnet/layers/layer3-22-conv3.bin"};
//layer4
const char *layer4_bin[]={
"resnet101_cnet/layers/layer4-0-conv1.bin",
"resnet101_cnet/layers/layer4-0-conv2.bin",
"resnet101_cnet/layers/layer4-0-conv3.bin",
"resnet101_cnet/layers/layer4-0-downsample-0.bin",
"resnet101_cnet/layers/layer4-1-conv1.bin",
"resnet101_cnet/layers/layer4-1-conv2.bin",
"resnet101_cnet/layers/layer4-1-conv3.bin",
"resnet101_cnet/layers/layer4-2-conv1.bin",
"resnet101_cnet/layers/layer4-2-conv2.bin",
"resnet101_cnet/layers/layer4-2-conv3.bin"};
const char *d_conv1_bin = "resnet101_cnet/layers/deconv_layers-0-conv_offset_mask.bin";
const char *deform1_bin = "resnet101_cnet/layers/deconv_layers-0.bin";
const char *deconv1_bin = "resnet101_cnet/layers/deconv_layers-3.bin";
const char *d_conv2_bin = "resnet101_cnet/layers/deconv_layers-6-conv_offset_mask.bin";
const char *deform2_bin = "resnet101_cnet/layers/deconv_layers-6.bin";
const char *deconv2_bin = "resnet101_cnet/layers/deconv_layers-9.bin";
const char *d_conv3_bin = "resnet101_cnet/layers/deconv_layers-12-conv_offset_mask.bin";
const char *deform3_bin = "resnet101_cnet/layers/deconv_layers-12.bin";
const char *deconv3_bin = "resnet101_cnet/layers/deconv_layers-15.bin";
const char *hm_conv1_bin = "resnet101_cnet/layers/hm-0.bin";
const char *hm_conv2_bin = "resnet101_cnet/layers/hm-2.bin";
const char *wh_conv1_bin = "resnet101_cnet/layers/wh-0.bin";
const char *wh_conv2_bin = "resnet101_cnet/layers/wh-2.bin";
const char *reg_conv1_bin = "resnet101_cnet/layers/reg-0.bin";
const char *reg_conv2_bin = "resnet101_cnet/layers/reg-2.bin";
//final
const char *fc_bin = "resnet101_cnet/layers/fc.bin";
const char *output_bin[]={
"resnet101_cnet/debug/hm.bin",
"resnet101_cnet/debug/wh.bin",
"resnet101_cnet/debug/reg.bin"};
int main()
{
downloadWeightsifDoNotExist(input_bin, "resnet101_cnet", "https://cloud.hipert.unimore.it/s/5BTjHMWBcJk8g3i/download");
// Network layout
tk::dnn::dataDim_t dim(1, 3, 512, 512, 1);
tk::dnn::Network net(dim);
tk::dnn::Conv2d conv1(&net, 64, 7, 7, 2, 2, 3, 3, conv1_bin, true);
tk::dnn::Activation relu3(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Pooling maxpool4(&net, 3, 3, 2, 2, 1, 1, tk::dnn::POOLING_MAX);
//layer 1
int id_layer1_bin = 0;
tk::dnn::Layer *last = &maxpool4;
for(int i=0; i<3;i++)
{
tk::dnn::Conv2d *layer1_0_conv1 = new tk::dnn::Conv2d(&net, 64, 1, 1, 1, 1, 0, 0, layer1_bin[id_layer1_bin++], true);
tk::dnn::Activation *relu1_0_1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv2 = new tk::dnn::Conv2d(&net, 64, 3, 3, 1, 1, 1, 1, layer1_bin[id_layer1_bin++], true);
tk::dnn::Activation *relu1_0_2 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv3 = new tk::dnn::Conv2d(&net, 256, 1, 1, 1, 1, 0, 0, layer1_bin[id_layer1_bin++], true);
if(i==0) {
tk::dnn::Layer *route_1_0_layers[1] = { last };
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *layer1_0_downsample_0 = new tk::dnn::Conv2d(&net, 256, 1, 1, 1, 1, 0, 0, layer1_bin[id_layer1_bin++], true);
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, layer1_0_conv3);
} else {
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, last);
}
tk::dnn::Activation *layer1_0_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
last = layer1_0_relu;
}
// layer 2
int id_layer2_bin = 0;
for(int i=0; i<4;i++)
{
tk::dnn::Conv2d *layer1_0_conv1 = new tk::dnn::Conv2d(&net, 128, 1, 1, 1, 1, 0, 0, layer2_bin[id_layer2_bin++], true);
tk::dnn::Activation *relu1_0_1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv2;
if(i==0)
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 128, 3, 3, 2, 2, 1, 1, layer2_bin[id_layer2_bin++], true);
else
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 128, 3, 3, 1, 1, 1, 1, layer2_bin[id_layer2_bin++], true);
tk::dnn::Activation *relu1_0_2 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv3 = new tk::dnn::Conv2d(&net, 512, 1, 1, 1, 1, 0, 0, layer2_bin[id_layer2_bin++], true);
if(i==0)
{
tk::dnn::Layer *route_1_0_layers[1] = { last };
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *layer1_0_downsample_0 = new tk::dnn::Conv2d(&net, 512, 1, 1, 2, 2, 0, 0, layer2_bin[id_layer2_bin++], true);
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, layer1_0_conv3);
}
else
{
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, last);
}
tk::dnn::Activation *layer1_0_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
last = layer1_0_relu;
}
// layer 3
int id_layer3_bin = 0;
for(int i=0; i<23;i++)
{
tk::dnn::Conv2d *layer1_0_conv1 = new tk::dnn::Conv2d(&net, 256, 1, 1, 1, 1, 0, 0, layer3_bin[id_layer3_bin++], true);
tk::dnn::Activation *relu1_0_1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv2;
if(i==0)
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 256, 3, 3, 2, 2, 1, 1, layer3_bin[id_layer3_bin++], true);
else
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 256, 3, 3, 1, 1, 1, 1, layer3_bin[id_layer3_bin++], true);
tk::dnn::Activation *relu1_0_2 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv3 = new tk::dnn::Conv2d(&net, 1024, 1, 1, 1, 1, 0, 0, layer3_bin[id_layer3_bin++], true);
if(i==0)
{
tk::dnn::Layer *route_1_0_layers[1] = { last };
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *layer1_0_downsample_0 = new tk::dnn::Conv2d(&net, 1024, 1, 1, 2, 2, 0, 0, layer3_bin[id_layer3_bin++], true);
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, layer1_0_conv3);
}
else
{
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, last);
}
tk::dnn::Activation *layer1_0_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
last = layer1_0_relu;
}
// layer 4
int id_layer4_bin = 0;
for(int i=0; i<3;i++)
{
tk::dnn::Conv2d *layer1_0_conv1 = new tk::dnn::Conv2d(&net, 512, 1, 1, 1, 1, 0, 0, layer4_bin[id_layer4_bin++], true);
tk::dnn::Activation *relu1_0_1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv2;
if(i==0)
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 512, 3, 3, 2, 2, 1, 1, layer4_bin[id_layer4_bin++], true);
else
layer1_0_conv2 = new tk::dnn::Conv2d(&net, 512, 3, 3, 1, 1, 1, 1, layer4_bin[id_layer4_bin++], true);
tk::dnn::Activation *relu1_0_2 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *layer1_0_conv3 = new tk::dnn::Conv2d(&net, 2048, 1, 1, 1, 1, 0, 0, layer4_bin[id_layer4_bin++], true);
if(i==0)
{
tk::dnn::Layer *route_1_0_layers[1] = { last };
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *layer1_0_downsample_0 = new tk::dnn::Conv2d(&net, 2048, 1, 1, 2, 2, 0, 0, layer4_bin[id_layer4_bin++], true);
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, layer1_0_conv3);
}
else
{
tk::dnn::Shortcut *s1_0 = new tk::dnn::Shortcut(&net, last);
}
tk::dnn::Activation *layer1_0_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
last = layer1_0_relu;
}
tk::dnn::DeformConv2d *layer0_deform1 = new tk::dnn::DeformConv2d(&net, 256, 1, 3, 3, 1, 1, 1, 1, deform1_bin, d_conv1_bin, true);
tk::dnn::Activation *layer0_deform1_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d *layer0_deconv1 = new tk::dnn::DeConv2d(&net, 256, 4, 4, 2, 2, 1, 1, deconv1_bin, true);
tk::dnn::Activation *layer0_deconv1_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeformConv2d *layer1_deform1 = new tk::dnn::DeformConv2d(&net, 128, 1, 3, 3, 1, 1, 1, 1, deform2_bin, d_conv2_bin, true);
tk::dnn::Activation *layer1_deform1_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d *layer1_deconv1 = new tk::dnn::DeConv2d(&net, 128, 4, 4, 2, 2, 1, 1, deconv2_bin, true);
tk::dnn::Activation *layer1_deconv1_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeformConv2d *layer2_deform1 = new tk::dnn::DeformConv2d(&net, 64, 1, 3, 3, 1, 1, 1, 1, deform3_bin, d_conv3_bin, true);
tk::dnn::Activation *layer2_deform1_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::DeConv2d *layer2_deconv1 = new tk::dnn::DeConv2d(&net, 64, 4, 4, 2, 2, 1, 1, deconv3_bin, true);
tk::dnn::Activation *layer2_deconv1_relu = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Layer *route_1_0_layers[1] = { layer2_deconv1_relu };
tk::dnn::Conv2d *hm_conv1 = new tk::dnn::Conv2d(&net, 64, 3, 3, 1, 1, 1, 1, hm_conv1_bin, false);
tk::dnn::Activation *hm_relu1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *hm = new tk::dnn::Conv2d(&net, 80, 1, 1, 1, 1, 0, 0, hm_conv2_bin, false);
hm->setFinal();
int kernel = 3;
int pad = (kernel - 1)/2;
tk::dnn::Activation *hm_sig = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_SIGMOID);
tk::dnn::Pooling *hmax = new tk::dnn::Pooling(&net, kernel, kernel, 1, 1, pad, pad, tk::dnn::POOLING_MAX);
hmax->setFinal();
tk::dnn::Route *route_1_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *wh_conv1 = new tk::dnn::Conv2d(&net, 64, 3, 3, 1, 1, 1, 1, wh_conv1_bin, false);
tk::dnn::Activation *wh_relu1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *wh = new tk::dnn::Conv2d(&net, 2, 1, 1, 1, 1, 0, 0, wh_conv2_bin, false);
wh->setFinal();
tk::dnn::Route *route_2_0 = new tk::dnn::Route(&net, route_1_0_layers, 1);
tk::dnn::Conv2d *reg_conv1 = new tk::dnn::Conv2d(&net, 64, 3, 3, 1, 1, 1, 1, reg_conv1_bin, false);
tk::dnn::Activation *reg_relu1 = new tk::dnn::Activation(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Conv2d *reg = new tk::dnn::Conv2d(&net, 2, 1, 1, 1, 1, 0, 0, reg_conv2_bin, false);
reg->setFinal();
// 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("resnet101_cnet"));
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30);
{
dim1.print();
TKDNN_TSTART
net.infer(dim1, data);
TKDNN_TSTOP
dim1.print();
}
// printDeviceVector(64, cudnn_out, true);
tk::dnn::dataDim_t dim2 = dim;
printCenteredTitle(" TENSORRT inference ", '=', 30);
{
dim2.print();
TKDNN_TSTART
netRT.infer(dim2, data);
TKDNN_TSTOP
dim2.print();
}
tk::dnn::Layer *outs[3] = { hm, wh, reg };
int out_count = 1;
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
for(int i=0; i<3; i++) {
printCenteredTitle((std::string(" RESNET CHECK RESULTS ") + std::to_string(i) + " ").c_str(), '=', 30);
outs[i]->output_dim.print();
dnnType *out, *out_h;
int odim = outs[i]->output_dim.tot();
readBinaryFile(output_bin[i], odim, &out_h, &out);
// std::cout<<"OUTPUT BIN:\n";
// printDeviceVector(odim, cudnn_out, true);
// std::cout<<"FILE BIN:\n";
// printDeviceVector(odim, out, true);
dnnType *cudnn_out, *rt_out;
cudnn_out = outs[i]->dstData;
rt_out = (dnnType *)netRT.buffersRT[i+out_count];
// there is the maxpool. It isn't an output but it is necessary for the process section
if(i==0)
out_count ++;
std::cout<<"CUDNN vs correct";
ret_cudnn |= checkResult(odim, cudnn_out, out) == 0 ? 0: ERROR_CUDNN;
std::cout<<"TRT vs correct";
ret_tensorrt |= checkResult(odim, rt_out, out) == 0 ? 0 : ERROR_TENSORRT;
std::cout<<"CUDNN vs TRT ";
ret_cudnn_tensorrt |= checkResult(odim, cudnn_out, rt_out) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
}
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-258
View File
@@ -1,258 +0,0 @@
[net]
# Testing
#batch=1
#subdivisions=1
# Training
batch=32
subdivisions=8
width=608
height=608
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
#######
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[route]
layers=-9
[convolutional]
batch_normalize=1
size=1
stride=1
pad=1
filters=64
activation=leaky
[reorg]
stride=2
[route]
layers=-1,-4
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=425
activation=linear
[region]
anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828
bias_match=1
classes=80
coords=4
num=5
softmax=1
jitter=.3
rescore=1
object_scale=5
noobject_scale=1
class_scale=1
coord_scale=1
absolute=1
thresh = .6
random=1
-258
View File
@@ -1,258 +0,0 @@
[net]
# Testing
batch=1
subdivisions=1
# Training
# batch=64
# subdivisions=8
height=416
width=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 80200
policy=steps
steps=40000,60000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
#######
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[route]
layers=-9
[convolutional]
batch_normalize=1
size=1
stride=1
pad=1
filters=64
activation=leaky
[reorg]
stride=2
[route]
layers=-1,-4
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=125
activation=linear
[region]
anchors = 1.3221, 1.73145, 3.19275, 4.00944, 5.05587, 8.09892, 9.47112, 4.84053, 11.2364, 10.0071
bias_match=1
classes=20
coords=4
num=5
softmax=1
jitter=.3
rescore=1
object_scale=5
noobject_scale=1
class_scale=1
coord_scale=1
absolute=1
thresh = .6
random=1
-139
View File
@@ -1,139 +0,0 @@
[net]
# Training
batch=64
subdivisions=8
# Testing
# batch=1
# subdivisions=1
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=1
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
###########
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=425
activation=linear
[region]
anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828
bias_match=1
classes=80
coords=4
num=5
softmax=1
jitter=.2
rescore=0
object_scale=5
noobject_scale=1
class_scale=1
coord_scale=1
absolute=1
thresh = .6
random=1
-789
View File
@@ -1,789 +0,0 @@
[net]
# Testing
# batch=1
# subdivisions=1
# Training
batch=32
subdivisions=32
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
# Downsample
[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=32
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=128
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=256
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=512
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
######################
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 6,7,8
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 61
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 36
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
-789
View File
@@ -1,789 +0,0 @@
[net]
# Testing
# batch=1
# subdivisions=1
# Training
batch=32
subdivisions=32
width=512
height=512
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
# Downsample
[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=32
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=128
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=256
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=512
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
######################
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 6,7,8
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 61
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 36
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=80
num=9
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
-785
View File
@@ -1,785 +0,0 @@
[net]
# Testing
batch=1
subdivisions=1
# Training
#batch=32
#subdivisions=8
width=544
height=320
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 50200
policy=steps
steps=40000,45000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
# Downsample
[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=32
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=128
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=256
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=512
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
######################
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=45
activation=linear
[yolo]
mask = 6,7,8
anchors = 8.2087,8.5515, 18.4134,20.3391, 40.2194,29.2990, 31.6137,69.2240, 69.8497,48.3838, 108.8817,76.6316, 96.5753,145.5743, 165.9182,117.4493, 215.7497,198.4648
classes=10
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=0
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 61
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=45
activation=linear
[yolo]
mask = 3,4,5
anchors = 8.2087,8.5515, 18.4134,20.3391, 40.2194,29.2990, 31.6137,69.2240, 69.8497,48.3838, 108.8817,76.6316, 96.5753,145.5743, 165.9182,117.4493, 215.7497,198.4648
classes=10
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=0
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 36
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=45
activation=linear
[yolo]
mask = 0,1,2
anchors = 8.2087,8.5515, 18.4134,20.3391, 40.2194,29.2990, 31.6137,69.2240, 69.8497,48.3838, 108.8817,76.6316, 96.5753,145.5743, 165.9182,117.4493, 215.7497,198.4648
classes=10
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=0
-785
View File
@@ -1,785 +0,0 @@
[net]
# Testing
batch=1
subdivisions=1
# Training
#batch=32
#subdivisions=8
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 50200
policy=steps
steps=40000,45000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
# Downsample
[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=32
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=128
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=256
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=512
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
######################
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=27
activation=linear
[yolo]
mask = 6,7,8
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=4
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 61
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=27
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=4
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 36
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=27
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=4
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=1
-785
View File
@@ -1,785 +0,0 @@
[net]
# Testing
#batch=1
#subdivisions=1
# Training
batch=32
subdivisions=8
width=544
height=320
channels=1
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 20000
policy=steps
steps=8000,9000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
# Downsample
[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=32
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=128
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=256
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=512
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
# Downsample
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
[shortcut]
from=-3
activation=linear
######################
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=1024
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=24
activation=linear
[yolo]
mask = 6,7,8
anchors = 8.2087,8.5515, 18.4134,20.3391, 40.2194,29.2990, 31.6137,69.2240, 69.8497,48.3838, 108.8817,76.6316, 96.5753,145.5743, 165.9182,117.4493, 215.7497,198.4648
classes=3
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=0
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 61
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=512
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=24
activation=linear
[yolo]
mask = 3,4,5
anchors = 8.2087,8.5515, 18.4134,20.3391, 40.2194,29.2990, 31.6137,69.2240, 69.8497,48.3838, 108.8817,76.6316, 96.5753,145.5743, 165.9182,117.4493, 215.7497,198.4648
classes=3
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=0
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 36
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
size=3
stride=1
pad=1
filters=256
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=24
activation=linear
[yolo]
mask = 0,1,2
anchors = 8.2087,8.5515, 18.4134,20.3391, 40.2194,29.2990, 31.6137,69.2240, 69.8497,48.3838, 108.8817,76.6316, 96.5753,145.5743, 165.9182,117.4493, 215.7497,198.4648
classes=3
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=0
-182
View File
@@ -1,182 +0,0 @@
[net]
# Testing
batch=1
subdivisions=1
# Training
# batch=64
# subdivisions=2
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=1
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
###########
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 8
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
-182
View File
@@ -1,182 +0,0 @@
[net]
# Testing
batch=1
subdivisions=1
# Training
# batch=64
# subdivisions=2
width=512
height=512
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.001
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=16
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[maxpool]
size=2
stride=1
[convolutional]
batch_normalize=1
filters=1024
size=3
stride=1
pad=1
activation=leaky
###########
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 8
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 0,1,2
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
ignore_thresh = .7
truth_thresh = 1
random=1
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
-281
View File
@@ -1,281 +0,0 @@
[net]
# Testing
#batch=1
#subdivisions=1
# Training
batch=64
subdivisions=1
width=416
height=416
channels=3
momentum=0.9
decay=0.0005
angle=0
saturation = 1.5
exposure = 1.5
hue=.1
learning_rate=0.00261
burn_in=1000
max_batches = 500200
policy=steps
steps=400000,450000
scales=.1,.1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=2
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[route]
layers=-1
groups=2
group_id=1
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=32
size=3
stride=1
pad=1
activation=leaky
[route]
layers = -1,-2
[convolutional]
batch_normalize=1
filters=64
size=1
stride=1
pad=1
activation=leaky
[route]
layers = -6,-1
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[route]
layers=-1
groups=2
group_id=1
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=64
size=3
stride=1
pad=1
activation=leaky
[route]
layers = -1,-2
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[route]
layers = -6,-1
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[route]
layers=-1
groups=2
group_id=1
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=128
size=3
stride=1
pad=1
activation=leaky
[route]
layers = -1,-2
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[route]
layers = -6,-1
[maxpool]
size=2
stride=2
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
##################################
[convolutional]
batch_normalize=1
filters=256
size=1
stride=1
pad=1
activation=leaky
[convolutional]
batch_normalize=1
filters=512
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 3,4,5
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
scale_x_y = 1.05
cls_normalizer=1.0
iou_normalizer=0.07
iou_loss=ciou
ignore_thresh = .7
truth_thresh = 1
random=0
resize=1.5
nms_kind=greedynms
beta_nms=0.6
[route]
layers = -4
[convolutional]
batch_normalize=1
filters=128
size=1
stride=1
pad=1
activation=leaky
[upsample]
stride=2
[route]
layers = -1, 23
[convolutional]
batch_normalize=1
filters=256
size=3
stride=1
pad=1
activation=leaky
[convolutional]
size=1
stride=1
pad=1
filters=255
activation=linear
[yolo]
mask = 1,2,3
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
classes=80
num=6
jitter=.3
scale_x_y = 1.05
cls_normalizer=1.0
iou_normalizer=0.07
iou_loss=ciou
ignore_thresh = .7
truth_thresh = 1
random=0
resize=1.5
nms_kind=greedynms
beta_nms=0.6
File diff suppressed because it is too large Load Diff
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "csresnext50-panet-spp";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.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 wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/csresnext50-panet-spp.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/Kcs4xBozwY4wFx8/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "csresnext50-panet-spp_berkeley";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.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 wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/csresnext50-panet-spp_berkeley.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/berkeley.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/q82qHAtqpoaFYo5/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-10
View File
@@ -1,10 +0,0 @@
person
car
truck
bus
motor
bike
rider
traffic light
traffic sign
train
-80
View File
@@ -1,80 +0,0 @@
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
-4
View File
@@ -1,4 +0,0 @@
person
bicycle
car
motorbike
-3
View File
@@ -1,3 +0,0 @@
person
bike
car
-4
View File
@@ -1,4 +0,0 @@
blue-cone
yellow-cone
orange-cone
big-orange-cone
-20
View File
@@ -1,20 +0,0 @@
aeroplane
bicycle
bird
boat
bottle
bus
car
cat
chair
cow
diningtable
dog
horse
motorbike
person
pottedplant
sheep
sofa
train
tvmonitor
-70
View File
@@ -1,70 +0,0 @@
#include<iostream>
#include<vector>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
#include "NetworkViz.h"
int main(int argc, char *argv[]) {
if(argc <2)
FatalError("you must provide an input image");
std::string input_image = argv[1];
std::string bin_path = "yolo3";
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(wgs_path, bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
// input data
dnnType *input_d;
checkCuda( cudaMalloc(&input_d, sizeof(dnnType)*net->input_dim.tot()));
// load image
cv::Mat frame, frameFloat;
frame = cv::imread(input_image);
cv::resize(frame, frame, cv::Size(net->input_dim.w, net->input_dim.h));
frame.convertTo(frameFloat, CV_32FC3, 1/255.0);
//split channels
cv::Mat bgr[3];
cv::split(frameFloat,bgr);//split source
//write channels
for(int i=0; i<net->input_dim.c; i++) {
int idx = i*frameFloat.rows*frameFloat.cols;
int ch = net->input_dim.c-1 -i;
checkCuda( cudaMemcpy(input_d + idx, (void*)bgr[ch].data, frameFloat.rows*frameFloat.cols*sizeof(dnnType), cudaMemcpyHostToDevice));
}
tk::dnn::dataDim_t dim = net->input_dim;
dim.print();
std::cout<<"infer\n";
net->infer(dim, input_d);
// output directory
std::string output_viz = "viz/";
system( (std::string("mkdir -p ") + output_viz).c_str() );
for(int i=0; i<net->num_layers; i++) {
std::string output_png = output_viz + "/layer" + std::to_string(i) + ".png";
std::cout<<"saving "<<output_png<<"\n";
cv::Mat viz = vizLayer2Mat(net, i);
cv::imwrite(output_png, viz);
//cv::imshow("layer", viz);
//cv::waitKey(0);
}
checkCuda(cudaFree(input_d));
net->releaseLayers();
delete net;
return 0;
}
-32
View File
@@ -1,32 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo2";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/layers/output.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo2.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/nf4PJ3k8bxBETwL/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-33
View File
@@ -1,33 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo2_voc";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/layers/output.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo2_voc.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/voc.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/DJC5Fi2pEjfNDP9/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-33
View File
@@ -1,33 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo2tiny";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/layers/output.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo2tiny.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
// FIXME: wrong weights
//downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s//download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo3";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer82_out.bin",
bin_path + "/debug/layer94_out.bin",
bin_path + "/debug/layer106_out.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo3_512";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer82_out.bin",
bin_path + "/debug/layer94_out.bin",
bin_path + "/debug/layer106_out.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3_512.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/RGecMeGLD4cXEWL/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo3_berkeley";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer82_out.bin",
bin_path + "/debug/layer94_out.bin",
bin_path + "/debug/layer106_out.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3_berkeley.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/berkeley.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/o5cHa4AjTKS64oD/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo3_coco4";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer82_out.bin",
bin_path + "/debug/layer94_out.bin",
bin_path + "/debug/layer106_out.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3_coco4.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco4.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/o27NDzSAartbyc4/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo3_flir";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer82_out.bin",
bin_path + "/debug/layer94_out.bin",
bin_path + "/debug/layer106_out.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3_flir.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/flir.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/62DECncmF6bMMiH/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-33
View File
@@ -1,33 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo3tiny";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer16_out.bin",
bin_path + "/debug/layer23_out.bin",
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3tiny.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/LMcSHtWaLeps8yN/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-33
View File
@@ -1,33 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo3tiny_512";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer16_out.bin",
bin_path + "/debug/layer23_out.bin",
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo3tiny_512.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/8Zt6bHwHADqP4JC/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo4-csp";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer144_out.bin",
bin_path + "/debug/layer159_out.bin",
bin_path + "/debug/layer174_out.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4-csp.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/AfzHE4BfTeEm2gH/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo4";
std::vector<std::string> input_bins = {
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 wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo4_berkeley";
std::vector<std::string> input_bins = {
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 wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4_berkeley.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/berkeley.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/nkWFa5fgb4NTdnB/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-34
View File
@@ -1,34 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo4_mmr";
std::vector<std::string> input_bins = {
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 wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4_mmr.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/mmr.names";
// downloadWeightsifDoNotExist(input_bins[0], bin_path, "");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-33
View File
@@ -1,33 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo4tiny";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer30_out.bin",
bin_path + "/debug/layer37_out.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4tiny.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-36
View File
@@ -1,36 +0,0 @@
#include<iostream>
#include<vector>
#include "tkdnn.h"
#include "test.h"
#include "DarknetParser.h"
int main() {
std::string bin_path = "yolo4x";
std::vector<std::string> input_bins = {
bin_path + "/layers/input.bin"
};
std::vector<std::string> output_bins = {
bin_path + "/debug/layer168_out.bin",
bin_path + "/debug/layer185_out.bin",
bin_path + "/debug/layer202_out.bin"
};
std::string wgs_path = bin_path + "/layers";
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4x.cfg";
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names";
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/5MFjtNtgbDGdJEo/download");
// parse darknet network
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
net->print();
//convert network to tensorRT
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
int ret = testInference(input_bins, output_bins, net, netRT);
net->releaseLayers();
delete net;
delete netRT;
return ret;
}
-38
View File
@@ -1,38 +0,0 @@
import argparse
import os
import msgpack
import lmdb
import random
import caffe
import numpy as np
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='CAFFE WEIGHTS EXPORTER TO CUDNN')
parser.add_argument('model',type=str,
help='Path to prototxt network model')
parser.add_argument('weights',type=str,
help='Path to caffemodel file')
parser.add_argument('--output', type=str, help="output directory", default="layers")
args = parser.parse_args()
if not os.path.exists(args.output):
os.makedirs(args.output)
print "\n\n ====== NET LOADED ====== "
net = caffe.Net(args.model, args.weights, caffe.TEST)
n_lay = len(net.params)
print "Number of layers: ", n_lay
for i in xrange(n_lay):
key = net.params.keys()[i]
print "Layer", key
t = net.layer_dict[key].type
print " type: ", t
w = net.params[key][0].data
b = net.params[key][1].data
print " weights shape:", np.shape(w)
print " bias shape:", np.shape(b)
w.tofile(args.output + "/" + t + str(i) + ".bin", format="f")
b.tofile(args.output + "/" + t + str(i) + ".bias.bin", format="f")
-138
View File
@@ -1,138 +0,0 @@
import keras
from keras.models import load_model
import keras.backend.tensorflow_backend as KTF
import numpy as np
import argparse
import tensorflow as tf
import os
import random
import struct
from keras.models import Sequential, Model
def bin_write(f, data):
data = data.flatten()
fmt = 'f'*len(data)
bin = struct.pack(fmt, *data)
f.write(bin)
def export_layer(name, weights, bias):
print ("######## EXPORT", name, "LAYER ########")
print("wgs pretranpose: ", np.shape(weights))
# convert NHWC to NCHW
if(weights.ndim == 4):
weights = weights.transpose(3,2,0,1)
elif(weights.ndim == 3):
weights = weights.transpose(2,1,0)
elif(weights.ndim == 2):
weights = weights.transpose(1,0)
else:
print("Ndim", weights.ndim)
raise("not implemented with dim" )
print("weights: ", np.shape(weights))
print("bias: ", np.shape(bias))
weights = np.array(weights.flatten(), dtype=np.float32)
bias = np.array(bias, dtype=np.float32)
print(len(weights) + len(bias))
f = open(name + ".bin", mode='wb')
bin_write(f, weights)
bin_write(f, bias)
print ("WEIGHTS saved\n")
def export_bidir(name, params, paramsb):
print ("######## EXPORT", name, "LAYER ########")
f = open(name + ".bin", mode='wb')
print("FORWARD")
ker = params[0]
rec_ker = params[1]
bias = params[2]
print ("export kernels: ", np.shape(ker))
units = np.shape(ker)[1] // 4
bin_write(f, ker[:,:units])
bin_write(f, ker[:,units:units*2])
bin_write(f, ker[:,units*2:units*3])
bin_write(f, ker[:,units*3:])
print ("export recurrent kernels: ", np.shape(rec_ker))
bin_write(f, rec_ker[:,:units])
bin_write(f, rec_ker[:,units:units*2])
bin_write(f, rec_ker[:,units*2:units*3])
bin_write(f, rec_ker[:,units*3:])
print ("export kernels: ", np.shape(ker))
bin_write(f, bias)
print("WEIGHTS saved\n")
print("BACKWARD")
ker = paramsb[0]
rec_ker = paramsb[1]
bias = paramsb[2]
print ("export kernels: ", np.shape(ker))
units = np.shape(ker)[1] // 4
bin_write(f, ker[:,:units])
bin_write(f, ker[:,units:units*2])
bin_write(f, ker[:,units*2:units*3])
bin_write(f, ker[:,units*3:])
print ("export recurrent kernels: ", np.shape(rec_ker))
bin_write(f, rec_ker[:,:units])
bin_write(f, rec_ker[:,units:units*2])
bin_write(f, rec_ker[:,units*2:units*3])
bin_write(f, rec_ker[:,units*3:])
print ("export kernels: ", np.shape(ker))
bin_write(f, bias)
print("WEIGHTS saved\n")
#https://github.com/fchollet/keras/wiki/Converting-convolution-kernels-from-Theano-to-TensorFlow-and-vice-versa
if __name__ == '__main__':
print("DATA FORMAT: ", keras.backend.image_data_format())
parser = argparse.ArgumentParser(description='KERAS WEIGHTS EXPORTER TO CUDNN')
parser.add_argument('model',type=str,
help='Path to model h5 file. Model should be on the same path.')
parser.add_argument('--output', type=str, help="output directory", default="layers")
args = parser.parse_args()
print("DATA FORMAT: ", keras.backend.image_data_format())
print("Load model: ", args.model)
model = load_model(args.model)
model.summary()
weights = model.get_weights()
ws = np.shape(weights)
print("Weights shape:", ws)
if not os.path.exists(args.output):
os.makedirs(args.output)
name_num = 0
for l in model.layers:
print("\n\nNAME: ", l.name)
print("input: ", l.input_shape, " output: ", l.output_shape)
wgs = l.get_weights()
print("wgs num: ", len(wgs))
name = l.name
if name.startswith("conv3d"):
export_layer(args.output + "/" + name, wgs[0], wgs[1])
elif name.startswith("conv2d"):
export_layer(args.output + "/" + name, wgs[0], wgs[1])
elif name.startswith("conv1d"):
export_layer(args.output + "/" + name, wgs[0], wgs[1])
elif name.startswith("dense"):
export_layer(args.output + "/" + name, wgs[0], wgs[1])
elif name.startswith("bidirectional"):
wgs = l.forward_layer.get_weights()
export_bidir(args.output + "/" + name, l.forward_layer.get_weights(), l.backward_layer.get_weights())
else:
print ("skip:", name, "has no weights")
continue
-78
View File
@@ -1,78 +0,0 @@
#include<iostream>
#include "tkDNN/ImuOdom.h"
const char *i0_bin = "imuodom/layers/input0.bin";
const char *i1_bin = "imuodom/layers/input1.bin";
const char *i2_bin = "imuodom/layers/input2.bin";
const char *o0_bin = "imuodom/layers/output0.bin";
const char *o1_bin = "imuodom/layers/output1.bin";
int main() {
// V1
downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/ZAy34K5w2ixED6x/download");
// V2
//downloadWeightsifDoNotExist(i0_bin, "imuodom", "https://cloud.hipert.unimore.it/s/BBSEbEbQbPKxp4s/download");
tk::dnn::ImuOdom ImuNet;
ImuNet.init("imuodom/layers/");
const int N = 19513;
// Network layout
tk::dnn::dataDim_t dim0(1, 4, 1, 100);
tk::dnn::dataDim_t dim1(1, 3, 1, 100);
tk::dnn::dataDim_t dim2(1, 3, 1, 100);
// Load input
dnnType *i0_d, *i1_d, *i2_d;
dnnType *i0_h, *i1_h, *i2_h;
readBinaryFile(i0_bin, dim0.tot()*N, &i0_h, &i0_d);
readBinaryFile(i1_bin, dim1.tot()*N, &i1_h, &i1_d);
readBinaryFile(i2_bin, dim2.tot()*N, &i2_h, &i2_d);
dnnType *data;
tk::dnn::dataDim_t dim;
dnnType *out0, *out1;
dnnType *out0_h, *out1_h;
readBinaryFile(o0_bin, ImuNet.odim0.tot()*N, &out0_h, &out0);
readBinaryFile(o1_bin, ImuNet.odim1.tot()*N, &out1_h, &out1);
std::ofstream path("path.txt");
int ret_cudnn = 0;
for(int i=0; i<N; i++) {
std::cout<<"i: "<<i<<"\n";
//TKDNN_TSTART
// Inference
ImuNet.update(i0_h, i1_h, i2_h);
//TKDNN_TSTOP
// log path
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
printCenteredTitle( (std::string(" CHECK RESULT ") + std::to_string(i) + " ").c_str() , '=');
ImuNet.odim0.print();
ret_cudnn |= checkResult(ImuNet.odim0.tot(), out0, ImuNet.o0_d) == 0 ? 0 : ERROR_CUDNN;
ImuNet.odim1.print();
ret_cudnn |= checkResult(ImuNet.odim0.tot(), out1, ImuNet.o1_d) == 0 ? 0 : ERROR_CUDNN;
i0_h += ImuNet.dim0.tot();
i1_h += ImuNet.dim1.tot();
i2_h += ImuNet.dim2.tot();
out0 += ImuNet.odim0.tot();
out1 += ImuNet.odim1.tot();
}
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;
}
-87
View File
@@ -1,87 +0,0 @@
import keras
from keras.models import load_model
import keras.backend.tensorflow_backend as KTF
import numpy as np
import argparse
import tensorflow as tf
import os
import random
import struct
from keras.models import Sequential, Model
import pickle
def bin_write(f, data):
data = data.flatten()
fmt = 'f'*len(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: ", "ferrariSEP.hdf5")
model = load_model("ferrariSEP.hdf5")
model.summary()
weights = model.get_weights()
indata = pickle.load(open("input.pk", 'rb'))
outdata = pickle.load(open("output.pk", 'rb'))
x_angle = indata[0]
x_gyro = indata[1]
x_acc = indata[2]
[yhat_delta_p, yhat_delta_q] = model.predict(indata, batch_size=1, verbose=1)
predictdata = [yhat_delta_p, yhat_delta_q]
error = outdata[0] - predictdata[0]
print("error delta_p: ", error.sum())
error = outdata[1] - predictdata[1]
print("error delta_q: ", error.sum())
#layer_name = 'dense_4'
#intermediate_layer_model = Model(inputs=model.input,
# outputs=model.get_layer(layer_name).output)
#intermediate_output = intermediate_layer_model.predict([x_angle, x_gyro, x_acc])
x_angle = np.array([x_angle])
x_gyro = np.array([x_gyro])
x_acc = np.array([x_acc])
#intermediate_output = np.array([intermediate_output])
x_angle = x_angle.transpose(1, 3, 0, 2)
x_gyro = x_gyro.transpose(1, 3, 0, 2)
x_acc = x_acc.transpose(1, 3, 0, 2)
#intermediate_output = intermediate_output.transpose(0, 3, 1, 2)
#print("Aggregate:")
#print(intermediate_output.tolist())
print("x0: ", np.shape(x_angle))
#print("out: ",np.shape(intermediate_output))
x_angle = np.array(x_angle.flatten(), dtype=np.float32)
x_gyro = np.array(x_gyro.flatten(), dtype=np.float32)
x_acc = np.array(x_acc.flatten(), dtype=np.float32)
yhat_delta_p = np.array(yhat_delta_p.flatten(), dtype=np.float32)
yhat_delta_q = np.array(yhat_delta_q.flatten(), dtype=np.float32)
#intermediate_output = np.array(intermediate_output.flatten(), dtype=np.float32)
f = open("layers/input0.bin", mode='wb')
bin_write(f, x_angle)
f = open("layers/input1.bin", mode='wb')
bin_write(f, x_gyro)
f = open("layers/input2.bin", mode='wb')
bin_write(f, x_acc)
f = open("layers/output0.bin", mode='wb')
bin_write(f, yhat_delta_p)
f = open("layers/output1.bin", mode='wb')
bin_write(f, yhat_delta_q)
#f = open("layers/output.bin", mode='wb')
#bin_write(f, intermediate_output)
-32
View File
@@ -1,32 +0,0 @@
#!/usr/bin/env python
# mail: admin@9crk.com
# author: 9crk.from China.ShenZhen
# time: 2017-03-22
import caffe
import numpy as np
import cv2
import sys
import Image
import matplotlib.pyplot as plt
model = 'lenet.prototxt';
weights = 'lenet.caffemodel';
net = caffe.Net(model,weights,caffe.TEST);
caffe.set_mode_gpu()
img = np.array(np.random.rand(28,28), dtype=np.float32)
#revert the image,and normalize it to 0-1 range
print "INPUT: ", img
img.tofile("input.bin", format="f")
print "SHAPE: ", np.shape(img)
out = net.forward_all(data=np.asarray([img]))
out = out[out.keys()[0]]
print out
print np.shape(out)
out.tofile("output.bin", format="f")
#print out['prob'][0]
#print out['prob'][0].argmax()
-74
View File
@@ -1,74 +0,0 @@
#include<iostream>
#include "tkdnn.h"
const char *input_bin = "mnist/input.bin";
const char *c0_bin = "mnist/layers/c0.bin";
const char *c1_bin = "mnist/layers/c1.bin";
const char *d2_bin = "mnist/layers/d2.bin";
const char *d3_bin = "mnist/layers/d3.bin";
const char *output_bin = "mnist/output.bin";
int main() {
downloadWeightsifDoNotExist(input_bin, "mnist", "https://cloud.hipert.unimore.it/s/2TyQkMJL3LArLAS/download");
// Network layout
tk::dnn::dataDim_t dim(1, 1, 28, 28, 1);
tk::dnn::Network net(dim);
tk::dnn::Conv2d l0(&net, 20, 5, 5, 1, 1, 0, 0, c0_bin);
tk::dnn::Pooling l1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
tk::dnn::Conv2d l2(&net, 50, 5, 5, 1, 1, 0, 0, c1_bin);
tk::dnn::Pooling l3(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
tk::dnn::Dense l4(&net, 500, d2_bin);
tk::dnn::Activation l5(&net, tk::dnn::ACTIVATION_LEAKY);
tk::dnn::Dense l6(&net, 10, d3_bin);
tk::dnn::Softmax l7(&net);
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("mnist"));
// Load input
dnnType *data;
dnnType *input_h;
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
dnnType *out_data, *out_data2;
std::cout<<"CUDNN inference:\n"; {
dim.print(); //print initial dimension
TKDNN_TSTART
out_data = net.infer(dim, data);
TKDNN_TSTOP
dim.print();
}
// Print result
//std::cout<<"\n======= CUDNN RESULT =======\n";
//printDeviceVector(10, out_data);
tk::dnn::dataDim_t dim2(1, 1, 28, 28, 1);
std::cout<<"TENSORRT inference:\n"; {
dim2.print();
TKDNN_TSTART
out_data2 = netRT.infer(dim2, data);
TKDNN_TSTOP
dim2.print();
}
// Print result
//std::cout<<"\n======= TENRT RESULT =======\n";
//printDeviceVector(10, out_data);
std::cout<<"\n======= CHECK RESULT =======\n";
int ret_tensorrt = checkResult(dim.tot(), out_data, out_data2) == 0 ? 0 : ERROR_TENSORRT;
/*
// Print real test
std::cout<<"\n==== CHECK RESULT ====\n";
dnnType *out;
dnnType *out_h;
readBinaryFile(output_bin, dim.tot(), &out_h, &out);
printDeviceVector(dim.tot(), out);
*/
return ret_tensorrt;
}
-180
View File
@@ -1,180 +0,0 @@
#include<iostream>
#include<cassert>
#include "tkdnn.h"
#include "NvInfer.h"
const char *input_bin = "mnist/input.bin";
const char *c0_bin = "mnist/layers/c0.bin";
const char *c1_bin = "mnist/layers/c1.bin";
const char *d2_bin = "mnist/layers/d2.bin";
const char *d3_bin = "mnist/layers/d3.bin";
const char *output_bin = "mnist/output.bin";
using namespace nvinfer1;
// Logger for info/warning/errors
class Logger : public ILogger
{
void log(Severity severity, const char* msg) override
{
// suppress info-level messages
if (severity != Severity::kINFO)
std::cout << msg << std::endl;
}
} gLogger;
int main() {
downloadWeightsifDoNotExist(input_bin, "mnist", "https://cloud.hipert.unimore.it/s/2TyQkMJL3LArLAS/download");
std::cout<<"\n==== CUDNN ====\n";
// Network layout
tk::dnn::dataDim_t dim(1, 1, 28, 28, 1);
tk::dnn::Network net(dim);
tk::dnn::Conv2d l0(&net, 20, 5, 5, 1, 1, 0, 0, c0_bin);
tk::dnn::Pooling l1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
tk::dnn::Conv2d l2(&net, 50, 5, 5, 1, 1, 0, 0, c1_bin);
tk::dnn::Pooling l3(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
tk::dnn::Dense l4(&net, 500, d2_bin);
tk::dnn::Activation l5(&net, CUDNN_ACTIVATION_RELU);
tk::dnn::Dense l6(&net, 10, d3_bin);
tk::dnn::Softmax l7(&net);
// Load input
dnnType *data;
dnnType *input_h;
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
dim.print(); //print initial dimension
// Inference
{
TKDNN_TSTART
data = net.infer(dim, data);
TKDNN_TSTOP
dim.print();
}
// Print real test
std::cout<<"\n==== CHECK CUDNN RESULT ====\n";
dnnType *out;
dnnType *out_h;
readBinaryFile(output_bin, dim.tot(), &out_h, &out);
std::cout<<"Diff: "<<checkResult(dim.tot(), out, data)<<"\n";
std::cout<<"\n==== TensorRT ====\n";
// create the builder
IBuilder* builder = nvinfer1::createInferBuilder(gLogger);
INetworkDefinition* network = builder->createNetwork();
DataType dt = DataType::kFLOAT;
// Create input of shape { 1, 1, 28, 28 } with name referenced by "data"
auto input = network->addInput("data", dt, DimsCHW{ 1, 28, 28});
assert(input != nullptr);
tk::dnn::Conv2d *c0 = &l0;
Weights w { dt, c0->data_h, c0->inputs*c0->outputs*c0->kernelH*c0->kernelW};
Weights b { dt, c0->bias_h, c0->outputs};
// Add a convolution layer with 20 outputs and a 5x5 filter.
auto conv1 = network->addConvolution(*input, 20, DimsHW{5, 5}, w, b);
assert(conv1 != nullptr);
conv1->setStride(DimsHW{1, 1});
// Add a max pooling layer with stride of 2x2 and kernel size of 2x2.
auto pool1 = network->addPooling(*conv1->getOutput(0), PoolingType::kMAX, DimsHW{2, 2});
assert(pool1 != nullptr);
pool1->setStride(DimsHW{2, 2});
tk::dnn::Conv2d *c1 = &l2;
Weights w1 { dt, c1->data_h, c1->inputs*c1->outputs*c1->kernelH*c1->kernelW};
Weights b1 { dt, c1->bias_h, c1->outputs};
// Add a second convolution layer with 50 outputs and a 5x5 filter.
auto conv2 = network->addConvolution(*pool1->getOutput(0), 50, DimsHW{5, 5}, w1, b1);
assert(conv2 != nullptr);
conv2->setStride(DimsHW{1, 1});
// Add a second max pooling layer with stride of 2x2 and kernel size of 2x3>
auto pool2 = network->addPooling(*conv2->getOutput(0), PoolingType::kMAX, DimsHW{2, 2});
assert(pool2 != nullptr);
pool2->setStride(DimsHW{2, 2});
tk::dnn::Dense *d2 = &l4;
Weights w2 { dt, d2->data_h, d2->inputs*d2->outputs};
Weights b2 { dt, d2->bias_h, d2->outputs};
// Add a fully connected layer with 500 outputs.
auto ip1 = network->addFullyConnected(*pool2->getOutput(0), 500, w2, b2);
assert(ip1 != nullptr);
// Add an activation layer using the ReLU algorithm.
auto relu1 = network->addActivation(*ip1->getOutput(0), ActivationType::kRELU);
assert(relu1 != nullptr);
tk::dnn::Dense *d3 = &l6;
Weights w3 { dt, d3->data_h, d3->inputs*d3->outputs};
Weights b3 { dt, d3->bias_h, d3->outputs};
// Add a second fully connected layer with 20 outputs.
auto ip2 = network->addFullyConnected(*relu1->getOutput(0), 10, w3, b3);
assert(ip2 != nullptr);
// Add a softmax layer to determine the probability.
auto prob = network->addSoftMax(*ip2->getOutput(0));
assert(prob != nullptr);
prob->getOutput(0)->setName("out");
network->markOutput(*prob->getOutput(0));
// Build the engine
builder->setMaxBatchSize(1);
builder->setMaxWorkspaceSize(1 << 20);
auto engine = builder->buildCudaEngine(*network);
// we don't need the network any more
network->destroy();
IExecutionContext *context = engine->createExecutionContext();
// run inference
// input and output buffer pointers that we pass to the engine - the engine requires exactly IEngine::getNbBindings(),
// of these, but in this case we know that there is exactly one input and one output.
assert(engine->getNbBindings() == 2);
void* buffers[2];
// In order to bind the buffers, we need to know the names of the input and output tensors.
// note that indices are guaranteed to be less than IEngine::getNbBindings()
int inputIndex = engine->getBindingIndex("data");
int outputIndex = engine->getBindingIndex("out");
float output[10];
// create GPU buffers and a stream
checkCuda(cudaMalloc(&buffers[inputIndex], 28*28*sizeof(float)));
checkCuda(cudaMalloc(&buffers[outputIndex], 10*sizeof(float)));
cudaStream_t stream;
checkCuda(cudaStreamCreate(&stream));
// DMA the input to the GPU, execute the batch asynchronously, and DMA it back:
{
checkCuda(cudaMemcpyAsync(buffers[inputIndex], input_h, 1 * 28*28* sizeof(float), cudaMemcpyHostToDevice, stream));
cudaStreamSynchronize(stream); //want to test only the inference time
TKDNN_TSTART
context->enqueue(1, buffers, stream, nullptr);
TKDNN_TSTOP
checkCuda(cudaMemcpyAsync(output, buffers[outputIndex],10*sizeof(float), cudaMemcpyDeviceToHost, stream));
cudaStreamSynchronize(stream);
}
std::cout<<"\n==== CHECK CUDNN RESULT ====\n";
std::cout<<"Diff: "<<checkResult(dim.tot(), (float*)buffers[outputIndex], data)<<"\n";
// release the stream and the buffers
cudaStreamDestroy(stream);
checkCuda(cudaFree(buffers[inputIndex]));
checkCuda(cudaFree(buffers[outputIndex]));
// destroy the engine
context->destroy();
engine->destroy();
return 0;
}
@@ -1,546 +0,0 @@
#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/jzRBxcEJYJ99RLa/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();
TKDNN_TSTART
net.infer(dim1, data);
TKDNN_TSTOP
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();
TKDNN_TSTART
netRT.infer(dim2, data);
TKDNN_TSTOP
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;
}
@@ -1,546 +0,0 @@
#include <iostream>
#include "tkdnn.h"
const char *output_bin1 = "mobilenetv2ssd/debug/classification_headers-5.bin";
const char *output_bin2 = "mobilenetv2ssd/debug/regression_headers-5.bin";
const char *input_bin = "mobilenetv2ssd/debug/input.bin";
const char *conv0_bin = "mobilenetv2ssd/layers/base_net-0-0.bin";
const char *inverted_residual1[] = {
"mobilenetv2ssd/layers/base_net-1-conv-0.bin",
"mobilenetv2ssd/layers/base_net-1-conv-3.bin"};
const char *inverted_residual2[] = {
"mobilenetv2ssd/layers/base_net-2-conv-0.bin",
"mobilenetv2ssd/layers/base_net-2-conv-3.bin",
"mobilenetv2ssd/layers/base_net-2-conv-6.bin"};
const char *inverted_residual3[] = {
"mobilenetv2ssd/layers/base_net-3-conv-0.bin",
"mobilenetv2ssd/layers/base_net-3-conv-3.bin",
"mobilenetv2ssd/layers/base_net-3-conv-6.bin"};
const char *inverted_residual4[] = {
"mobilenetv2ssd/layers/base_net-4-conv-0.bin",
"mobilenetv2ssd/layers/base_net-4-conv-3.bin",
"mobilenetv2ssd/layers/base_net-4-conv-6.bin"};
const char *inverted_residual5[] = {
"mobilenetv2ssd/layers/base_net-5-conv-0.bin",
"mobilenetv2ssd/layers/base_net-5-conv-3.bin",
"mobilenetv2ssd/layers/base_net-5-conv-6.bin"};
const char *inverted_residual6[] = {
"mobilenetv2ssd/layers/base_net-6-conv-0.bin",
"mobilenetv2ssd/layers/base_net-6-conv-3.bin",
"mobilenetv2ssd/layers/base_net-6-conv-6.bin"};
const char *inverted_residual7[] = {
"mobilenetv2ssd/layers/base_net-7-conv-0.bin",
"mobilenetv2ssd/layers/base_net-7-conv-3.bin",
"mobilenetv2ssd/layers/base_net-7-conv-6.bin"};
const char *inverted_residual8[] = {
"mobilenetv2ssd/layers/base_net-8-conv-0.bin",
"mobilenetv2ssd/layers/base_net-8-conv-3.bin",
"mobilenetv2ssd/layers/base_net-8-conv-6.bin"};
const char *inverted_residual9[] = {
"mobilenetv2ssd/layers/base_net-9-conv-0.bin",
"mobilenetv2ssd/layers/base_net-9-conv-3.bin",
"mobilenetv2ssd/layers/base_net-9-conv-6.bin"};
const char *inverted_residual10[] = {
"mobilenetv2ssd/layers/base_net-10-conv-0.bin",
"mobilenetv2ssd/layers/base_net-10-conv-3.bin",
"mobilenetv2ssd/layers/base_net-10-conv-6.bin"};
const char *inverted_residual11[] = {
"mobilenetv2ssd/layers/base_net-11-conv-0.bin",
"mobilenetv2ssd/layers/base_net-11-conv-3.bin",
"mobilenetv2ssd/layers/base_net-11-conv-6.bin"};
const char *inverted_residual12[] = {
"mobilenetv2ssd/layers/base_net-12-conv-0.bin",
"mobilenetv2ssd/layers/base_net-12-conv-3.bin",
"mobilenetv2ssd/layers/base_net-12-conv-6.bin"};
const char *inverted_residual13[] = {
"mobilenetv2ssd/layers/base_net-13-conv-0.bin",
"mobilenetv2ssd/layers/base_net-13-conv-3.bin",
"mobilenetv2ssd/layers/base_net-13-conv-6.bin"};
const char *inverted_residual14[] = {
"mobilenetv2ssd/layers/base_net-14-conv-0.bin",
"mobilenetv2ssd/layers/base_net-14-conv-3.bin",
"mobilenetv2ssd/layers/base_net-14-conv-6.bin"};
const char *inverted_residual15[] = {
"mobilenetv2ssd/layers/base_net-15-conv-0.bin",
"mobilenetv2ssd/layers/base_net-15-conv-3.bin",
"mobilenetv2ssd/layers/base_net-15-conv-6.bin"};
const char *inverted_residual16[] = {
"mobilenetv2ssd/layers/base_net-16-conv-0.bin",
"mobilenetv2ssd/layers/base_net-16-conv-3.bin",
"mobilenetv2ssd/layers/base_net-16-conv-6.bin"};
const char *inverted_residual17[] = {
"mobilenetv2ssd/layers/base_net-17-conv-0.bin",
"mobilenetv2ssd/layers/base_net-17-conv-3.bin",
"mobilenetv2ssd/layers/base_net-17-conv-6.bin"};
const char *conv18 = "mobilenetv2ssd/layers/base_net-18-0.bin";
const char *extras0[] = {
"mobilenetv2ssd/layers/extras-0-conv-0.bin",
"mobilenetv2ssd/layers/extras-0-conv-3.bin",
"mobilenetv2ssd/layers/extras-0-conv-6.bin"};
const char *extras1[] = {
"mobilenetv2ssd/layers/extras-1-conv-0.bin",
"mobilenetv2ssd/layers/extras-1-conv-3.bin",
"mobilenetv2ssd/layers/extras-1-conv-6.bin"};
const char *extras2[] = {
"mobilenetv2ssd/layers/extras-2-conv-0.bin",
"mobilenetv2ssd/layers/extras-2-conv-3.bin",
"mobilenetv2ssd/layers/extras-2-conv-6.bin"};
const char *extras3[] = {
"mobilenetv2ssd/layers/extras-3-conv-0.bin",
"mobilenetv2ssd/layers/extras-3-conv-3.bin",
"mobilenetv2ssd/layers/extras-3-conv-6.bin"};
const char *classification_header0[] = {
"mobilenetv2ssd/layers/classification_headers-0-0.bin",
"mobilenetv2ssd/layers/classification_headers-0-3.bin"};
const char *classification_header1[] = {
"mobilenetv2ssd/layers/classification_headers-1-0.bin",
"mobilenetv2ssd/layers/classification_headers-1-3.bin"};
const char *classification_header2[] = {
"mobilenetv2ssd/layers/classification_headers-2-0.bin",
"mobilenetv2ssd/layers/classification_headers-2-3.bin"};
const char *classification_header3[] = {
"mobilenetv2ssd/layers/classification_headers-3-0.bin",
"mobilenetv2ssd/layers/classification_headers-3-3.bin"};
const char *classification_header4[] = {
"mobilenetv2ssd/layers/classification_headers-4-0.bin",
"mobilenetv2ssd/layers/classification_headers-4-3.bin"};
const char *classification_header5 = "mobilenetv2ssd/layers/classification_headers-5.bin";
const char *regression_header0[] = {
"mobilenetv2ssd/layers/regression_headers-0-0.bin",
"mobilenetv2ssd/layers/regression_headers-0-3.bin"};
const char *regression_header1[] = {
"mobilenetv2ssd/layers/regression_headers-1-0.bin",
"mobilenetv2ssd/layers/regression_headers-1-3.bin"};
const char *regression_header2[] = {
"mobilenetv2ssd/layers/regression_headers-2-0.bin",
"mobilenetv2ssd/layers/regression_headers-2-3.bin"};
const char *regression_header3[] = {
"mobilenetv2ssd/layers/regression_headers-3-0.bin",
"mobilenetv2ssd/layers/regression_headers-3-3.bin"};
const char *regression_header4[] = {
"mobilenetv2ssd/layers/regression_headers-4-0.bin",
"mobilenetv2ssd/layers/regression_headers-4-3.bin"};
const char *regression_header5 = "mobilenetv2ssd/layers/regression_headers-5.bin";
int main()
{
downloadWeightsifDoNotExist(input_bin, "mobilenetv2ssd", "https://cloud.hipert.unimore.it/s/x4ZfxBKN23zAJQp/download");
int classes = 21;
// 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, 126, 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, 126, 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, 126, 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, 126, 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, 126, 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, 126, 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("mobilenetv2ssd"));
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30);
{
dim1.print();
TKDNN_TSTART
net.infer(dim1, data);
TKDNN_TSTOP
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();
TKDNN_TSTART
netRT.infer(dim2, data);
TKDNN_TSTOP
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;
}
@@ -1,545 +0,0 @@
#include <iostream>
#include "tkdnn.h"
const char *output_bin1 = "mobilenetv2ssd512/debug/classification_headers-5.bin";
const char *output_bin2 = "mobilenetv2ssd512/debug/regression_headers-5.bin";
const char *input_bin = "mobilenetv2ssd512/debug/input.bin";
const char *conv0_bin = "mobilenetv2ssd512/layers/base_net-0-0.bin";
const char *inverted_residual1[] = {
"mobilenetv2ssd512/layers/base_net-1-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-1-conv-3.bin"};
const char *inverted_residual2[] = {
"mobilenetv2ssd512/layers/base_net-2-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-2-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-2-conv-6.bin"};
const char *inverted_residual3[] = {
"mobilenetv2ssd512/layers/base_net-3-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-3-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-3-conv-6.bin"};
const char *inverted_residual4[] = {
"mobilenetv2ssd512/layers/base_net-4-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-4-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-4-conv-6.bin"};
const char *inverted_residual5[] = {
"mobilenetv2ssd512/layers/base_net-5-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-5-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-5-conv-6.bin"};
const char *inverted_residual6[] = {
"mobilenetv2ssd512/layers/base_net-6-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-6-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-6-conv-6.bin"};
const char *inverted_residual7[] = {
"mobilenetv2ssd512/layers/base_net-7-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-7-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-7-conv-6.bin"};
const char *inverted_residual8[] = {
"mobilenetv2ssd512/layers/base_net-8-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-8-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-8-conv-6.bin"};
const char *inverted_residual9[] = {
"mobilenetv2ssd512/layers/base_net-9-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-9-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-9-conv-6.bin"};
const char *inverted_residual10[] = {
"mobilenetv2ssd512/layers/base_net-10-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-10-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-10-conv-6.bin"};
const char *inverted_residual11[] = {
"mobilenetv2ssd512/layers/base_net-11-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-11-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-11-conv-6.bin"};
const char *inverted_residual12[] = {
"mobilenetv2ssd512/layers/base_net-12-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-12-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-12-conv-6.bin"};
const char *inverted_residual13[] = {
"mobilenetv2ssd512/layers/base_net-13-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-13-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-13-conv-6.bin"};
const char *inverted_residual14[] = {
"mobilenetv2ssd512/layers/base_net-14-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-14-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-14-conv-6.bin"};
const char *inverted_residual15[] = {
"mobilenetv2ssd512/layers/base_net-15-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-15-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-15-conv-6.bin"};
const char *inverted_residual16[] = {
"mobilenetv2ssd512/layers/base_net-16-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-16-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-16-conv-6.bin"};
const char *inverted_residual17[] = {
"mobilenetv2ssd512/layers/base_net-17-conv-0.bin",
"mobilenetv2ssd512/layers/base_net-17-conv-3.bin",
"mobilenetv2ssd512/layers/base_net-17-conv-6.bin"};
const char *conv18 = "mobilenetv2ssd512/layers/base_net-18-0.bin";
const char *extras0[] = {
"mobilenetv2ssd512/layers/extras-0-conv-0.bin",
"mobilenetv2ssd512/layers/extras-0-conv-3.bin",
"mobilenetv2ssd512/layers/extras-0-conv-6.bin"};
const char *extras1[] = {
"mobilenetv2ssd512/layers/extras-1-conv-0.bin",
"mobilenetv2ssd512/layers/extras-1-conv-3.bin",
"mobilenetv2ssd512/layers/extras-1-conv-6.bin"};
const char *extras2[] = {
"mobilenetv2ssd512/layers/extras-2-conv-0.bin",
"mobilenetv2ssd512/layers/extras-2-conv-3.bin",
"mobilenetv2ssd512/layers/extras-2-conv-6.bin"};
const char *extras3[] = {
"mobilenetv2ssd512/layers/extras-3-conv-0.bin",
"mobilenetv2ssd512/layers/extras-3-conv-3.bin",
"mobilenetv2ssd512/layers/extras-3-conv-6.bin"};
const char *classification_header0[] = {
"mobilenetv2ssd512/layers/classification_headers-0-0.bin",
"mobilenetv2ssd512/layers/classification_headers-0-3.bin"};
const char *classification_header1[] = {
"mobilenetv2ssd512/layers/classification_headers-1-0.bin",
"mobilenetv2ssd512/layers/classification_headers-1-3.bin"};
const char *classification_header2[] = {
"mobilenetv2ssd512/layers/classification_headers-2-0.bin",
"mobilenetv2ssd512/layers/classification_headers-2-3.bin"};
const char *classification_header3[] = {
"mobilenetv2ssd512/layers/classification_headers-3-0.bin",
"mobilenetv2ssd512/layers/classification_headers-3-3.bin"};
const char *classification_header4[] = {
"mobilenetv2ssd512/layers/classification_headers-4-0.bin",
"mobilenetv2ssd512/layers/classification_headers-4-3.bin"};
const char *classification_header5 = "mobilenetv2ssd512/layers/classification_headers-5.bin";
const char *regression_header0[] = {
"mobilenetv2ssd512/layers/regression_headers-0-0.bin",
"mobilenetv2ssd512/layers/regression_headers-0-3.bin"};
const char *regression_header1[] = {
"mobilenetv2ssd512/layers/regression_headers-1-0.bin",
"mobilenetv2ssd512/layers/regression_headers-1-3.bin"};
const char *regression_header2[] = {
"mobilenetv2ssd512/layers/regression_headers-2-0.bin",
"mobilenetv2ssd512/layers/regression_headers-2-3.bin"};
const char *regression_header3[] = {
"mobilenetv2ssd512/layers/regression_headers-3-0.bin",
"mobilenetv2ssd512/layers/regression_headers-3-3.bin"};
const char *regression_header4[] = {
"mobilenetv2ssd512/layers/regression_headers-4-0.bin",
"mobilenetv2ssd512/layers/regression_headers-4-3.bin"};
const char *regression_header5 = "mobilenetv2ssd512/layers/regression_headers-5.bin";
int main()
{
downloadWeightsifDoNotExist(input_bin, "mobilenetv2ssd512", "https://cloud.hipert.unimore.it/s/pdCw2dYyHMJrcEM/download");
int classes = 81;
// Network layout
tk::dnn::dataDim_t dim(1, 3, 512, 512, 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, 486, 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, 486, 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, 486, 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, 486, 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, 486, 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, 486, 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::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("mobilenetv2ssd512"));
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30);
{
dim1.print();
TKDNN_TSTART
net.infer(dim1, data);
TKDNN_TSTOP
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();
TKDNN_TSTART
netRT.infer(dim2, data);
TKDNN_TSTOP
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;
}
-54
View File
@@ -1,54 +0,0 @@
import keras
import numpy as np
from keras.models import Sequential
from keras.layers import Input, Dense, Activation, Flatten, Dropout, ELU, Reshape, Lambda, Conv1D
from keras.layers import Bidirectional, CuDNNLSTM
from keras.layers.convolutional import Convolution2D, Convolution3D
from keras.layers.pooling import MaxPooling2D, MaxPooling3D, AveragePooling3D
from keras.models import Sequential, Model
from keras.layers import Cropping2D
import keras.backend.tensorflow_backend as KTF
import struct
from keras.models import Sequential, Model
def bin_write(f, data):
data = data.flatten()
fmt = 'f'*len(data)
bin = struct.pack(fmt, *data)
f.write(bin)
def create_model():
x1 = Input((3, 8), name='x1')
conv = Conv1D(4, 2)(x1)
lstm = Bidirectional(CuDNNLSTM(5, return_sequences=True))(conv)
lstm2 = Bidirectional(CuDNNLSTM(5, return_sequences=False))(lstm)
model = Model([x1], [lstm2])
model.summary()
return model
if __name__ == '__main__':
print ("DATA FORMAT: ", keras.backend.image_data_format())
model = create_model()
model.save("net.hdf5")
np.random.seed(2)
x = np.random.rand(1,1,3,8)
r = model.predict( x[0], batch_size=1)
r = np.array([r])
x = x.transpose(0, 3, 1, 2)
#r = r.transpose(0, 3, 1, 2)
print("in: ", np.shape(x))
print("out: ", np.shape(r))
print("output: ", r.tolist())
x = np.array(x.flatten(), dtype=np.float32)
f = open("input.bin", mode='wb')
bin_write(f, x)
r = np.array(r.flatten(), dtype=np.float32)
f = open("output.bin", mode='wb')
bin_write(f, r)
-73
View File
@@ -1,73 +0,0 @@
#include<iostream>
#include "tkdnn.h"
const char *input_bin = "simple/input.bin";
const char *c0_bin = "simple/layers/conv1d_1.bin";
const char *l1_bin = "simple/layers/bidirectional_1.bin";
const char *l2_bin = "simple/layers/bidirectional_2.bin";
const char *output_bin = "simple/output.bin";
int main() {
// Network layout
tk::dnn::dataDim_t dim(1, 8, 1, 3);
tk::dnn::Network net(dim);
tk::dnn::Conv2d l0(&net, 4, 1, 2, 1, 1, 0, 0, c0_bin);
tk::dnn::LSTM l1(&net, 5, true, l1_bin);
tk::dnn::LSTM l2(&net, 5, false, l2_bin);
net.print();
net.print();
// Load input
dnnType *data;
dnnType *input_h;
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
// Print input
std::cout<<"\n======= INPUT =======\n";
printDeviceVector(dim.tot(), data);
std::cout<<"\n";
//convert network to tensorRT
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("simple"));
dnnType *out_data, *out_data2; // cudnn output, tensorRT output
tk::dnn::dataDim_t dim1 = dim; //input dim
printCenteredTitle(" CUDNN inference ", '=', 30); {
dim1.print();
TKDNN_TSTART
out_data = net.infer(dim1, data);
TKDNN_TSTOP
dim1.print();
}
tk::dnn::dataDim_t dim2 = dim;
printCenteredTitle(" TENSORRT inference ", '=', 30); {
dim2.print();
TKDNN_TSTART
out_data2 = netRT.infer(dim2, data);
TKDNN_TSTOP
dim2.print();
}
std::cout<<"\n======= CUDNN =======\n";
printDeviceVector(dim.tot(), out_data);
std::cout<<"\n======= TENSORRT =======\n";
printDeviceVector(dim.tot(), out_data2);
printCenteredTitle(" CHECK RESULTS ", '=', 30);
dnnType *out, *out_h;
int out_dim = net.getOutputDim().tot();
//readBinaryFile(output_bin, out_dim, &out_h, &out);
// std::cout<<"CUDNN vs correct";
// int ret_cudnn = checkResult(out_dim, out_data, out) == 0 ? 0: ERROR_CUDNN;
// std::cout<<"TRT vs correct";
// int ret_tensorrt = checkResult(out_dim, out_data2, out) == 0 ? 0 : ERROR_TENSORRT;
std::cout<<"CUDNN vs TRT ";
int ret_cudnn_tensorrt = checkResult(out_dim, out_data, out_data2) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
return ret_cudnn_tensorrt;
}
-63
View File
@@ -1,63 +0,0 @@
#include<iostream>
#include "tkdnn.h"
#include <stdlib.h> /* srand, rand */
int main(int argc, char *argv[]) {
if(argc < 2 || !fileExist(argv[1]))
FatalError("unable to read serialRT file");
int BATCH_SIZE = 1;
if(argc >2)
BATCH_SIZE = atoi(argv[2]);
//always same test
srand (0);
//convert network to tensorRT
tk::dnn::NetworkRT netRT(NULL, argv[1]);
tk::dnn::dataDim_t idim = netRT.input_dim;
tk::dnn::dataDim_t odim = netRT.output_dim;
idim.n = BATCH_SIZE;
odim.n = BATCH_SIZE;
dnnType *input = new float[idim.tot()];
dnnType *output = new float[odim.tot()];
dnnType *input_d;
checkCuda( cudaMalloc(&input_d, idim.tot()*sizeof(dnnType)));
int ret_tensorrt = 0;
std::cout<<"Testing with batchsize: "<<BATCH_SIZE<<"\n";
printCenteredTitle(" TENSORRT inference ", '=', 30);
float total_time = 0;
for(int i=0; i<1200; i++) {
// generate input
for(int j=0; j<netRT.input_dim.tot(); j++) {
dnnType val = ((float) rand() / (RAND_MAX));
for(int b=0; b<BATCH_SIZE; b++)
input[netRT.input_dim.tot()*b + j] = val;
}
checkCuda(cudaMemcpy(input_d, input, idim.tot()*sizeof(dnnType), cudaMemcpyHostToDevice));
tk::dnn::dataDim_t dim = idim;
TKDNN_TSTART
netRT.infer(dim, input_d);
TKDNN_TSTOP
total_time+= t_ns;
// control output
std::cout<<"Output Buffers: "<<netRT.getBuffersN()-1<<"\n";
for(int o=1; o<netRT.getBuffersN(); o++) {
for(int b=1; b<BATCH_SIZE; b++) {
dnnType *out_d = (dnnType*) netRT.buffersRT[o];
dnnType *out0_d = out_d;
dnnType *outI_d = out_d + netRT.buffersDIM[o].tot()*b;
ret_tensorrt |= checkResult(netRT.buffersDIM[o].tot(), outI_d, out0_d) == 0 ? 0 : ERROR_TENSORRT;
}
}
}
std::cout<<"avg: "<<total_time/1200.<<std::endl;
return ret_tensorrt;
}