Merge remote-tracking branch 'origin/master' into cnet
Signed-off-by: Davide Sapienza <sapienza.dav@gmail.com>
This commit is contained in:
@@ -12,3 +12,5 @@ build/
|
||||
*.hdf5
|
||||
*.pk
|
||||
*.table
|
||||
demo/COCO_val2017
|
||||
demo/BDD100K_val
|
||||
+46
-104
@@ -10,6 +10,7 @@ if(DEBUG)
|
||||
add_definitions(-DDEBUG)
|
||||
endif()
|
||||
|
||||
add_definitions(-DTKDNN_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# CUDA
|
||||
@@ -20,6 +21,8 @@ SET(CUDA_SEPARABLE_COMPILATION ON)
|
||||
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32)
|
||||
|
||||
find_package(CUDNN REQUIRED)
|
||||
include_directories(${CUDNN_INCLUDE_DIR})
|
||||
|
||||
|
||||
# compile
|
||||
file(GLOB tkdnn_CUSRC "src/kernels/*.cu" "src/sorting.cu")
|
||||
@@ -36,7 +39,8 @@ include_directories(${EIGEN3_INCLUDE_DIR})
|
||||
find_package(OpenCV REQUIRED)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV")
|
||||
|
||||
find_package(yaml-cpp REQUIRED)
|
||||
# gives problems in cross-compiling, probably malformed cmake config
|
||||
#find_package(yaml-cpp REQUIRED)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Build Libraries
|
||||
@@ -47,12 +51,13 @@ set(tkdnn_LIBS kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRAR
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} ${NVINFER_INCLUDES})
|
||||
add_library(tkDNN SHARED ${tkdnn_SRC})
|
||||
target_link_libraries(tkDNN ${tkdnn_LIBS} nvinfer_plugin)
|
||||
target_link_libraries(tkDNN ${tkdnn_LIBS})
|
||||
|
||||
#static
|
||||
#add_library(tkDNN_static STATIC ${tkdnn_SRC})
|
||||
#target_link_libraries(tkDNN_static ${tkdnn_LIBS})
|
||||
|
||||
# SMALL NETS
|
||||
add_executable(test_simple tests/simple/test_simple.cpp)
|
||||
target_link_libraries(test_simple tkDNN)
|
||||
|
||||
@@ -62,97 +67,49 @@ target_link_libraries(test_mnist tkDNN)
|
||||
add_executable(test_mnistRT tests/mnist/test_mnistRT.cpp)
|
||||
target_link_libraries(test_mnistRT tkDNN)
|
||||
|
||||
## YOLO NETS
|
||||
add_executable(test_yolo tests/yolo/yolo.cpp)
|
||||
target_link_libraries(test_yolo tkDNN)
|
||||
|
||||
add_executable(test_yolo_voc tests/yolo_voc/yolo_voc.cpp)
|
||||
target_link_libraries(test_yolo_voc tkDNN)
|
||||
|
||||
add_executable(test_yolo_tiny tests/yolo_tiny/yolo_tiny.cpp)
|
||||
target_link_libraries(test_yolo_tiny tkDNN)
|
||||
|
||||
add_executable(test_yolo_relu tests/yolo_relu/yolo_relu.cpp)
|
||||
target_link_libraries(test_yolo_relu tkDNN)
|
||||
|
||||
|
||||
add_executable(test_yolo_224 tests/yolo_224/yolo_224.cpp)
|
||||
target_link_libraries(test_yolo_224 tkDNN)
|
||||
|
||||
add_executable(test_yolo_berkeley tests/yolo_berkeley/yolo_berkeley.cpp)
|
||||
target_link_libraries(test_yolo_berkeley tkDNN)
|
||||
|
||||
add_executable(test_yolo3_coco4 tests/yolo3_coco4/yolo3_coco4.cpp)
|
||||
target_link_libraries(test_yolo3_coco4 tkDNN)
|
||||
|
||||
add_executable(test_yolo3 tests/yolo3/yolo3.cpp)
|
||||
target_link_libraries(test_yolo3 tkDNN)
|
||||
|
||||
add_executable(test_yolo3_512 tests/yolo3_512/yolo3_512.cpp)
|
||||
target_link_libraries(test_yolo3_512 tkDNN)
|
||||
|
||||
add_executable(test_yolo3_512tp tests/yolo3_512tp/yolo3_512tp.cpp)
|
||||
target_link_libraries(test_yolo3_512tp tkDNN)
|
||||
|
||||
add_executable(test_yolo3_tiny tests/yolo3_tiny/yolo3_tiny.cpp)
|
||||
target_link_libraries(test_yolo3_tiny tkDNN)
|
||||
|
||||
add_executable(test_yolo3_tiny512 tests/yolo3_tiny512/yolo3_tiny512.cpp)
|
||||
target_link_libraries(test_yolo3_tiny512 tkDNN)
|
||||
|
||||
add_executable(test_yolo3_tinyNM512 tests/yolo3_tinyNM512/yolo3_tinyNM512.cpp)
|
||||
target_link_libraries(test_yolo3_tinyNM512 tkDNN)
|
||||
|
||||
add_executable(test_yolo3_tiny512tp tests/yolo3_tiny512tp/yolo3_tiny512tp.cpp)
|
||||
target_link_libraries(test_yolo3_tiny512tp tkDNN)
|
||||
|
||||
add_executable(test_yolo3_berkeley tests/yolo3_berkeley/yolo3_berkeley.cpp)
|
||||
target_link_libraries(test_yolo3_berkeley tkDNN)
|
||||
|
||||
add_executable(test_yolo3_flir tests/yolo3_flir/yolo3_flir.cpp)
|
||||
target_link_libraries(test_yolo3_flir tkDNN)
|
||||
|
||||
add_executable(test_yolo4 tests/yolo4/yolo4.cpp)
|
||||
target_link_libraries(test_yolo4 tkDNN)
|
||||
|
||||
add_executable(test_mobilenetv2ssd tests/mobilenetv2ssd/mobilenetv2ssd.cpp)
|
||||
target_link_libraries(test_mobilenetv2ssd tkDNN)
|
||||
|
||||
add_executable(test_bdd-mobilenetv2ssd tests/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp)
|
||||
target_link_libraries(test_bdd-mobilenetv2ssd tkDNN)
|
||||
|
||||
add_executable(test_mobilenetv2ssd512 tests/mobilenetv2ssd512/mobilenetv2ssd512.cpp)
|
||||
target_link_libraries(test_mobilenetv2ssd512 tkDNN)
|
||||
|
||||
add_executable(test_resnet101 tests/resnet101/resnet101.cpp)
|
||||
target_link_libraries(test_resnet101 tkDNN)
|
||||
|
||||
add_executable(test_csresnext50-panet-spp tests/csresnext50-panet-spp/csresnext50-panet-spp.cpp)
|
||||
target_link_libraries(test_csresnext50-panet-spp tkDNN)
|
||||
|
||||
add_executable(test_bdd-csresnext50-panet-spp tests/bdd-csresnext50-panet-spp/bdd-csresnext50-panet-spp.cpp)
|
||||
target_link_libraries(test_bdd-csresnext50-panet-spp tkDNN)
|
||||
|
||||
add_executable(test_resnet101_cnet tests/resnet101_cnet/resnet101_cnet.cpp)
|
||||
target_link_libraries(test_resnet101_cnet tkDNN)
|
||||
|
||||
add_executable(test_resnet101_cnet3d tests/resnet101_cnet3d/resnet101_cnet3d.cpp)
|
||||
target_link_libraries(test_resnet101_cnet3d tkDNN)
|
||||
|
||||
add_executable(test_dla34 tests/dla34/dla34.cpp)
|
||||
target_link_libraries(test_dla34 tkDNN)
|
||||
|
||||
add_executable(test_dla34_cnet tests/dla34_cnet/dla34_cnet.cpp)
|
||||
target_link_libraries(test_dla34_cnet tkDNN)
|
||||
|
||||
add_executable(test_dla34_cnet3d tests/dla34_cnet3d/dla34_cnet3d.cpp)
|
||||
target_link_libraries(test_dla34_cnet3d tkDNN)
|
||||
|
||||
add_executable(test_imuodom tests/imuodom/imuodom.cpp)
|
||||
target_link_libraries(test_imuodom tkDNN)
|
||||
################################################################################
|
||||
|
||||
# DARKNET
|
||||
file(GLOB darknet_SRC "tests/darknet/*.cpp")
|
||||
foreach(test_SRC ${darknet_SRC})
|
||||
get_filename_component(test_NAME "${test_SRC}" NAME_WE)
|
||||
set(test_NAME test_${test_NAME})
|
||||
add_executable(${test_NAME} ${test_SRC})
|
||||
target_link_libraries(${test_NAME} tkDNN)
|
||||
endforeach()
|
||||
|
||||
# MOBILENET
|
||||
add_executable(test_mobilenetv2ssd tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp)
|
||||
target_link_libraries(test_mobilenetv2ssd tkDNN)
|
||||
|
||||
add_executable(test_bdd-mobilenetv2ssd tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp)
|
||||
target_link_libraries(test_bdd-mobilenetv2ssd tkDNN)
|
||||
|
||||
add_executable(test_mobilenetv2ssd512 tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp)
|
||||
target_link_libraries(test_mobilenetv2ssd512 tkDNN)
|
||||
|
||||
# BACKBONES
|
||||
add_executable(test_resnet101 tests/backbones/resnet101/resnet101.cpp)
|
||||
target_link_libraries(test_resnet101 tkDNN)
|
||||
|
||||
add_executable(test_dla34 tests/backbones/dla34/dla34.cpp)
|
||||
target_link_libraries(test_dla34 tkDNN)
|
||||
|
||||
# CENTERNET
|
||||
add_executable(test_resnet101_cnet tests/centernet/resnet101_cnet/resnet101_cnet.cpp)
|
||||
target_link_libraries(test_resnet101_cnet tkDNN)
|
||||
|
||||
add_executable(test_dla34_cnet tests/centernet/dla34_cnet/dla34_cnet.cpp)
|
||||
target_link_libraries(test_dla34_cnet tkDNN)
|
||||
|
||||
add_executable(test_resnet101_cnet3d tests/centernet/resnet101_cnet3d/resnet101_cnet3d.cpp)
|
||||
target_link_libraries(test_resnet101_cnet3d tkDNN)
|
||||
|
||||
add_executable(test_dla34_cnet3d tests/centernet/dla34_cnet3d/dla34_cnet3d.cpp)
|
||||
target_link_libraries(test_dla34_cnet3d tkDNN)
|
||||
|
||||
# DEMOS
|
||||
add_executable(test_rtinference tests/test_rtinference/rtinference.cpp)
|
||||
target_link_libraries(test_rtinference tkDNN)
|
||||
|
||||
@@ -179,18 +136,3 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" # source directory
|
||||
DESTINATION "share/tkDNN/cmake/" # target directory
|
||||
)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Prepare for test (not needed anymore)
|
||||
#-------------------------------------------------------------------------------
|
||||
#set(TEST_DATA true CACHE BOOL "If true download deps")
|
||||
#if( ${TEST_DATA} )
|
||||
# message("Launching pre-build dependency installer script...")
|
||||
#
|
||||
# execute_process (COMMAND bash -c "bash build_models.sh download"
|
||||
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
#
|
||||
# set(TEST_DATA false CACHE BOOL "If true download deps" FORCE)
|
||||
# message("Finished dowloading test weights")
|
||||
#endif()
|
||||
|
||||
|
||||
@@ -1,21 +1,339 @@
|
||||
MIT License
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (c) 2017 Francesco Gatti
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
Preamble
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
tkDNN
|
||||
Copyright (C) 2017 Francesco Gatti
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<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.
|
||||
|
||||
@@ -1,7 +1,67 @@
|
||||
# tkDNN
|
||||
tkDNN is a Deep Neural Network library built with cuDNN and tensorRT primitives, specifically thought to work on NVIDIA Jetson Boards. It has been tested on TK1(branch cudnn2), TX1, TX2, AGX Xavier and several discrete GPU.
|
||||
tkDNN is a Deep Neural Network library built with cuDNN and tensorRT primitives, specifically thought to work on NVIDIA Jetson Boards. It has been tested on TK1(branch cudnn2), TX1, TX2, AGX Xavier, Nano and several discrete GPUs.
|
||||
The main goal of this project is to exploit NVIDIA boards as much as possible to obtain the best inference performance. It does not allow training.
|
||||
|
||||
|
||||
If you use tkDNN in your research, please cite the [following paper](https://ieeexplore.ieee.org/stamp/stamp.jsp?arnumber=9212130&casa_token=sQTJXi7tJNoAAAAA:BguH9xCIY48MxbtDS3LXzIXzO-9sWArm7Hd7y7BwaLmqRuM_Gx8bOYizFPNMNtpo5K0kB-P-). For use in commercial solutions, write at gattifrancesco@hotmail.it and micaela.verucchi@unimore.it or refer to https://hipert.unimore.it/ .
|
||||
|
||||
```
|
||||
@inproceedings{verucchi2020systematic,
|
||||
title={A Systematic Assessment of Embedded Neural Networks for Object Detection},
|
||||
author={Verucchi, Micaela and Brilli, Gianluca and Sapienza, Davide and Verasani, Mattia and Arena, Marco and Gatti, Francesco and Capotondi, Alessandro and Cavicchioli, Roberto and Bertogna, Marko and Solieri, Marco},
|
||||
booktitle={2020 25th IEEE International Conference on Emerging Technologies and Factory Automation (ETFA)},
|
||||
volume={1},
|
||||
pages={937--944},
|
||||
year={2020},
|
||||
organization={IEEE}
|
||||
}
|
||||
```
|
||||
|
||||
## FPS Results
|
||||
Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimension as the input size, on
|
||||
* RTX 2080Ti (CUDA 10.2, TensorRT 7.0.0, Cudnn 7.6.5);
|
||||
* Xavier AGX, Jetpack 4.3 (CUDA 10.0, CUDNN 7.6.3, tensorrt 6.0.1 );
|
||||
* Xavier NX, Jetpack 4.4 (CUDA 10.2, CUDNN 8.0.0, tensorrt 7.1.0 ).
|
||||
* Tx2, Jetpack 4.2 (CUDA 10.0, CUDNN 7.3.1, tensorrt 5.0.6 );
|
||||
* Jetson Nano, Jetpack 4.4 (CUDA 10.2, CUDNN 8.0.0, tensorrt 7.1.0 ).
|
||||
|
||||
| Platform | Network | FP32, B=1 | FP32, B=4 | FP16, B=1 | FP16, B=4 | INT8, B=1 | INT8, B=4 |
|
||||
| :------: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: |
|
||||
| RTX 2080Ti | yolo4 320 | 118.59 | 237.31 | 207.81 | 443.32 | 262.37 | 530.93 |
|
||||
| RTX 2080Ti | yolo4 416 | 104.81 | 162.86 | 169.06 | 293.78 | 206.93 | 353.26 |
|
||||
| RTX 2080Ti | yolo4 512 | 92.98 | 132.43 | 140.36 | 215.17 | 165.35 | 254.96 |
|
||||
| RTX 2080Ti | yolo4 608 | 63.77 | 81.53 | 111.39 | 152.89 | 127.79 | 184.72 |
|
||||
| AGX Xavier | yolo4 320 | 26.78 | 32.05 | 57.14 | 79.05 | 73.15 | 97.56 |
|
||||
| AGX Xavier | yolo4 416 | 19.96 | 21.52 | 41.01 | 49.00 | 50.81 | 60.61 |
|
||||
| AGX Xavier | yolo4 512 | 16.58 | 16.98 | 31.12 | 33.84 | 37.82 | 41.28 |
|
||||
| AGX Xavier | yolo4 608 | 9.45 | 10.13 | 21.92 | 23.36 | 27.05 | 28.93 |
|
||||
| Xavier NX | yolo4 320 | 14.56 | 16.25 | 30.14 | 41.15 | 42.13 | 53.42 |
|
||||
| Xavier NX | yolo4 416 | 10.02 | 10.60 | 22.43 | 25.59 | 29.08 | 32.94 |
|
||||
| Xavier NX | yolo4 512 | 8.10 | 8.32 | 15.78 | 17.13 | 20.51 | 22.46 |
|
||||
| Xavier NX | yolo4 608 | 5.26 | 5.18 | 11.54 | 12.06 | 15.09 | 15.82 |
|
||||
| Tx2 | yolo4 320 | 11.18 | 12.07 | 15.32 | 16.31 | - | - |
|
||||
| Tx2 | yolo4 416 | 7.30 | 7.58 | 9.45 | 9.90 | - | - |
|
||||
| Tx2 | yolo4 512 | 5.96 | 5.95 | 7.22 | 7.23 | - | - |
|
||||
| Tx2 | yolo4 608 | 3.63 | 3.65 | 4.67 | 4.70 | - | - |
|
||||
| Nano | yolo4 320 | 4.23 | 4.55 | 6.14 | 6.53 | - | - |
|
||||
| Nano | yolo4 416 | 2.88 | 3.00 | 3.90 | 4.04 | - | - |
|
||||
| Nano | yolo4 512 | 2.32 | 2.34 | 3.02 | 3.04 | - | - |
|
||||
| Nano | yolo4 608 | 1.40 | 1.41 | 1.92 | 1.93 | - | - |
|
||||
|
||||
## MAP Results
|
||||
Results for COCO val 2017 (5k images), on RTX 2080Ti, with conf threshold=0.001
|
||||
|
||||
| | CodaLab | CodaLab | CodaLab | CodaLab | tkDNN map | tkDNN map |
|
||||
| -------------------- | :-----------: | :-------: | :-----------: | :---------: | :-----------: | :-------: |
|
||||
| | **tkDNN** | **tkDNN** | **darknet** | **darknet** | **tkDNN** | **tkDNN** |
|
||||
| | MAP(0.5:0.95) | AP50 | MAP(0.5:0.95) | AP50 | MAP(0.5:0.95) | AP50 |
|
||||
| Yolov3 (416x416) | 0.381 | 0.675 | 0.380 | 0.675 | 0.372 | 0.663 |
|
||||
| yolov4 (416x416) | 0.468 | 0.705 | 0.471 | 0.710 | 0.459 | 0.695 |
|
||||
| yolov3tiny (416x416) | 0.096 | 0.202 | 0.096 | 0.201 | 0.093 | 0.198 |
|
||||
| yolov4tiny (416x416) | 0.202 | 0.400 | 0.201 | 0.400 | 0.197 | 0.395 |
|
||||
| Cnet-dla34 (512x512) | 0.366 | 0.543 | \- | \- | 0.361 | 0.535 |
|
||||
| mv2SSD (512x512) | 0.226 | 0.381 | \- | \- | 0.223 | 0.378 |
|
||||
|
||||
## Index
|
||||
- [tkDNN](#tkdnn)
|
||||
- [Index](#index)
|
||||
@@ -69,10 +129,10 @@ Weights are essential for any network to run inference. For each test a folder o
|
||||
Therefore, once the weights have been exported, the folders layers and debug should be placed in the corresponding test.
|
||||
|
||||
### 1)Export weights from darknet
|
||||
To export weights for NNs that are defined in darknet framework, use [this](https://github.com/ceccocats/darknet) fork of darknet and follow these steps to obtain a correct debug and layers folder, ready for tkDNN.
|
||||
To export weights for NNs that are defined in darknet framework, use [this](https://git.hipert.unimore.it/fgatti/darknet.git) fork of darknet and follow these steps to obtain a correct debug and layers folder, ready for tkDNN.
|
||||
|
||||
```
|
||||
git clone https://github.com/ceccocats/darknet
|
||||
git clone https://git.hipert.unimore.it/fgatti/darknet.git
|
||||
cd darknet
|
||||
make
|
||||
mkdir layers debug
|
||||
@@ -101,7 +161,6 @@ python demo.py --input_res 512 --arch resdcn_101 ctdet --demo /path/to/image/or/
|
||||
python demo.py --input_res 512 --arch dla_34 ctdet --demo /path/to/image/or/folder/or/video/or/webcam --load_model ../models/ctdet_coco_dla_2x.pth --exp_wo --exp_wo_dim 512
|
||||
```
|
||||
### 4)Export weights for MobileNetSSD
|
||||
|
||||
To get the weights needed to run Mobilenet tests use [this](https://github.com/mive93/pytorch-ssd) fork of a Pytorch implementation of SSD network.
|
||||
|
||||
```
|
||||
@@ -110,25 +169,68 @@ cd pytorch-ssd
|
||||
conda env create -f env_mobv2ssd.yml
|
||||
python run_ssd_live_demo.py mb2-ssd-lite <pth-model-fil> <labels-file>
|
||||
```
|
||||
## Run the demo
|
||||
|
||||
To run the an object detection demo follow these steps (example with yolov3):
|
||||
## Darknet Parser
|
||||
tkDNN implement and easy parser for darknet cfg files, a network can be converted with *tk::dnn::darknetParser*:
|
||||
```
|
||||
rm yolo3_FP32.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo3 # run the yolo test (is slow)
|
||||
./demo yolo3_FP32.rt ../demo/yolo_test.mp4 y
|
||||
// example of parsing yolo4
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser("yolov4.cfg", "yolov4/layers", "coco.names");
|
||||
net->print();
|
||||
```
|
||||
In general the demo program takes 4 parameters:
|
||||
All models from darknet are now parsed directly from cfg, you still need to export the weights with the described tools in the previous section.
|
||||
<details>
|
||||
<summary>Supported layers</summary>
|
||||
convolutional
|
||||
maxpool
|
||||
avgpool
|
||||
shortcut
|
||||
upsample
|
||||
route
|
||||
reorg
|
||||
region
|
||||
yolo
|
||||
</details>
|
||||
<details>
|
||||
<summary>Supported activations</summary>
|
||||
relu
|
||||
leaky
|
||||
mish
|
||||
</details>
|
||||
|
||||
## Run the demo
|
||||
This is an example using yolov4.
|
||||
|
||||
To run the an object detection first create the .rt file by running:
|
||||
```
|
||||
./demo <network-rt-file> <path-to-video> <kind-of-network> <number-of-classes>
|
||||
rm yolo4_fp32.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo4 # run the yolo test (is slow)
|
||||
```
|
||||
If you get problems in the creation, try to check the error activating the debug of TensorRT in this way:
|
||||
```
|
||||
cmake .. -DDEBUG=True
|
||||
make
|
||||
```
|
||||
|
||||
Once you have successfully created your rt file, run the demo:
|
||||
```
|
||||
./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y
|
||||
```
|
||||
In general the demo program takes 7 parameters:
|
||||
```
|
||||
./demo <network-rt-file> <path-to-video> <kind-of-network> <number-of-classes> <n-batches> <show-flag>
|
||||
```
|
||||
where
|
||||
* ```<network-rt-file>``` is the rt file generated by a test
|
||||
* ```<<path-to-video>``` is the path to a video file or a camera input
|
||||
* ```<kind-of-network>``` is the type of network. Thee types are currently supported: ```y``` (YOLO family), ```c``` (CenterNet family) and ```m``` (MobileNet-SSD family)
|
||||
* ```<number-of-classes>```is the number of classes the network is trained on
|
||||
* ```<n-batches>``` number of batches to use in inference (N.B. you should first export TKDNN_BATCHSIZE to the required n_batches and create again the rt file for the network).
|
||||
* ```<show-flag>``` if set to 0 the demo will not show the visualization but save the video into result.mp4 (if n-batches ==1)
|
||||
* ```<conf-thresh>``` confidence threshold for the detector. Only bounding boxes with threshold greater than conf-thresh will be displayed.
|
||||
|
||||
N.b. By default it is used FP32 inference
|
||||
|
||||
|
||||

|
||||
|
||||
### Run the 3D demo
|
||||
@@ -149,36 +251,59 @@ The demo3D program takes the same parameters of the demo program:
|
||||
To run the an object detection demo with FP16 inference follow these steps (example with yolov3):
|
||||
```
|
||||
export TKDNN_MODE=FP16 # set the half floating point optimization
|
||||
rm yolo3_FP16.rt # be sure to delete(or move) old tensorRT files
|
||||
rm yolo3_fp16.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo3 # run the yolo test (is slow)
|
||||
./demo yolo3_FP16.rt ../demo/yolo_test.mp4 y
|
||||
./demo yolo3_fp16.rt ../demo/yolo_test.mp4 y
|
||||
```
|
||||
N.b. Using FP16 inference will lead to some errors in the results (first or second decimal).
|
||||
|
||||
### INT8 inference
|
||||
|
||||
To run the an object detection demo with INT8 inference follow these steps (example with yolov3):
|
||||
To run the an object detection demo with INT8 inference three environment variables need to be set:
|
||||
* ```export TKDNN_MODE=INT8```: set the 8-bit integer optimization
|
||||
* ```export TKDNN_CALIB_IMG_PATH=/path/to/calibration/image_list.txt``` : image_list.txt has in each line the absolute path to a calibration image
|
||||
* ```export TKDNN_CALIB_LABEL_PATH=/path/to/calibration/label_list.txt```: label_list.txt has in each line the absolute path to a calibration label
|
||||
|
||||
You should provide image_list.txt and label_list.txt, using training images. However, if you want to quickly test the INT8 inference you can run (from this repo root folder)
|
||||
```
|
||||
export TKDNN_MODE=INT8 # set the 8-bit integer optimization
|
||||
bash scripts/download_validation.sh COCO
|
||||
```
|
||||
to automatically download COCO2017 validation (inside demo folder) and create those needed file. Use BDD instead of COCO to download BDD validation.
|
||||
|
||||
# image_list.txt contains the list of the absolute paths to the calibration images
|
||||
export TKDNN_CALIB_IMG_PATH=/path/to/calibration/image_list.txt
|
||||
|
||||
# label_list.txt contains the list of the absolute paths to the calibration labels
|
||||
export TKDNN_CALIB_LABEL_PATH=/path/to/calibration/label_list.txt
|
||||
rm yolo3_INT8.rt # be sure to delete(or move) old tensorRT files
|
||||
Then a complete example using yolo3 and COCO dataset would be:
|
||||
```
|
||||
export TKDNN_MODE=INT8
|
||||
export TKDNN_CALIB_LABEL_PATH=../demo/COCO_val2017/all_labels.txt
|
||||
export TKDNN_CALIB_IMG_PATH=../demo/COCO_val2017/all_images.txt
|
||||
rm yolo3_int8.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo3 # run the yolo test (is slow)
|
||||
./demo yolo3_INT8.rt ../demo/yolo_test.mp4 y
|
||||
./demo yolo3_int8.rt ../demo/yolo_test.mp4 y
|
||||
```
|
||||
N.b. Using INT8 inference will lead to some errors in the results.
|
||||
|
||||
N.b. The test will be slower: this is due to the INT8 calibration, which may take some time to complete.
|
||||
|
||||
N.b. INT8 calibration requires TensorRT version greater than or equal to 6.0
|
||||
N.B.
|
||||
* Using INT8 inference will lead to some errors in the results.
|
||||
* The test will be slower: this is due to the INT8 calibration, which may take some time to complete.
|
||||
* INT8 calibration requires TensorRT version greater than or equal to 6.0
|
||||
* Only 100 images are used to create the calibration table by default (set in the code).
|
||||
|
||||
### BatchSize bigger than 1
|
||||
```
|
||||
export TKDNN_BATCHSIZE=2
|
||||
# build tensorRT files
|
||||
```
|
||||
This will create a TensorRT file with the desired **max** batch size.
|
||||
The test will still run with a batch of 1, but the created tensorRT can manage the desired batch size.
|
||||
|
||||
### Test batch Inference
|
||||
This will test the network with random input and check if the output of each batch is the same.
|
||||
```
|
||||
./test_rtinference <network-rt-file> <number-of-batches>
|
||||
# <number-of-batches> should be less or equal to the max batch size of the <network-rt-file>
|
||||
|
||||
# example
|
||||
export TKDNN_BATCHSIZE=4 # set max batch size
|
||||
rm yolo3_fp32.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo3 # build RT file
|
||||
./test_rtinference yolo3_fp32.rt 4 # test with a batch size of 4
|
||||
```
|
||||
|
||||
## mAP demo
|
||||
@@ -212,6 +337,8 @@ cd build
|
||||
./map_demo dla34_cnet_FP32.rt c ../demo/COCO_val2017/all_labels.txt ../demo/config.yaml
|
||||
```
|
||||
|
||||
This demo also creates a json file named ```net_name_COCO_res.json``` containing all the detections computed. The detections are in COCO format, the correct format to submit the results to [CodaLab COCO detection challenge](https://competitions.codalab.org/competitions/20794#participate).
|
||||
|
||||
## Existing tests and supported networks
|
||||
|
||||
| Test Name | Network | Dataset | N Classes | Input size | Weights |
|
||||
@@ -237,6 +364,9 @@ cd build
|
||||
| resnet101_cnet | Centernet (Resnet101 backend)<sup>4</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/5BTjHMWBcJk8g3i/download) |
|
||||
| csresnext50-panet-spp | Cross Stage Partial Network <sup>7</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/Kcs4xBozwY4wFx8/download) |
|
||||
| yolo4 | Yolov4 <sup>8</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) |
|
||||
| yolo4_berkeley | Yolov4 <sup>8</sup> | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 540x320 | [weights](https://cloud.hipert.unimore.it/s/nkWFa5fgb4NTdnB/download) |
|
||||
| yolo4tiny | Yolov4 tiny <sup>9</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download) |
|
||||
| yolo4x | Yolov4x-mish <sup>9</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 672x672 | [weights](https://cloud.hipert.unimore.it/s/BLPpiAigZJLorQD/download) |
|
||||
|
||||
|
||||
## References
|
||||
@@ -249,3 +379,4 @@ cd build
|
||||
6. He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.
|
||||
7. Wang, Chien-Yao, et al. "CSPNet: A New Backbone that can Enhance Learning Capability of CNN." arXiv preprint arXiv:1911.11929 (2019).
|
||||
8. Bochkovskiy, Alexey, Chien-Yao Wang, and Hong-Yuan Mark Liao. "YOLOv4: Optimal Speed and Accuracy of Object Detection." arXiv preprint arXiv:2004.10934 (2020).
|
||||
9. Bochkovskiy, Alexey, "Yolo v4, v3 and v2 for Windows and Linux" (https://github.com/AlexeyAB/darknet)
|
||||
|
||||
+60
-27
@@ -1,33 +1,66 @@
|
||||
# Find the header files
|
||||
# find the library
|
||||
if(CUDA_FOUND)
|
||||
find_cuda_helper_libs(cudnn)
|
||||
set(CUDNN_LIBRARY ${CUDA_cudnn_LIBRARY} CACHE FILEPATH "location of the cuDNN library")
|
||||
unset(CUDA_cudnn_LIBRARY CACHE)
|
||||
|
||||
find_path(CUDNN_INCLUDE_DIR
|
||||
${CMAKE_SYSROOT}/usr/local/include
|
||||
${CMAKE_SYSROOT}/usr/include
|
||||
/usr/local/nvidia/tensorrt/include/
|
||||
find_cuda_helper_libs(nvinfer)
|
||||
set(NVINFER_LIBRARY ${CUDA_nvinfer_LIBRARY} CACHE FILEPATH "location of the nvinfer library")
|
||||
unset(CUDA_nvinfer_LIBRARY CACHE)
|
||||
endif()
|
||||
|
||||
# find the include
|
||||
if(CUDNN_LIBRARY)
|
||||
find_path(CUDNN_INCLUDE_DIR
|
||||
cudnn.h
|
||||
PATHS ${CUDA_TOOLKIT_INCLUDE}
|
||||
DOC "location of cudnn.h"
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if(NOT CUDNN_INCLUDE_DIR)
|
||||
find_path(CUDNN_INCLUDE_DIR
|
||||
cudnn.h
|
||||
DOC "location of cudnn.h"
|
||||
)
|
||||
endif()
|
||||
|
||||
message("-- Found CUDNN: " ${CUDNN_LIBRARY})
|
||||
message("-- Found CUDNN include: " ${CUDNN_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
if(NVINFER_LIBRARY)
|
||||
find_path(NVINFER_INCLUDE_DIR
|
||||
NvInfer.h
|
||||
PATHS ${CUDA_TOOLKIT_INCLUDE}
|
||||
DOC "location of NvInfer.h"
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if(NOT NVINFER_INCLUDE_DIR)
|
||||
find_path(NVINFER_INCLUDE_DIR
|
||||
NvInfer.h
|
||||
DOC "location of NvInfer.h"
|
||||
)
|
||||
endif()
|
||||
|
||||
message("-- Found NVINFER: " ${NVINFER_LIBRARY})
|
||||
message("-- Found NVINFER include: " ${NVINFER_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(CUDNN
|
||||
FOUND_VAR CUDNN_FOUND
|
||||
REQUIRED_VARS
|
||||
CUDNN_LIBRARY
|
||||
CUDNN_INCLUDE_DIR
|
||||
VERSION_VAR CUDNN_VERSION
|
||||
)
|
||||
|
||||
set(OLD_ROOT ${CMAKE_FIND_ROOT_PATH})
|
||||
list(APPEND CMAKE_FIND_ROOT_PATH /)
|
||||
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.7)
|
||||
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.5)
|
||||
find_library(CUDNN_LIB
|
||||
NAMES cudnn
|
||||
PATHS
|
||||
/usr/local/driveworks/targets/${CMAKE_SYSTEM_PROCESSOR}-Linux/lib
|
||||
/usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
find_library(CUDNN_NVLIB
|
||||
NAMES "nvinfer"
|
||||
PATHS
|
||||
/usr/local/driveworks/targets/${CMAKE_SYSTEM_PROCESSOR}-Linux/lib
|
||||
/usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
set(CMAKE_FIND_ROOT_PATH ${OLD_ROOT})
|
||||
if(CUDNN_FOUND)
|
||||
set(CUDNN_LIBRARIES ${CUDNN_LIBRARY} ${NVINFER_LIBRARY})
|
||||
set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR} ${NVINFER_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
set(CUDNN_LIBRARIES ${CUDNN_LIB} ${CUDNN_NVLIB})
|
||||
message("-- Found CUDNN: " ${CUDNN_LIB})
|
||||
message("-- Found NVINFER: " ${CUDNN_NVLIB})
|
||||
set(CUDNN_FOUND true)
|
||||
+1
-1
@@ -3,5 +3,5 @@ map_points : 101 #number of recall points (0 for all, 101 for COCO, 11 Pascal
|
||||
map_levels : 10 #number of IoU step for the AP
|
||||
map_step : 0.05 #step of IoU
|
||||
IoU_thresh : 0.5 #starting IoU threshold
|
||||
conf_thresh : 0.0 #threshold on the condifence of the bbox
|
||||
conf_thresh : 0.001 #threshold on the condifence of the bbox
|
||||
verbose : false #print on screen information
|
||||
|
||||
+41
-13
@@ -34,6 +34,21 @@ int main(int argc, char *argv[]) {
|
||||
int n_classes = 80;
|
||||
if(argc > 4)
|
||||
n_classes = atoi(argv[4]);
|
||||
int n_batch = 1;
|
||||
if(argc > 5)
|
||||
n_batch = atoi(argv[5]);
|
||||
bool show = true;
|
||||
if(argc > 6)
|
||||
show = atoi(argv[6]);
|
||||
float conf_thresh=0.3;
|
||||
if(argc > 7)
|
||||
conf_thresh = atof(argv[7]);
|
||||
|
||||
if(n_batch < 1 || n_batch > 64)
|
||||
FatalError("Batch dim not supported");
|
||||
|
||||
if(!show)
|
||||
SAVE_RESULT = true;
|
||||
|
||||
tk::dnn::Yolo3Detection yolo;
|
||||
tk::dnn::CenternetDetection cnet;
|
||||
@@ -57,7 +72,7 @@ int main(int argc, char *argv[]) {
|
||||
FatalError("Network type not allowed (3rd parameter)\n");
|
||||
}
|
||||
|
||||
detNN->init(net, n_classes);
|
||||
detNN->init(net, n_classes, n_batch, conf_thresh);
|
||||
|
||||
gRun = true;
|
||||
|
||||
@@ -75,27 +90,40 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
cv::Mat frame;
|
||||
cv::Mat dnn_input;
|
||||
if(show)
|
||||
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
||||
|
||||
std::vector<tk::dnn::box> detected_bbox;
|
||||
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) {
|
||||
if(!frame.data)
|
||||
break;
|
||||
}
|
||||
|
||||
batch_frame.push_back(frame);
|
||||
|
||||
// this will be resized to the net format
|
||||
dnn_input = frame.clone();
|
||||
batch_dnn_input.push_back(frame.clone());
|
||||
}
|
||||
if(!frame.data)
|
||||
break;
|
||||
|
||||
//inference
|
||||
detNN->update(dnn_input);
|
||||
frame = detNN->draw(frame);
|
||||
detNN->update(batch_dnn_input, n_batch);
|
||||
detNN->draw(batch_frame);
|
||||
|
||||
cv::imshow("detection", frame);
|
||||
if(show){
|
||||
for(int bi=0; bi< n_batch; ++bi){
|
||||
cv::imshow("detection", batch_frame[bi]);
|
||||
cv::waitKey(1);
|
||||
if(SAVE_RESULT)
|
||||
}
|
||||
}
|
||||
if(n_batch == 1 && SAVE_RESULT)
|
||||
resultVideo << frame;
|
||||
}
|
||||
|
||||
@@ -103,10 +131,10 @@ int main(int argc, char *argv[]) {
|
||||
double mean = 0;
|
||||
|
||||
std::cout<<COL_GREENB<<"\n\nTime stats:\n";
|
||||
std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())<<" ms\n";
|
||||
std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())<<" ms\n";
|
||||
std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
|
||||
std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
|
||||
for(int i=0; i<detNN->stats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size();
|
||||
std::cout<<"Avg: "<<mean<<" ms\n"<<COL_END;
|
||||
std::cout<<"Avg: "<<mean/n_batch<<" ms\t"<<1000/(mean/n_batch)<<" FPS\n"<<COL_END;
|
||||
|
||||
|
||||
return 0;
|
||||
|
||||
+39
-17
@@ -34,6 +34,7 @@ int main(int argc, char *argv[])
|
||||
bool show = false;
|
||||
bool write_dets = false;
|
||||
bool write_res_on_file = true;
|
||||
bool write_coco_json = true;
|
||||
int n_images = 5000;
|
||||
|
||||
bool verbose;
|
||||
@@ -43,6 +44,7 @@ int main(int argc, char *argv[])
|
||||
double vm_total = 0, rss_total = 0;
|
||||
double vm, rss;
|
||||
|
||||
//read args
|
||||
if(argc > 1)
|
||||
net = argv[1];
|
||||
if(argc > 2)
|
||||
@@ -52,6 +54,7 @@ int main(int argc, char *argv[])
|
||||
if(argc > 4)
|
||||
config_filename = argv[4];
|
||||
|
||||
//check if files needed exist
|
||||
if(!fileExist(config_filename))
|
||||
FatalError("Wrong config file path.");
|
||||
if(!fileExist(net))
|
||||
@@ -63,26 +66,31 @@ int main(int argc, char *argv[])
|
||||
tk::dnn::readmAPParams( config_filename, classes, map_points, map_levels, map_step,
|
||||
IoU_thresh, conf_thresh, verbose);
|
||||
|
||||
std::ofstream times, memory;
|
||||
//extract network name from rt path
|
||||
std::string net_name;
|
||||
removePathAndExtension(net, net_name);
|
||||
std::cout<<"Network: "<<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;
|
||||
@@ -97,9 +105,9 @@ int main(int argc, char *argv[])
|
||||
default:
|
||||
FatalError("Network type not allowed (3rd parameter)\n");
|
||||
}
|
||||
detNN->init(net, n_classes, 1, conf_thresh);
|
||||
|
||||
detNN->init(net, n_classes);
|
||||
|
||||
//read images
|
||||
std::ifstream all_labels(labels_path);
|
||||
std::string l_filename;
|
||||
std::vector<tk::dnn::Frame> images;
|
||||
@@ -124,24 +132,28 @@ int main(int argc, char *argv[])
|
||||
FatalError("Wrong image file path.");
|
||||
|
||||
cv::Mat frame = cv::imread(f.iFilename.c_str(), cv::IMREAD_COLOR);
|
||||
std::vector<cv::Mat> batch_frames;
|
||||
batch_frames.push_back(frame);
|
||||
int height = frame.rows;
|
||||
int width = frame.cols;
|
||||
|
||||
cv::Mat dnn_input;
|
||||
if(!frame.data)
|
||||
break;
|
||||
dnn_input = frame.clone();
|
||||
std::vector<cv::Mat> batch_dnn_input;
|
||||
batch_dnn_input.push_back(frame.clone());
|
||||
|
||||
//inference
|
||||
|
||||
detected_bbox.clear();
|
||||
detNN->update(dnn_input, write_res_on_file, ×);
|
||||
frame = detNN->draw(frame);
|
||||
detNN->update(batch_dnn_input,1,write_res_on_file, ×, write_coco_json);
|
||||
detNN->draw(batch_frames);
|
||||
detected_bbox = detNN->detected;
|
||||
|
||||
if(write_coco_json)
|
||||
printJsonCOCOFormat(&coco_json, f.iFilename.c_str(), detected_bbox, classes, width, height);
|
||||
|
||||
std::ofstream myfile;
|
||||
if(write_dets)
|
||||
myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("000")));
|
||||
myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("labels/") + 7));
|
||||
|
||||
// save detections labels
|
||||
for(auto d:detected_bbox){
|
||||
@@ -157,16 +169,18 @@ int main(int argc, char *argv[])
|
||||
f.det.push_back(b);
|
||||
|
||||
if(write_dets)
|
||||
myfile << d.cl << " "<< d.prob << " "<< d.x << " "<< d.y << " "<< d.w << " "<< d.h <<"\n";
|
||||
myfile << d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n";
|
||||
|
||||
if(show)// draw rectangle for detection
|
||||
cv::rectangle(frame, cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2);
|
||||
cv::rectangle(batch_frames[0], cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2);
|
||||
}
|
||||
|
||||
if(write_dets)
|
||||
myfile.close();
|
||||
|
||||
// read and save groundtruth labels
|
||||
if(fileExist(f.lFilename.c_str()))
|
||||
{
|
||||
std::ifstream labels(l_filename);
|
||||
for(std::string line; std::getline(labels, line); ){
|
||||
std::istringstream in(line);
|
||||
@@ -177,13 +191,14 @@ int main(int argc, char *argv[])
|
||||
f.gt.push_back(b);
|
||||
|
||||
if(show)// draw rectangle for groundtruth
|
||||
cv::rectangle(frame, cv::Point((b.x-b.w/2)*width, (b.y-b.h/2)*height), cv::Point((b.x+b.w/2)*width,(b.y+b.h/2)*height), cv::Scalar(0, 255, 0), 2);
|
||||
cv::rectangle(batch_frames[0], cv::Point((b.x-b.w/2)*width, (b.y-b.h/2)*height), cv::Point((b.x+b.w/2)*width,(b.y+b.h/2)*height), cv::Scalar(0, 255, 0), 2);
|
||||
}
|
||||
}
|
||||
|
||||
images.push_back(f);
|
||||
|
||||
if(show){
|
||||
cv::imshow("detection", frame);
|
||||
cv::imshow("detection", batch_frames[0]);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
|
||||
@@ -193,6 +208,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(write_coco_json){
|
||||
coco_json.seekp (coco_json.tellp() - std::streampos(2));
|
||||
coco_json << "\n]\n";
|
||||
coco_json.close();
|
||||
}
|
||||
|
||||
std::cout << "Avg VM[MB]: " << vm_total/images_done/1024.0 << ";Avg RSS[MB]: " << rss_total/images_done/1024.0 << std::endl;
|
||||
|
||||
//compute mAP
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
FROM ceccocats/tkdnn:latest
|
||||
LABEL maintainer "Francesco Gatti"
|
||||
|
||||
RUN cd && git clone https://github.com/ceccocats/tkDNN.git && cd tkDNN && mkdir build && cd build \
|
||||
&& cmake .. && make -j12
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
|
||||
LABEL maintainer "Francesco Gatti"
|
||||
|
||||
ADD nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb /tmp/trt.deb
|
||||
RUN apt-get update && dpkg -i /tmp/trt.deb && rm /tmp/trt.deb && apt-get update
|
||||
RUN apt install -y libnvinfer7=7.0.0-1+cuda10.2 libnvinfer-dev=7.0.0-1+cuda10.2
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt install -y git wget libeigen3-dev libyaml-cpp-dev
|
||||
RUN cd /tmp && \
|
||||
wget https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-x86_64.sh && \
|
||||
chmod +x cmake-3.17.3-Linux-x86_64.sh && \
|
||||
./cmake-3.17.3-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir --skip-license && \
|
||||
rm ./cmake-3.17.3-Linux-x86_64.sh
|
||||
|
||||
RUN echo "INSTALL OPENCV"
|
||||
RUN apt-get install -y build-essential \
|
||||
unzip \
|
||||
pkg-config \
|
||||
libjpeg-dev \
|
||||
libpng-dev \
|
||||
libtiff-dev \
|
||||
libavcodec-dev \
|
||||
libavformat-dev \
|
||||
libswscale-dev \
|
||||
libv4l-dev \
|
||||
libxvidcore-dev \
|
||||
libx264-dev \
|
||||
libgtk-3-dev \
|
||||
libatlas-base-dev \
|
||||
gfortran \
|
||||
libgstreamer1.0-dev \
|
||||
libgstreamer-plugins-base1.0-dev \
|
||||
libdc1394-22-dev \
|
||||
libavresample-dev
|
||||
RUN cd && wget https://github.com/opencv/opencv/archive/4.3.0.tar.gz && tar -xf 4.3.0.tar.gz && rm *.tar.gz
|
||||
RUN cd && wget https://github.com/opencv/opencv_contrib/archive/4.3.0.tar.gz && tar -xf 4.3.0.tar.gz && rm *.tar.gz
|
||||
RUN cd && \
|
||||
cd opencv-4.3.0 && mkdir build && cd build && \
|
||||
cmake -D CMAKE_BUILD_TYPE=RELEASE \
|
||||
-D CMAKE_INSTALL_PREFIX=/usr/local \
|
||||
-D INSTALL_PYTHON_EXAMPLES=OFF \
|
||||
-D INSTALL_C_EXAMPLES=OFF \
|
||||
-D OPENCV_EXTRA_MODULES_PATH='~/opencv_contrib-4.3.0/modules' \
|
||||
-D BUILD_EXAMPLES=OFF \
|
||||
-D WITH_CUDA=ON \
|
||||
-D CUDA_ARCH_BIN=7.2 \
|
||||
-D CUDA_ARCH_PTX="" \
|
||||
-D ENABLE_FAST_MATH=ON \
|
||||
-D CUDA_FAST_MATH=ON \
|
||||
-D WITH_CUBLAS=ON \
|
||||
-D WITH_LIBV4L=ON \
|
||||
-D WITH_GSTREAMER=ON \
|
||||
-D WITH_GSTREAMER_0_10=OFF \
|
||||
-D WITH_TBB=ON \
|
||||
../ && make -j12 && make install
|
||||
RUN apt clean
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
# Use the prebuilt image
|
||||
```
|
||||
# build image
|
||||
docker build -t tkdnn:build -f Dockerfile .
|
||||
```
|
||||
|
||||
# Build Base Docker image
|
||||
```
|
||||
# make nvidia docker working
|
||||
# follow this guide: https://github.com/NVIDIA/nvidia-docker
|
||||
|
||||
# dowload tensorrt
|
||||
# from: https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.0/7.0.0.11/local_repo/nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb
|
||||
|
||||
# build image
|
||||
docker build -t ceccocats/tkdnn:latest -f Dockerfile.base .
|
||||
|
||||
# run image
|
||||
docker run -ti --gpus all --rm ceccocats/tkdnn:latest bash
|
||||
```
|
||||
|
||||
@@ -73,9 +73,9 @@ public:
|
||||
CenternetDetection() {};
|
||||
~CenternetDetection() {};
|
||||
|
||||
bool init(const std::string& tensor_path, const int n_classes=80);
|
||||
void preprocess(cv::Mat &frame);
|
||||
void postprocess();
|
||||
bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include "tkDNN/tkdnn.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
struct darknetFields_t{
|
||||
std::string type = "";
|
||||
int width = 0;
|
||||
int height = 0;
|
||||
int channels = 3;
|
||||
int batch_normalize=0;
|
||||
int groups = 1;
|
||||
int group_id = 0;
|
||||
int filters=1;
|
||||
int size_x=1;
|
||||
int size_y=1;
|
||||
int stride_x=1;
|
||||
int stride_y=1;
|
||||
int padding_x = 0;
|
||||
int padding_y = 0;
|
||||
int n_mask = 0;
|
||||
int classes = 20;
|
||||
int num = 1;
|
||||
int pad = 0;
|
||||
int coords = 4;
|
||||
int nms_kind = 0;
|
||||
int new_coords= 0;
|
||||
float scale_xy = 1;
|
||||
float nms_thresh = 0.45;
|
||||
std::vector<int> layers;
|
||||
std::string activation = "linear";
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const darknetFields_t& f){
|
||||
os << f.width << " " << f.height << " " << f.channels << " " << f.batch_normalize<< " " << f.filters << " " << f.activation<< " " << f.scale_xy;
|
||||
return os;
|
||||
}
|
||||
};
|
||||
|
||||
std::string darknetParseType(const std::string& line);
|
||||
bool divideNameAndValue(const std::string& line, std::string&name, std::string& value);
|
||||
std::vector<int> fromStringToIntVec(const std::string& line, const char delimiter);
|
||||
|
||||
bool darknetParseFields(const std::string& line, darknetFields_t& fields);
|
||||
tk::dnn::Network *darknetAddNet(darknetFields_t &fields);
|
||||
void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &f, std::string wgs_path,
|
||||
std::vector<tk::dnn::Layer*> &netLayers, const std::vector<std::string>& names);
|
||||
std::vector<std::string> darknetReadNames(const std::string& names_file);
|
||||
tk::dnn::Network* darknetParser(const std::string& cfg_file, const std::string& wgs_path, const std::string& names_file);
|
||||
|
||||
}}
|
||||
+53
-34
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "tkdnn.h"
|
||||
|
||||
//#define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib.
|
||||
// #define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib.
|
||||
|
||||
#ifdef OPENCV_CUDACONTRIB
|
||||
#include <opencv2/cudawarping.hpp>
|
||||
@@ -30,10 +30,12 @@ class DetectionNN {
|
||||
tk::dnn::NetworkRT *netRT = nullptr;
|
||||
dnnType *input_d;
|
||||
|
||||
cv::Size originalSize;
|
||||
std::vector<cv::Size> originalSize;
|
||||
|
||||
cv::Scalar colors[256];
|
||||
|
||||
int nBatches = 1;
|
||||
|
||||
#ifdef OPENCV_CUDACONTRIB
|
||||
cv::cuda::GpuMat bgr[3];
|
||||
cv::cuda::GpuMat imagePreproc;
|
||||
@@ -47,21 +49,26 @@ class DetectionNN {
|
||||
* This method preprocess the image, before feeding it to the NN.
|
||||
*
|
||||
* @param frame original frame to adapt for inference.
|
||||
* @param bi batch index
|
||||
*/
|
||||
virtual void preprocess(cv::Mat &frame) = 0;
|
||||
virtual void preprocess(cv::Mat &frame, const int bi=0) = 0;
|
||||
|
||||
/**
|
||||
* This method postprocess the output of the NN to obtain the correct
|
||||
* boundig boxes.
|
||||
*
|
||||
* @param bi batch index
|
||||
* @param mAP set to true only if all the probabilities for a bounding
|
||||
* box are needed, as in some cases for the mAP calculation
|
||||
*/
|
||||
virtual void postprocess() = 0;
|
||||
virtual void postprocess(const int bi=0,const bool mAP=false) = 0;
|
||||
|
||||
public:
|
||||
int classes = 0;
|
||||
float confThreshold = 0.3; /*threshold on the confidence of the boxes*/
|
||||
|
||||
std::vector<tk::dnn::box> detected; /*bounding boxes in output*/
|
||||
std::vector<std::vector<tk::dnn::box>> batchDetected; /*bounding boxes in output*/
|
||||
std::vector<double> stats; /*keeps track of inference times (ms)*/
|
||||
std::vector<std::string> classesNames;
|
||||
|
||||
@@ -69,66 +76,76 @@ class DetectionNN {
|
||||
~DetectionNN(){};
|
||||
|
||||
/**
|
||||
* Method used to inialize the class, allocate memory and compute
|
||||
* Method used to initialize the class, allocate memory and compute
|
||||
* needed data.
|
||||
*
|
||||
* @param tensor_path path to the rt file og the NN.
|
||||
* @param tensor_path path to the rt file of the NN.
|
||||
* @param n_classes number of classes for the given dataset.
|
||||
* @param n_batches maximum number of batches to use in inference
|
||||
* @return true if everything is correct, false otherwise.
|
||||
*/
|
||||
virtual bool init(const std::string& tensor_path, const int n_classes=80) = 0;
|
||||
virtual bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3) = 0;
|
||||
|
||||
/**
|
||||
* This method performs the whole detection of the NN.
|
||||
*
|
||||
* @param frame frame to run detection on.
|
||||
* @param frames frames to run detection on.
|
||||
* @param cur_batches number of batches to use in inference
|
||||
* @param save_times if set to true, preprocess, inference and postprocess times
|
||||
* are saved on a csv file, otherwise not.
|
||||
* @param times pointer to the output stream where to write times
|
||||
* @param mAP set to true only if all the probabilities for a bounding
|
||||
* box are needed, as in some cases for the mAP calculation
|
||||
*/
|
||||
void update(cv::Mat &frame, bool save_times=false, std::ofstream *times=nullptr){
|
||||
if(!frame.data)
|
||||
FatalError("No image data feed to detection");
|
||||
|
||||
void update(std::vector<cv::Mat>& frames, const int cur_batches=1, bool save_times=false, std::ofstream *times=nullptr, const bool mAP=false){
|
||||
if(save_times && times==nullptr)
|
||||
FatalError("save_times set to true, but no valid ofstream given");
|
||||
if(cur_batches > nBatches)
|
||||
FatalError("A batch size greater than nBatches cannot be used");
|
||||
|
||||
originalSize = frame.size();
|
||||
printCenteredTitle(" TENSORRT detection ", '=', 30);
|
||||
originalSize.clear();
|
||||
if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30);
|
||||
{
|
||||
TIMER_START
|
||||
preprocess(frame);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTART
|
||||
for(int bi=0; bi<cur_batches;++bi){
|
||||
if(!frames[bi].data)
|
||||
FatalError("No image data feed to detection");
|
||||
originalSize.push_back(frames[bi].size());
|
||||
preprocess(frames[bi], bi);
|
||||
}
|
||||
TKDNN_TSTOP
|
||||
if(save_times) *times<<t_ns<<";";
|
||||
}
|
||||
|
||||
//do inference
|
||||
tk::dnn::dataDim_t dim = netRT->input_dim;
|
||||
dim.n = cur_batches;
|
||||
{
|
||||
dim.print();
|
||||
TIMER_START
|
||||
if(TKDNN_VERBOSE) dim.print();
|
||||
TKDNN_TSTART
|
||||
netRT->infer(dim, input_d);
|
||||
TIMER_STOP
|
||||
dim.print();
|
||||
TKDNN_TSTOP
|
||||
if(TKDNN_VERBOSE) dim.print();
|
||||
stats.push_back(t_ns);
|
||||
if(save_times) *times<<t_ns<<";";
|
||||
}
|
||||
|
||||
batchDetected.clear();
|
||||
{
|
||||
TIMER_START
|
||||
postprocess();
|
||||
TIMER_STOP
|
||||
TKDNN_TSTART
|
||||
for(int bi=0; bi<cur_batches;++bi)
|
||||
postprocess(bi, mAP);
|
||||
TKDNN_TSTOP
|
||||
if(save_times) *times<<t_ns<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to draw boundixg boxes and labels on a frame.
|
||||
* Method to draw bounding boxes and labels on a frame.
|
||||
*
|
||||
* @param frame orginal frame to draw bounding box on.
|
||||
* @return frame with boundig boxes.
|
||||
* @param frames original frame to draw bounding box on.
|
||||
*/
|
||||
cv::Mat draw(cv::Mat &frame) {
|
||||
void draw(std::vector<cv::Mat>& frames) {
|
||||
tk::dnn::box b;
|
||||
int x0, w, x1, y0, h, y1;
|
||||
int objClass;
|
||||
@@ -137,9 +154,11 @@ class DetectionNN {
|
||||
int baseline = 0;
|
||||
float font_scale = 0.5;
|
||||
int thickness = 2;
|
||||
|
||||
for(int bi=0; bi<frames.size(); ++bi){
|
||||
// draw dets
|
||||
for(int i=0; i<detected.size(); i++) {
|
||||
b = detected[i];
|
||||
for(int i=0; i<batchDetected[bi].size(); i++) {
|
||||
b = batchDetected[bi][i];
|
||||
x0 = b.x;
|
||||
x1 = b.x + b.w;
|
||||
y0 = b.y;
|
||||
@@ -147,14 +166,14 @@ class DetectionNN {
|
||||
det_class = classesNames[b.cl];
|
||||
|
||||
// draw rectangle
|
||||
cv::rectangle(frame, cv::Point(x0, y0), cv::Point(x1, y1), colors[b.cl], 2);
|
||||
cv::rectangle(frames[bi], cv::Point(x0, y0), cv::Point(x1, y1), colors[b.cl], 2);
|
||||
|
||||
// draw label
|
||||
cv::Size text_size = getTextSize(det_class, cv::FONT_HERSHEY_SIMPLEX, font_scale, thickness, &baseline);
|
||||
cv::rectangle(frame, cv::Point(x0, y0), cv::Point((x0 + text_size.width - 2), (y0 - text_size.height - 2)), colors[b.cl], -1);
|
||||
cv::putText(frame, det_class, cv::Point(x0, (y0 - (baseline / 2))), cv::FONT_HERSHEY_SIMPLEX, font_scale, cv::Scalar(255, 255, 255), thickness);
|
||||
cv::rectangle(frames[bi], cv::Point(x0, y0), cv::Point((x0 + text_size.width - 2), (y0 - text_size.height - 2)), colors[b.cl], -1);
|
||||
cv::putText(frames[bi], det_class, cv::Point(x0, (y0 - (baseline / 2))), cv::FONT_HERSHEY_SIMPLEX, font_scale, cv::Scalar(255, 255, 255), thickness);
|
||||
}
|
||||
}
|
||||
return frame;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -104,9 +104,9 @@ class DetectionNN3D {
|
||||
originalSize = frame.size();
|
||||
printCenteredTitle(" TENSORRT detection ", '=', 30);
|
||||
{
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
preprocess(frame);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
if(save_times) *times<<t_ns<<";";
|
||||
}
|
||||
|
||||
@@ -114,18 +114,18 @@ class DetectionNN3D {
|
||||
tk::dnn::dataDim_t dim = netRT->input_dim;
|
||||
{
|
||||
dim.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
netRT->infer(dim, input_d);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim.print();
|
||||
stats.push_back(t_ns);
|
||||
if(save_times) *times<<t_ns<<";";
|
||||
}
|
||||
|
||||
{
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
postprocess();
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
if(save_times) *times<<t_ns<<"\n";
|
||||
}
|
||||
}
|
||||
|
||||
+20
-4
@@ -35,7 +35,8 @@ class ImuOdom {
|
||||
// output eigen CPU
|
||||
Eigen::MatrixXf deltaP, deltaQ;
|
||||
|
||||
Eigen::MatrixXd odomPOS, odomROT;
|
||||
Eigen::MatrixXd odomPOS, odomEULER;
|
||||
Eigen::Matrix3d odomROT;
|
||||
Eigen::Isometry3f tf = Eigen::Isometry3f::Identity();
|
||||
|
||||
ImuOdom() {}
|
||||
@@ -43,7 +44,7 @@ class ImuOdom {
|
||||
virtual ~ImuOdom() {}
|
||||
|
||||
/**
|
||||
* Method used for inizialize the class
|
||||
* Method used for initialize the class
|
||||
*
|
||||
* @return Success of the initialization
|
||||
*/
|
||||
@@ -109,10 +110,14 @@ class ImuOdom {
|
||||
|
||||
odomPOS = Eigen::MatrixXd::Zero(3, 1);
|
||||
odomROT = Eigen::MatrixXd::Identity(3, 3);
|
||||
|
||||
odomEULER = Eigen::MatrixXd::Zero(3, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
void close() {
|
||||
// TODO: dealloc :)
|
||||
}
|
||||
|
||||
void update(dnnType *x0, dnnType *x1, dnnType *x2) {
|
||||
|
||||
checkCuda( cudaMemcpy(i0_d, x0, dim0.tot()*sizeof(dnnType), cudaMemcpyHostToDevice) );
|
||||
@@ -132,9 +137,20 @@ class ImuOdom {
|
||||
q.x() = deltaQ(1);
|
||||
q.y() = deltaQ(2);
|
||||
q.z() = deltaQ(3);
|
||||
odomPOS = odomPOS + odomROT*deltaP.cast<double>();
|
||||
odomPOS = odomPOS + odomROT*deltaP.cast<double>(); // V1
|
||||
//odomPOS = odomPOS + deltaP.cast<double>(); // V2
|
||||
odomROT = odomROT * q.normalized().toRotationMatrix();
|
||||
|
||||
// compute Euler
|
||||
auto newEULER = odomROT.eulerAngles(0, 1, 2);
|
||||
for(int i=0; i<3; i++) {
|
||||
while( fabs(newEULER(i) - odomEULER(i)) > M_PI_2 ) {
|
||||
newEULER(i) += newEULER(i) - odomEULER(i) > 0 ? -M_PI : +M_PI;
|
||||
//std::cout<<newEULER(i)<<" "<<odomEULER(i)<<"\n";
|
||||
}
|
||||
}
|
||||
odomEULER = newEULER;
|
||||
|
||||
// compose tf
|
||||
tf.matrix().block(0, 0, 3, 3) = odomROT.cast<float>();
|
||||
tf.matrix().block(0, 3, 3, 1) = odomPOS.cast<float>();
|
||||
|
||||
+79
-31
@@ -50,7 +50,7 @@ public:
|
||||
}
|
||||
void setFinal() { this->final = true; }
|
||||
dataDim_t input_dim, output_dim;
|
||||
dnnType *dstData; //where results will be putted
|
||||
dnnType *dstData = nullptr; //where results will be putted
|
||||
|
||||
int id = 0;
|
||||
bool final; //if the layer is the final one
|
||||
@@ -108,29 +108,70 @@ public:
|
||||
|
||||
// additional bias for DCN
|
||||
bool additional_bias;
|
||||
dnnType *bias2_h, *bias2_d;
|
||||
dnnType *bias2_h = nullptr, *bias2_d = nullptr;
|
||||
|
||||
//batchnorm
|
||||
bool batchnorm;
|
||||
dnnType *power_h;
|
||||
dnnType *scales_h, *scales_d;
|
||||
dnnType *mean_h, *mean_d;
|
||||
dnnType *variance_h, *variance_d;
|
||||
dnnType *power_h = nullptr;
|
||||
dnnType *scales_h = nullptr, *scales_d = nullptr;
|
||||
dnnType *mean_h = nullptr, *mean_d = nullptr;
|
||||
dnnType *variance_h = nullptr, *variance_d = nullptr;
|
||||
|
||||
//fp16
|
||||
__half *data16_h, *bias16_h;
|
||||
__half *data16_d, *bias16_d;
|
||||
__half *bias216_h, *bias216_d;
|
||||
__half *data16_h = nullptr, *bias16_h = nullptr;
|
||||
__half *data16_d = nullptr, *bias16_d = nullptr;
|
||||
__half *bias216_h = nullptr, *bias216_d = nullptr;
|
||||
|
||||
__half *power16_h, *power16_d;
|
||||
__half *scales16_h, *scales16_d;
|
||||
__half *mean16_h, *mean16_d;
|
||||
__half *variance16_h, *variance16_d;
|
||||
__half *power16_h = nullptr, *power16_d = nullptr;
|
||||
__half *scales16_h = nullptr, *scales16_d = nullptr;
|
||||
__half *mean16_h = nullptr, *mean16_d = nullptr;
|
||||
__half *variance16_h = nullptr, *variance16_d = nullptr;
|
||||
|
||||
void releaseHost(bool release32 = true, bool release16 = true) {
|
||||
if(release32) {
|
||||
if( data_h != nullptr) { delete [] data_h; data_h = nullptr; }
|
||||
if( bias_h != nullptr) { delete [] bias_h; bias_h = nullptr; }
|
||||
if( bias2_h != nullptr) { delete [] bias2_h; bias2_h = nullptr; }
|
||||
if( scales_h != nullptr) { delete [] scales_h; scales_h = nullptr; }
|
||||
if( mean_h != nullptr) { delete [] mean_h; mean_h = nullptr; }
|
||||
if(variance_h != nullptr) { delete [] variance_h; variance_h = nullptr; }
|
||||
if( power_h != nullptr) { delete [] power_h; power_h = nullptr; }
|
||||
}
|
||||
if(net->fp16 && release16) {
|
||||
if( data16_h != nullptr) { delete [] data16_h; data16_h = nullptr; }
|
||||
if( bias16_h != nullptr) { delete [] bias16_h; bias16_h = nullptr; }
|
||||
if( bias216_h != nullptr) { delete [] bias216_h; bias216_h = nullptr; }
|
||||
if( scales16_h != nullptr) { delete [] scales16_h; scales16_h = nullptr; }
|
||||
if( mean16_h != nullptr) { delete [] mean16_h; mean16_h = nullptr; }
|
||||
if(variance16_h != nullptr) { delete [] variance16_h; variance16_h = nullptr; }
|
||||
if( power16_h != nullptr) { delete [] power16_h; power16_h = nullptr; }
|
||||
|
||||
}
|
||||
}
|
||||
void releaseDevice(bool release32 = true, bool release16 = true) {
|
||||
if(release32) {
|
||||
if( data_d != nullptr) { cudaFree( data_d); data_d = nullptr; }
|
||||
if( bias_d != nullptr) { cudaFree( bias_d); bias_d = nullptr; }
|
||||
if( bias2_d != nullptr) { cudaFree( bias2_d); bias2_d = nullptr; }
|
||||
if( scales_d != nullptr) { cudaFree( scales_d); scales_d = nullptr; }
|
||||
if( mean_d != nullptr) { cudaFree( mean_d); mean_d = nullptr; }
|
||||
if(variance_d != nullptr) { cudaFree(variance_d); variance_d = nullptr; }
|
||||
}
|
||||
if(net->fp16 && release16) {
|
||||
if( data16_d != nullptr) { cudaFree( data16_d); data16_d = nullptr; }
|
||||
if( bias16_d != nullptr) { cudaFree( bias16_d); bias16_d = nullptr; }
|
||||
if( bias216_d != nullptr) { cudaFree( bias216_d); bias216_d = nullptr; }
|
||||
if( scales16_d != nullptr) { cudaFree( scales16_d); scales16_d = nullptr; }
|
||||
if( mean16_d != nullptr) { cudaFree( mean16_d); mean16_d = nullptr; }
|
||||
if(variance16_d != nullptr) { cudaFree(variance16_d); variance16_d = nullptr; }
|
||||
if( power16_d != nullptr) { cudaFree( power16_d); power16_d = nullptr; }
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Input layer (it doesnt need weigths)
|
||||
Input layer (it doesn't need weights)
|
||||
*/
|
||||
class Input : public Layer {
|
||||
|
||||
@@ -166,7 +207,7 @@ public:
|
||||
|
||||
|
||||
/**
|
||||
Avaible activation functions
|
||||
Available activation functions
|
||||
*/
|
||||
typedef enum {
|
||||
ACTIVATION_ELU = 100,
|
||||
@@ -175,7 +216,7 @@ typedef enum {
|
||||
} tkdnnActivationMode_t;
|
||||
|
||||
/**
|
||||
Activation layer (it doesnt need weigths)
|
||||
Activation layer (it doesn't need weights)
|
||||
*/
|
||||
class Activation : public Layer {
|
||||
|
||||
@@ -232,8 +273,8 @@ public:
|
||||
protected:
|
||||
cudnnFilterDescriptor_t filterDesc;
|
||||
cudnnConvolutionDescriptor_t convDesc;
|
||||
cudnnConvolutionFwdAlgo_t algo;
|
||||
cudnnConvolutionBwdDataAlgo_t bwAlgo;
|
||||
cudnnConvolutionFwdAlgoPerf_t algo;
|
||||
cudnnConvolutionBwdDataAlgoPerf_t bwAlgo;
|
||||
cudnnTensorDescriptor_t biasTensorDesc;
|
||||
|
||||
void initCUDNN(bool back = false);
|
||||
@@ -277,9 +318,9 @@ public:
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
|
||||
const bool bidirectional = true; /**> is the net bidir */
|
||||
bool returnSeq = false; /**> if false return only the result of last timestep */
|
||||
bool returnSeq = false; /**> if false return only the result of last timestamp */
|
||||
int stateSize = 0; /**> number of hidden states */
|
||||
int seqLen = 0; /**> number of timesteps */
|
||||
int seqLen = 0; /**> number of timestamp */
|
||||
int numLayers = 1; /**> number of internal layers */
|
||||
|
||||
protected:
|
||||
@@ -326,7 +367,7 @@ public:
|
||||
|
||||
|
||||
/**
|
||||
Deformable Convolutionl 2d layer
|
||||
Deformable Convolutional 2d layer
|
||||
*/
|
||||
class DeformConv2d : public LayerWgs {
|
||||
|
||||
@@ -408,7 +449,7 @@ protected:
|
||||
|
||||
|
||||
/**
|
||||
Avaible pooling functions (padding on tkDNN is not supported)
|
||||
Available pooling functions (padding on tkDNN is not supported)
|
||||
*/
|
||||
typedef enum {
|
||||
POOLING_MAX = 0,
|
||||
@@ -419,7 +460,7 @@ typedef enum {
|
||||
|
||||
/**
|
||||
Pooling layer
|
||||
currenty supported only 2d pooing (also on 3d input)
|
||||
currently supported only 2d pooing (also on 3d input)
|
||||
*/
|
||||
class Pooling : public Layer {
|
||||
|
||||
@@ -468,7 +509,7 @@ public:
|
||||
class Route : public Layer {
|
||||
|
||||
public:
|
||||
Route(Network *net, Layer **layers, int layers_n);
|
||||
Route(Network *net, Layer **layers, int layers_n, int groups = 1, int group_id = 0);
|
||||
virtual ~Route();
|
||||
virtual layerType_t getLayerType() { return LAYER_ROUTE; };
|
||||
|
||||
@@ -478,12 +519,14 @@ public:
|
||||
static const int MAX_LAYERS = 32;
|
||||
Layer *layers[MAX_LAYERS]; //ids of layers to be merged
|
||||
int layers_n; //number of layers
|
||||
int groups;
|
||||
int group_id;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Reorg layer
|
||||
Mantain same dimension but change C*H*W distribution
|
||||
Maintains same dimension but change C*H*W distribution
|
||||
*/
|
||||
class Reorg : public Layer {
|
||||
|
||||
@@ -516,7 +559,7 @@ public:
|
||||
|
||||
/**
|
||||
Upsample layer
|
||||
Mantain same dimension but change C*H*W distribution
|
||||
Maintains same dimension but change C*H*W distribution
|
||||
*/
|
||||
class Upsample : public Layer {
|
||||
|
||||
@@ -535,6 +578,7 @@ struct box {
|
||||
int cl;
|
||||
float x, y, w, h;
|
||||
float prob;
|
||||
std::vector<float> probs;
|
||||
|
||||
void print()
|
||||
{
|
||||
@@ -576,24 +620,28 @@ public:
|
||||
int sort_class;
|
||||
};
|
||||
|
||||
Yolo(Network *net, int classes, int num, std::string fname_weights,int n_masks=3, float scale_xy=1);
|
||||
enum nmsKind_t {GREEDY_NMS=0, DIOU_NMS=1};
|
||||
|
||||
Yolo(Network *net, int classes, int num, std::string fname_weights,int n_masks=3, float scale_xy=1, double nms_thresh=0.45, nmsKind_t nsm_kind=GREEDY_NMS, int new_coords=0);
|
||||
virtual ~Yolo();
|
||||
virtual layerType_t getLayerType() { return LAYER_YOLO; };
|
||||
|
||||
int classes, num, n_masks;
|
||||
int classes, num, n_masks, new_coords;
|
||||
dnnType *mask_h, *mask_d; //anchors
|
||||
dnnType *bias_h, *bias_d; //anchors
|
||||
float scaleXY;
|
||||
double nms_thresh;
|
||||
nmsKind_t nsm_kind;
|
||||
std::vector<std::string> classesNames;
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
int computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh);
|
||||
int computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh, int new_coords=0);
|
||||
|
||||
dnnType *predictions;
|
||||
|
||||
static const int MAX_DETECTIONS = 2048;
|
||||
static const int MAX_DETECTIONS = 8192*2;
|
||||
static Yolo::detection *allocateDetections(int nboxes, int classes);
|
||||
static void mergeDetections(Yolo::detection *dets, int ndets, int classes);
|
||||
static void mergeDetections(Yolo::detection *dets, int ndets, int classes, double nms_thresh=0.45, nmsKind_t nsm_kind=GREEDY_NMS);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -65,9 +65,9 @@ public:
|
||||
MobilenetDetection() {};
|
||||
~MobilenetDetection() {};
|
||||
|
||||
bool init(const std::string& tensor_path, const int n_classes);
|
||||
void preprocess(cv::Mat &frame);
|
||||
void postprocess();
|
||||
bool init(const std::string& tensor_path, const int n_classes, const int n_batches=1, const float conf_thresh=0.3);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
/**
|
||||
Data rapresentation beetween layers
|
||||
Data representation between layers
|
||||
n = batch size
|
||||
c = channels
|
||||
h = heigth (lines)
|
||||
h = height (lines)
|
||||
w = width (rows)
|
||||
l = lenght (3rd dimension)
|
||||
l = length (3rd dimension)
|
||||
*/
|
||||
struct dataDim_t {
|
||||
|
||||
@@ -40,9 +40,10 @@ class Network {
|
||||
public:
|
||||
Network(dataDim_t input_dim);
|
||||
virtual ~Network();
|
||||
void releaseLayers();
|
||||
|
||||
/**
|
||||
Do inferece for every added layer
|
||||
Do inference for every added layer
|
||||
*/
|
||||
dnnType* infer(dataDim_t &dim, dnnType* data);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ using namespace nvinfer1;
|
||||
#include "pluginsRT/ActivationMishRT.h"
|
||||
#include "pluginsRT/ReorgRT.h"
|
||||
#include "pluginsRT/RegionRT.h"
|
||||
//#include "pluginsRT/RouteRT.h"
|
||||
#include "pluginsRT/RouteRT.h"
|
||||
#include "pluginsRT/ShortcutRT.h"
|
||||
#include "pluginsRT/YoloRT.h"
|
||||
#include "pluginsRT/UpsampleRT.h"
|
||||
@@ -91,7 +91,7 @@ public:
|
||||
}
|
||||
|
||||
/**
|
||||
Do inferece
|
||||
Do inference
|
||||
*/
|
||||
dnnType* infer(dataDim_t &dim, dnnType* data);
|
||||
void enqueue(int batchSize = 1);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include <iostream>
|
||||
#include <opencv2/core/types.hpp>
|
||||
#include "tkdnn.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
cv::Mat vizFloat2colorMap(cv::Mat map);
|
||||
cv::Mat vizData2Mat(dnnType *dataInput, tk::dnn::dataDim_t dim, int imgdim);
|
||||
cv::Mat vizLayer2Mat(tk::dnn::Network *net, int layer, int imgdim = 1000);
|
||||
|
||||
}}
|
||||
@@ -24,9 +24,9 @@ public:
|
||||
Yolo3Detection() {};
|
||||
~Yolo3Detection() {};
|
||||
|
||||
bool init(const std::string& tensor_path, const int n_classes=80);
|
||||
void preprocess(cv::Mat &frame);
|
||||
void postprocess();
|
||||
bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -73,12 +73,12 @@ double computeMap( std::vector<Frame> &images,const int classes,
|
||||
* all the recall levels are evaluated, otherwise only
|
||||
* map_point recall levels are used. For COCO evaluation
|
||||
* 101 points are used.
|
||||
* @param map_step step used to increment IoU theshold
|
||||
* @param map_step step used to increment IoU threshold
|
||||
* @param map_levels number of IoU step to perform
|
||||
* @param verbose is set to true, prints on screen additional info
|
||||
* @param write_on_file if set to true, the results produced by this function
|
||||
* are written on file
|
||||
* @param net name of the considerd neural network
|
||||
* @param net name of the considered neural network
|
||||
*
|
||||
* @return mAP IoU_tresh:IoU_tresh+map_step*map_levels (e.g. mAP 0.5:0.95 when
|
||||
* map_step=0.05 and map_levels=10)
|
||||
@@ -89,7 +89,7 @@ double computeMapNIoULevels(std::vector<Frame> &images,const int classes,
|
||||
const int map_levels=10, const bool verbose=false,
|
||||
const bool write_on_file = false, std::string net = "");
|
||||
/**
|
||||
* This method computes the numper of True Positive (TP), False Positive (FP),
|
||||
* This method computes the number of True Positive (TP), False Positive (FP),
|
||||
* False Negative (FN), precision, recall and f1-score.
|
||||
* Those values are computer over all the detections, over all the classes.
|
||||
*
|
||||
@@ -101,13 +101,16 @@ double computeMapNIoULevels(std::vector<Frame> &images,const int classes,
|
||||
* @param verbose is set to true, prints on screen additional info
|
||||
* @param write_on_file if set to true, the results produced by this function
|
||||
* are written on file
|
||||
* @param net name of the considerd neural network
|
||||
* @param net name of the considered neural network
|
||||
*/
|
||||
void computeTPFPFN( std::vector<Frame> &images,const int classes,
|
||||
const float IoU_thresh=0.5, const float conf_thresh=0.3,
|
||||
bool verbose=false, const bool write_on_file=false,
|
||||
std::string net="");
|
||||
|
||||
|
||||
void printJsonCOCOFormat(std::ofstream *out_file, const std::string image_path, std::vector<tk::dnn::box> bbox, const int classes, const int w, const int h);
|
||||
|
||||
}}
|
||||
#endif /*EVALUATION_H*/
|
||||
|
||||
|
||||
@@ -1,289 +0,0 @@
|
||||
int preYoloFilters = (classes+5)*3;
|
||||
|
||||
std::string input_bin = 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 c0_bin = bin_path + "/layers/c0.bin";
|
||||
std::string c1_bin = bin_path + "/layers/c1.bin";
|
||||
std::string c2_bin = bin_path + "/layers/c2.bin";
|
||||
std::string c3_bin = bin_path + "/layers/c3.bin";
|
||||
std::string c5_bin = bin_path + "/layers/c5.bin";
|
||||
std::string c6_bin = bin_path + "/layers/c6.bin";
|
||||
std::string c7_bin = bin_path + "/layers/c7.bin";
|
||||
std::string c9_bin = bin_path + "/layers/c9.bin";
|
||||
std::string c10_bin = bin_path + "/layers/c10.bin";
|
||||
std::string c12_bin = bin_path + "/layers/c12.bin";
|
||||
std::string c13_bin = bin_path + "/layers/c13.bin";
|
||||
std::string c14_bin = bin_path + "/layers/c14.bin";
|
||||
std::string c16_bin = bin_path + "/layers/c16.bin";
|
||||
std::string c17_bin = bin_path + "/layers/c17.bin";
|
||||
std::string c19_bin = bin_path + "/layers/c19.bin";
|
||||
std::string c20_bin = bin_path + "/layers/c20.bin";
|
||||
std::string c22_bin = bin_path + "/layers/c22.bin";
|
||||
std::string c23_bin = bin_path + "/layers/c23.bin";
|
||||
std::string c25_bin = bin_path + "/layers/c25.bin";
|
||||
std::string c26_bin = bin_path + "/layers/c26.bin";
|
||||
std::string c28_bin = bin_path + "/layers/c28.bin";
|
||||
std::string c29_bin = bin_path + "/layers/c29.bin";
|
||||
std::string c31_bin = bin_path + "/layers/c31.bin";
|
||||
std::string c32_bin = bin_path + "/layers/c32.bin";
|
||||
std::string c34_bin = bin_path + "/layers/c34.bin";
|
||||
std::string c35_bin = bin_path + "/layers/c35.bin";
|
||||
std::string c37_bin = bin_path + "/layers/c37.bin";
|
||||
std::string c38_bin = bin_path + "/layers/c38.bin";
|
||||
std::string c39_bin = bin_path + "/layers/c39.bin";
|
||||
std::string c41_bin = bin_path + "/layers/c41.bin";
|
||||
std::string c42_bin = bin_path + "/layers/c42.bin";
|
||||
std::string c44_bin = bin_path + "/layers/c44.bin";
|
||||
std::string c45_bin = bin_path + "/layers/c45.bin";
|
||||
std::string c47_bin = bin_path + "/layers/c47.bin";
|
||||
std::string c48_bin = bin_path + "/layers/c48.bin";
|
||||
std::string c50_bin = bin_path + "/layers/c50.bin";
|
||||
std::string c51_bin = bin_path + "/layers/c51.bin";
|
||||
std::string c53_bin = bin_path + "/layers/c53.bin";
|
||||
std::string c54_bin = bin_path + "/layers/c54.bin";
|
||||
std::string c56_bin = bin_path + "/layers/c56.bin";
|
||||
std::string c57_bin = bin_path + "/layers/c57.bin";
|
||||
std::string c59_bin = bin_path + "/layers/c59.bin";
|
||||
std::string c60_bin = bin_path + "/layers/c60.bin";
|
||||
std::string c62_bin = bin_path + "/layers/c62.bin";
|
||||
std::string c63_bin = bin_path + "/layers/c63.bin";
|
||||
std::string c64_bin = bin_path + "/layers/c64.bin";
|
||||
std::string c66_bin = bin_path + "/layers/c66.bin";
|
||||
std::string c67_bin = bin_path + "/layers/c67.bin";
|
||||
std::string c69_bin = bin_path + "/layers/c69.bin";
|
||||
std::string c70_bin = bin_path + "/layers/c70.bin";
|
||||
std::string c72_bin = bin_path + "/layers/c72.bin";
|
||||
std::string c73_bin = bin_path + "/layers/c73.bin";
|
||||
std::string c75_bin = bin_path + "/layers/c75.bin";
|
||||
std::string c76_bin = bin_path + "/layers/c76.bin";
|
||||
std::string c77_bin = bin_path + "/layers/c77.bin";
|
||||
std::string c78_bin = bin_path + "/layers/c78.bin";
|
||||
std::string c79_bin = bin_path + "/layers/c79.bin";
|
||||
std::string c80_bin = bin_path + "/layers/c80.bin";
|
||||
std::string c81_bin = bin_path + "/layers/c81.bin";
|
||||
std::string g82_bin = bin_path + "/layers/g82.bin";
|
||||
std::string c84_bin = bin_path + "/layers/c84.bin";
|
||||
std::string c87_bin = bin_path + "/layers/c87.bin";
|
||||
std::string c88_bin = bin_path + "/layers/c88.bin";
|
||||
std::string c89_bin = bin_path + "/layers/c89.bin";
|
||||
std::string c90_bin = bin_path + "/layers/c90.bin";
|
||||
std::string c91_bin = bin_path + "/layers/c91.bin";
|
||||
std::string c92_bin = bin_path + "/layers/c92.bin";
|
||||
std::string c93_bin = bin_path + "/layers/c93.bin";
|
||||
std::string g94_bin = bin_path + "/layers/g94.bin";
|
||||
std::string c96_bin = bin_path + "/layers/c96.bin";
|
||||
std::string c99_bin = bin_path + "/layers/c99.bin";
|
||||
std::string c100_bin = bin_path + "/layers/c100.bin";
|
||||
std::string c101_bin = bin_path + "/layers/c101.bin";
|
||||
std::string c102_bin = bin_path + "/layers/c102.bin";
|
||||
std::string c103_bin = bin_path + "/layers/c103.bin";
|
||||
std::string c104_bin = bin_path + "/layers/c104.bin";
|
||||
std::string c105_bin = bin_path + "/layers/c105.bin";
|
||||
std::string g106_bin = bin_path + "/layers/g106.bin";
|
||||
|
||||
tk::dnn::Conv2d c0 (&net, 32, 3, 3, 1, 1, 1, 1, c0_bin, true);
|
||||
tk::dnn::Activation a0 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c1 (&net, 64, 3, 3, 2, 2, 1, 1, c1_bin, true);
|
||||
tk::dnn::Activation a1 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c2 (&net, 32, 1, 1, 1, 1, 0, 0, c2_bin, true);
|
||||
tk::dnn::Activation a2 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c3 (&net, 64, 3, 3, 1, 1, 1, 1, c3_bin, true);
|
||||
tk::dnn::Activation a3 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s4 (&net, &a1);
|
||||
tk::dnn::Conv2d c5 (&net, 128, 3, 3, 2, 2, 1, 1, c5_bin, true);
|
||||
tk::dnn::Activation a5 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c6 (&net, 64, 1, 1, 1, 1, 0, 0, c6_bin, true);
|
||||
tk::dnn::Activation a6 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c7 (&net, 128, 3, 3, 1, 1, 1, 1, c7_bin, true);
|
||||
tk::dnn::Activation a7 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s8 (&net, &a5);
|
||||
tk::dnn::Conv2d c9 (&net, 64, 1, 1, 1, 1, 0, 0, c9_bin, true);
|
||||
tk::dnn::Activation a9 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c10 (&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true);
|
||||
tk::dnn::Activation a10 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s11 (&net, &s8);
|
||||
|
||||
tk::dnn::Conv2d c12 (&net, 256, 3, 3, 2, 2, 1, 1, c12_bin, true);
|
||||
tk::dnn::Activation a12 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c13 (&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true);
|
||||
tk::dnn::Activation a13 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c14 (&net, 256, 3, 3, 1, 1, 1, 1, c14_bin, true);
|
||||
tk::dnn::Activation a14 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s15 (&net, &a12);
|
||||
|
||||
tk::dnn::Conv2d c16 (&net, 128, 1, 1, 1, 1, 0, 0, c16_bin, true);
|
||||
tk::dnn::Activation a16 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c17 (&net, 256, 3, 3, 1, 1, 1, 1, c17_bin, true);
|
||||
tk::dnn::Activation a17 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s18 (&net, &s15);
|
||||
tk::dnn::Conv2d c19 (&net, 128, 1, 1, 1, 1, 0, 0, c19_bin, true);
|
||||
tk::dnn::Activation a19 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c20 (&net, 256, 3, 3, 1, 1, 1, 1, c20_bin, true);
|
||||
tk::dnn::Activation a20 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s21 (&net, &s18);
|
||||
tk::dnn::Conv2d c22 (&net, 128, 1, 1, 1, 1, 0, 0, c22_bin, true);
|
||||
tk::dnn::Activation a22 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c23 (&net, 256, 3, 3, 1, 1, 1, 1, c23_bin, true);
|
||||
tk::dnn::Activation a23 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s24 (&net, &s21);
|
||||
tk::dnn::Conv2d c25 (&net, 128, 1, 1, 1, 1, 0, 0, c25_bin, true);
|
||||
tk::dnn::Activation a25 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c26 (&net, 256, 3, 3, 1, 1, 1, 1, c26_bin, true);
|
||||
tk::dnn::Activation a26 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s27 (&net, &s24);
|
||||
tk::dnn::Conv2d c28 (&net, 128, 1, 1, 1, 1, 0, 0, c28_bin, true);
|
||||
tk::dnn::Activation a28 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c29 (&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true);
|
||||
tk::dnn::Activation a29 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s30 (&net, &s27);
|
||||
tk::dnn::Conv2d c31 (&net, 128, 1, 1, 1, 1, 0, 0, c31_bin, true);
|
||||
tk::dnn::Activation a31 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c32 (&net, 256, 3, 3, 1, 1, 1, 1, c32_bin, true);
|
||||
tk::dnn::Activation a32 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s33 (&net, &s30);
|
||||
tk::dnn::Conv2d c34 (&net, 128, 1, 1, 1, 1, 0, 0, c34_bin, true);
|
||||
tk::dnn::Activation a34 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c35 (&net, 256, 3, 3, 1, 1, 1, 1, c35_bin, true);
|
||||
tk::dnn::Activation a35 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s36 (&net, &s33);
|
||||
|
||||
tk::dnn::Conv2d c37 (&net, 512, 3, 3, 2, 2, 1, 1, c37_bin, true);
|
||||
tk::dnn::Activation a37 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c38 (&net, 256, 1, 1, 1, 1, 0, 0, c38_bin, true);
|
||||
tk::dnn::Activation a38 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c39 (&net, 512, 3, 3, 1, 1, 1, 1, c39_bin, true);
|
||||
tk::dnn::Activation a39 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s40 (&net, &a37);
|
||||
|
||||
tk::dnn::Conv2d c41 (&net, 256, 1, 1, 1, 1, 0, 0, c41_bin, true);
|
||||
tk::dnn::Activation a41 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c42 (&net, 512, 3, 3, 1, 1, 1, 1, c42_bin, true);
|
||||
tk::dnn::Activation a42 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s43 (&net, &s40);
|
||||
tk::dnn::Conv2d c44 (&net, 256, 1, 1, 1, 1, 0, 0, c44_bin, true);
|
||||
tk::dnn::Activation a44 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c45 (&net, 512, 3, 3, 1, 1, 1, 1, c45_bin, true);
|
||||
tk::dnn::Activation a45 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s46 (&net, &s43);
|
||||
tk::dnn::Conv2d c47 (&net, 256, 1, 1, 1, 1, 0, 0, c47_bin, true);
|
||||
tk::dnn::Activation a47 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c48 (&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true);
|
||||
tk::dnn::Activation a48 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s49 (&net, &s46);
|
||||
tk::dnn::Conv2d c50 (&net, 256, 1, 1, 1, 1, 0, 0, c50_bin, true);
|
||||
tk::dnn::Activation a50 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c51 (&net, 512, 3, 3, 1, 1, 1, 1, c51_bin, true);
|
||||
tk::dnn::Activation a51 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s52 (&net, &s49);
|
||||
tk::dnn::Conv2d c53 (&net, 256, 1, 1, 1, 1, 0, 0, c53_bin, true);
|
||||
tk::dnn::Activation a53 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c54 (&net, 512, 3, 3, 1, 1, 1, 1, c54_bin, true);
|
||||
tk::dnn::Activation a54 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s55 (&net, &s52);
|
||||
tk::dnn::Conv2d c56 (&net, 256, 1, 1, 1, 1, 0, 0, c56_bin, true);
|
||||
tk::dnn::Activation a56 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c57 (&net, 512, 3, 3, 1, 1, 1, 1, c57_bin, true);
|
||||
tk::dnn::Activation a57 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s58 (&net, &s55);
|
||||
tk::dnn::Conv2d c59 (&net, 256, 1, 1, 1, 1, 0, 0, c59_bin, true);
|
||||
tk::dnn::Activation a59 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c60 (&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true);
|
||||
tk::dnn::Activation a60 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s61 (&net, &s58);
|
||||
|
||||
tk::dnn::Conv2d c62 (&net,1024, 3, 3, 2, 2, 1, 1, c62_bin, true);
|
||||
tk::dnn::Activation a62 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c63 (&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true);
|
||||
tk::dnn::Activation a63 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c64 (&net,1024, 3, 3, 1, 1, 1, 1, c64_bin, true);
|
||||
tk::dnn::Activation a64 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s65 (&net, &a62);
|
||||
|
||||
tk::dnn::Conv2d c66 (&net, 512, 1, 1, 1, 1, 0, 0, c66_bin, true);
|
||||
tk::dnn::Activation a66 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c67 (&net,1024, 3, 3, 1, 1, 1, 1, c67_bin, true);
|
||||
tk::dnn::Activation a67 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s68 (&net, &s65);
|
||||
|
||||
tk::dnn::Conv2d c69 (&net, 512, 1, 1, 1, 1, 0, 0, c69_bin, true);
|
||||
tk::dnn::Activation a69 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c70 (&net,1024, 3, 3, 1, 1, 1, 1, c70_bin, true);
|
||||
tk::dnn::Activation a70 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s71 (&net, &s68);
|
||||
|
||||
tk::dnn::Conv2d c72 (&net, 512, 1, 1, 1, 1, 0, 0, c72_bin, true);
|
||||
tk::dnn::Activation a72 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c73 (&net,1024, 3, 3, 1, 1, 1, 1, c73_bin, true);
|
||||
tk::dnn::Activation a73 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Shortcut s74 (&net, &s71);
|
||||
|
||||
tk::dnn::Conv2d c75 (&net, 512, 1, 1, 1, 1, 0, 0, c75_bin, true);
|
||||
tk::dnn::Activation a75 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c76 (&net,1024, 3, 3, 1, 1, 1, 1, c76_bin, true);
|
||||
tk::dnn::Activation a76 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c77 (&net, 512, 1, 1, 1, 1, 0, 0, c77_bin, true);
|
||||
tk::dnn::Activation a77 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c78 (&net,1024, 3, 3, 1, 1, 1, 1, c78_bin, true);
|
||||
tk::dnn::Activation a78 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c79 (&net, 512, 1, 1, 1, 1, 0, 0, c79_bin, true);
|
||||
tk::dnn::Activation a79 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c80 (&net,1024, 3, 3, 1, 1, 1, 1, c80_bin, true);
|
||||
tk::dnn::Activation a80 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c81 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c81_bin, false);
|
||||
tk::dnn::Yolo yolo0 (&net, classes, 3, g82_bin);
|
||||
|
||||
tk::dnn::Layer *m83_layers[1] = { &a79 };
|
||||
tk::dnn::Route m83 (&net, m83_layers, 1);
|
||||
tk::dnn::Conv2d c84 (&net, 256, 1, 1, 1, 1, 0, 0, c84_bin, true);
|
||||
tk::dnn::Activation a84 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Upsample u85 (&net, 2);
|
||||
|
||||
tk::dnn::Layer *m86_layers[2] = { &u85, &s61 };
|
||||
tk::dnn::Route m86 (&net, m86_layers, 2);
|
||||
tk::dnn::Conv2d c87 (&net, 256, 1, 1, 1, 1, 0, 0, c87_bin, true);
|
||||
tk::dnn::Activation a87 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c88 (&net, 512, 3, 3, 1, 1, 1, 1, c88_bin, true);
|
||||
tk::dnn::Activation a88 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c89 (&net, 256, 1, 1, 1, 1, 0, 0, c89_bin, true);
|
||||
tk::dnn::Activation a89 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c90 (&net, 512, 3, 3, 1, 1, 1, 1, c90_bin, true);
|
||||
tk::dnn::Activation a90 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c91 (&net, 256, 1, 1, 1, 1, 0, 0, c91_bin, true);
|
||||
tk::dnn::Activation a91 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Conv2d c92 (&net, 512, 3, 3, 1, 1, 1, 1, c92_bin, true);
|
||||
tk::dnn::Activation a92 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c93 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c93_bin, false);
|
||||
tk::dnn::Yolo yolo1 (&net, classes, 3, g94_bin);
|
||||
|
||||
tk::dnn::Layer *m95_layers[1] = { &a91 };
|
||||
tk::dnn::Route m95 (&net, m95_layers, 1);
|
||||
tk::dnn::Conv2d c96 (&net, 128, 1, 1, 1, 1, 0, 0, c96_bin, true);
|
||||
tk::dnn::Activation a96 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Upsample u97 (&net, 2);
|
||||
|
||||
tk::dnn::Layer *m98_layers[2] = { &u97, &s36 };
|
||||
tk::dnn::Route m98 (&net, m98_layers, 2);
|
||||
tk::dnn::Conv2d c99 (&net, 128, 1, 1, 1, 1, 0, 0, c99_bin, true);
|
||||
tk::dnn::Activation a99 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c100 (&net, 256, 3, 3, 1, 1, 1, 1, c100_bin, true);
|
||||
tk::dnn::Activation a100 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c101 (&net, 128, 1, 1, 1, 1, 0, 0, c101_bin, true);
|
||||
tk::dnn::Activation a101 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c102 (&net, 256, 3, 3, 1, 1, 1, 1, c102_bin, true);
|
||||
tk::dnn::Activation a102 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c103 (&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true);
|
||||
tk::dnn::Activation a103 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Conv2d c104 (&net, 256, 3, 3, 1, 1, 1, 1, c104_bin, true);
|
||||
tk::dnn::Activation a104 (&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c105 (&net, preYoloFilters, 1, 1, 1, 1, 0, 0, c105_bin, false);
|
||||
tk::dnn::Yolo yolo2 (&net, classes, 3, g106_bin);
|
||||
|
||||
yolo[0] = &yolo0;
|
||||
yolo[1] = &yolo1;
|
||||
yolo[2] = &yolo2;
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
for(int b=0; b<batchSize; b++) {
|
||||
checkCuda(cudaMemcpy(offset, output_conv + b * 3 * chunk_dim, 2*chunk_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
checkCuda(cudaMemcpy(mask, output_conv + b * 3 * chunk_dim + 2*chunk_dim, chunk_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
// kernel sigmoide
|
||||
// kernel sigmoid
|
||||
activationSIGMOIDForward(mask, mask, chunk_dim);
|
||||
// deformable convolution
|
||||
dcnV2CudaForward(stat, handle,
|
||||
|
||||
@@ -8,7 +8,9 @@ class RouteRT : public IPlugin {
|
||||
*/
|
||||
|
||||
public:
|
||||
RouteRT() {
|
||||
RouteRT(int groups, int group_id) {
|
||||
this->groups = groups;
|
||||
this->group_id = group_id;
|
||||
}
|
||||
|
||||
~RouteRT(){
|
||||
@@ -22,7 +24,7 @@ public:
|
||||
Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override {
|
||||
int out_c = 0;
|
||||
for(int i=0; i<nbInputDims; i++) out_c += inputs[i].d[0];
|
||||
return DimsCHW{out_c, inputs[0].d[1], inputs[0].d[2]};
|
||||
return DimsCHW{out_c/groups, inputs[0].d[1], inputs[0].d[2]};
|
||||
}
|
||||
|
||||
void configure(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, int maxBatchSize) override {
|
||||
@@ -34,6 +36,7 @@ public:
|
||||
}
|
||||
h = inputDims[0].d[1];
|
||||
w = inputDims[0].d[2];
|
||||
c /= groups;
|
||||
}
|
||||
|
||||
int initialize() override {
|
||||
@@ -52,12 +55,15 @@ public:
|
||||
|
||||
dnnType *dstData = reinterpret_cast<dnnType*>(outputs[0]);
|
||||
|
||||
for(int b=0; b<batchSize; b++) {
|
||||
int offset = 0;
|
||||
for(int i=0; i<in; i++) {
|
||||
dnnType *input = (dnnType*)reinterpret_cast<const dnnType*>(inputs[i]);
|
||||
int in_dim = c_in[i]*h*w;
|
||||
checkCuda( cudaMemcpyAsync(dstData + offset, input, in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream) );
|
||||
offset += in_dim;
|
||||
int part_in_dim = in_dim / this->groups;
|
||||
checkCuda( cudaMemcpyAsync(dstData + b*c*w*h + offset, input + b*c*w*h*groups + this->group_id*part_in_dim, part_in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream) );
|
||||
offset += part_in_dim;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -65,11 +71,13 @@ public:
|
||||
|
||||
|
||||
virtual size_t getSerializationSize() override {
|
||||
return (4+MAX_INPUTS)*sizeof(int);
|
||||
return (6+MAX_INPUTS)*sizeof(int);
|
||||
}
|
||||
|
||||
virtual void serialize(void* buffer) override {
|
||||
char *buf = reinterpret_cast<char*>(buffer);
|
||||
tk::dnn::writeBUF(buf, groups);
|
||||
tk::dnn::writeBUF(buf, group_id);
|
||||
tk::dnn::writeBUF(buf, in);
|
||||
for(int i=0; i<MAX_INPUTS; i++)
|
||||
tk::dnn::writeBUF(buf, c_in[i]);
|
||||
@@ -83,4 +91,5 @@ public:
|
||||
int in;
|
||||
int c_in[MAX_INPUTS];
|
||||
int c, h, w;
|
||||
int groups, group_id;
|
||||
};
|
||||
|
||||
@@ -8,12 +8,15 @@ class YoloRT : public IPlugin {
|
||||
|
||||
|
||||
public:
|
||||
YoloRT(int classes, int num, tk::dnn::Yolo *yolo = nullptr, int n_masks=3, float scale_xy=1) {
|
||||
YoloRT(int classes, int num, tk::dnn::Yolo *yolo = nullptr, int n_masks=3, float scale_xy=1, float nms_thresh=0.45, int nms_kind=0, int new_coords=0) {
|
||||
|
||||
this->classes = classes;
|
||||
this->num = num;
|
||||
this->n_masks = n_masks;
|
||||
this->scaleXY = scale_xy;
|
||||
this->nms_thresh = nms_thresh;
|
||||
this->nms_kind = nms_kind;
|
||||
this->new_coords = new_coords;
|
||||
|
||||
mask = new dnnType[n_masks];
|
||||
bias = new dnnType[num*n_masks*2];
|
||||
@@ -64,7 +67,10 @@ public:
|
||||
for (int b = 0; b < batchSize; ++b){
|
||||
for(int n = 0; n < n_masks; ++n){
|
||||
int index = entry_index(b, n*w*h, 0);
|
||||
activationLOGISTICForward(srcData + index, dstData + index, 2*w*h, stream);
|
||||
if (new_coords == 1)
|
||||
activationLOGISTICForward(srcData + index, dstData + index, 4*w*h, stream); //x,y,w,h
|
||||
else
|
||||
activationLOGISTICForward(srcData + index, dstData + index, 2*w*h, stream); //x,y
|
||||
|
||||
if (this->scaleXY != 1) scalAdd(dstData + index, 2 * w*h, this->scaleXY, -0.5*(this->scaleXY - 1), 1);
|
||||
|
||||
@@ -79,7 +85,7 @@ public:
|
||||
|
||||
|
||||
virtual size_t getSerializationSize() override {
|
||||
return 6*sizeof(int) + sizeof(float)+ n_masks*sizeof(dnnType) + num*n_masks*2*sizeof(dnnType) + YOLORT_CLASSNAME_W*classes*sizeof(char);
|
||||
return 8*sizeof(int) + 2*sizeof(float)+ n_masks*sizeof(dnnType) + num*n_masks*2*sizeof(dnnType) + YOLORT_CLASSNAME_W*classes*sizeof(char);
|
||||
}
|
||||
|
||||
virtual void serialize(void* buffer) override {
|
||||
@@ -87,10 +93,13 @@ public:
|
||||
tk::dnn::writeBUF(buf, classes);
|
||||
tk::dnn::writeBUF(buf, num);
|
||||
tk::dnn::writeBUF(buf, n_masks);
|
||||
tk::dnn::writeBUF(buf, scaleXY);
|
||||
tk::dnn::writeBUF(buf, nms_thresh);
|
||||
tk::dnn::writeBUF(buf, nms_kind);
|
||||
tk::dnn::writeBUF(buf, new_coords);
|
||||
tk::dnn::writeBUF(buf, c);
|
||||
tk::dnn::writeBUF(buf, h);
|
||||
tk::dnn::writeBUF(buf, w);
|
||||
tk::dnn::writeBUF(buf, scaleXY);
|
||||
for(int i=0; i<n_masks; i++)
|
||||
tk::dnn::writeBUF(buf, mask[i]);
|
||||
for(int i=0; i<n_masks*2*num; i++)
|
||||
@@ -109,6 +118,9 @@ public:
|
||||
int c, h, w;
|
||||
int classes, num, n_masks;
|
||||
float scaleXY;
|
||||
float nms_thresh;
|
||||
int nms_kind;
|
||||
int new_coords;
|
||||
std::vector<std::string> classesNames;
|
||||
|
||||
dnnType *mask;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
|
||||
#include <tkdnn.h>
|
||||
int testInference(std::vector<std::string> input_bins, std::vector<std::string> output_bins,
|
||||
tk::dnn::Network *net, tk::dnn::NetworkRT *netRT = nullptr) {
|
||||
|
||||
std::vector<tk::dnn::Layer*> outputs;
|
||||
for(int i=0; i<net->num_layers; i++) {
|
||||
if(net->layers[i]->final)
|
||||
outputs.push_back(net->layers[i]);
|
||||
}
|
||||
// no final layers, set last as output
|
||||
if(outputs.size() == 0) {
|
||||
outputs.push_back(net->layers[net->num_layers-1]);
|
||||
}
|
||||
|
||||
|
||||
// check input
|
||||
if(input_bins.size() != 1) {
|
||||
FatalError("currently support only 1 input");
|
||||
}
|
||||
if(output_bins.size() != outputs.size()) {
|
||||
std::cout<<output_bins.size()<<" "<<outputs.size()<<"\n";
|
||||
FatalError("outputs size mismatch");
|
||||
}
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
dnnType *input_h;
|
||||
readBinaryFile(input_bins[0], net->input_dim.tot(), &input_h, &data);
|
||||
|
||||
// outputs
|
||||
dnnType *cudnn_out[outputs.size()], *rt_out[outputs.size()];
|
||||
|
||||
tk::dnn::dataDim_t dim1 = net->input_dim; //input dim
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30); {
|
||||
dim1.print();
|
||||
TKDNN_TSTART
|
||||
net->infer(dim1, data);
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
for(int i=0; i<outputs.size(); i++) cudnn_out[i] = outputs[i]->dstData;
|
||||
|
||||
if(netRT != nullptr) {
|
||||
tk::dnn::dataDim_t dim2 = net->input_dim;
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30); {
|
||||
dim2.print();
|
||||
TKDNN_TSTART
|
||||
netRT->infer(dim2, data);
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
for(int i=0; i<outputs.size(); i++) rt_out[i] = (dnnType*)netRT->buffersRT[i+1];
|
||||
}
|
||||
|
||||
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
|
||||
for(int i=0; i<outputs.size(); i++) {
|
||||
printCenteredTitle((std::string(" OUTPUT ") + std::to_string(i) + " CHECK RESULTS ").c_str(), '=', 30);
|
||||
dnnType *out, *out_h;
|
||||
int odim = outputs[i]->output_dim.tot();
|
||||
readBinaryFile(output_bins[i], odim, &out_h, &out);
|
||||
std::cout<<"CUDNN vs correct";
|
||||
ret_cudnn |= checkResult(odim, cudnn_out[i], out) == 0 ? 0: ERROR_CUDNN;
|
||||
if(netRT != nullptr) {
|
||||
std::cout<<"TRT vs correct";
|
||||
ret_tensorrt |= checkResult(odim, rt_out[i], out) == 0 ? 0 : ERROR_TENSORRT;
|
||||
std::cout<<"CUDNN vs TRT ";
|
||||
ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
|
||||
}
|
||||
|
||||
delete [] out_h;
|
||||
checkCuda( cudaFree(out) );
|
||||
}
|
||||
delete [] input_h;
|
||||
checkCuda( cudaFree(data) );
|
||||
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
|
||||
}
|
||||
@@ -5,4 +5,4 @@
|
||||
#include "Layer.h"
|
||||
#include "NetworkRT.h"
|
||||
|
||||
#define TKDNN_VERSION 400
|
||||
#define TKDNN_VERSION 500
|
||||
|
||||
+11
-4
@@ -36,16 +36,18 @@
|
||||
#define COL_PURPLEB "\033[1;35m"
|
||||
#define COL_CYANB "\033[1;36m"
|
||||
|
||||
#define TKDNN_VERBOSE 0
|
||||
|
||||
// Simple Timer
|
||||
#define TIMER_START timespec start, end; \
|
||||
#define TKDNN_TSTART timespec start, end; \
|
||||
clock_gettime(CLOCK_MONOTONIC, &start);
|
||||
|
||||
#define TIMER_STOP_C(col) clock_gettime(CLOCK_MONOTONIC, &end); \
|
||||
#define TKDNN_TSTOP_C(col, show) clock_gettime(CLOCK_MONOTONIC, &end); \
|
||||
double t_ns = ((double)(end.tv_sec - start.tv_sec) * 1.0e9 + \
|
||||
(double)(end.tv_nsec - start.tv_nsec))/1.0e6; \
|
||||
std::cout<<col<<"Time:"<<std::setw(16)<<t_ns<<" ms\n"<<COL_END;
|
||||
if(show) std::cout<<col<<"Time:"<<std::setw(16)<<t_ns<<" ms\n"<<COL_END;
|
||||
|
||||
#define TIMER_STOP TIMER_STOP_C(COL_CYANB)
|
||||
#define TKDNN_TSTOP TKDNN_TSTOP_C(COL_CYANB, TKDNN_VERBOSE)
|
||||
|
||||
/********************************************************
|
||||
* Prints the error message, and exits
|
||||
@@ -114,5 +116,10 @@ void matrixMulAdd( cublasHandle_t handle, dnnType* srcData, dnnType* dstData,
|
||||
dnnType* add_vector, int dim, dnnType mul);
|
||||
|
||||
void getMemUsage(double& vm_usage_kb, double& resident_set_kb);
|
||||
void printCudaMemUsage();
|
||||
void removePathAndExtension(const std::string &full_string, std::string &name);
|
||||
static inline bool isCudaPointer(void *data) {
|
||||
cudaPointerAttributes attr;
|
||||
return cudaPointerGetAttributes(&attr, data) == 0;
|
||||
}
|
||||
#endif //UTILS_H
|
||||
|
||||
@@ -62,5 +62,5 @@ make -j4
|
||||
sudo make install
|
||||
sudo ldconfig
|
||||
|
||||
cd '~/Downloads/opencv4/lib/python3.6/site-packages'
|
||||
cd ~/Downloads/opencv4/lib/python3.6/site-packages
|
||||
ln -s /usr/local/lib/python3.6/site-packages/cv2.cpython-36m-aarch64-linux-gnu.so cv2.so
|
||||
|
||||
+16
-12
@@ -68,27 +68,31 @@ do
|
||||
export TKDNN_BATCHSIZE=2
|
||||
echo -e "${ORANGE}Batch $TKDNN_BATCHSIZE ${NC}"
|
||||
|
||||
test_net mnist
|
||||
./test_imuodom &>> $out_file
|
||||
print_output $? imuodom
|
||||
|
||||
test_net yolo4
|
||||
test_net resnet101_cnet
|
||||
test_net yolo4x
|
||||
test_net yolo4_berkeley
|
||||
test_net yolo4tiny
|
||||
test_net yolo3
|
||||
test_net yolo3_berkeley
|
||||
test_net yolo3_coco4
|
||||
test_net yolo3_flir
|
||||
test_net yolo3_512
|
||||
test_net yolo3_tiny
|
||||
test_net yolo3tiny
|
||||
test_net yolo3tiny_512
|
||||
test_net yolo2
|
||||
test_net yolo2_voc
|
||||
#test_net yolo2tiny
|
||||
test_net csresnext50-panet-spp
|
||||
test_net mobilenetv2ssd
|
||||
test_net yolo3_tiny512
|
||||
test_net yolo_tiny
|
||||
test_net mobilenetv2ssd512
|
||||
test_net mnist
|
||||
test_net yolo
|
||||
test_net yolo3_berkeley
|
||||
test_net yolo_voc
|
||||
#test_net csresnext50-panet-spp_berkeley
|
||||
test_net resnet101_cnet
|
||||
test_net dla34_cnet
|
||||
test_net yolo3_coco4
|
||||
|
||||
test_net mobilenetv2ssd
|
||||
test_net mobilenetv2ssd512
|
||||
test_net bdd-mobilenetv2ssd
|
||||
done
|
||||
|
||||
echo "If errors occured, check logfile $out_file"
|
||||
|
||||
+20
-17
@@ -3,10 +3,12 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
bool CenternetDetection::init(const std::string& tensor_path, const int n_classes){
|
||||
bool CenternetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh){
|
||||
std::cout<<(tensor_path).c_str()<<"\n";
|
||||
netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str() );
|
||||
classes = n_classes;
|
||||
nBatches = n_batches;
|
||||
confThreshold = conf_thresh;
|
||||
|
||||
dim = netRT->input_dim;
|
||||
|
||||
@@ -41,7 +43,7 @@ bool CenternetDetection::init(const std::string& tensor_path, const int n_classe
|
||||
trans = cv::Mat(cv::Size(3,2), CV_32F);
|
||||
trans2 = cv::Mat(cv::Size(3,2), CV_32F);
|
||||
|
||||
checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*netRT->input_dim.tot()));
|
||||
checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*netRT->input_dim.tot() * nBatches));
|
||||
|
||||
dim_hm = tk::dnn::dataDim_t(1, 80, 128, 128, 1);
|
||||
dim_wh = tk::dnn::dataDim_t(1, 2, 128, 128, 1);
|
||||
@@ -98,7 +100,7 @@ bool CenternetDetection::init(const std::string& tensor_path, const int n_classe
|
||||
checkCuda(cudaMemcpy(mean_d, mean, 3*sizeof(float), cudaMemcpyHostToDevice));
|
||||
checkCuda(cudaMemcpy(stddev_d, stddev, 3*sizeof(float), cudaMemcpyHostToDevice));
|
||||
#else
|
||||
checkCuda(cudaMallocHost(&input, sizeof(dnnType)*netRT->input_dim.tot()));
|
||||
checkCuda(cudaMallocHost(&input, sizeof(dnnType)*netRT->input_dim.tot()* nBatches));
|
||||
mean << 0.408, 0.447, 0.47;
|
||||
stddev << 0.289, 0.274, 0.278;
|
||||
#endif
|
||||
@@ -120,13 +122,13 @@ bool CenternetDetection::init(const std::string& tensor_path, const int n_classe
|
||||
}
|
||||
|
||||
|
||||
void CenternetDetection::preprocess(cv::Mat &frame){
|
||||
void CenternetDetection::preprocess(cv::Mat &frame, const int bi){
|
||||
// -----------------------------------pre-process ------------------------------------------
|
||||
|
||||
// auto start_t = std::chrono::steady_clock::now();
|
||||
// auto step_t = std::chrono::steady_clock::now();
|
||||
// auto end_t = std::chrono::steady_clock::now();
|
||||
cv::Size sz = originalSize;
|
||||
cv::Size sz = originalSize[bi];
|
||||
// std::cout<<"image: "<<sz.width<<", "<<sz.height<<std::endl;
|
||||
cv::Size sz_old;
|
||||
float scale = 1.0;
|
||||
@@ -212,7 +214,7 @@ void CenternetDetection::preprocess(cv::Mat &frame){
|
||||
// std::cout << " TIME normalize: " << std::chrono::duration_cast<std::chrono:: microseconds>(end_t - step_t).count() << " us" << std::endl;
|
||||
// step_t = end_t;
|
||||
|
||||
checkCuda(cudaMemcpy(input_d, d_ptrs, dim2.tot()*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
checkCuda(cudaMemcpy(input_d+ netRT->input_dim.tot()*bi, d_ptrs, dim2.tot()*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
|
||||
// end_t = std::chrono::steady_clock::now();
|
||||
// std::cout << " TIME Memcpy to input_d: " << std::chrono::duration_cast<std::chrono:: microseconds>(end_t - step_t).count() << " us" << std::endl;
|
||||
@@ -254,18 +256,18 @@ void CenternetDetection::preprocess(cv::Mat &frame){
|
||||
int idx = i*imageF.rows*imageF.cols;
|
||||
int ch = dim2.c-3 +i;
|
||||
// std::cout<<"i: "<<i<<", idx: "<<idx<<", ch: "<<ch<<std::endl;
|
||||
memcpy((void*)&input[idx], (void*)bgr[ch].data, imageF.rows*imageF.cols*sizeof(dnnType));
|
||||
memcpy((void*)&input[idx+ netRT->input_dim.tot()*bi], (void*)bgr[ch].data, imageF.rows*imageF.cols*sizeof(dnnType));
|
||||
}
|
||||
checkCuda(cudaMemcpyAsync(input_d, input, dim2.tot()*sizeof(dnnType), cudaMemcpyHostToDevice));
|
||||
checkCuda(cudaMemcpyAsync(input_d+ netRT->input_dim.tot()*bi, input+ netRT->input_dim.tot()*bi, dim2.tot()*sizeof(dnnType), cudaMemcpyHostToDevice));
|
||||
#endif
|
||||
}
|
||||
|
||||
void CenternetDetection::postprocess(){
|
||||
void CenternetDetection::postprocess(const int bi, const bool mAP){
|
||||
dnnType *rt_out[4];
|
||||
rt_out[0] = (dnnType *)netRT->buffersRT[1];
|
||||
rt_out[1] = (dnnType *)netRT->buffersRT[2];
|
||||
rt_out[2] = (dnnType *)netRT->buffersRT[3];
|
||||
rt_out[3] = (dnnType *)netRT->buffersRT[4];
|
||||
rt_out[0] = (dnnType *)netRT->buffersRT[1]+ netRT->buffersDIM[1].tot()*bi;
|
||||
rt_out[1] = (dnnType *)netRT->buffersRT[2]+ netRT->buffersDIM[2].tot()*bi;
|
||||
rt_out[2] = (dnnType *)netRT->buffersRT[3]+ netRT->buffersDIM[3].tot()*bi;
|
||||
rt_out[3] = (dnnType *)netRT->buffersRT[4]+ netRT->buffersDIM[4].tot()*bi;
|
||||
|
||||
// auto start_t = std::chrono::steady_clock::now();
|
||||
// auto step_t = std::chrono::steady_clock::now();
|
||||
@@ -370,10 +372,10 @@ void CenternetDetection::postprocess(){
|
||||
// std::cout<<"th: "<<scores[j]<<" - cl: "<<clses[j]<<" i: "<<i<<std::endl;
|
||||
//add coco bbox
|
||||
//det[0:4], i, det[4]
|
||||
int x0 = target_coords[j*4];
|
||||
int y0 = target_coords[j*4+1];
|
||||
int x1 = target_coords[j*4+2];
|
||||
int y1 = target_coords[j*4+3];
|
||||
float x0 = target_coords[j*4];
|
||||
float y0 = target_coords[j*4+1];
|
||||
float x1 = target_coords[j*4+2];
|
||||
float y1 = target_coords[j*4+3];
|
||||
int obj_class = clses[j];
|
||||
float prob = scores[j];
|
||||
// std::cout<<"("<<x0<<", "<<y0<<"),("<<x1<<", "<<y1<<")"<<std::endl;
|
||||
@@ -389,6 +391,7 @@ void CenternetDetection::postprocess(){
|
||||
}
|
||||
}
|
||||
|
||||
batchDetected.push_back(detected);
|
||||
// end_t = std::chrono::steady_clock::now();
|
||||
// std::cout << " TIME detections: " << std::chrono::duration_cast<std::chrono:: microseconds>(end_t - step_t).count() << " us" << std::endl;
|
||||
// step_t = end_t;
|
||||
|
||||
+14
-9
@@ -62,25 +62,30 @@ void Conv2d::initCUDNN(bool back) {
|
||||
// init workspace
|
||||
workSpace = NULL;
|
||||
ws_sizeInBytes = 0;
|
||||
int algo_count = 0;
|
||||
if(back) {
|
||||
checkCUDNN( cudnnGetConvolutionBackwardDataAlgorithm(net->cudnnHandle,
|
||||
filterDesc, dstTensor, convDesc, srcTensor,
|
||||
CUDNN_CONVOLUTION_BWD_DATA_PREFER_FASTEST, 0, &bwAlgo) );
|
||||
checkCUDNN( cudnnGetConvolutionBackwardDataAlgorithm_v7(net->cudnnHandle,
|
||||
filterDesc, dstTensor, convDesc, srcTensor, 1, &algo_count, &bwAlgo) );
|
||||
checkCUDNN(cudnnGetConvolutionBackwardDataWorkspaceSize(net->cudnnHandle,
|
||||
filterDesc, dstTensor, convDesc, srcTensor,
|
||||
bwAlgo, &ws_sizeInBytes));
|
||||
bwAlgo.algo, &ws_sizeInBytes));
|
||||
|
||||
|
||||
// invert tensors
|
||||
srcTensorDesc = dstTensor;
|
||||
dstTensorDesc = srcTensor;
|
||||
} else {
|
||||
checkCUDNN( cudnnGetConvolutionForwardAlgorithm(net->cudnnHandle,
|
||||
|
||||
checkCUDNN( cudnnGetConvolutionForwardAlgorithm_v7(net->cudnnHandle,
|
||||
srcTensor, filterDesc, convDesc, dstTensor,
|
||||
CUDNN_CONVOLUTION_FWD_PREFER_FASTEST, 0, &algo) );
|
||||
1, &algo_count, &algo) );
|
||||
checkCUDNN(cudnnGetConvolutionForwardWorkspaceSize(net->cudnnHandle,
|
||||
srcTensor, filterDesc, convDesc, dstTensor,
|
||||
algo, &ws_sizeInBytes));
|
||||
algo.algo, &ws_sizeInBytes));
|
||||
}
|
||||
|
||||
if(algo_count < 1)
|
||||
FatalError("Cannot retrieve convolutional algo");
|
||||
}
|
||||
|
||||
void Conv2d::inferCUDNN(dnnType* srcData, bool back) {
|
||||
@@ -91,12 +96,12 @@ void Conv2d::inferCUDNN(dnnType* srcData, bool back) {
|
||||
checkCUDNN(cudnnConvolutionBackwardData(net->cudnnHandle,
|
||||
&alpha, filterDesc, data_d,
|
||||
srcTensorDesc, srcData,
|
||||
convDesc, bwAlgo, workSpace, ws_sizeInBytes,
|
||||
convDesc, bwAlgo.algo, workSpace, ws_sizeInBytes,
|
||||
&beta, dstTensorDesc, dstData));
|
||||
} else {
|
||||
checkCUDNN(cudnnConvolutionForward(net->cudnnHandle,
|
||||
&alpha, srcTensorDesc, srcData, filterDesc,
|
||||
data_d, convDesc, algo, workSpace, ws_sizeInBytes,
|
||||
data_d, convDesc, algo.algo, workSpace, ws_sizeInBytes,
|
||||
&beta, dstTensorDesc, dstData));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,273 @@
|
||||
#include "tkDNN/DarknetParser.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
std::string darknetParseType(const std::string& line){
|
||||
size_t start = line.find("[");
|
||||
size_t end = line.find("]");
|
||||
if( start == std::string::npos || end == std::string::npos)
|
||||
return "";
|
||||
start++;
|
||||
std::string type = line.substr(start, end-start);
|
||||
return type;
|
||||
}
|
||||
|
||||
bool divideNameAndValue(const std::string& line, std::string&name, std::string& value){
|
||||
size_t sep = line.find("=");
|
||||
if(sep == std::string::npos)
|
||||
return false;
|
||||
|
||||
name = line.substr(0, sep);
|
||||
value = line.substr(sep+1, line.size() - (sep+1));
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<int> fromStringToIntVec(const std::string& line, const char delimiter){
|
||||
std::stringstream linestream(line);
|
||||
std::string value;
|
||||
std::vector<int> values;
|
||||
|
||||
while(getline(linestream,value,delimiter))
|
||||
values.push_back(std::stoi(value));
|
||||
return values;
|
||||
}
|
||||
|
||||
bool darknetParseFields(const std::string& line, darknetFields_t& fields){
|
||||
|
||||
std::string name,value;
|
||||
if(!divideNameAndValue(line, name, value))
|
||||
return false;
|
||||
|
||||
if(name.find("new_coords") != std::string::npos)
|
||||
fields.new_coords = std::stoi(value);
|
||||
else if(name.find("width") != std::string::npos)
|
||||
fields.width = std::stoi(value);
|
||||
else if(name.find("height") != std::string::npos)
|
||||
fields.height = std::stoi(value);
|
||||
else if(name.find("channels") != std::string::npos)
|
||||
fields.channels = std::stoi(value);
|
||||
else if(name.find("batch_normalize") != std::string::npos)
|
||||
fields.batch_normalize = std::stoi(value);
|
||||
else if(name.find("filters") != std::string::npos)
|
||||
fields.filters = std::stoi(value);
|
||||
else if(name.find("activation") != std::string::npos)
|
||||
fields.activation = value;
|
||||
else if(name.find("size") != std::string::npos){
|
||||
fields.size_x = std::stoi(value);
|
||||
fields.size_y = std::stoi(value);
|
||||
}
|
||||
else if(name.find("size_x") != std::string::npos)
|
||||
fields.size_x = std::stoi(value);
|
||||
else if(name.find("size_y") != std::string::npos)
|
||||
fields.size_y = std::stoi(value);
|
||||
else if(name.find("stride") != std::string::npos){
|
||||
fields.stride_x = std::stoi(value);
|
||||
fields.stride_y = std::stoi(value);
|
||||
}
|
||||
else if(name.find("stride_x") != std::string::npos)
|
||||
fields.stride_x = std::stoi(value);
|
||||
else if(name.find("stride_y") != std::string::npos)
|
||||
fields.stride_y = std::stoi(value);
|
||||
else if(name.find("pad") != std::string::npos)
|
||||
fields.pad = std::stoi(value);
|
||||
else if(name.find("classes") != std::string::npos)
|
||||
fields.classes = std::stoi(value);
|
||||
else if(name.find("num") != std::string::npos)
|
||||
fields.num = std::stoi(value);
|
||||
else if(name.find("coords") != std::string::npos)
|
||||
fields.coords = std::stoi(value);
|
||||
else if(name.find("groups") != std::string::npos)
|
||||
fields.groups = std::stoi(value);
|
||||
else if(name.find("group_id") != std::string::npos)
|
||||
fields.group_id = std::stoi(value);
|
||||
else if(name.find("scale_x_y") != std::string::npos)
|
||||
fields.scale_xy = std::stof(value);
|
||||
else if(name.find("beta_nms") != std::string::npos)
|
||||
fields.nms_thresh = std::stof(value);
|
||||
else if(name.find("nms_kind") != std::string::npos){
|
||||
if(value == "greedynms") fields.nms_kind = 0;
|
||||
else if(value == "diounms") fields.nms_kind = 1;
|
||||
else std::cout<<"Not supported nms_kind "<<value<<", setting to greedynms"<<std::endl;
|
||||
}
|
||||
else if(name.find("from") != std::string::npos)
|
||||
fields.layers.push_back(std::stof(value));
|
||||
else if(name.find("mask") != std::string::npos){
|
||||
auto vec = fromStringToIntVec(value, ',');
|
||||
fields.n_mask = vec.size();
|
||||
}
|
||||
else if(name.find("layers") != std::string::npos)
|
||||
fields.layers = fromStringToIntVec(value, ',');
|
||||
|
||||
else
|
||||
std::cout<<"Not supported field: "<<line<<std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
tk::dnn::Network *darknetAddNet(darknetFields_t &fields) {
|
||||
//std::cout<<"Add Net: "<<fields.type<<"\n";
|
||||
dataDim_t dim(1, fields.channels, fields.height, fields.width);
|
||||
return new tk::dnn::Network(dim);
|
||||
}
|
||||
|
||||
|
||||
void darknetAddLayer(tk::dnn::Network *net, darknetFields_t &f, std::string wgs_path, std::vector<tk::dnn::Layer*> &netLayers, const std::vector<std::string>& names) {
|
||||
if(net == nullptr)
|
||||
FatalError("Cant add a layer without a Net\n");
|
||||
|
||||
// padding compute
|
||||
if(f.pad == 1) {
|
||||
f.padding_x = f.padding_y = f.size_x /2;
|
||||
}
|
||||
//std::cout<<"Add layer: "<<f.type<<"\n";
|
||||
if(f.type == "convolutional") {
|
||||
std::string wgs = wgs_path + "/c" + std::to_string(netLayers.size()) + ".bin";
|
||||
//printf("%d (%d,%d) (%d,%d) (%d,%d) %s %d %d\n", f.filters, f.size_x, f.size_y, f.stride_x, f.stride_y, f.padding_x, f.padding_y, wgs.c_str(), f.batch_normalize, f.groups);
|
||||
tk::dnn::Conv2d *l= new tk::dnn::Conv2d(net, f.filters, f.size_x, f.size_y, f.stride_x,
|
||||
f.stride_y, f.padding_x, f.padding_y, wgs, f.batch_normalize, false, f.groups);
|
||||
netLayers.push_back(l);
|
||||
} else if(f.type == "maxpool") {
|
||||
if(f.stride_x == 1 && f.stride_y == 1)
|
||||
netLayers.push_back(new tk::dnn::Pooling(net, f.size_x, f.size_y, f.stride_x, f.stride_y,
|
||||
f.padding_x, f.padding_y, tk::dnn::POOLING_MAX_FIXEDSIZE));
|
||||
else
|
||||
netLayers.push_back(new tk::dnn::Pooling(net, f.size_x, f.size_y, f.stride_x, f.stride_y,
|
||||
f.padding_x, f.padding_y, tk::dnn::POOLING_MAX));
|
||||
|
||||
} else if(f.type == "avgpool") {
|
||||
netLayers.push_back(new tk::dnn::Pooling(net, f.size_x, f.size_y, f.stride_x, f.stride_y,
|
||||
f.padding_x, f.padding_y, tk::dnn::POOLING_AVERAGE));
|
||||
|
||||
} else if(f.type == "shortcut") {
|
||||
if(f.layers.size() != 1) FatalError("no layers to shortcut\n");
|
||||
int layerIdx = f.layers[0];
|
||||
if(layerIdx < 0)
|
||||
layerIdx = netLayers.size() + layerIdx;
|
||||
if(layerIdx < 0 || layerIdx >= netLayers.size()) FatalError("impossible to shortcut\n");
|
||||
//std::cout<<"shortcut to "<<layerIdx<<" "<<netLayers[layerIdx]->getLayerName()<<"\n";
|
||||
netLayers.push_back(new tk::dnn::Shortcut(net, netLayers[layerIdx]));
|
||||
|
||||
} else if(f.type == "upsample") {
|
||||
netLayers.push_back(new tk::dnn::Upsample(net, f.stride_x));
|
||||
|
||||
} else if(f.type == "route") {
|
||||
if(f.layers.size() == 0) FatalError("no layers to Route\n");
|
||||
std::vector<tk::dnn::Layer*> layers;
|
||||
for(int i=0; i<f.layers.size(); i++) {
|
||||
int layerIdx = f.layers[i];
|
||||
if(layerIdx < 0)
|
||||
layerIdx = netLayers.size() + layerIdx;
|
||||
if(layerIdx < 0 || layerIdx >= netLayers.size()) FatalError("impossible to route\n");
|
||||
//std::cout<<"Route to "<<layerIdx<<" "<<netLayers[layerIdx]->getLayerName()<<"\n";
|
||||
layers.push_back(netLayers[layerIdx]);
|
||||
}
|
||||
netLayers.push_back(new tk::dnn::Route(net, layers.data(), layers.size(), f.groups, f.group_id));
|
||||
|
||||
} else if(f.type == "reorg") {
|
||||
netLayers.push_back(new tk::dnn::Reorg(net, f.stride_x));
|
||||
|
||||
} else if(f.type == "region") {
|
||||
netLayers.push_back(new tk::dnn::Region(net, f.classes, f.coords, f.num));
|
||||
|
||||
} else if(f.type == "yolo") {
|
||||
std::string wgs = wgs_path + "/g" + std::to_string(netLayers.size()) + ".bin";
|
||||
//printf("%d %d %s %d %f\n", f.classes, f.num/f.n_mask, wgs.c_str(), f.n_mask, f.scale_xy);
|
||||
tk::dnn::Yolo *l = new tk::dnn::Yolo(net, f.classes, f.num/f.n_mask, wgs, f.n_mask, f.scale_xy, f.nms_thresh, (tk::dnn::Yolo::nmsKind_t) f.nms_kind, f.new_coords);
|
||||
if(names.size() != f.classes)
|
||||
FatalError("Mismatch between number of classes and names");
|
||||
l->classesNames = names;
|
||||
netLayers.push_back(l);
|
||||
|
||||
} else{
|
||||
FatalError("layer not supported: " + f.type);
|
||||
}
|
||||
|
||||
// add activation
|
||||
if(netLayers.size() > 0 && f.activation != "linear") {
|
||||
tkdnnActivationMode_t act;
|
||||
if(f.activation == "relu") act = tkdnnActivationMode_t(CUDNN_ACTIVATION_RELU);
|
||||
else if(f.activation == "leaky") act = tk::dnn::ACTIVATION_LEAKY;
|
||||
else if(f.activation == "mish") act = tk::dnn::ACTIVATION_MISH;
|
||||
else { FatalError("activation not supported: " + f.activation); }
|
||||
netLayers[netLayers.size()-1] = new tk::dnn::Activation(net, act);
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<std::string> darknetReadNames(const std::string& names_file){
|
||||
std::ifstream if_names(names_file);
|
||||
if(!if_names.is_open())
|
||||
FatalError("cloud not open names file: " + names_file);
|
||||
|
||||
std::vector<std::string> names;
|
||||
std::string line;
|
||||
while(std::getline(if_names, line))
|
||||
if(line != "")
|
||||
names.push_back(line);
|
||||
|
||||
if_names.close();
|
||||
return names;
|
||||
}
|
||||
|
||||
tk::dnn::Network* darknetParser(const std::string& cfg_file, const std::string& wgs_path, const std::string& names_file) {
|
||||
|
||||
tk::dnn::Network *net = nullptr;
|
||||
|
||||
// layers without activations to retrieve correct id number
|
||||
std::vector<tk::dnn::Layer*> netLayers;
|
||||
|
||||
std::ifstream if_cfg(cfg_file);
|
||||
if(!if_cfg.is_open())
|
||||
FatalError("cloud not open cfg file: " + cfg_file);
|
||||
|
||||
std::vector<std::string> names = darknetReadNames(names_file);
|
||||
|
||||
darknetFields_t fields; // will be filled with layers fields
|
||||
std::string line;
|
||||
while(std::getline(if_cfg, line)) {
|
||||
// remove comments
|
||||
std::size_t found = line.find("#");
|
||||
if ( found != std::string::npos ) {
|
||||
line = line.substr(0, found);
|
||||
}
|
||||
|
||||
// skip empty lines
|
||||
if(line.size() == 0)
|
||||
continue;
|
||||
|
||||
std::string type = darknetParseType(line);
|
||||
if(type.size() > 0) {
|
||||
// end of filled type
|
||||
if(fields.type != "") {
|
||||
if(fields.type == "net")
|
||||
net = darknetAddNet(fields);
|
||||
else
|
||||
darknetAddLayer(net, fields, wgs_path, netLayers, names);
|
||||
}
|
||||
|
||||
// new type
|
||||
//std::cout<<"type: "<<type<<"\n";
|
||||
fields = darknetFields_t(); // reset to default
|
||||
fields.type = type;
|
||||
continue;
|
||||
}
|
||||
|
||||
if(darknetParseFields(line, fields)) {
|
||||
// already parsed do nothing
|
||||
} else {
|
||||
FatalError("could not parse line: " + line);
|
||||
}
|
||||
}
|
||||
|
||||
// end of filled type
|
||||
if(fields.type != "") {
|
||||
darknetAddLayer(net, fields, wgs_path, netLayers, names);
|
||||
}
|
||||
|
||||
if(net == nullptr) {
|
||||
FatalError("net not found\n");
|
||||
}
|
||||
return net;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}}
|
||||
@@ -95,7 +95,7 @@ dnnType* DeformConv2d::infer(dataDim_t &dim, dnnType* srcData) {
|
||||
// split conv2d outputs into offset and mask
|
||||
checkCuda(cudaMemcpy(offset, output_conv, 2*chunk_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
checkCuda(cudaMemcpy(mask, output_conv + 2*chunk_dim, chunk_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
// kernel sigmoide
|
||||
// kernel sigmoid
|
||||
activationSIGMOIDForward(mask, mask, chunk_dim);
|
||||
|
||||
// deformable convolution
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ dnnType* Dense::infer(dataDim_t &dim, dnnType* srcData) {
|
||||
// place bias into dstData
|
||||
checkCuda( cudaMemcpy(dstData, bias_d, dim_y*sizeof(dnnType), cudaMemcpyDeviceToDevice) );
|
||||
|
||||
//do matrix moltiplication
|
||||
//do matrix multiplication
|
||||
checkERROR( cublasSgemv(net->cublasHandle, CUBLAS_OP_T,
|
||||
dim_x, dim_y,
|
||||
&alpha,
|
||||
|
||||
+6
-13
@@ -132,21 +132,14 @@ void BatchStream::readCVimage(std::string inputFileName, std::vector<float>& res
|
||||
|
||||
void BatchStream::readLabels(std::string inputFileName, std::vector<float>& ris) {
|
||||
std::ifstream is(inputFileName.c_str());
|
||||
//read only the first number: the image sub-portion class
|
||||
while (true) {
|
||||
|
||||
std::string line;
|
||||
while (std::getline(is, line))
|
||||
{
|
||||
std::istringstream iss(line);
|
||||
float val;
|
||||
is >> val;
|
||||
if (!is) {
|
||||
break;
|
||||
}
|
||||
// insert the first number and skip all others
|
||||
if(!(iss >> val)) { break; } // error
|
||||
ris.push_back(val);
|
||||
while( true ) {
|
||||
char c;
|
||||
is >> c;
|
||||
if (is.peek() == '\n') //detect "\n"
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -86,7 +86,11 @@ LSTM::LSTM( Network *net, int hiddensize, bool returnSeq, std::string fname_weig
|
||||
// RNN descriptors
|
||||
checkCUDNN(cudnnCreateRNNDescriptor(&rnnDesc));
|
||||
|
||||
#if CUDNN_MAJOR > 7
|
||||
checkCUDNN(cudnnSetRNNDescriptor_v6(net->cudnnHandle,
|
||||
#else
|
||||
checkCUDNN(cudnnSetRNNDescriptor(net->cudnnHandle,
|
||||
#endif
|
||||
rnnDesc, stateSize, numLayers, dropoutDesc,
|
||||
cudnnRNNInputMode_t::CUDNN_LINEAR_INPUT,
|
||||
//(bidirectional ? cudnnDirectionMode_t::CUDNN_BIDIRECTIONAL : cudnnDirectionMode_t::CUDNN_UNIDIRECTIONAL),
|
||||
@@ -129,7 +133,7 @@ LSTM::LSTM( Network *net, int hiddensize, bool returnSeq, std::string fname_weig
|
||||
output_dim = input_dim;
|
||||
output_dim.c = stateSize*(bidirectional ? 2 : 1);
|
||||
|
||||
// if retunseq is disabled only the last timestep is returned
|
||||
// if retunseq is disabled only the last timestamp is returned
|
||||
if(!returnSeq) {
|
||||
output_dim.h = 1;
|
||||
output_dim.w = 1;
|
||||
@@ -303,7 +307,7 @@ dnnType* LSTM::infer(dataDim_t &dim, dnnType* srcData) {
|
||||
one_output_dim.c*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
}
|
||||
|
||||
// if retunseq is disabled only the last timestep is returned
|
||||
// if retunseq is disabled only the last timestamp is returned
|
||||
if(returnSeq) {
|
||||
// forward transpose
|
||||
matrixTranspose(net->cublasHandle, dstF, dstData,
|
||||
|
||||
@@ -24,6 +24,11 @@ Layer::~Layer() {
|
||||
|
||||
checkCUDNN( cudnnDestroyTensorDescriptor(srcTensorDesc) );
|
||||
checkCUDNN( cudnnDestroyTensorDescriptor(dstTensorDesc) );
|
||||
|
||||
if(dstData != nullptr) {
|
||||
cudaFree(dstData);
|
||||
dstData = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
+5
-16
@@ -95,7 +95,6 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs,
|
||||
cudaMemcpy(power16_h, power16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
|
||||
//mean array
|
||||
|
||||
cudaMemcpy(tmp_d, mean_h, b_size*sizeof(float), cudaMemcpyHostToDevice);
|
||||
float2half(tmp_d, mean16_d, b_size);
|
||||
cudaMemcpy(mean16_h, mean16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
@@ -106,27 +105,17 @@ LayerWgs::LayerWgs(Network *net, int inputs, int outputs,
|
||||
float2half(tmp_d, variance16_d, b_size);
|
||||
cudaMemcpy(variance16_h, variance16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
|
||||
//conver scales
|
||||
//convert scales
|
||||
float2half(scales_d, scales16_d, b_size);
|
||||
cudaMemcpy(scales16_h, scales16_d, b_size*sizeof(__half), cudaMemcpyDeviceToHost);
|
||||
|
||||
cudaFree(tmp_d);
|
||||
}
|
||||
}
|
||||
|
||||
LayerWgs::~LayerWgs() {
|
||||
|
||||
delete [] data_h;
|
||||
delete [] bias_h;
|
||||
checkCuda( cudaFree(data_d) );
|
||||
checkCuda( cudaFree(bias_d) );
|
||||
|
||||
if(batchnorm) {
|
||||
delete [] scales_h;
|
||||
delete [] mean_h;
|
||||
delete [] variance_h;
|
||||
checkCuda( cudaFree(scales_d) );
|
||||
checkCuda( cudaFree(mean_d) );
|
||||
checkCuda( cudaFree(variance_d) );
|
||||
}
|
||||
releaseHost();
|
||||
releaseDevice();
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
+19
-12
@@ -126,11 +126,13 @@ float MobilenetDetection::iou(const tk::dnn::box &a, const tk::dnn::box &b){
|
||||
return iou;
|
||||
}
|
||||
|
||||
bool MobilenetDetection::init(const std::string& tensor_path, const int n_classes){
|
||||
bool MobilenetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh){
|
||||
std::cout<<(tensor_path).c_str()<<"\n";
|
||||
netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str());
|
||||
imageSize = netRT->input_dim.h;
|
||||
classes = n_classes;
|
||||
nBatches = n_batches;
|
||||
confThreshold = conf_thresh;
|
||||
|
||||
SSDSpec specs[N_SSDSPEC];
|
||||
|
||||
@@ -157,9 +159,9 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe
|
||||
generate_ssd_priors(specs, N_SSDSPEC);
|
||||
|
||||
#ifndef OPENCV_CUDACONTRIB
|
||||
checkCuda(cudaMallocHost(&input, sizeof(dnnType) * netRT->input_dim.tot()));
|
||||
checkCuda(cudaMallocHost(&input, sizeof(dnnType) * netRT->input_dim.tot() * nBatches));
|
||||
#endif
|
||||
checkCuda(cudaMalloc(&input_d, sizeof(dnnType) * netRT->input_dim.tot()));
|
||||
checkCuda(cudaMalloc(&input_d, sizeof(dnnType) * netRT->input_dim.tot() * nBatches));
|
||||
|
||||
locations_h = (float *)malloc(N_COORDS * nPriors * sizeof(float));
|
||||
confidences_h = (float *)malloc(nPriors * classes * sizeof(float));
|
||||
@@ -208,7 +210,7 @@ bool MobilenetDetection::init(const std::string& tensor_path, const int n_classe
|
||||
return 1;
|
||||
}
|
||||
|
||||
void MobilenetDetection::preprocess(cv::Mat &frame){
|
||||
void MobilenetDetection::preprocess(cv::Mat &frame, const int bi){
|
||||
#ifdef OPENCV_CUDACONTRIB
|
||||
//move original image on GPU
|
||||
cv::cuda::GpuMat orig_img, frame_nomean;
|
||||
@@ -224,7 +226,7 @@ void MobilenetDetection::preprocess(cv::Mat &frame){
|
||||
|
||||
for(int i=0; i < netRT->input_dim.c; i++){
|
||||
int idx = i * imagePreproc.rows * imagePreproc.cols;
|
||||
checkCuda( cudaMemcpy((void *)&input_d[idx], (void *)bgr[i].data, imagePreproc.rows * imagePreproc.cols* sizeof(float), cudaMemcpyDeviceToDevice) );
|
||||
checkCuda( cudaMemcpy((void *)&input_d[idx + netRT->input_dim.tot()*bi], (void *)bgr[i].data, imagePreproc.rows * imagePreproc.cols* sizeof(float), cudaMemcpyDeviceToDevice) );
|
||||
}
|
||||
#else
|
||||
//resize image, remove mean, divide by std
|
||||
@@ -237,17 +239,17 @@ void MobilenetDetection::preprocess(cv::Mat &frame){
|
||||
cv::split(imagePreproc, bgr);
|
||||
for (int i = 0; i < netRT->input_dim.c; i++){
|
||||
int idx = i * imagePreproc.rows * imagePreproc.cols;
|
||||
memcpy((void *)&input[idx], (void *)bgr[i].data, imagePreproc.rows * imagePreproc.cols * sizeof(dnnType));
|
||||
memcpy((void *)&input[idx + netRT->input_dim.tot()*bi], (void *)bgr[i].data, imagePreproc.rows * imagePreproc.cols * sizeof(dnnType));
|
||||
}
|
||||
checkCuda(cudaMemcpyAsync(input_d, input, netRT->input_dim.tot() * sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream));
|
||||
checkCuda(cudaMemcpyAsync(input_d+ netRT->input_dim.tot()*bi, input + netRT->input_dim.tot()*bi, netRT->input_dim.tot() * sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream));
|
||||
#endif
|
||||
}
|
||||
|
||||
void MobilenetDetection::postprocess(){
|
||||
void MobilenetDetection::postprocess(const int bi, const bool mAP){
|
||||
//get confidences and locations_h
|
||||
dnnType *rt_out[2];
|
||||
rt_out[0] = (dnnType *)netRT->buffersRT[3];
|
||||
rt_out[1] = (dnnType *)netRT->buffersRT[4];
|
||||
rt_out[0] = (dnnType *)netRT->buffersRT[3]+ netRT->buffersDIM[3].tot()*bi;
|
||||
rt_out[1] = (dnnType *)netRT->buffersRT[4]+ netRT->buffersDIM[4].tot()*bi;
|
||||
|
||||
detected.clear();
|
||||
|
||||
@@ -255,8 +257,8 @@ void MobilenetDetection::postprocess(){
|
||||
checkCuda(cudaMemcpy(locations_h, rt_out[1], N_COORDS * nPriors * sizeof(float), cudaMemcpyDeviceToHost));
|
||||
convert_locatios_to_boxes_and_center();
|
||||
|
||||
int width = originalSize.width;
|
||||
int height = originalSize.height;
|
||||
int width = originalSize[bi].width;
|
||||
int height = originalSize[bi].height;
|
||||
|
||||
float *conf_per_class;
|
||||
for (int i = 1; i < classes; i++){
|
||||
@@ -273,6 +275,10 @@ void MobilenetDetection::postprocess(){
|
||||
b.w = locations_h[j * N_COORDS + 2];
|
||||
b.h = locations_h[j * N_COORDS + 3];
|
||||
|
||||
if(mAP)
|
||||
for(int c=1; c<classes; c++)
|
||||
b.probs.push_back(confidences_h[c * nPriors + j]);
|
||||
|
||||
boxes.push_back(b);
|
||||
}
|
||||
}
|
||||
@@ -298,6 +304,7 @@ void MobilenetDetection::postprocess(){
|
||||
boxes = remaining;
|
||||
}
|
||||
}
|
||||
batchDetected.push_back(detected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ MulAdd::MulAdd(Network *net, dnnType mul, dnnType add) : Layer(net) {
|
||||
|
||||
int size = input_dim.tot();
|
||||
|
||||
// create a vector with all value setted to add
|
||||
// create a vector with all value set to add
|
||||
dnnType *add_vector_h = new dnnType[size];
|
||||
for(int i=0; i<size; i++)
|
||||
add_vector_h[i] = add;
|
||||
|
||||
+7
-1
@@ -59,11 +59,16 @@ Network::Network(dataDim_t input_dim) {
|
||||
}
|
||||
|
||||
Network::~Network() {
|
||||
|
||||
checkCUDNN( cudnnDestroy(cudnnHandle) );
|
||||
checkERROR( cublasDestroy(cublasHandle) );
|
||||
}
|
||||
|
||||
void Network::releaseLayers() {
|
||||
for(int i=0; i<num_layers; i++)
|
||||
delete layers[i];
|
||||
num_layers = 0;
|
||||
}
|
||||
|
||||
dnnType* Network::infer(dataDim_t &dim, dnnType* data) {
|
||||
|
||||
//do infer for every layer
|
||||
@@ -123,6 +128,7 @@ void Network::print() {
|
||||
}
|
||||
printCenteredTitle("", '=', 60);
|
||||
std::cout<<"\n";
|
||||
printCudaMemUsage();
|
||||
}
|
||||
const char *Network::getNetworkRTName(const char *network_name){
|
||||
networkName = network_name;
|
||||
|
||||
+22
-14
@@ -122,7 +122,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
input = Ilay->getOutput(0);
|
||||
input->setName( (l->getLayerName() + std::to_string(i) + "_out").c_str() );
|
||||
|
||||
if(l->getLayerType() == LAYER_YOLO || l->final)
|
||||
if(l->final)
|
||||
networkRT->markOutput(*input);
|
||||
tensors[l] = input;
|
||||
}
|
||||
@@ -134,6 +134,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
networkRT->markOutput(*input);
|
||||
|
||||
std::cout<<"Selected maxBatchSize: "<<builderRT->getMaxBatchSize()<<"\n";
|
||||
printCudaMemUsage();
|
||||
std::cout<<"Building tensorRT cuda engine...\n";
|
||||
#if NV_TENSORRT_MAJOR >= 6
|
||||
engineRT = builderRT->buildEngineWithConfig(*networkRT, *configRT);
|
||||
@@ -162,7 +163,7 @@ NetworkRT::NetworkRT(Network *net, const char *name) {
|
||||
// note that indices are guaranteed to be less than IEngine::getNbBindings()
|
||||
buf_input_idx = engineRT->getBindingIndex("data");
|
||||
buf_output_idx = engineRT->getBindingIndex("out");
|
||||
std::cout<<"input idex = "<<buf_input_idx<<" -> output index = "<<buf_output_idx<<"\n";
|
||||
std::cout<<"input index = "<<buf_input_idx<<" -> output index = "<<buf_output_idx<<"\n";
|
||||
|
||||
|
||||
Dims iDim = engineRT->getBindingDimensions(buf_input_idx);
|
||||
@@ -449,11 +450,14 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Route *l) {
|
||||
// std::cout<<"\n";
|
||||
}
|
||||
|
||||
IConcatenationLayer *lRT = networkRT->addConcatenation(tens, l->layers_n);
|
||||
//IPlugin *plugin = new RouteRT();
|
||||
//IPluginLayer *lRT = networkRT->addPlugin(tens, l->layers_n, *plugin);
|
||||
if(l->groups > 1){
|
||||
IPlugin *plugin = new RouteRT(l->groups, l->group_id);
|
||||
IPluginLayer *lRT = networkRT->addPlugin(tens, l->layers_n, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
}
|
||||
IConcatenationLayer *lRT = networkRT->addConcatenation(tens, l->layers_n);
|
||||
checkNULL(lRT);
|
||||
|
||||
return lRT;
|
||||
}
|
||||
|
||||
@@ -525,7 +529,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Yolo *l) {
|
||||
//std::cout<<"convert Yolo\n";
|
||||
|
||||
//std::cout<<"New plugin YOLO\n";
|
||||
IPlugin *plugin = new YoloRT(l->classes, l->num, l, l->n_masks, l->scaleXY);
|
||||
IPlugin *plugin = new YoloRT(l->classes, l->num, l, l->n_masks, l->scaleXY, l->nms_thresh, l->nsm_kind, l->new_coords);
|
||||
IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin);
|
||||
checkNULL(lRT);
|
||||
return lRT;
|
||||
@@ -594,7 +598,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, DeformConv2d *l) {
|
||||
|
||||
bool NetworkRT::serialize(const char *filename) {
|
||||
|
||||
std::ofstream p(filename);
|
||||
std::ofstream p(filename, std::ios::binary);
|
||||
if (!p) {
|
||||
FatalError("could not open plan output file");
|
||||
return false;
|
||||
@@ -735,12 +739,16 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
if(name.find("Yolo") == 0) {
|
||||
YoloRT *r = new YoloRT(readBUF<int>(buf), //classes
|
||||
readBUF<int>(buf), //num
|
||||
nullptr,
|
||||
readBUF<int>(buf)); //n_masks
|
||||
nullptr, //yolo
|
||||
readBUF<int>(buf), //n_masks
|
||||
readBUF<float>(buf), //scale_xy
|
||||
readBUF<float>(buf), //nms_thresh
|
||||
readBUF<int>(buf), //nms_kind
|
||||
readBUF<int>(buf) //new_coords
|
||||
);
|
||||
r->c = readBUF<int>(buf);
|
||||
r->h = readBUF<int>(buf);
|
||||
r->w = readBUF<int>(buf);
|
||||
r->scaleXY = readBUF<float>(buf);
|
||||
for(int i=0; i<r->n_masks; i++)
|
||||
r->mask[i] = readBUF<dnnType>(buf);
|
||||
for(int i=0; i<r->n_masks*2*r->num; i++)
|
||||
@@ -765,9 +773,9 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
r->w = readBUF<int>(buf);
|
||||
return r;
|
||||
}
|
||||
/*
|
||||
|
||||
if(name.find("Route") == 0) {
|
||||
RouteRT *r = new RouteRT();
|
||||
RouteRT *r = new RouteRT(readBUF<int>(buf),readBUF<int>(buf));
|
||||
r->in = readBUF<int>(buf);
|
||||
for(int i=0; i<RouteRT::MAX_INPUTS; i++)
|
||||
r->c_in[i] = readBUF<int>(buf);
|
||||
@@ -776,7 +784,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa
|
||||
r->w = readBUF<int>(buf);
|
||||
return r;
|
||||
}
|
||||
*/
|
||||
|
||||
if(name.find("Deformable") == 0) {
|
||||
DeformableConvRT *r = new DeformableConvRT(readBUF<int>(buf), readBUF<int>(buf), readBUF<int>(buf),
|
||||
readBUF<int>(buf), readBUF<int>(buf), readBUF<int>(buf),
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
#include "tkDNN/NetworkViz.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
cv::Mat vizFloat2colorMap(cv::Mat map) {
|
||||
|
||||
double min;
|
||||
double max;
|
||||
cv::minMaxIdx(map, &min, &max);
|
||||
cv::Mat adjMap;
|
||||
// expand your range to 0..255. Similar to histEq();
|
||||
map.convertTo(adjMap,CV_8UC1, 255 / (max-min), -min);
|
||||
//return adjMap;
|
||||
|
||||
|
||||
cv::Mat falseColorsMap;
|
||||
applyColorMap(adjMap, falseColorsMap, cv::COLORMAP_HOT);
|
||||
return falseColorsMap;
|
||||
}
|
||||
|
||||
cv::Mat vizData2Mat(dnnType *dataInput, tk::dnn::dataDim_t dim, int imgdim) {
|
||||
dnnType *data = nullptr;
|
||||
|
||||
// copy to CPU
|
||||
if(isCudaPointer(dataInput)) {
|
||||
data = new dnnType[dim.tot()];
|
||||
checkCuda( cudaMemcpy(data, dataInput, dim.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost) );
|
||||
} else {
|
||||
data = dataInput;
|
||||
}
|
||||
|
||||
int gridDim = ceil(sqrt(dim.c));
|
||||
cv::Size gridSize(dim.w*gridDim, dim.h*gridDim);
|
||||
cv::Mat grid = cv::Mat(gridSize, CV_8UC3, cv::Scalar(0));
|
||||
|
||||
for(int i=0; i<dim.c;i++) {
|
||||
cv::Mat raw = vizFloat2colorMap(cv::Mat(cv::Size(dim.w, dim.h),CV_32FC1, data + dim.w*dim.h*i));
|
||||
int r = i / gridDim;
|
||||
int c = i - r * gridDim;
|
||||
raw.copyTo(grid.rowRange(r*dim.h, r*dim.h + dim.h).colRange(c*dim.w, c*dim.w + dim.w));
|
||||
}
|
||||
|
||||
float ar = float(dim.w)/dim.h;
|
||||
cv::Size vdim(ar*imgdim, imgdim);
|
||||
cv::Mat viz;
|
||||
cv::resize(grid, viz, vdim, 0, 0, 0);
|
||||
|
||||
// free memory
|
||||
if(isCudaPointer(dataInput)) {
|
||||
delete [] data;
|
||||
}
|
||||
return viz;
|
||||
}
|
||||
|
||||
cv::Mat vizLayer2Mat(tk::dnn::Network *net, int layer, int imgdim) {
|
||||
if(layer >= net->num_layers)
|
||||
FatalError("Could not viz layer\n");
|
||||
return vizData2Mat(net->layers[layer]->dstData, net->layers[layer]->output_dim, imgdim);
|
||||
|
||||
//cv::imwrite("viz/layer" + std::to_string(layer) + ".png", viz);
|
||||
//cv::imshow("layer", viz);
|
||||
//cv::waitKey(0);
|
||||
}
|
||||
|
||||
}}
|
||||
+1
-2
@@ -13,7 +13,6 @@ namespace tk { namespace dnn {
|
||||
|
||||
Region::Region(Network *net, int classes, int coords, int num) :
|
||||
Layer(net) {
|
||||
|
||||
this->classes = classes;
|
||||
this->coords = coords;
|
||||
this->num = num;
|
||||
@@ -64,7 +63,7 @@ dnnType* Region::infer(dataDim_t &dim, dnnType* srcData) {
|
||||
}
|
||||
|
||||
|
||||
/* Intepret class */
|
||||
/* Interpret class */
|
||||
RegionInterpret::RegionInterpret(dataDim_t input_dim, dataDim_t output_dim,
|
||||
int classes, int coords, int num, float thresh, std::string fname_weights) {
|
||||
|
||||
|
||||
+7
-3
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
Route::Route(Network *net, Layer **layers, int layers_n) : Layer(net) {
|
||||
Route::Route(Network *net, Layer **layers, int layers_n, int groups, int group_id) : Layer(net) {
|
||||
|
||||
// copy input layers
|
||||
if(layers_n > MAX_LAYERS) {
|
||||
@@ -15,6 +15,8 @@ Route::Route(Network *net, Layer **layers, int layers_n) : Layer(net) {
|
||||
this->layers[i] = layers[i];
|
||||
}
|
||||
this->layers_n = layers_n;
|
||||
this->groups = groups;
|
||||
this->group_id = group_id;
|
||||
|
||||
//get dims
|
||||
output_dim.l = 1;
|
||||
@@ -32,6 +34,7 @@ Route::Route(Network *net, Layer **layers, int layers_n) : Layer(net) {
|
||||
output_dim.c += layers[i]->output_dim.c;
|
||||
}
|
||||
|
||||
output_dim.c /= this->groups;
|
||||
input_dim = output_dim;
|
||||
|
||||
checkCuda( cudaMalloc(&dstData, output_dim.tot()*sizeof(dnnType)) );
|
||||
@@ -49,8 +52,9 @@ dnnType* Route::infer(dataDim_t &dim, dnnType* srcData) {
|
||||
for(int i=0; i<layers_n; i++) {
|
||||
dnnType *input = layers[i]->dstData;
|
||||
int in_dim = layers[i]->output_dim.tot();
|
||||
checkCuda( cudaMemcpy(dstData + offset, input, in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
offset += in_dim;
|
||||
int part_in_dim = in_dim / this->groups;
|
||||
checkCuda( cudaMemcpy(dstData + offset, input + this->group_id*part_in_dim, part_in_dim*sizeof(dnnType), cudaMemcpyDeviceToDevice));
|
||||
offset += part_in_dim;
|
||||
}
|
||||
|
||||
//update data dimensions
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ Shortcut::Shortcut(Network *net, Layer *backLayer) : Layer(net) {
|
||||
if( /*backLayer->output_dim.c != input_dim.c ||*/
|
||||
backLayer->output_dim.w != input_dim.w ||
|
||||
backLayer->output_dim.h != input_dim.h )
|
||||
FatalError("Shortcut dim missmatch");
|
||||
FatalError("Shortcut dim mismatch");
|
||||
}
|
||||
|
||||
Shortcut::~Shortcut() {
|
||||
|
||||
+50
-9
@@ -11,13 +11,17 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_masks, float scale_xy) :
|
||||
Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_masks, float scale_xy, double nms_thresh, nmsKind_t nsm_kind, int new_coords) :
|
||||
Layer(net) {
|
||||
this->final = true;
|
||||
|
||||
this->classes = classes;
|
||||
this->num = num;
|
||||
this->n_masks = n_masks;
|
||||
this->scaleXY = scale_xy;
|
||||
this->nms_thresh = nms_thresh;
|
||||
this->nsm_kind = nsm_kind;
|
||||
this->new_coords = new_coords;
|
||||
|
||||
// load anchors
|
||||
if(fname_weights != "") {
|
||||
@@ -58,12 +62,21 @@ int entry_index(int batch, int location, int entry,
|
||||
entry*input_dim.w*input_dim.h + loc;
|
||||
}
|
||||
|
||||
Yolo::box get_yolo_box(float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, int stride) {
|
||||
Yolo::box get_yolo_box(float *x, float *biases, int n, int index, int i, int j, int lw, int lh, int w, int h, int stride, int new_coords) {
|
||||
Yolo::box b;
|
||||
|
||||
if(new_coords == 0){
|
||||
b.x = (i + x[index + 0*stride]) / lw;
|
||||
b.y = (j + x[index + 1*stride]) / lh;
|
||||
b.w = exp(x[index + 2*stride]) * biases[2*n] / w;
|
||||
b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h;
|
||||
}
|
||||
else{
|
||||
b.x = (i + x[index + 0 * stride] * 2 - 0.5) / lw;
|
||||
b.y = (j + x[index + 1 * stride] * 2 - 0.5) / lh;
|
||||
b.w = x[index + 2 * stride] * x[index + 2 * stride] * 4 * biases[2 * n] / w;
|
||||
b.h = x[index + 3 * stride] * x[index + 3 * stride] * 4 * biases[2 * n + 1] / h;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -74,6 +87,9 @@ dnnType* Yolo::infer(dataDim_t &dim, dnnType* srcData) {
|
||||
for (int b = 0; b < dim.n; ++b){
|
||||
for(int n = 0; n < n_masks; ++n){
|
||||
int index = entry_index(b, n*dim.w*dim.h, 0, classes, input_dim, output_dim);
|
||||
if (new_coords == 1)
|
||||
activationLOGISTICForward(srcData + index, dstData + index, 4*dim.w*dim.h);
|
||||
else
|
||||
activationLOGISTICForward(srcData + index, dstData + index, 2*dim.w*dim.h);
|
||||
|
||||
if (this->scaleXY != 1) scalAdd(dstData + index, 2 * dim.w*dim.h, this->scaleXY, -0.5*(this->scaleXY - 1), 1);
|
||||
@@ -115,7 +131,7 @@ void correct_yolo_boxes(Yolo::detection *dets, int n, int w, int h, int netw, in
|
||||
}
|
||||
}
|
||||
|
||||
int Yolo::computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh) {
|
||||
int Yolo::computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh, int new_coords) {
|
||||
|
||||
if(predictions == nullptr)
|
||||
predictions = new dnnType[output_dim.tot()];
|
||||
@@ -139,7 +155,7 @@ int Yolo::computeDetections(Yolo::detection *dets, int &ndets, int netw, int net
|
||||
if(objectness <= thresh) continue;
|
||||
int box_index = entry_index(0, n*lw*lh + i, 0, classes, input_dim, output_dim);
|
||||
|
||||
dets[count].bbox = get_yolo_box(predictions, bias_h, mask_h[n], box_index, col, row, lw, lh, netw, neth, lw*lh);
|
||||
dets[count].bbox = get_yolo_box(predictions, bias_h, mask_h[n], box_index, col, row, lw, lh, netw, neth, lw*lh, new_coords);
|
||||
dets[count].objectness = objectness;
|
||||
dets[count].classes = classes;
|
||||
for(j = 0; j < classes; ++j){
|
||||
@@ -192,6 +208,32 @@ float yolo_box_iou(Yolo::box a, Yolo::box b)
|
||||
return yolo_box_intersection(a, b)/yolo_box_union(a, b);
|
||||
}
|
||||
|
||||
void box_c(const Yolo::box a, const Yolo::box b, float& top, float& bot, float& left, float& right) {
|
||||
top = std::min(a.y - a.h / 2, b.y - b.h / 2);
|
||||
bot = std::max(a.y + a.h / 2, b.y + b.h / 2);
|
||||
left = std::min(a.x - a.w / 2, b.x - b.w / 2);
|
||||
right = std::max(a.x + a.w / 2, b.x + b.w / 2);
|
||||
}
|
||||
|
||||
// https://github.com/Zzh-tju/DIoU-darknet
|
||||
// https://arxiv.org/abs/1911.08287
|
||||
float yolo_box_diou(const Yolo::box a, const Yolo::box b, const float nms_thresh=0.6)
|
||||
{
|
||||
float top, bot, left, right;
|
||||
box_c(a, b, top, bot, left, right);
|
||||
float w = right - left;
|
||||
float h = bot - top;
|
||||
float c = w * w + h * h;
|
||||
float iou = yolo_box_iou(a, b);
|
||||
if (c == 0)
|
||||
return iou;
|
||||
|
||||
float d = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
|
||||
float u = pow(d / c, nms_thresh);
|
||||
float diou_term = u;
|
||||
return iou - diou_term;
|
||||
}
|
||||
|
||||
int yolo_nms_comparator(const void *pa, const void *pb)
|
||||
{
|
||||
Yolo::detection a = *(Yolo::detection *)pa;
|
||||
@@ -218,8 +260,7 @@ Yolo::detection *Yolo::allocateDetections(int nboxes, int classes) {
|
||||
return dets;
|
||||
}
|
||||
|
||||
void Yolo::mergeDetections(Yolo::detection *dets, int ndets, int classes) {
|
||||
double nms_thresh = 0.45;
|
||||
void Yolo::mergeDetections(Yolo::detection *dets, int ndets, int classes, double nms_thresh, nmsKind_t nsm_kind) {
|
||||
int total = ndets;
|
||||
|
||||
int i, j, k;
|
||||
@@ -245,13 +286,13 @@ void Yolo::mergeDetections(Yolo::detection *dets, int ndets, int classes) {
|
||||
box a = dets[i].bbox;
|
||||
for(j = i+1; j < total; ++j){
|
||||
box b = dets[j].bbox;
|
||||
if (yolo_box_iou(a, b) > nms_thresh){
|
||||
if (nsm_kind == GREEDY_NMS && yolo_box_iou(a, b) > nms_thresh)
|
||||
dets[j].prob[k] = 0;
|
||||
else if (nsm_kind == DIOU_NMS && yolo_box_diou(a, b, nms_thresh) > nms_thresh)
|
||||
dets[j].prob[k] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
+42
-29
@@ -3,12 +3,17 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) {
|
||||
bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh) {
|
||||
|
||||
//convert network to tensorRT
|
||||
std::cout<<(tensor_path).c_str()<<"\n";
|
||||
netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str() );
|
||||
|
||||
nBatches = n_batches;
|
||||
confThreshold = conf_thresh;
|
||||
tk::dnn::dataDim_t idim = netRT->input_dim;
|
||||
idim.n = nBatches;
|
||||
|
||||
if(netRT->pluginFactory->n_yolos < 2 ) {
|
||||
FatalError("this is not yolo3");
|
||||
}
|
||||
@@ -19,7 +24,7 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) {
|
||||
num = yRT->num;
|
||||
nMasks = yRT->n_masks;
|
||||
|
||||
// make a yolo layer for interpret predictions
|
||||
// make a yolo layer to interpret predictions
|
||||
yolo[i] = new tk::dnn::Yolo(nullptr, classes, nMasks, ""); // yolo without input and bias
|
||||
yolo[i]->mask_h = new dnnType[nMasks];
|
||||
yolo[i]->bias_h = new dnnType[num*nMasks*2];
|
||||
@@ -27,13 +32,16 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) {
|
||||
memcpy(yolo[i]->bias_h, yRT->bias, sizeof(dnnType)*num*nMasks*2);
|
||||
yolo[i]->input_dim = yolo[i]->output_dim = tk::dnn::dataDim_t(1, yRT->c, yRT->h, yRT->w);
|
||||
yolo[i]->classesNames = yRT->classesNames;
|
||||
yolo[i]->nms_thresh = yRT->nms_thresh;
|
||||
yolo[i]->nsm_kind = (tk::dnn::Yolo::nmsKind_t) yRT->nms_kind;
|
||||
yolo[i]->new_coords = yRT->new_coords;
|
||||
}
|
||||
|
||||
dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes);
|
||||
#ifndef OPENCV_CUDACONTRIB
|
||||
checkCuda(cudaMallocHost(&input, sizeof(dnnType)*netRT->input_dim.tot()));
|
||||
checkCuda(cudaMallocHost(&input, sizeof(dnnType)*idim.tot()));
|
||||
#endif
|
||||
checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*netRT->input_dim.tot()));
|
||||
checkCuda(cudaMalloc(&input_d, sizeof(dnnType)*idim.tot()));
|
||||
|
||||
// class colors precompute
|
||||
for(int c=0; c<classes; c++) {
|
||||
@@ -48,7 +56,7 @@ bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Yolo3Detection::preprocess(cv::Mat &frame){
|
||||
void Yolo3Detection::preprocess(cv::Mat &frame, const int bi){
|
||||
#ifdef OPENCV_CUDACONTRIB
|
||||
cv::cuda::GpuMat orig_img, img_resized;
|
||||
orig_img = cv::cuda::GpuMat(frame);
|
||||
@@ -64,7 +72,7 @@ void Yolo3Detection::preprocess(cv::Mat &frame){
|
||||
int size = imagePreproc.rows * imagePreproc.cols;
|
||||
int ch = netRT->input_dim.c-1 -i;
|
||||
bgr[ch].download(bgr_h); //TODO: don't copy back on CPU
|
||||
checkCuda( cudaMemcpy(input_d + i*size, (float*)bgr_h.data, size*sizeof(dnnType), cudaMemcpyHostToDevice));
|
||||
checkCuda( cudaMemcpy(input_d + i*size + netRT->input_dim.tot()*bi, (float*)bgr_h.data, size*sizeof(dnnType), cudaMemcpyHostToDevice));
|
||||
}
|
||||
#else
|
||||
cv::resize(frame, frame, cv::Size(netRT->input_dim.w, netRT->input_dim.h));
|
||||
@@ -77,54 +85,50 @@ void Yolo3Detection::preprocess(cv::Mat &frame){
|
||||
for(int i=0; i<netRT->input_dim.c; i++) {
|
||||
int idx = i*imagePreproc.rows*imagePreproc.cols;
|
||||
int ch = netRT->input_dim.c-1 -i;
|
||||
memcpy((void*)&input[idx], (void*)bgr[ch].data, imagePreproc.rows*imagePreproc.cols*sizeof(dnnType));
|
||||
memcpy((void*)&input[idx + netRT->input_dim.tot()*bi], (void*)bgr[ch].data, imagePreproc.rows*imagePreproc.cols*sizeof(dnnType));
|
||||
}
|
||||
checkCuda(cudaMemcpyAsync(input_d, input, netRT->input_dim.tot()*sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream));
|
||||
checkCuda(cudaMemcpyAsync(input_d + netRT->input_dim.tot()*bi, input + netRT->input_dim.tot()*bi, netRT->input_dim.tot()*sizeof(dnnType), cudaMemcpyHostToDevice, netRT->stream));
|
||||
#endif
|
||||
}
|
||||
|
||||
void Yolo3Detection::postprocess(){
|
||||
void Yolo3Detection::postprocess(const int bi, const bool mAP){
|
||||
|
||||
//get yolo outputs
|
||||
dnnType *rt_out[netRT->pluginFactory->n_yolos];
|
||||
for(int i=0; i<netRT->pluginFactory->n_yolos; i++) {
|
||||
rt_out[i] = (dnnType*)netRT->buffersRT[i+1];
|
||||
}
|
||||
for(int i=0; i<netRT->pluginFactory->n_yolos; i++)
|
||||
rt_out[i] = (dnnType*)netRT->buffersRT[i+1] + netRT->buffersDIM[i+1].tot()*bi;
|
||||
|
||||
float x_ratio = float(originalSize.width) / float(netRT->input_dim.w);
|
||||
float y_ratio = float(originalSize.height) / float(netRT->input_dim.h);
|
||||
float x_ratio = float(originalSize[bi].width) / float(netRT->input_dim.w);
|
||||
float y_ratio = float(originalSize[bi].height) / float(netRT->input_dim.h);
|
||||
|
||||
// compute dets
|
||||
nDets = 0;
|
||||
for(int i=0; i<netRT->pluginFactory->n_yolos; i++) {
|
||||
yolo[i]->dstData = rt_out[i];
|
||||
yolo[i]->computeDetections(dets, nDets, netRT->input_dim.w, netRT->input_dim.h, confThreshold);
|
||||
yolo[i]->computeDetections(dets, nDets, netRT->input_dim.w, netRT->input_dim.h, confThreshold, yolo[i]->new_coords);
|
||||
}
|
||||
tk::dnn::Yolo::mergeDetections(dets, nDets, classes);
|
||||
tk::dnn::Yolo::mergeDetections(dets, nDets, classes, yolo[0]->nms_thresh, yolo[0]->nsm_kind);
|
||||
|
||||
// fill detected
|
||||
detected.clear();
|
||||
for(int j=0; j<nDets; j++) {
|
||||
tk::dnn::Yolo::box b = dets[j].bbox;
|
||||
int x0 = (b.x-b.w/2.);
|
||||
int x1 = (b.x+b.w/2.);
|
||||
int y0 = (b.y-b.h/2.);
|
||||
int y1 = (b.y+b.h/2.);
|
||||
int obj_class = -1;
|
||||
float prob = 0;
|
||||
for(int c=0; c<classes; c++) {
|
||||
if(dets[j].prob[c] >= confThreshold) {
|
||||
obj_class = c;
|
||||
prob = dets[j].prob[c];
|
||||
}
|
||||
}
|
||||
float x0 = (b.x-b.w/2.);
|
||||
float x1 = (b.x+b.w/2.);
|
||||
float y0 = (b.y-b.h/2.);
|
||||
float y1 = (b.y+b.h/2.);
|
||||
|
||||
if(obj_class >= 0) {
|
||||
// convert to image coords
|
||||
x0 = x_ratio*x0;
|
||||
x1 = x_ratio*x1;
|
||||
y0 = y_ratio*y0;
|
||||
y1 = y_ratio*y1;
|
||||
|
||||
for(int c=0; c<classes; c++) {
|
||||
if(dets[j].prob[c] >= confThreshold) {
|
||||
int obj_class = c;
|
||||
float prob = dets[j].prob[c];
|
||||
|
||||
tk::dnn::box res;
|
||||
res.cl = obj_class;
|
||||
res.prob = prob;
|
||||
@@ -132,9 +136,18 @@ void Yolo3Detection::postprocess(){
|
||||
res.y = y0;
|
||||
res.w = x1 - x0;
|
||||
res.h = y1 - y0;
|
||||
|
||||
// FIXME: this shuld be useless
|
||||
// if(mAP)
|
||||
// for(int c=0; c<classes; c++)
|
||||
// res.probs.push_back(dets[j].prob[c]);
|
||||
|
||||
detected.push_back(res);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
batchDetected.push_back(detected);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+44
-3
@@ -63,7 +63,7 @@ double computeMap( std::vector<Frame> &images,const int classes,
|
||||
|
||||
int gt_checked = 0;
|
||||
|
||||
// for each detection comput IoU with groundtruth and match detetcion and
|
||||
// for each detection compute IoU with groundtruth and match detetcion and
|
||||
// groundtruth with IoU greater than IoU_thresh
|
||||
for(auto &img:images){
|
||||
for(size_t i=0; i<img.det.size(); i++){
|
||||
@@ -153,7 +153,7 @@ double computeMap( std::vector<Frame> &images,const int classes,
|
||||
}
|
||||
}
|
||||
|
||||
//compute average precision for each class. Two methods are avaible,
|
||||
//compute average precision for each class. Two methods are available,
|
||||
//based on map_points required
|
||||
double mean_average_precision = 0;
|
||||
double last_recall, last_precision, delta_recall;
|
||||
@@ -287,7 +287,7 @@ void computeTPFPFN( std::vector<Frame> &images,const int classes,
|
||||
}
|
||||
}
|
||||
|
||||
//count all TP, FP, FN and compute precsion, recall and f1-score
|
||||
//count all TP, FP, FN and compute precision, recall and f1-score
|
||||
double avg_precision = 0, avg_recall = 0, f1_score = 0;
|
||||
int TP = 0, FP = 0, FN = 0;
|
||||
for(size_t i=0; i<classes; i++){
|
||||
@@ -315,4 +315,45 @@ void computeTPFPFN( std::vector<Frame> &images,const int classes,
|
||||
std::cout<<"avg precision: "<<avg_precision<<"\tavg recall: "<<avg_recall<<"\tavg f1 score:"<<f1_score<<std::endl;
|
||||
}
|
||||
|
||||
void printJsonCOCOFormat(std::ofstream *out_file, const std::string image_path, std::vector<tk::dnn::box> bbox, const int classes, const int w, const int h)
|
||||
{
|
||||
int coco_ids[] = { 1,2,3,4,5,6,7,8,9,10,11,13,14,15,16,17,18,19,20,21,22,23,24,25,27,28,31,32,33,34,35,36,37,38,39,40,41,42,43,44,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,67,70,72,73,74,75,76,77,78,79,80,81,82,84,85,86,87,88,89,90 };
|
||||
std::string id = image_path.substr(image_path.find("images/")+7, image_path.find(".jpg") - image_path.find("images/") -7);
|
||||
int image_id = std::stoi(id);
|
||||
for (int i = 0; i < bbox.size(); ++i) {
|
||||
float xmin = bbox[i].x ;
|
||||
float xmax = bbox[i].x + float(bbox[i].w);
|
||||
float ymin = bbox[i].y;
|
||||
float ymax = bbox[i].y + float(bbox[i].h);
|
||||
|
||||
//limit to image borders
|
||||
if (xmin < 0) xmin = 0;
|
||||
if (ymin < 0) ymin = 0;
|
||||
if (xmax > w) xmax = w;
|
||||
if (ymax > h) ymax = h;
|
||||
|
||||
float bx = xmin;
|
||||
float by = ymin;
|
||||
float bw = xmax - xmin;
|
||||
float bh = ymax - ymin;
|
||||
|
||||
if(bbox[i].probs.size() == classes)
|
||||
for (int j = 0; j < classes; ++j) {
|
||||
//min threshold confidence is set in DetectionNN.h
|
||||
if (bbox[i].probs[j] > 0) {
|
||||
|
||||
*out_file << "{\"image_id\":" << image_id <<
|
||||
", \"category_id\":" << coco_ids[j] <<
|
||||
", \"bbox\":[" << bx << ", " << by << ", " << bw << ", " << bh <<
|
||||
"], \"score\":" << bbox[i].probs[j] << "},\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
*out_file << "{\"image_id\":" << image_id <<
|
||||
", \"category_id\":" << coco_ids[bbox[i].cl] <<
|
||||
", \"bbox\":[" << bx << ", " << by << ", " << bw << ", " << bh <<
|
||||
"], \"score\":" << bbox[i].prob << "},\n";
|
||||
}
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -3,20 +3,39 @@
|
||||
|
||||
#define MISH_THRESHOLD 20
|
||||
|
||||
__device__ float tanh_activate_kernel(float x){return (2/(1 + expf(-2*x)) - 1);}
|
||||
__device__ float softplus_kernel(float x, float threshold = 20) {
|
||||
__device__
|
||||
float tanh_activate_kernel(float x){return (2/(1 + expf(-2*x)) - 1);}
|
||||
|
||||
__device__
|
||||
float softplus_kernel(float x, float threshold = 20) {
|
||||
if (x > threshold) return x; // too large
|
||||
else if (x < -threshold) return expf(x); // too small
|
||||
return logf(expf(x) + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
__device__
|
||||
float mish_yashas(float x) {
|
||||
float e = __expf(x);
|
||||
if (x <= -18.0f)
|
||||
return x * e;
|
||||
|
||||
float n = e * e + 2 * e;
|
||||
if (x <= -5.0f)
|
||||
return x * __fdividef(n, n + 2);
|
||||
|
||||
return x - 2 * __fdividef(x, n + 2);
|
||||
}
|
||||
|
||||
// https://github.com/digantamisra98/Mish
|
||||
// https://github.com/AlexeyAB/darknet/blob/master/src/activation_kernels.cu
|
||||
__global__
|
||||
void activation_mish(dnnType *input, dnnType *output, int size) {
|
||||
int i = (blockIdx.x + blockIdx.y*gridDim.x) * blockDim.x + threadIdx.x;
|
||||
if (i < size)
|
||||
output[i] = input[i] * tanh_activate_kernel( softplus_kernel(input[i], MISH_THRESHOLD));
|
||||
// output[i] = input[i] * tanh_activate_kernel( softplus_kernel(input[i], MISH_THRESHOLD));
|
||||
output[i] = mish_yashas(input[i]);
|
||||
}
|
||||
|
||||
/**
|
||||
+11
-4
@@ -26,10 +26,11 @@ void downloadWeightsifDoNotExist(const std::string& input_bin, const std::string
|
||||
std::string wget_cmd = "wget " + weights_url + " -O " + test_folder + "/weights.zip";
|
||||
std::string unzip_cmd = "unzip " + test_folder + "/weights.zip -d" + test_folder;
|
||||
std::string rm_cmd = "rm " + test_folder + "/weights.zip";
|
||||
system(mkdir_cmd.c_str());
|
||||
system(wget_cmd.c_str());
|
||||
system(unzip_cmd.c_str());
|
||||
system(rm_cmd.c_str());
|
||||
int err = 0;
|
||||
err = system(mkdir_cmd.c_str());
|
||||
err = system(wget_cmd.c_str());
|
||||
err = system(unzip_cmd.c_str());
|
||||
err = system(rm_cmd.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +197,12 @@ void getMemUsage(double& vm_usage_kb, double& resident_set_kb){
|
||||
resident_set_kb = rss * page_size_kb;
|
||||
}
|
||||
|
||||
void printCudaMemUsage() {
|
||||
size_t free, total;
|
||||
checkCuda( cudaMemGetInfo(&free, &total) );
|
||||
std::cout<<"GPU free memory: "<<double(free)/1e6<<" mb.\n";
|
||||
}
|
||||
|
||||
void removePathAndExtension(const std::string &full_string, std::string &name){
|
||||
name = full_string;
|
||||
std::string tmp_str = full_string;
|
||||
|
||||
@@ -312,9 +312,9 @@ int main()
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
net.infer(dim1, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
cudnn_out = net.layers[net.num_layers-1]->dstData;
|
||||
@@ -326,9 +326,9 @@ int main()
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
rt_out = (dnnType *)netRT.buffersRT[1];
|
||||
@@ -301,9 +301,9 @@ int main()
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
net.infer(dim1, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
cudnn_out = net.layers[net.num_layers-1]->dstData;
|
||||
@@ -314,9 +314,9 @@ int main()
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
rt_out = (dnnType *)netRT.buffersRT[1];
|
||||
@@ -1,554 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "tkdnn.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
// Network layout
|
||||
tk::dnn::dataDim_t dim(1, 3, 320, 544, 1);
|
||||
tk::dnn::Network net(dim);
|
||||
|
||||
// create bdd-csresnext50-panet-spp model
|
||||
std::string bin_path = "bdd-csresnext50-panet-spp";
|
||||
int classes = 10;
|
||||
tk::dnn::Yolo *yolo[3];
|
||||
|
||||
std::string input_bin = bin_path + "/layers/input.bin";
|
||||
std::string output_bin = bin_path + "/debug/layer137_out.bin";
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer115_out.bin",
|
||||
bin_path + "/debug/layer126_out.bin",
|
||||
bin_path + "/debug/layer137_out.bin"};
|
||||
std::string c0_bin = bin_path + "/layers/c0.bin";
|
||||
std::string c2_bin = bin_path + "/layers/c2.bin";
|
||||
std::string c4_bin = bin_path + "/layers/c4.bin";
|
||||
std::string c5_bin = bin_path + "/layers/c5.bin";
|
||||
std::string c6_bin = bin_path + "/layers/c6.bin";
|
||||
std::string c7_bin = bin_path + "/layers/c7.bin";
|
||||
std::string c9_bin = bin_path + "/layers/c9.bin";
|
||||
std::string c10_bin = bin_path + "/layers/c10.bin";
|
||||
std::string c11_bin = bin_path + "/layers/c11.bin";
|
||||
std::string c13_bin = bin_path + "/layers/c13.bin";
|
||||
std::string c14_bin = bin_path + "/layers/c14.bin";
|
||||
std::string c15_bin = bin_path + "/layers/c15.bin";
|
||||
std::string c17_bin = bin_path + "/layers/c17.bin";
|
||||
std::string c19_bin = bin_path + "/layers/c19.bin";
|
||||
std::string c20_bin = bin_path + "/layers/c20.bin";
|
||||
std::string c21_bin = bin_path + "/layers/c21.bin";
|
||||
std::string c23_bin = bin_path + "/layers/c23.bin";
|
||||
std::string c24_bin = bin_path + "/layers/c24.bin";
|
||||
std::string c25_bin = bin_path + "/layers/c25.bin";
|
||||
std::string c26_bin = bin_path + "/layers/c26.bin";
|
||||
std::string c28_bin = bin_path + "/layers/c28.bin";
|
||||
std::string c29_bin = bin_path + "/layers/c29.bin";
|
||||
std::string c30_bin = bin_path + "/layers/c30.bin";
|
||||
std::string c32_bin = bin_path + "/layers/c32.bin";
|
||||
std::string c33_bin = bin_path + "/layers/c33.bin";
|
||||
std::string c34_bin = bin_path + "/layers/c34.bin";
|
||||
std::string c36_bin = bin_path + "/layers/c36.bin";
|
||||
std::string c38_bin = bin_path + "/layers/c38.bin";
|
||||
std::string c39_bin = bin_path + "/layers/c39.bin";
|
||||
std::string c40_bin = bin_path + "/layers/c40.bin";
|
||||
std::string c42_bin = bin_path + "/layers/c42.bin";
|
||||
std::string c43_bin = bin_path + "/layers/c43.bin";
|
||||
std::string c44_bin = bin_path + "/layers/c44.bin";
|
||||
std::string c45_bin = bin_path + "/layers/c45.bin";
|
||||
std::string c47_bin = bin_path + "/layers/c47.bin";
|
||||
std::string c48_bin = bin_path + "/layers/c48.bin";
|
||||
std::string c49_bin = bin_path + "/layers/c49.bin";
|
||||
std::string c51_bin = bin_path + "/layers/c51.bin";
|
||||
std::string c52_bin = bin_path + "/layers/c52.bin";
|
||||
std::string c53_bin = bin_path + "/layers/c53.bin";
|
||||
std::string c55_bin = bin_path + "/layers/c55.bin";
|
||||
std::string c56_bin = bin_path + "/layers/c56.bin";
|
||||
std::string c57_bin = bin_path + "/layers/c57.bin";
|
||||
std::string c59_bin = bin_path + "/layers/c59.bin";
|
||||
std::string c60_bin = bin_path + "/layers/c60.bin";
|
||||
std::string c61_bin = bin_path + "/layers/c61.bin";
|
||||
std::string c63_bin = bin_path + "/layers/c63.bin";
|
||||
std::string c65_bin = bin_path + "/layers/c65.bin";
|
||||
std::string c66_bin = bin_path + "/layers/c66.bin";
|
||||
std::string c67_bin = bin_path + "/layers/c67.bin";
|
||||
std::string c69_bin = bin_path + "/layers/c69.bin";
|
||||
std::string c70_bin = bin_path + "/layers/c70.bin";
|
||||
std::string c71_bin = bin_path + "/layers/c71.bin";
|
||||
std::string c72_bin = bin_path + "/layers/c72.bin";
|
||||
std::string c74_bin = bin_path + "/layers/c74.bin";
|
||||
std::string c75_bin = bin_path + "/layers/c75.bin";
|
||||
std::string c76_bin = bin_path + "/layers/c76.bin";
|
||||
std::string c78_bin = bin_path + "/layers/c78.bin";
|
||||
std::string c80_bin = bin_path + "/layers/c80.bin";
|
||||
std::string c81_bin = bin_path + "/layers/c81.bin";
|
||||
std::string c82_bin = bin_path + "/layers/c82.bin";
|
||||
std::string c83_bin = bin_path + "/layers/c83.bin";
|
||||
std::string c90_bin = bin_path + "/layers/c90.bin";
|
||||
std::string c91_bin = bin_path + "/layers/c91.bin";
|
||||
std::string c92_bin = bin_path + "/layers/c92.bin";
|
||||
std::string c93_bin = bin_path + "/layers/c93.bin";
|
||||
std::string c96_bin = bin_path + "/layers/c96.bin";
|
||||
std::string c98_bin = bin_path + "/layers/c98.bin";
|
||||
std::string c99_bin = bin_path + "/layers/c99.bin";
|
||||
std::string c100_bin = bin_path + "/layers/c100.bin";
|
||||
std::string c101_bin = bin_path + "/layers/c101.bin";
|
||||
std::string c102_bin = bin_path + "/layers/c102.bin";
|
||||
std::string c103_bin = bin_path + "/layers/c103.bin";
|
||||
std::string c106_bin = bin_path + "/layers/c106.bin";
|
||||
std::string c108_bin = bin_path + "/layers/c108.bin";
|
||||
std::string c109_bin = bin_path + "/layers/c109.bin";
|
||||
std::string c110_bin = bin_path + "/layers/c110.bin";
|
||||
std::string c111_bin = bin_path + "/layers/c111.bin";
|
||||
std::string c112_bin = bin_path + "/layers/c112.bin";
|
||||
std::string c113_bin = bin_path + "/layers/c113.bin";
|
||||
std::string c114_bin = bin_path + "/layers/c114.bin";
|
||||
std::string c117_bin = bin_path + "/layers/c117.bin";
|
||||
std::string c119_bin = bin_path + "/layers/c119.bin";
|
||||
std::string c120_bin = bin_path + "/layers/c120.bin";
|
||||
std::string c121_bin = bin_path + "/layers/c121.bin";
|
||||
std::string c122_bin = bin_path + "/layers/c122.bin";
|
||||
std::string c123_bin = bin_path + "/layers/c123.bin";
|
||||
std::string c124_bin = bin_path + "/layers/c124.bin";
|
||||
std::string c125_bin = bin_path + "/layers/c125.bin";
|
||||
std::string c128_bin = bin_path + "/layers/c128.bin";
|
||||
std::string c130_bin = bin_path + "/layers/c130.bin";
|
||||
std::string c131_bin = bin_path + "/layers/c131.bin";
|
||||
std::string c132_bin = bin_path + "/layers/c132.bin";
|
||||
std::string c133_bin = bin_path + "/layers/c133.bin";
|
||||
std::string c134_bin = bin_path + "/layers/c134.bin";
|
||||
std::string c135_bin = bin_path + "/layers/c135.bin";
|
||||
std::string c136_bin = bin_path + "/layers/c136.bin";
|
||||
std::string g115_bin = bin_path + "/layers/g115.bin";
|
||||
std::string g126_bin = bin_path + "/layers/g126.bin";
|
||||
std::string g137_bin = bin_path + "/layers/g137.bin";
|
||||
|
||||
// downloadWeightsifDoNotExist(input_bin, bin_path, "https://cloud.hipert.unimore.it/s//download");
|
||||
|
||||
tk::dnn::Conv2d c0(&net, 64, 7, 7, 2, 2, 3, 3, c0_bin, true);
|
||||
tk::dnn::Activation a0(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Pooling p1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
|
||||
|
||||
tk::dnn::Conv2d c2(&net, 128, 1, 1, 1, 1, 0, 0, c2_bin, true);
|
||||
tk::dnn::Activation a2(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r3_layers[1] = {&p1};
|
||||
tk::dnn::Route r3(&net, r3_layers, 1);
|
||||
|
||||
tk::dnn::Conv2d c4(&net, 64, 1, 1, 1, 1, 0, 0, c4_bin, true);
|
||||
tk::dnn::Activation a4(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// //1-1
|
||||
tk::dnn::Conv2d c5(&net, 128, 1, 1, 1, 1, 0, 0, c5_bin, true);
|
||||
tk::dnn::Activation a5(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c6(&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true, false, 32, false);
|
||||
tk::dnn::Activation a6(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c7(&net, 128, 1, 1, 1, 1, 0, 0, c7_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s8(&net, &a4);
|
||||
tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//1-2
|
||||
tk::dnn::Conv2d c9(&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true);
|
||||
tk::dnn::Activation a9(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c10(&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true, false, 32);
|
||||
tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c11(&net, 128, 1, 1, 1, 1, 0, 0, c11_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s12(&net, &a8);
|
||||
tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//1-3
|
||||
tk::dnn::Conv2d c13(&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true);
|
||||
tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c14(&net, 128, 3, 3, 1, 1, 1, 1, c14_bin, true, false, 32);
|
||||
tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c15(&net, 128, 1, 1, 1, 1, 0, 0, c15_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s16(&net, &a12);
|
||||
tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// //1-T
|
||||
tk::dnn::Conv2d c17(&net, 128, 1, 1, 1, 1, 0, 0, c17_bin, true);
|
||||
tk::dnn::Activation a17(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r18_layers[2] = {&a17, &a2};
|
||||
tk::dnn::Route r18(&net, r18_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c19(&net, 256, 1, 1, 1, 1, 0, 0, c19_bin, true);
|
||||
tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c20(&net, 256, 3, 3, 2, 2, 1, 1, c20_bin, true, false, 32);
|
||||
tk::dnn::Activation a20(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c21(&net, 256, 1, 1, 1, 1, 0, 0, c21_bin, true);
|
||||
|
||||
tk::dnn::Layer *r22_layers[2] = {&a20};
|
||||
tk::dnn::Route r22(&net, r22_layers, 1);
|
||||
|
||||
tk::dnn::Conv2d c23(&net, 256, 1, 1, 1, 1, 0, 0, c23_bin, true);
|
||||
|
||||
//2-1
|
||||
tk::dnn::Conv2d c24(&net, 256, 1, 1, 1, 1, 0, 0, c24_bin, true);
|
||||
tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c25(&net, 256, 3, 3, 1, 1, 1, 1, c25_bin, true, false, 32);
|
||||
tk::dnn::Activation a25(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c26(&net, 256, 1, 1, 1, 1, 0, 0, c26_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s27(&net, &c23);
|
||||
tk::dnn::Activation a27(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//2-2
|
||||
tk::dnn::Conv2d c28(&net, 256, 1, 1, 1, 1, 0, 0, c28_bin, true);
|
||||
tk::dnn::Activation a28(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c29(&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true, false, 32);
|
||||
tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c30(&net, 256, 1, 1, 1, 1, 0, 0, c30_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s31(&net, &a27);
|
||||
tk::dnn::Activation a31(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//2-3
|
||||
tk::dnn::Conv2d c32(&net, 256, 1, 1, 1, 1, 0, 0, c32_bin, true);
|
||||
tk::dnn::Activation a32(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c33(&net, 256, 3, 3, 1, 1, 1, 1, c33_bin, true, false, 32);
|
||||
tk::dnn::Activation a33(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c34(&net, 256, 1, 1, 1, 1, 0, 0, c34_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s35(&net, &a31);
|
||||
tk::dnn::Activation a35(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// //2-T
|
||||
tk::dnn::Conv2d c36(&net, 256, 1, 1, 1, 1, 0, 0, c36_bin, true);
|
||||
tk::dnn::Activation a36(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r37_layers[2] = {&a36, &c21};
|
||||
tk::dnn::Route r37(&net, r37_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c38(&net, 512, 1, 1, 1, 1, 0, 0, c38_bin, true);
|
||||
tk::dnn::Activation a38(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c39(&net, 512, 3, 3, 2, 2, 1, 1, c39_bin, true, false, 32);
|
||||
tk::dnn::Activation a39(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c40(&net, 512, 1, 1, 1, 1, 0, 0, c40_bin, true);
|
||||
|
||||
tk::dnn::Layer *r41_layers[2] = {&a39};
|
||||
tk::dnn::Route r41(&net, r41_layers, 1);
|
||||
|
||||
tk::dnn::Conv2d c42(&net, 512, 1, 1, 1, 1, 0, 0, c42_bin, true);
|
||||
|
||||
//3-1
|
||||
tk::dnn::Conv2d c43(&net, 512, 1, 1, 1, 1, 0, 0, c43_bin, true);
|
||||
tk::dnn::Activation a43(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c44(&net, 512, 3, 3, 1, 1, 1, 1, c44_bin, true, false, 32);
|
||||
tk::dnn::Activation a44(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c45(&net, 512, 1, 1, 1, 1, 0, 0, c45_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s46(&net, &c42);
|
||||
tk::dnn::Activation a46(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-2
|
||||
tk::dnn::Conv2d c47(&net, 512, 1, 1, 1, 1, 0, 0, c47_bin, true);
|
||||
tk::dnn::Activation a47(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c48(&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true, false, 32);
|
||||
tk::dnn::Activation a48(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c49(&net, 512, 1, 1, 1, 1, 0, 0, c49_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s50(&net, &a46);
|
||||
tk::dnn::Activation a50(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-3
|
||||
tk::dnn::Conv2d c51(&net, 512, 1, 1, 1, 1, 0, 0, c51_bin, true);
|
||||
tk::dnn::Activation a51(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c52(&net, 512, 3, 3, 1, 1, 1, 1, c52_bin, true, false, 32);
|
||||
tk::dnn::Activation a52(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c53(&net, 512, 1, 1, 1, 1, 0, 0, c53_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s54(&net, &a50);
|
||||
tk::dnn::Activation a54(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-4
|
||||
tk::dnn::Conv2d c55(&net, 512, 1, 1, 1, 1, 0, 0, c55_bin, true);
|
||||
tk::dnn::Activation a55(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c56(&net, 512, 3, 3, 1, 1, 1, 1, c56_bin, true, false, 32);
|
||||
tk::dnn::Activation a56(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c57(&net, 512, 1, 1, 1, 1, 0, 0, c57_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s58(&net, &a54);
|
||||
tk::dnn::Activation a58(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-5
|
||||
tk::dnn::Conv2d c59(&net, 512, 1, 1, 1, 1, 0, 0, c59_bin, true);
|
||||
tk::dnn::Activation a59(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c60(&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true, false, 32);
|
||||
tk::dnn::Activation a60(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c61(&net, 512, 1, 1, 1, 1, 0, 0, c61_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s62(&net, &a58);
|
||||
tk::dnn::Activation a62(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-T
|
||||
tk::dnn::Conv2d c63(&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true);
|
||||
tk::dnn::Activation a63(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r64_layers[2] = {&a63, &c40};
|
||||
tk::dnn::Route r64(&net, r64_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c65(&net, 1024, 1, 1, 1, 1, 0, 0, c65_bin, true);
|
||||
tk::dnn::Activation a65(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c66(&net, 1024, 3, 3, 2, 2, 1, 1, c66_bin, true, false, 32);
|
||||
tk::dnn::Activation a66(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c67(&net, 1024, 1, 1, 1, 1, 0, 0, c67_bin, true);
|
||||
tk::dnn::Activation a67(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r68_layers[2] = {&a66};
|
||||
tk::dnn::Route r68(&net, r68_layers, 1);
|
||||
|
||||
tk::dnn::Conv2d c69(&net, 1024, 1, 1, 1, 1, 0, 0, c69_bin, true);
|
||||
tk::dnn::Activation a69(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//4-1
|
||||
tk::dnn::Conv2d c70(&net, 1024, 1, 1, 1, 1, 0, 0, c70_bin, true);
|
||||
tk::dnn::Activation a70(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c71(&net, 1024, 3, 3, 1, 1, 1, 1, c71_bin, true, false, 32);
|
||||
tk::dnn::Activation a71(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c72(&net, 1024, 1, 1, 1, 1, 0, 0, c72_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s73(&net, &a69);
|
||||
tk::dnn::Activation a73(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//4-2
|
||||
tk::dnn::Conv2d c74(&net, 1024, 1, 1, 1, 1, 0, 0, c74_bin, true);
|
||||
tk::dnn::Activation a74(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c75(&net, 1024, 3, 3, 1, 1, 1, 1, c75_bin, true, false, 32);
|
||||
tk::dnn::Activation a75(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c76(&net, 1024, 1, 1, 1, 1, 0, 0, c76_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s77(&net, &a73);
|
||||
tk::dnn::Activation a77(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//4-T
|
||||
tk::dnn::Conv2d c78(&net, 1024, 1, 1, 1, 1, 0, 0, c78_bin, true);
|
||||
tk::dnn::Activation a78(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r79_layers[2] = {&a78, &a67};
|
||||
tk::dnn::Route r79(&net, r79_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c80(&net, 2048, 1, 1, 1, 1, 0, 0, c80_bin, true);
|
||||
tk::dnn::Activation a80(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// ////////////////////
|
||||
|
||||
tk::dnn::Conv2d c81(&net, 512, 1, 1, 1, 1, 0, 0, c81_bin, true);
|
||||
tk::dnn::Activation a81(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c82(&net, 1024, 3, 3, 1, 1, 1, 1, c82_bin, true);
|
||||
tk::dnn::Activation a82(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c83(&net, 512, 1, 1, 1, 1, 0, 0, c83_bin, true);
|
||||
tk::dnn::Activation a83(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//SPP
|
||||
tk::dnn::Pooling p84(&net, 5, 5, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE);
|
||||
tk::dnn::Layer *r85_layers[1] = {&a83};
|
||||
tk::dnn::Route r85(&net, r85_layers, 1);
|
||||
|
||||
tk::dnn::Pooling p86(&net, 9, 9, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE);
|
||||
tk::dnn::Layer *r87_layers[1] = {&a83};
|
||||
tk::dnn::Route r87(&net, r87_layers, 1);
|
||||
|
||||
tk::dnn::Pooling p88(&net, 13, 13, 1, 1, 12, 12, tk::dnn::POOLING_MAX_FIXEDSIZE);
|
||||
tk::dnn::Layer *r89_layers[4] = {&p88, &p86, &p84, &a83};
|
||||
tk::dnn::Route r89(&net, r89_layers, 4);
|
||||
//END SPP
|
||||
|
||||
tk::dnn::Conv2d c90(&net, 512, 1, 1, 1, 1, 0, 0, c90_bin, true);
|
||||
tk::dnn::Activation a90(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c91(&net, 1024, 3, 3, 1, 1, 1, 1, c91_bin, true);
|
||||
tk::dnn::Activation a91(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c92(&net, 512, 1, 1, 1, 1, 0, 0, c92_bin, true);
|
||||
tk::dnn::Activation a92(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c93(&net, 256, 1, 1, 1, 1, 0, 0, c93_bin, true);
|
||||
tk::dnn::Activation a93(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Upsample u94(&net, 2);
|
||||
tk::dnn::Layer *r95_layers[1] = {&a65};
|
||||
tk::dnn::Route r95(&net, r95_layers, 1);
|
||||
tk::dnn::Conv2d c96(&net, 256, 1, 1, 1, 1, 0, 0, c96_bin, true);
|
||||
tk::dnn::Activation a96(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Layer *r97_layers[2] = {&a96,&u94};
|
||||
tk::dnn::Route r97(&net, r97_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c98(&net, 256, 1, 1, 1, 1, 0, 0, c98_bin, true);
|
||||
tk::dnn::Activation a98(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c99(&net, 512, 3, 3, 1, 1, 1, 1, c99_bin, true);
|
||||
tk::dnn::Activation a99(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c100(&net, 256, 1, 1, 1, 1, 0, 0, c100_bin, true);
|
||||
tk::dnn::Activation a100(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c101(&net, 512, 3, 3, 1, 1, 1, 1, c101_bin, true);
|
||||
tk::dnn::Activation a101(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c102(&net, 256, 1, 1, 1, 1, 0, 0, c102_bin, true);
|
||||
tk::dnn::Activation a102(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c103(&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true);
|
||||
tk::dnn::Activation a103(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Upsample u104(&net, 2);
|
||||
tk::dnn::Layer *r105_layers[1] = {&a38};
|
||||
tk::dnn::Route r105(&net, r105_layers, 1);
|
||||
tk::dnn::Conv2d c106(&net, 128, 1, 1, 1, 1, 0, 0, c106_bin, true);
|
||||
tk::dnn::Activation a106(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Layer *r107_layers[2] = {&a106,&u104};
|
||||
tk::dnn::Route r107(&net, r107_layers, 2);
|
||||
|
||||
|
||||
tk::dnn::Conv2d c108(&net, 128, 1, 1, 1, 1, 0, 0, c108_bin, true);
|
||||
tk::dnn::Activation a108(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c109(&net, 256, 3, 3, 1, 1, 1, 1, c109_bin, true);
|
||||
tk::dnn::Activation a109(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c110(&net, 128, 1, 1, 1, 1, 0, 0, c110_bin, true);
|
||||
tk::dnn::Activation a110(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c111(&net, 256, 3, 3, 1, 1, 1, 1, c111_bin, true);
|
||||
tk::dnn::Activation a111(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c112(&net, 128, 1, 1, 1, 1, 0, 0, c112_bin, true);
|
||||
tk::dnn::Activation a112(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// ###########################
|
||||
|
||||
tk::dnn::Conv2d c113(&net, 256, 3, 3, 1, 1, 1, 1, c113_bin, true);
|
||||
tk::dnn::Activation a113(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c114(&net, 45, 1, 1, 1, 1, 0, 0, c114_bin, false);
|
||||
tk::dnn::Yolo yolo115(&net, classes, 3, g115_bin);
|
||||
|
||||
tk::dnn::Layer *r116_layers[1] = {&a112};
|
||||
tk::dnn::Route r116(&net, r116_layers, 1);
|
||||
tk::dnn::Conv2d c117(&net, 256, 3, 3, 2, 2, 1, 1, c117_bin, true);
|
||||
tk::dnn::Activation a117(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Layer *r118_layers[2] = {&a117,&a102};
|
||||
tk::dnn::Route r118(&net, r118_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c119(&net, 256, 1, 1, 1, 1, 0, 0, c119_bin, true);
|
||||
tk::dnn::Activation a119(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c120(&net, 512, 3, 3, 1, 1, 1, 1, c120_bin, true);
|
||||
tk::dnn::Activation a120(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c121(&net, 256, 1, 1, 1, 1, 0, 0, c121_bin, true);
|
||||
tk::dnn::Activation a121(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c122(&net, 512, 3, 3, 1, 1, 1, 1, c122_bin, true);
|
||||
tk::dnn::Activation a122(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c123(&net, 256, 1, 1, 1, 1, 0, 0, c123_bin, true);
|
||||
tk::dnn::Activation a123(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Conv2d c124(&net, 512, 3, 3, 1, 1, 1, 1, c124_bin, true);
|
||||
tk::dnn::Activation a124(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c125(&net, 45, 1, 1, 1, 1, 0, 0, c125_bin, false);
|
||||
tk::dnn::Yolo yolo126(&net, classes, 3, g126_bin);
|
||||
|
||||
tk::dnn::Layer *r127_layers[1] = {&a123};
|
||||
tk::dnn::Route r127(&net, r127_layers, 1);
|
||||
tk::dnn::Conv2d c128(&net, 512, 3, 3, 2, 2, 1, 1, c128_bin, true);
|
||||
tk::dnn::Activation a128(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Layer *r129_layers[2] = {&a128,&a92};
|
||||
tk::dnn::Route r129(&net, r129_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c130(&net, 512, 1, 1, 1, 1, 0, 0, c130_bin, true);
|
||||
tk::dnn::Activation a130(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c131(&net, 1024, 3, 3, 1, 1, 1, 1, c131_bin, true);
|
||||
tk::dnn::Activation a131(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c132(&net, 512, 1, 1, 1, 1, 0, 0, c132_bin, true);
|
||||
tk::dnn::Activation a132(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c133(&net, 1024, 3, 3, 1, 1, 1, 1, c133_bin, true);
|
||||
tk::dnn::Activation a133(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c134(&net, 512, 1, 1, 1, 1, 0, 0, c134_bin, true);
|
||||
tk::dnn::Activation a134(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Conv2d c135(&net, 1024, 3, 3, 1, 1, 1, 1, c135_bin, true);
|
||||
tk::dnn::Activation a135(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c136(&net, 45, 1, 1, 1, 1, 0, 0, c136_bin, false);
|
||||
tk::dnn::Yolo yolo137(&net, classes, 3, g137_bin);
|
||||
|
||||
yolo[0] = &yolo115;
|
||||
yolo[1] = &yolo126;
|
||||
yolo[2] = &yolo137;
|
||||
|
||||
// fill classes names
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
yolo[i]->classesNames = {"person","car","truck","bus","motor","bike","rider","traffic light","traffic sign","train"};
|
||||
}
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
dnnType *input_h;
|
||||
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
|
||||
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// //convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("bdd-csresnext50-panet-spp"));
|
||||
|
||||
// the network have 3 outputs
|
||||
tk::dnn::dataDim_t out_dim[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
out_dim[i] = yolo[i]->output_dim;
|
||||
dnnType *cudnn_out[3], *rt_out[3];
|
||||
|
||||
tk::dnn::dataDim_t dim1 = dim; //input dim
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TIMER_START
|
||||
net.infer(dim1, data);
|
||||
TIMER_STOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
cudnn_out[i] = yolo[i]->dstData;
|
||||
|
||||
printCenteredTitle(" compute detections ", '=', 30);
|
||||
TIMER_START
|
||||
int ndets = 0;
|
||||
tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes);
|
||||
for (int i = 0; i < 3; i++)
|
||||
yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5);
|
||||
tk::dnn::Yolo::mergeDetections(dets, ndets, classes);
|
||||
|
||||
for (int j = 0; j < ndets; j++)
|
||||
{
|
||||
tk::dnn::Yolo::box b = dets[j].bbox;
|
||||
int x0 = (b.x - b.w / 2.);
|
||||
int x1 = (b.x + b.w / 2.);
|
||||
int y0 = (b.y - b.h / 2.);
|
||||
int y1 = (b.y + b.h / 2.);
|
||||
|
||||
int cl = 0;
|
||||
for (int c = 0; c < classes; ++c)
|
||||
{
|
||||
float prob = dets[j].prob[c];
|
||||
if (prob > 0)
|
||||
cl = c;
|
||||
}
|
||||
std::cout << cl << ": " << x0 << " " << y0 << " " << x1 << " " << y1 << "\n";
|
||||
}
|
||||
TIMER_STOP
|
||||
|
||||
tk::dnn::dataDim_t dim2 = dim;
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TIMER_START
|
||||
netRT.infer(dim2, data);
|
||||
TIMER_STOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
rt_out[i] = (dnnType *)netRT.buffersRT[i + 1];
|
||||
|
||||
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
printCenteredTitle((std::string(" YOLO ") + std::to_string(i) + " CHECK RESULTS ").c_str(), '=', 30);
|
||||
dnnType *out, *out_h;
|
||||
int odim = out_dim[i].tot();
|
||||
readBinaryFile(output_bins[i], odim, &out_h, &out);
|
||||
std::cout<<"CUDNN vs correct";
|
||||
ret_cudnn |= checkResult(odim, cudnn_out[i], out) == 0 ? 0: ERROR_CUDNN;
|
||||
std::cout<<"TRT vs correct";
|
||||
ret_tensorrt |= checkResult(odim, rt_out[i], out) == 0 ? 0 : ERROR_TENSORRT;
|
||||
std::cout<<"CUDNN vs TRT ";
|
||||
ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
|
||||
}
|
||||
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
#!/bin/bash
|
||||
if [ "$1" == "download" ]; then
|
||||
wget https://github.com/ceccocats/tkDNN/releases/download/testData/tkDNN_testwg.tar.gz --no-check-certificate
|
||||
tar -xf tkDNN_testwg.tar.gz
|
||||
rm tkDNN_testwg.tar.gz
|
||||
exit
|
||||
fi
|
||||
|
||||
echo "build test Model"
|
||||
cd test
|
||||
python test_model.py
|
||||
cd ..
|
||||
cd mnist
|
||||
python mnist_model.py
|
||||
cd ..
|
||||
echo "export weights"
|
||||
python weights_exporter.py test/net.h5 --output test/layers
|
||||
python caffe_weights_exporter.py mnist/lenet.prototxt mnist/lenet.caffemodel --output mnist/layers
|
||||
@@ -486,9 +486,9 @@ int main()
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
net.infer(dim1, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
@@ -496,9 +496,9 @@ int main()
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
@@ -516,9 +516,9 @@ int main()
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
net.infer(dim1, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
@@ -526,9 +526,9 @@ int main()
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
+4
-4
@@ -361,9 +361,9 @@ int main()
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
net.infer(dim1, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
@@ -373,9 +373,9 @@ int main()
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
+4
-4
@@ -391,9 +391,9 @@ int main()
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
net.infer(dim1, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
@@ -403,9 +403,9 @@ int main()
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TIMER_START
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TIMER_STOP
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
@@ -1,554 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "tkdnn.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
// Network layout
|
||||
tk::dnn::dataDim_t dim(1, 3, 416, 416, 1);
|
||||
tk::dnn::Network net(dim);
|
||||
|
||||
// create csresnext50-panet-spp model
|
||||
std::string bin_path = "csresnext50-panet-spp";
|
||||
int classes = 80;
|
||||
tk::dnn::Yolo *yolo[3];
|
||||
|
||||
std::string input_bin = bin_path + "/layers/input.bin";
|
||||
std::string output_bin = bin_path + "/debug/layer137_out.bin";
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer115_out.bin",
|
||||
bin_path + "/debug/layer126_out.bin",
|
||||
bin_path + "/debug/layer137_out.bin"};
|
||||
std::string c0_bin = bin_path + "/layers/c0.bin";
|
||||
std::string c2_bin = bin_path + "/layers/c2.bin";
|
||||
std::string c4_bin = bin_path + "/layers/c4.bin";
|
||||
std::string c5_bin = bin_path + "/layers/c5.bin";
|
||||
std::string c6_bin = bin_path + "/layers/c6.bin";
|
||||
std::string c7_bin = bin_path + "/layers/c7.bin";
|
||||
std::string c9_bin = bin_path + "/layers/c9.bin";
|
||||
std::string c10_bin = bin_path + "/layers/c10.bin";
|
||||
std::string c11_bin = bin_path + "/layers/c11.bin";
|
||||
std::string c13_bin = bin_path + "/layers/c13.bin";
|
||||
std::string c14_bin = bin_path + "/layers/c14.bin";
|
||||
std::string c15_bin = bin_path + "/layers/c15.bin";
|
||||
std::string c17_bin = bin_path + "/layers/c17.bin";
|
||||
std::string c19_bin = bin_path + "/layers/c19.bin";
|
||||
std::string c20_bin = bin_path + "/layers/c20.bin";
|
||||
std::string c21_bin = bin_path + "/layers/c21.bin";
|
||||
std::string c23_bin = bin_path + "/layers/c23.bin";
|
||||
std::string c24_bin = bin_path + "/layers/c24.bin";
|
||||
std::string c25_bin = bin_path + "/layers/c25.bin";
|
||||
std::string c26_bin = bin_path + "/layers/c26.bin";
|
||||
std::string c28_bin = bin_path + "/layers/c28.bin";
|
||||
std::string c29_bin = bin_path + "/layers/c29.bin";
|
||||
std::string c30_bin = bin_path + "/layers/c30.bin";
|
||||
std::string c32_bin = bin_path + "/layers/c32.bin";
|
||||
std::string c33_bin = bin_path + "/layers/c33.bin";
|
||||
std::string c34_bin = bin_path + "/layers/c34.bin";
|
||||
std::string c36_bin = bin_path + "/layers/c36.bin";
|
||||
std::string c38_bin = bin_path + "/layers/c38.bin";
|
||||
std::string c39_bin = bin_path + "/layers/c39.bin";
|
||||
std::string c40_bin = bin_path + "/layers/c40.bin";
|
||||
std::string c42_bin = bin_path + "/layers/c42.bin";
|
||||
std::string c43_bin = bin_path + "/layers/c43.bin";
|
||||
std::string c44_bin = bin_path + "/layers/c44.bin";
|
||||
std::string c45_bin = bin_path + "/layers/c45.bin";
|
||||
std::string c47_bin = bin_path + "/layers/c47.bin";
|
||||
std::string c48_bin = bin_path + "/layers/c48.bin";
|
||||
std::string c49_bin = bin_path + "/layers/c49.bin";
|
||||
std::string c51_bin = bin_path + "/layers/c51.bin";
|
||||
std::string c52_bin = bin_path + "/layers/c52.bin";
|
||||
std::string c53_bin = bin_path + "/layers/c53.bin";
|
||||
std::string c55_bin = bin_path + "/layers/c55.bin";
|
||||
std::string c56_bin = bin_path + "/layers/c56.bin";
|
||||
std::string c57_bin = bin_path + "/layers/c57.bin";
|
||||
std::string c59_bin = bin_path + "/layers/c59.bin";
|
||||
std::string c60_bin = bin_path + "/layers/c60.bin";
|
||||
std::string c61_bin = bin_path + "/layers/c61.bin";
|
||||
std::string c63_bin = bin_path + "/layers/c63.bin";
|
||||
std::string c65_bin = bin_path + "/layers/c65.bin";
|
||||
std::string c66_bin = bin_path + "/layers/c66.bin";
|
||||
std::string c67_bin = bin_path + "/layers/c67.bin";
|
||||
std::string c69_bin = bin_path + "/layers/c69.bin";
|
||||
std::string c70_bin = bin_path + "/layers/c70.bin";
|
||||
std::string c71_bin = bin_path + "/layers/c71.bin";
|
||||
std::string c72_bin = bin_path + "/layers/c72.bin";
|
||||
std::string c74_bin = bin_path + "/layers/c74.bin";
|
||||
std::string c75_bin = bin_path + "/layers/c75.bin";
|
||||
std::string c76_bin = bin_path + "/layers/c76.bin";
|
||||
std::string c78_bin = bin_path + "/layers/c78.bin";
|
||||
std::string c80_bin = bin_path + "/layers/c80.bin";
|
||||
std::string c81_bin = bin_path + "/layers/c81.bin";
|
||||
std::string c82_bin = bin_path + "/layers/c82.bin";
|
||||
std::string c83_bin = bin_path + "/layers/c83.bin";
|
||||
std::string c90_bin = bin_path + "/layers/c90.bin";
|
||||
std::string c91_bin = bin_path + "/layers/c91.bin";
|
||||
std::string c92_bin = bin_path + "/layers/c92.bin";
|
||||
std::string c93_bin = bin_path + "/layers/c93.bin";
|
||||
std::string c96_bin = bin_path + "/layers/c96.bin";
|
||||
std::string c98_bin = bin_path + "/layers/c98.bin";
|
||||
std::string c99_bin = bin_path + "/layers/c99.bin";
|
||||
std::string c100_bin = bin_path + "/layers/c100.bin";
|
||||
std::string c101_bin = bin_path + "/layers/c101.bin";
|
||||
std::string c102_bin = bin_path + "/layers/c102.bin";
|
||||
std::string c103_bin = bin_path + "/layers/c103.bin";
|
||||
std::string c106_bin = bin_path + "/layers/c106.bin";
|
||||
std::string c108_bin = bin_path + "/layers/c108.bin";
|
||||
std::string c109_bin = bin_path + "/layers/c109.bin";
|
||||
std::string c110_bin = bin_path + "/layers/c110.bin";
|
||||
std::string c111_bin = bin_path + "/layers/c111.bin";
|
||||
std::string c112_bin = bin_path + "/layers/c112.bin";
|
||||
std::string c113_bin = bin_path + "/layers/c113.bin";
|
||||
std::string c114_bin = bin_path + "/layers/c114.bin";
|
||||
std::string c117_bin = bin_path + "/layers/c117.bin";
|
||||
std::string c119_bin = bin_path + "/layers/c119.bin";
|
||||
std::string c120_bin = bin_path + "/layers/c120.bin";
|
||||
std::string c121_bin = bin_path + "/layers/c121.bin";
|
||||
std::string c122_bin = bin_path + "/layers/c122.bin";
|
||||
std::string c123_bin = bin_path + "/layers/c123.bin";
|
||||
std::string c124_bin = bin_path + "/layers/c124.bin";
|
||||
std::string c125_bin = bin_path + "/layers/c125.bin";
|
||||
std::string c128_bin = bin_path + "/layers/c128.bin";
|
||||
std::string c130_bin = bin_path + "/layers/c130.bin";
|
||||
std::string c131_bin = bin_path + "/layers/c131.bin";
|
||||
std::string c132_bin = bin_path + "/layers/c132.bin";
|
||||
std::string c133_bin = bin_path + "/layers/c133.bin";
|
||||
std::string c134_bin = bin_path + "/layers/c134.bin";
|
||||
std::string c135_bin = bin_path + "/layers/c135.bin";
|
||||
std::string c136_bin = bin_path + "/layers/c136.bin";
|
||||
std::string g115_bin = bin_path + "/layers/g115.bin";
|
||||
std::string g126_bin = bin_path + "/layers/g126.bin";
|
||||
std::string g137_bin = bin_path + "/layers/g137.bin";
|
||||
|
||||
downloadWeightsifDoNotExist(input_bin, bin_path, "https://cloud.hipert.unimore.it/s/Kcs4xBozwY4wFx8/download");
|
||||
|
||||
tk::dnn::Conv2d c0(&net, 64, 7, 7, 2, 2, 3, 3, c0_bin, true);
|
||||
tk::dnn::Activation a0(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Pooling p1(&net, 2, 2, 2, 2, 0, 0, tk::dnn::POOLING_MAX);
|
||||
|
||||
tk::dnn::Conv2d c2(&net, 128, 1, 1, 1, 1, 0, 0, c2_bin, true);
|
||||
tk::dnn::Activation a2(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r3_layers[1] = {&p1};
|
||||
tk::dnn::Route r3(&net, r3_layers, 1);
|
||||
|
||||
tk::dnn::Conv2d c4(&net, 64, 1, 1, 1, 1, 0, 0, c4_bin, true);
|
||||
tk::dnn::Activation a4(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// //1-1
|
||||
tk::dnn::Conv2d c5(&net, 128, 1, 1, 1, 1, 0, 0, c5_bin, true);
|
||||
tk::dnn::Activation a5(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c6(&net, 128, 3, 3, 1, 1, 1, 1, c6_bin, true, false, 32, false);
|
||||
tk::dnn::Activation a6(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c7(&net, 128, 1, 1, 1, 1, 0, 0, c7_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s8(&net, &a4);
|
||||
tk::dnn::Activation a8(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//1-2
|
||||
tk::dnn::Conv2d c9(&net, 128, 1, 1, 1, 1, 0, 0, c9_bin, true);
|
||||
tk::dnn::Activation a9(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c10(&net, 128, 3, 3, 1, 1, 1, 1, c10_bin, true, false, 32);
|
||||
tk::dnn::Activation a10(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c11(&net, 128, 1, 1, 1, 1, 0, 0, c11_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s12(&net, &a8);
|
||||
tk::dnn::Activation a12(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//1-3
|
||||
tk::dnn::Conv2d c13(&net, 128, 1, 1, 1, 1, 0, 0, c13_bin, true);
|
||||
tk::dnn::Activation a13(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c14(&net, 128, 3, 3, 1, 1, 1, 1, c14_bin, true, false, 32);
|
||||
tk::dnn::Activation a14(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c15(&net, 128, 1, 1, 1, 1, 0, 0, c15_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s16(&net, &a12);
|
||||
tk::dnn::Activation a16(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// //1-T
|
||||
tk::dnn::Conv2d c17(&net, 128, 1, 1, 1, 1, 0, 0, c17_bin, true);
|
||||
tk::dnn::Activation a17(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r18_layers[2] = {&a17, &a2};
|
||||
tk::dnn::Route r18(&net, r18_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c19(&net, 256, 1, 1, 1, 1, 0, 0, c19_bin, true);
|
||||
tk::dnn::Activation a19(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c20(&net, 256, 3, 3, 2, 2, 1, 1, c20_bin, true, false, 32);
|
||||
tk::dnn::Activation a20(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c21(&net, 256, 1, 1, 1, 1, 0, 0, c21_bin, true);
|
||||
|
||||
tk::dnn::Layer *r22_layers[2] = {&a20};
|
||||
tk::dnn::Route r22(&net, r22_layers, 1);
|
||||
|
||||
tk::dnn::Conv2d c23(&net, 256, 1, 1, 1, 1, 0, 0, c23_bin, true);
|
||||
|
||||
//2-1
|
||||
tk::dnn::Conv2d c24(&net, 256, 1, 1, 1, 1, 0, 0, c24_bin, true);
|
||||
tk::dnn::Activation a24(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c25(&net, 256, 3, 3, 1, 1, 1, 1, c25_bin, true, false, 32);
|
||||
tk::dnn::Activation a25(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c26(&net, 256, 1, 1, 1, 1, 0, 0, c26_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s27(&net, &c23);
|
||||
tk::dnn::Activation a27(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//2-2
|
||||
tk::dnn::Conv2d c28(&net, 256, 1, 1, 1, 1, 0, 0, c28_bin, true);
|
||||
tk::dnn::Activation a28(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c29(&net, 256, 3, 3, 1, 1, 1, 1, c29_bin, true, false, 32);
|
||||
tk::dnn::Activation a29(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c30(&net, 256, 1, 1, 1, 1, 0, 0, c30_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s31(&net, &a27);
|
||||
tk::dnn::Activation a31(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//2-3
|
||||
tk::dnn::Conv2d c32(&net, 256, 1, 1, 1, 1, 0, 0, c32_bin, true);
|
||||
tk::dnn::Activation a32(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c33(&net, 256, 3, 3, 1, 1, 1, 1, c33_bin, true, false, 32);
|
||||
tk::dnn::Activation a33(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c34(&net, 256, 1, 1, 1, 1, 0, 0, c34_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s35(&net, &a31);
|
||||
tk::dnn::Activation a35(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// //2-T
|
||||
tk::dnn::Conv2d c36(&net, 256, 1, 1, 1, 1, 0, 0, c36_bin, true);
|
||||
tk::dnn::Activation a36(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r37_layers[2] = {&a36, &c21};
|
||||
tk::dnn::Route r37(&net, r37_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c38(&net, 512, 1, 1, 1, 1, 0, 0, c38_bin, true);
|
||||
tk::dnn::Activation a38(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c39(&net, 512, 3, 3, 2, 2, 1, 1, c39_bin, true, false, 32);
|
||||
tk::dnn::Activation a39(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c40(&net, 512, 1, 1, 1, 1, 0, 0, c40_bin, true);
|
||||
|
||||
tk::dnn::Layer *r41_layers[2] = {&a39};
|
||||
tk::dnn::Route r41(&net, r41_layers, 1);
|
||||
|
||||
tk::dnn::Conv2d c42(&net, 512, 1, 1, 1, 1, 0, 0, c42_bin, true);
|
||||
|
||||
//3-1
|
||||
tk::dnn::Conv2d c43(&net, 512, 1, 1, 1, 1, 0, 0, c43_bin, true);
|
||||
tk::dnn::Activation a43(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c44(&net, 512, 3, 3, 1, 1, 1, 1, c44_bin, true, false, 32);
|
||||
tk::dnn::Activation a44(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c45(&net, 512, 1, 1, 1, 1, 0, 0, c45_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s46(&net, &c42);
|
||||
tk::dnn::Activation a46(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-2
|
||||
tk::dnn::Conv2d c47(&net, 512, 1, 1, 1, 1, 0, 0, c47_bin, true);
|
||||
tk::dnn::Activation a47(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c48(&net, 512, 3, 3, 1, 1, 1, 1, c48_bin, true, false, 32);
|
||||
tk::dnn::Activation a48(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c49(&net, 512, 1, 1, 1, 1, 0, 0, c49_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s50(&net, &a46);
|
||||
tk::dnn::Activation a50(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-3
|
||||
tk::dnn::Conv2d c51(&net, 512, 1, 1, 1, 1, 0, 0, c51_bin, true);
|
||||
tk::dnn::Activation a51(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c52(&net, 512, 3, 3, 1, 1, 1, 1, c52_bin, true, false, 32);
|
||||
tk::dnn::Activation a52(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c53(&net, 512, 1, 1, 1, 1, 0, 0, c53_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s54(&net, &a50);
|
||||
tk::dnn::Activation a54(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-4
|
||||
tk::dnn::Conv2d c55(&net, 512, 1, 1, 1, 1, 0, 0, c55_bin, true);
|
||||
tk::dnn::Activation a55(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c56(&net, 512, 3, 3, 1, 1, 1, 1, c56_bin, true, false, 32);
|
||||
tk::dnn::Activation a56(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c57(&net, 512, 1, 1, 1, 1, 0, 0, c57_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s58(&net, &a54);
|
||||
tk::dnn::Activation a58(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-5
|
||||
tk::dnn::Conv2d c59(&net, 512, 1, 1, 1, 1, 0, 0, c59_bin, true);
|
||||
tk::dnn::Activation a59(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c60(&net, 512, 3, 3, 1, 1, 1, 1, c60_bin, true, false, 32);
|
||||
tk::dnn::Activation a60(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c61(&net, 512, 1, 1, 1, 1, 0, 0, c61_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s62(&net, &a58);
|
||||
tk::dnn::Activation a62(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//3-T
|
||||
tk::dnn::Conv2d c63(&net, 512, 1, 1, 1, 1, 0, 0, c63_bin, true);
|
||||
tk::dnn::Activation a63(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r64_layers[2] = {&a63, &c40};
|
||||
tk::dnn::Route r64(&net, r64_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c65(&net, 1024, 1, 1, 1, 1, 0, 0, c65_bin, true);
|
||||
tk::dnn::Activation a65(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c66(&net, 1024, 3, 3, 2, 2, 1, 1, c66_bin, true, false, 32);
|
||||
tk::dnn::Activation a66(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c67(&net, 1024, 1, 1, 1, 1, 0, 0, c67_bin, true);
|
||||
tk::dnn::Activation a67(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r68_layers[2] = {&a66};
|
||||
tk::dnn::Route r68(&net, r68_layers, 1);
|
||||
|
||||
tk::dnn::Conv2d c69(&net, 1024, 1, 1, 1, 1, 0, 0, c69_bin, true);
|
||||
tk::dnn::Activation a69(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//4-1
|
||||
tk::dnn::Conv2d c70(&net, 1024, 1, 1, 1, 1, 0, 0, c70_bin, true);
|
||||
tk::dnn::Activation a70(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c71(&net, 1024, 3, 3, 1, 1, 1, 1, c71_bin, true, false, 32);
|
||||
tk::dnn::Activation a71(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c72(&net, 1024, 1, 1, 1, 1, 0, 0, c72_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s73(&net, &a69);
|
||||
tk::dnn::Activation a73(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//4-2
|
||||
tk::dnn::Conv2d c74(&net, 1024, 1, 1, 1, 1, 0, 0, c74_bin, true);
|
||||
tk::dnn::Activation a74(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c75(&net, 1024, 3, 3, 1, 1, 1, 1, c75_bin, true, false, 32);
|
||||
tk::dnn::Activation a75(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c76(&net, 1024, 1, 1, 1, 1, 0, 0, c76_bin, true);
|
||||
|
||||
tk::dnn::Shortcut s77(&net, &a73);
|
||||
tk::dnn::Activation a77(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//4-T
|
||||
tk::dnn::Conv2d c78(&net, 1024, 1, 1, 1, 1, 0, 0, c78_bin, true);
|
||||
tk::dnn::Activation a78(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Layer *r79_layers[2] = {&a78, &a67};
|
||||
tk::dnn::Route r79(&net, r79_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c80(&net, 2048, 1, 1, 1, 1, 0, 0, c80_bin, true);
|
||||
tk::dnn::Activation a80(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// ////////////////////
|
||||
|
||||
tk::dnn::Conv2d c81(&net, 512, 1, 1, 1, 1, 0, 0, c81_bin, true);
|
||||
tk::dnn::Activation a81(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c82(&net, 1024, 3, 3, 1, 1, 1, 1, c82_bin, true);
|
||||
tk::dnn::Activation a82(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c83(&net, 512, 1, 1, 1, 1, 0, 0, c83_bin, true);
|
||||
tk::dnn::Activation a83(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
//SPP
|
||||
tk::dnn::Pooling p84(&net, 5, 5, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE);
|
||||
tk::dnn::Layer *r85_layers[1] = {&a83};
|
||||
tk::dnn::Route r85(&net, r85_layers, 1);
|
||||
|
||||
tk::dnn::Pooling p86(&net, 9, 9, 1, 1, 0, 0, tk::dnn::POOLING_MAX_FIXEDSIZE);
|
||||
tk::dnn::Layer *r87_layers[1] = {&a83};
|
||||
tk::dnn::Route r87(&net, r87_layers, 1);
|
||||
|
||||
tk::dnn::Pooling p88(&net, 13, 13, 1, 1, 12, 12, tk::dnn::POOLING_MAX_FIXEDSIZE);
|
||||
tk::dnn::Layer *r89_layers[4] = {&p88, &p86, &p84, &a83};
|
||||
tk::dnn::Route r89(&net, r89_layers, 4);
|
||||
//END SPP
|
||||
|
||||
tk::dnn::Conv2d c90(&net, 512, 1, 1, 1, 1, 0, 0, c90_bin, true);
|
||||
tk::dnn::Activation a90(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c91(&net, 1024, 3, 3, 1, 1, 1, 1, c91_bin, true);
|
||||
tk::dnn::Activation a91(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c92(&net, 512, 1, 1, 1, 1, 0, 0, c92_bin, true);
|
||||
tk::dnn::Activation a92(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c93(&net, 256, 1, 1, 1, 1, 0, 0, c93_bin, true);
|
||||
tk::dnn::Activation a93(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Upsample u94(&net, 2);
|
||||
tk::dnn::Layer *r95_layers[1] = {&a65};
|
||||
tk::dnn::Route r95(&net, r95_layers, 1);
|
||||
tk::dnn::Conv2d c96(&net, 256, 1, 1, 1, 1, 0, 0, c96_bin, true);
|
||||
tk::dnn::Activation a96(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Layer *r97_layers[2] = {&a96,&u94};
|
||||
tk::dnn::Route r97(&net, r97_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c98(&net, 256, 1, 1, 1, 1, 0, 0, c98_bin, true);
|
||||
tk::dnn::Activation a98(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c99(&net, 512, 3, 3, 1, 1, 1, 1, c99_bin, true);
|
||||
tk::dnn::Activation a99(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c100(&net, 256, 1, 1, 1, 1, 0, 0, c100_bin, true);
|
||||
tk::dnn::Activation a100(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c101(&net, 512, 3, 3, 1, 1, 1, 1, c101_bin, true);
|
||||
tk::dnn::Activation a101(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c102(&net, 256, 1, 1, 1, 1, 0, 0, c102_bin, true);
|
||||
tk::dnn::Activation a102(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c103(&net, 128, 1, 1, 1, 1, 0, 0, c103_bin, true);
|
||||
tk::dnn::Activation a103(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Upsample u104(&net, 2);
|
||||
tk::dnn::Layer *r105_layers[1] = {&a38};
|
||||
tk::dnn::Route r105(&net, r105_layers, 1);
|
||||
tk::dnn::Conv2d c106(&net, 128, 1, 1, 1, 1, 0, 0, c106_bin, true);
|
||||
tk::dnn::Activation a106(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Layer *r107_layers[2] = {&a106,&u104};
|
||||
tk::dnn::Route r107(&net, r107_layers, 2);
|
||||
|
||||
|
||||
tk::dnn::Conv2d c108(&net, 128, 1, 1, 1, 1, 0, 0, c108_bin, true);
|
||||
tk::dnn::Activation a108(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c109(&net, 256, 3, 3, 1, 1, 1, 1, c109_bin, true);
|
||||
tk::dnn::Activation a109(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c110(&net, 128, 1, 1, 1, 1, 0, 0, c110_bin, true);
|
||||
tk::dnn::Activation a110(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c111(&net, 256, 3, 3, 1, 1, 1, 1, c111_bin, true);
|
||||
tk::dnn::Activation a111(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c112(&net, 128, 1, 1, 1, 1, 0, 0, c112_bin, true);
|
||||
tk::dnn::Activation a112(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
// ###########################
|
||||
|
||||
tk::dnn::Conv2d c113(&net, 256, 3, 3, 1, 1, 1, 1, c113_bin, true);
|
||||
tk::dnn::Activation a113(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c114(&net, 255, 1, 1, 1, 1, 0, 0, c114_bin, false);
|
||||
tk::dnn::Yolo yolo115(&net, classes, 3, g115_bin);
|
||||
|
||||
tk::dnn::Layer *r116_layers[1] = {&a112};
|
||||
tk::dnn::Route r116(&net, r116_layers, 1);
|
||||
tk::dnn::Conv2d c117(&net, 256, 3, 3, 2, 2, 1, 1, c117_bin, true);
|
||||
tk::dnn::Activation a117(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Layer *r118_layers[2] = {&a117,&a102};
|
||||
tk::dnn::Route r118(&net, r118_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c119(&net, 256, 1, 1, 1, 1, 0, 0, c119_bin, true);
|
||||
tk::dnn::Activation a119(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c120(&net, 512, 3, 3, 1, 1, 1, 1, c120_bin, true);
|
||||
tk::dnn::Activation a120(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c121(&net, 256, 1, 1, 1, 1, 0, 0, c121_bin, true);
|
||||
tk::dnn::Activation a121(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c122(&net, 512, 3, 3, 1, 1, 1, 1, c122_bin, true);
|
||||
tk::dnn::Activation a122(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c123(&net, 256, 1, 1, 1, 1, 0, 0, c123_bin, true);
|
||||
tk::dnn::Activation a123(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Conv2d c124(&net, 512, 3, 3, 1, 1, 1, 1, c124_bin, true);
|
||||
tk::dnn::Activation a124(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c125(&net, 255, 1, 1, 1, 1, 0, 0, c125_bin, false);
|
||||
tk::dnn::Yolo yolo126(&net, classes, 3, g126_bin);
|
||||
|
||||
tk::dnn::Layer *r127_layers[1] = {&a123};
|
||||
tk::dnn::Route r127(&net, r127_layers, 1);
|
||||
tk::dnn::Conv2d c128(&net, 512, 3, 3, 2, 2, 1, 1, c128_bin, true);
|
||||
tk::dnn::Activation a128(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Layer *r129_layers[2] = {&a128,&a92};
|
||||
tk::dnn::Route r129(&net, r129_layers, 2);
|
||||
|
||||
tk::dnn::Conv2d c130(&net, 512, 1, 1, 1, 1, 0, 0, c130_bin, true);
|
||||
tk::dnn::Activation a130(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c131(&net, 1024, 3, 3, 1, 1, 1, 1, c131_bin, true);
|
||||
tk::dnn::Activation a131(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c132(&net, 512, 1, 1, 1, 1, 0, 0, c132_bin, true);
|
||||
tk::dnn::Activation a132(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c133(&net, 1024, 3, 3, 1, 1, 1, 1, c133_bin, true);
|
||||
tk::dnn::Activation a133(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c134(&net, 512, 1, 1, 1, 1, 0, 0, c134_bin, true);
|
||||
tk::dnn::Activation a134(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
|
||||
tk::dnn::Conv2d c135(&net, 1024, 3, 3, 1, 1, 1, 1, c135_bin, true);
|
||||
tk::dnn::Activation a135(&net, tk::dnn::ACTIVATION_LEAKY);
|
||||
tk::dnn::Conv2d c136(&net, 255, 1, 1, 1, 1, 0, 0, c136_bin, false);
|
||||
tk::dnn::Yolo yolo137(&net, classes, 3, g137_bin);
|
||||
|
||||
yolo[0] = &yolo115;
|
||||
yolo[1] = &yolo126;
|
||||
yolo[2] = &yolo137;
|
||||
|
||||
// fill classes names
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
yolo[i]->classesNames = {"person", "bicycle", "car", "motorbike", "aeroplane", "bus", "train", "truck", "boat", "traffic light", "fire hydrant", "stop sign", "parking meter", "bench", "bird", "cat", "dog", "horse", "sheep", "cow", "elephant", "bear", "zebra", "giraffe", "backpack", "umbrella", "handbag", "tie", "suitcase", "frisbee", "skis", "snowboard", "sports ball", "kite", "baseball bat", "baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", "wine glass", "cup", "fork", "knife", "spoon", "bowl", "banana", "apple", "sandwich", "orange", "broccoli", "carrot", "hot dog", "pizza", "donut", "cake", "chair", "sofa", "pottedplant", "bed", "diningtable", "toilet", "tvmonitor", "laptop", "mouse", "remote", "keyboard", "cell phone", "microwave", "oven", "toaster", "sink", "refrigerator", "book", "clock", "vase", "scissors", "teddy bear", "hair drier", "toothbrush"};
|
||||
}
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
dnnType *input_h;
|
||||
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
|
||||
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// //convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("csresnext50-panet-spp"));
|
||||
|
||||
// the network have 3 outputs
|
||||
tk::dnn::dataDim_t out_dim[3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
out_dim[i] = yolo[i]->output_dim;
|
||||
dnnType *cudnn_out[3], *rt_out[3];
|
||||
|
||||
tk::dnn::dataDim_t dim1 = dim; //input dim
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TIMER_START
|
||||
net.infer(dim1, data);
|
||||
TIMER_STOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
cudnn_out[i] = yolo[i]->dstData;
|
||||
|
||||
printCenteredTitle(" compute detections ", '=', 30);
|
||||
TIMER_START
|
||||
int ndets = 0;
|
||||
tk::dnn::Yolo::detection *dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes);
|
||||
for (int i = 0; i < 3; i++)
|
||||
yolo[i]->computeDetections(dets, ndets, net.input_dim.w, net.input_dim.h, 0.5);
|
||||
tk::dnn::Yolo::mergeDetections(dets, ndets, classes);
|
||||
|
||||
for (int j = 0; j < ndets; j++)
|
||||
{
|
||||
tk::dnn::Yolo::box b = dets[j].bbox;
|
||||
int x0 = (b.x - b.w / 2.);
|
||||
int x1 = (b.x + b.w / 2.);
|
||||
int y0 = (b.y - b.h / 2.);
|
||||
int y1 = (b.y + b.h / 2.);
|
||||
|
||||
int cl = 0;
|
||||
for (int c = 0; c < classes; ++c)
|
||||
{
|
||||
float prob = dets[j].prob[c];
|
||||
if (prob > 0)
|
||||
cl = c;
|
||||
}
|
||||
std::cout << cl << ": " << x0 << " " << y0 << " " << x1 << " " << y1 << "\n";
|
||||
}
|
||||
TIMER_STOP
|
||||
|
||||
tk::dnn::dataDim_t dim2 = dim;
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TIMER_START
|
||||
netRT.infer(dim2, data);
|
||||
TIMER_STOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
rt_out[i] = (dnnType *)netRT.buffersRT[i + 1];
|
||||
|
||||
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
printCenteredTitle((std::string(" YOLO ") + std::to_string(i) + " CHECK RESULTS ").c_str(), '=', 30);
|
||||
dnnType *out, *out_h;
|
||||
int odim = out_dim[i].tot();
|
||||
readBinaryFile(output_bins[i], odim, &out_h, &out);
|
||||
std::cout<<"CUDNN vs correct";
|
||||
ret_cudnn |= checkResult(odim, cudnn_out[i], out) == 0 ? 0: ERROR_CUDNN;
|
||||
std::cout<<"TRT vs correct";
|
||||
ret_tensorrt |= checkResult(odim, rt_out[i], out) == 0 ? 0 : ERROR_TENSORRT;
|
||||
std::cout<<"CUDNN vs TRT ";
|
||||
ret_cudnn_tensorrt |= checkResult(odim, cudnn_out[i], rt_out[i]) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
|
||||
}
|
||||
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
[net]
|
||||
Training
|
||||
# Training
|
||||
batch=64
|
||||
subdivisions=8
|
||||
# Testing
|
||||
@@ -90,9 +90,9 @@ stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
#[maxpool]
|
||||
#size=2
|
||||
#stride=1
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=1
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
@@ -1,10 +1,10 @@
|
||||
[net]
|
||||
# Testing
|
||||
#batch=1
|
||||
#subdivisions=1
|
||||
# batch=1
|
||||
# subdivisions=1
|
||||
# Training
|
||||
batch=16
|
||||
subdivisions=1
|
||||
batch=32
|
||||
subdivisions=32
|
||||
width=512
|
||||
height=512
|
||||
channels=3
|
||||
@@ -600,14 +600,14 @@ activation=leaky
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=24
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
|
||||
[yolo]
|
||||
mask = 6,7,8
|
||||
anchors = 10.256,16.494, 11.724,18.558, 17.678,16.437, 25.619,14.985, 46.845,79.02, 58.643,81.204, 23.646,208.56, 30.837,211.57, 37.921,211.16
|
||||
classes=3
|
||||
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
|
||||
classes=80
|
||||
num=9
|
||||
jitter=.3
|
||||
ignore_thresh = .7
|
||||
@@ -633,6 +633,7 @@ stride=2
|
||||
layers = -1, 61
|
||||
|
||||
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
@@ -685,14 +686,14 @@ activation=leaky
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=24
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
|
||||
[yolo]
|
||||
mask = 3,4,5
|
||||
anchors = 10.256,16.494, 11.724,18.558, 17.678,16.437, 25.619,14.985, 46.845,79.02, 58.643,81.204, 23.646,208.56, 30.837,211.57, 37.921,211.16
|
||||
classes=3
|
||||
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
|
||||
classes=80
|
||||
num=9
|
||||
jitter=.3
|
||||
ignore_thresh = .7
|
||||
@@ -772,16 +773,17 @@ activation=leaky
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=24
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
|
||||
[yolo]
|
||||
mask = 0,1,2
|
||||
anchors = 10.256,16.494, 11.724,18.558, 17.678,16.437, 25.619,14.985, 46.845,79.02, 58.643,81.204, 23.646,208.56, 30.837,211.57, 37.921,211.16
|
||||
classes=3
|
||||
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
|
||||
classes=80
|
||||
num=9
|
||||
jitter=.3
|
||||
ignore_thresh = .7
|
||||
truth_thresh = 1
|
||||
random=1
|
||||
|
||||
@@ -124,15 +124,15 @@ activation=leaky
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=24
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
|
||||
|
||||
[yolo]
|
||||
mask = 3,4,5
|
||||
anchors = 10.638,16.801, 13.183,19.091, 24.568,12.24, 54.462,77.421, 29.199,210.49, 37.495,212.21
|
||||
classes=3
|
||||
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
|
||||
classes=80
|
||||
num=6
|
||||
jitter=.3
|
||||
ignore_thresh = .7
|
||||
@@ -168,13 +168,13 @@ activation=leaky
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=24
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
[yolo]
|
||||
mask = 0,1,2
|
||||
anchors = 10.638,16.801, 13.183,19.091, 24.568,12.24, 54.462,77.421, 29.199,210.49, 37.495,212.21
|
||||
classes=3
|
||||
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
|
||||
classes=80
|
||||
num=6
|
||||
jitter=.3
|
||||
ignore_thresh = .7
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -3,10 +3,10 @@
|
||||
#batch=1
|
||||
#subdivisions=1
|
||||
# Training
|
||||
batch=64
|
||||
subdivisions=16
|
||||
width=224
|
||||
height=224
|
||||
batch=64
|
||||
subdivisions=1
|
||||
width=416
|
||||
height=416
|
||||
channels=3
|
||||
momentum=0.9
|
||||
decay=0.0005
|
||||
@@ -15,7 +15,7 @@ saturation = 1.5
|
||||
exposure = 1.5
|
||||
hue=.1
|
||||
|
||||
learning_rate=0.001
|
||||
learning_rate=0.00261
|
||||
burn_in=1000
|
||||
max_batches = 500200
|
||||
policy=steps
|
||||
@@ -26,13 +26,17 @@ scales=.1,.1
|
||||
batch_normalize=1
|
||||
filters=32
|
||||
size=3
|
||||
stride=1
|
||||
stride=2
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=3
|
||||
stride=2
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
@@ -42,217 +46,236 @@ stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=1024
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=1024
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=1024
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
|
||||
#######
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
filters=1024
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
filters=1024
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers=-9
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=64
|
||||
activation=leaky
|
||||
|
||||
[reorg]
|
||||
stride=2
|
||||
|
||||
[route]
|
||||
layers=-1,-4
|
||||
layers=-1
|
||||
groups=2
|
||||
group_id=1
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=32
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=32
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -1,-2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -6,-1
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers=-1
|
||||
groups=2
|
||||
group_id=1
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=64
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -1,-2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -6,-1
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers=-1
|
||||
groups=2
|
||||
group_id=1
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -1,-2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[route]
|
||||
layers = -6,-1
|
||||
|
||||
[maxpool]
|
||||
size=2
|
||||
stride=2
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
##################################
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=512
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
filters=1024
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=425
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
|
||||
[region]
|
||||
anchors = 0.57273, 0.677385, 1.87446, 2.06253, 3.33843, 5.47434, 7.88282, 3.52778, 9.77052, 9.16828
|
||||
bias_match=1
|
||||
|
||||
[yolo]
|
||||
mask = 3,4,5
|
||||
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
|
||||
classes=80
|
||||
coords=4
|
||||
num=5
|
||||
softmax=1
|
||||
num=6
|
||||
jitter=.3
|
||||
rescore=1
|
||||
scale_x_y = 1.05
|
||||
cls_normalizer=1.0
|
||||
iou_normalizer=0.07
|
||||
iou_loss=ciou
|
||||
ignore_thresh = .7
|
||||
truth_thresh = 1
|
||||
random=0
|
||||
resize=1.5
|
||||
nms_kind=greedynms
|
||||
beta_nms=0.6
|
||||
|
||||
object_scale=5
|
||||
noobject_scale=1
|
||||
class_scale=1
|
||||
coord_scale=1
|
||||
[route]
|
||||
layers = -4
|
||||
|
||||
absolute=1
|
||||
thresh = .6
|
||||
random=1
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=128
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[upsample]
|
||||
stride=2
|
||||
|
||||
[route]
|
||||
layers = -1, 23
|
||||
|
||||
[convolutional]
|
||||
batch_normalize=1
|
||||
filters=256
|
||||
size=3
|
||||
stride=1
|
||||
pad=1
|
||||
activation=leaky
|
||||
|
||||
[convolutional]
|
||||
size=1
|
||||
stride=1
|
||||
pad=1
|
||||
filters=255
|
||||
activation=linear
|
||||
|
||||
[yolo]
|
||||
mask = 1,2,3
|
||||
anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
|
||||
classes=80
|
||||
num=6
|
||||
jitter=.3
|
||||
scale_x_y = 1.05
|
||||
cls_normalizer=1.0
|
||||
iou_normalizer=0.07
|
||||
iou_loss=ciou
|
||||
ignore_thresh = .7
|
||||
truth_thresh = 1
|
||||
random=0
|
||||
resize=1.5
|
||||
nms_kind=greedynms
|
||||
beta_nms=0.6
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
person
|
||||
car
|
||||
truck
|
||||
bus
|
||||
motor
|
||||
bike
|
||||
rider
|
||||
traffic light
|
||||
traffic sign
|
||||
train
|
||||
@@ -0,0 +1,80 @@
|
||||
person
|
||||
bicycle
|
||||
car
|
||||
motorbike
|
||||
aeroplane
|
||||
bus
|
||||
train
|
||||
truck
|
||||
boat
|
||||
traffic light
|
||||
fire hydrant
|
||||
stop sign
|
||||
parking meter
|
||||
bench
|
||||
bird
|
||||
cat
|
||||
dog
|
||||
horse
|
||||
sheep
|
||||
cow
|
||||
elephant
|
||||
bear
|
||||
zebra
|
||||
giraffe
|
||||
backpack
|
||||
umbrella
|
||||
handbag
|
||||
tie
|
||||
suitcase
|
||||
frisbee
|
||||
skis
|
||||
snowboard
|
||||
sports ball
|
||||
kite
|
||||
baseball bat
|
||||
baseball glove
|
||||
skateboard
|
||||
surfboard
|
||||
tennis racket
|
||||
bottle
|
||||
wine glass
|
||||
cup
|
||||
fork
|
||||
knife
|
||||
spoon
|
||||
bowl
|
||||
banana
|
||||
apple
|
||||
sandwich
|
||||
orange
|
||||
broccoli
|
||||
carrot
|
||||
hot dog
|
||||
pizza
|
||||
donut
|
||||
cake
|
||||
chair
|
||||
sofa
|
||||
pottedplant
|
||||
bed
|
||||
diningtable
|
||||
toilet
|
||||
tvmonitor
|
||||
laptop
|
||||
mouse
|
||||
remote
|
||||
keyboard
|
||||
cell phone
|
||||
microwave
|
||||
oven
|
||||
toaster
|
||||
sink
|
||||
refrigerator
|
||||
book
|
||||
clock
|
||||
vase
|
||||
scissors
|
||||
teddy bear
|
||||
hair drier
|
||||
toothbrush
|
||||
@@ -0,0 +1,4 @@
|
||||
person
|
||||
bicycle
|
||||
car
|
||||
motorbike
|
||||
@@ -0,0 +1,3 @@
|
||||
person
|
||||
bike
|
||||
car
|
||||
@@ -0,0 +1,4 @@
|
||||
blue-cone
|
||||
yellow-cone
|
||||
orange-cone
|
||||
big-orange-cone
|
||||
@@ -0,0 +1,20 @@
|
||||
aeroplane
|
||||
bicycle
|
||||
bird
|
||||
boat
|
||||
bottle
|
||||
bus
|
||||
car
|
||||
cat
|
||||
chair
|
||||
cow
|
||||
diningtable
|
||||
dog
|
||||
horse
|
||||
motorbike
|
||||
person
|
||||
pottedplant
|
||||
sheep
|
||||
sofa
|
||||
train
|
||||
tvmonitor
|
||||
@@ -0,0 +1,70 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#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;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
#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;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user