Compare commits
59 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 615b4c8a52 | |||
| fe37bcdf1e | |||
| 6911752e3e | |||
| 33844c1ab2 | |||
| 7233b065a8 | |||
| 2fa9f691ab | |||
| cfb457fdec | |||
| 1af2b792b8 | |||
| d5ae26dfef | |||
| 35787cc771 | |||
| bb7d382d96 | |||
| 4a7b290fdf | |||
| 5a1c7fb83d | |||
| b1a3620061 | |||
| 5bbb3f3480 | |||
| 88e0f9393a | |||
| 2d62d2524c | |||
| 7f667af48f | |||
| 2bcf9ab53b | |||
| ed83dfd99b | |||
| 5f444825ad | |||
| 12fd8d0109 | |||
| 32b6d51949 | |||
| 86da302163 | |||
| ff5e376873 | |||
| a6d19d3698 | |||
| e38d8e82ca | |||
| caf4ddbce2 | |||
| 8627c5feeb | |||
| be31ae10d2 | |||
| f51a35ac5a | |||
| 428858eaae | |||
| 68ecd15125 | |||
| 3311196edb | |||
| 5c7301f7f4 | |||
| d2456b1d8a | |||
| 7d1d31ac45 | |||
| 1b9fe1ea61 | |||
| 753699104a | |||
| 978833fd6e | |||
| 17c5b7a818 | |||
| ca9d18c69e | |||
| 41ba8afa6d | |||
| ea1f0cc193 | |||
| 9b413b77ab | |||
| 9a4a65a3c3 | |||
| bd45b016bb | |||
| 28c012cade | |||
| 9b03bfcbd7 | |||
| 3c32d0c876 | |||
| 40c67e8536 | |||
| 38a1956404 | |||
| 21a698bb63 | |||
| 46c32edb94 | |||
| 1c4aa3c5d7 | |||
| d631169821 | |||
| 61b6621d2c | |||
| 39df47574e | |||
| 1c8122f22d |
@@ -1,4 +1,10 @@
|
||||
*~
|
||||
demo/demo/data/img_crop/
|
||||
demo/demo/data/img_disparity/
|
||||
demo/demo/data/map/
|
||||
demo/demo/data/masks_orient/
|
||||
demo/demo/data/pmat_new/
|
||||
demo/demo/data/masks_v2/
|
||||
build/
|
||||
.vscode/
|
||||
*.bin
|
||||
@@ -8,9 +14,6 @@ build/
|
||||
*.h5
|
||||
*.tar.gz
|
||||
*.weights
|
||||
*.zip
|
||||
.idea/
|
||||
*.hdf5
|
||||
*.pk
|
||||
*.table
|
||||
demo/COCO_val2017
|
||||
demo/BDD100K_val
|
||||
@@ -0,0 +1,6 @@
|
||||
[submodule "tracker_CLASS"]
|
||||
path = tracker_CLASS
|
||||
url = https://github.com/mive93/tracker_CLASS.git
|
||||
[submodule "masa_protocol"]
|
||||
path = masa_protocol
|
||||
url = https://git.hipert.unimore.it/rcavicchioli/masa_protocol.git
|
||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.5)
|
||||
|
||||
project (tkDNN)
|
||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wno-deprecated-declarations -Wno-unused-variable")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/tkDNN)
|
||||
|
||||
# project specific flags
|
||||
@@ -10,7 +10,6 @@ if(DEBUG)
|
||||
add_definitions(-DDEBUG)
|
||||
endif()
|
||||
|
||||
add_definitions(-DTKDNN_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# CUDA
|
||||
@@ -18,14 +17,11 @@ add_definitions(-DTKDNN_PATH="${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
find_package(CUDA 9.0 REQUIRED)
|
||||
SET(CUDA_SEPARABLE_COMPILATION ON)
|
||||
#set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_30 --compiler-options '-fPIC'")
|
||||
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")
|
||||
file(GLOB tkdnn_CUSRC "src/kernels/*.cu")
|
||||
cuda_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIRS})
|
||||
cuda_add_library(kernels SHARED ${tkdnn_CUSRC})
|
||||
|
||||
@@ -33,31 +29,35 @@ cuda_add_library(kernels SHARED ${tkdnn_CUSRC})
|
||||
#-------------------------------------------------------------------------------
|
||||
# External Libraries
|
||||
#-------------------------------------------------------------------------------
|
||||
find_package(Eigen3 REQUIRED)
|
||||
include_directories(${EIGEN3_INCLUDE_DIR})
|
||||
|
||||
find_package(OpenCV REQUIRED)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV")
|
||||
|
||||
# gives problems in cross-compiling, probably malformed cmake config
|
||||
#find_package(yaml-cpp REQUIRED)
|
||||
include_directories(/usr/include/gdal)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Build Libraries
|
||||
#-------------------------------------------------------------------------------
|
||||
file(GLOB tkdnn_SRC "src/*.cpp")
|
||||
set(tkdnn_LIBS kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRARIES} ${OpenCV_LIBS} yaml-cpp)
|
||||
set(tkdnn_LIBS kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRARIES} ${OpenCV_LIBS})
|
||||
|
||||
file(GLOB class_SRC "src/class_src/*.cpp")
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++11 -O3")
|
||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} ${NVINFER_INCLUDES} "~/repos/cereal/include" ${CMAKE_CURRENT_SOURCE_DIR}/tracker_CLASS/c++/src /usr/include/python2.7)
|
||||
|
||||
set(class_LIBS ${OpenCV_LIBS} -lgdal yaml-cpp python2.7)
|
||||
|
||||
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})
|
||||
|
||||
add_library(CLASS SHARED ${class_SRC})
|
||||
target_link_libraries(CLASS ${class_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)
|
||||
|
||||
@@ -67,51 +67,62 @@ 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_berkeley tests/yolo3_berkeley/yolo3_berkeley.cpp)
|
||||
target_link_libraries(test_yolo3_berkeley tkDNN)
|
||||
|
||||
add_executable(test_yolo3_tetrapack tests/yolo3_tetrapack/yolo3_tetrapack.cpp)
|
||||
target_link_libraries(test_yolo3_tetrapack tkDNN)
|
||||
|
||||
add_executable(test_yolo3_tetrapack_resize tests/yolo3_tetrapack_resize/yolo3_tetrapack_resize.cpp)
|
||||
target_link_libraries(test_yolo3_tetrapack_resize tkDNN)
|
||||
|
||||
add_executable(test_yolo3_BCDS6 tests/yolo3_BCDS6/yolo3_BCDS6.cpp)
|
||||
target_link_libraries(test_yolo3_BCDS6 tkDNN)
|
||||
add_executable(test_yolo3_flir tests/yolo3_flir/yolo3_flir.cpp)
|
||||
target_link_libraries(test_yolo3_flir tkDNN)
|
||||
|
||||
add_executable(test_imuodom tests/imuodom/imuodom.cpp)
|
||||
target_link_libraries(test_imuodom tkDNN)
|
||||
################################################################################
|
||||
|
||||
# DARKNET
|
||||
file(GLOB darknet_SRC "tests/darknet/*.cpp")
|
||||
foreach(test_SRC ${darknet_SRC})
|
||||
get_filename_component(test_NAME "${test_SRC}" NAME_WE)
|
||||
set(test_NAME test_${test_NAME})
|
||||
add_executable(${test_NAME} ${test_SRC})
|
||||
target_link_libraries(${test_NAME} tkDNN)
|
||||
endforeach()
|
||||
|
||||
# MOBILENET
|
||||
add_executable(test_mobilenetv2ssd tests/mobilenet/mobilenetv2ssd/mobilenetv2ssd.cpp)
|
||||
target_link_libraries(test_mobilenetv2ssd tkDNN)
|
||||
|
||||
add_executable(test_bdd-mobilenetv2ssd tests/mobilenet/bdd-mobilenetv2ssd/bdd-mobilenetv2ssd.cpp)
|
||||
target_link_libraries(test_bdd-mobilenetv2ssd tkDNN)
|
||||
|
||||
add_executable(test_mobilenetv2ssd512 tests/mobilenet/mobilenetv2ssd512/mobilenetv2ssd512.cpp)
|
||||
target_link_libraries(test_mobilenetv2ssd512 tkDNN)
|
||||
|
||||
# BACKBONES
|
||||
add_executable(test_resnet101 tests/backbones/resnet101/resnet101.cpp)
|
||||
target_link_libraries(test_resnet101 tkDNN)
|
||||
|
||||
add_executable(test_dla34 tests/backbones/dla34/dla34.cpp)
|
||||
target_link_libraries(test_dla34 tkDNN)
|
||||
|
||||
# CENTERNET
|
||||
add_executable(test_resnet101_cnet tests/centernet/resnet101_cnet/resnet101_cnet.cpp)
|
||||
target_link_libraries(test_resnet101_cnet tkDNN)
|
||||
|
||||
add_executable(test_dla34_cnet tests/centernet/dla34_cnet/dla34_cnet.cpp)
|
||||
target_link_libraries(test_dla34_cnet tkDNN)
|
||||
|
||||
# DEMOS
|
||||
add_executable(test_rtinference tests/test_rtinference/rtinference.cpp)
|
||||
target_link_libraries(test_rtinference tkDNN)
|
||||
|
||||
add_executable(map_demo demo/demo/map.cpp)
|
||||
target_link_libraries(map_demo tkDNN)
|
||||
add_executable(yolo3_demo demo/demo/demo.cpp
|
||||
tracker_CLASS/c++/src/ekf.cpp
|
||||
tracker_CLASS/c++/src/trackutils.cpp
|
||||
tracker_CLASS/c++/src/plot.cpp
|
||||
tracker_CLASS/c++/src/tracker.cpp )
|
||||
|
||||
|
||||
target_link_libraries(yolo3_demo tkDNN CLASS)
|
||||
|
||||
|
||||
|
||||
add_executable(demo demo/demo/demo.cpp)
|
||||
target_link_libraries(demo tkDNN)
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Install
|
||||
@@ -127,3 +138,18 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/" # source directory
|
||||
DESTINATION "share/tkDNN/cmake/" # target directory
|
||||
)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# Prepare for test
|
||||
#-------------------------------------------------------------------------------
|
||||
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,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
tkDNN
|
||||
Copyright (C) 2017 Francesco Gatti
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
@@ -1,344 +1,58 @@
|
||||
# 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, 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.
|
||||
tkDNN is a Deep Neural Network library built with cuDNN primitives specifically thought to work on NVIDIA TK1(and all successive) board.<br>
|
||||
The main scope is to do high performance inference on already trained models.
|
||||
|
||||
|
||||
If you use tkDNN in your research, please cite one of the following papers. For use in commercial solutions, write at gattifrancesco@hotmail.it and micaela.verucchi@unimore.it or refer to https://hipert.unimore.it/ .
|
||||
|
||||
```
|
||||
Accepted paper @ IRC 2020, will soon be published.
|
||||
M. Verucchi, L. Bartoli, F. Bagni, F. Gatti, P. Burgio and M. Bertogna, "Real-Time clustering and LiDAR-camera fusion on embedded platforms for self-driving cars", in proceedings in IEEE Robotic Computing (2020)
|
||||
|
||||
Accepted paper @ ETFA 2020, will soon be published.
|
||||
M. Verucchi, G. Brilli, D. Sapienza, M. Verasani, M. Arena, F. Gatti, A. Capotondi, R. Cavicchioli, M. Bertogna, M. Solieri
|
||||
"A Systematic Assessment of Embedded Neural Networks for Object Detection", in IEEE International Conference on Emerging Technologies and Factory Automation (2020)
|
||||
```
|
||||
|
||||
## Results
|
||||
Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimesion as the input size, on
|
||||
* RTX 2080Ti (CUDA 10.2, TensorRT 7.0.0, Cudnn 7.6.5);
|
||||
* Xavier AGX, Jetpack 4.3 (CUDA 10.0, CUDNN 7.6.3, tensorrt 6.0.1 );
|
||||
* Tx2, Jetpack 4.2 (CUDA 10.0, CUDNN 7.3.1, tensorrt 5.0.6 );
|
||||
* Jetson Nano, Jetpack 4.4 (CUDA 10.2, CUDNN 8.0.0, tensorrt 7.1.0 ).
|
||||
|
||||
| Platform | Network | FP32, B=1 | FP32, B=4 | FP16, B=1 | FP16, B=4 | INT8, B=1 | INT8, B=4 |
|
||||
| :------: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: |
|
||||
| RTX 2080Ti | yolo4 320 | 118,59 |237,31 | 207,81 | 443,32 | 262,37 | 530,93 |
|
||||
| RTX 2080Ti | yolo4 416 | 104,81 |162,86 | 169,06 | 293,78 | 206,93 | 353,26 |
|
||||
| RTX 2080Ti | yolo4 512 | 92,98 |132,43 | 140,36 | 215,17 | 165,35 | 254,96 |
|
||||
| RTX 2080Ti | yolo4 608 | 63,77 |81,53 | 111,39 | 152,89 | 127,79 | 184,72 |
|
||||
| AGX Xavier | yolo4 320 | 26,78 |32,05 | 57,14 | 79,05 | 73,15 | 97,56 |
|
||||
| AGX Xavier | yolo4 416 | 19,96 |21,52 | 41,01 | 49,00 | 50,81 | 60,61 |
|
||||
| AGX Xavier | yolo4 512 | 16,58 |16,98 | 31,12 | 33,84 | 37,82 | 41,28 |
|
||||
| AGX Xavier | yolo4 608 | 9,45 |10,13 | 21,92 | 23,36 | 27,05 | 28,93 |
|
||||
| Tx2 | yolo4 320 | 11,18 | 12,07 | 15,32 | 16,31 | - | - |
|
||||
| Tx2 | yolo4 416 | 7,30 | 7,58 | 9,45 | 9,90 | - | - |
|
||||
| Tx2 | yolo4 512 | 5,96 | 5,95 | 7,22 | 7,23 | - | - |
|
||||
| Tx2 | yolo4 608 | 3,63 | 3,65 | 4,67 | 4,70 | - | - |
|
||||
| Nano | yolo4 320 | 4,23 | 4,55 | 6,14 | 6,53 | - | - |
|
||||
| Nano | yolo4 416 | 2,88 | 3,00 | 3,90 | 4,04 | - | - |
|
||||
| Nano | yolo4 512 | 2,32 | 2,34 | 3,02 | 3,04 | - | - |
|
||||
| Nano | yolo4 608 | 1,40 | 1,41 | 1,92 | 1,93 | - | - |
|
||||
|
||||
## Index
|
||||
- [tkDNN](#tkdnn)
|
||||
- [Index](#index)
|
||||
- [Dependencies](#dependencies)
|
||||
- [About OpenCV](#about-opencv)
|
||||
- [How to compile this repo](#how-to-compile-this-repo)
|
||||
- [Workflow](#workflow)
|
||||
- [How to export weights](#how-to-export-weights)
|
||||
- [1)Export weights from darknet](#1export-weights-from-darknet)
|
||||
- [2)Export weights for DLA34 and ResNet101](#2export-weights-for-dla34-and-resnet101)
|
||||
- [3)Export weights for CenterNet](#3export-weights-for-centernet)
|
||||
- [4)Export weights for MobileNetSSD](#4export-weights-for-mobilenetssd)
|
||||
- [Run the demo](#run-the-demo)
|
||||
- [FP16 inference](#fp16-inference)
|
||||
- [INT8 inference](#int8-inference)
|
||||
- [mAP demo](#map-demo)
|
||||
- [Existing tests and supported networks](#existing-tests-and-supported-networks)
|
||||
- [References](#references)
|
||||
|
||||
|
||||
|
||||
|
||||
## Dependencies
|
||||
This branch works on every NVIDIA GPU that supports the dependencies:
|
||||
this branch actually work on every NVIDIA GPU that support the dependencies:
|
||||
* CUDA 10.0
|
||||
* CUDNN 7.603
|
||||
* TENSORRT 6.01
|
||||
* OPENCV 3.4
|
||||
* yaml-cpp 0.5.2 (sudo apt install libyaml-cpp-dev)
|
||||
* OPENCV 4.1
|
||||
|
||||
## About OpenCV
|
||||
To compile and install OpenCV4 with contrib us the script ```install_OpenCV4.sh```. It will download and compile OpenCV in Download folder.
|
||||
```
|
||||
bash scripts/install_OpenCV4.sh
|
||||
```
|
||||
When using openCV not compiled with contrib, comment the definition of OPENCV_CUDACONTRIBCONTRIB in include/tkDNN/DetectionNN.h. When commented, the preprocessing of the networks is computed on the CPU, otherwise on the GPU. In the latter case some milliseconds are saved in the end-to-end latency.
|
||||
## Dependencies
|
||||
|
||||
## How to compile this repo
|
||||
Build with cmake. If using Ubuntu 18.04 a new version of cmake is needed (3.15 or above).
|
||||
```
|
||||
git clone https://github.com/ceccocats/tkDNN
|
||||
cd tkDNN
|
||||
mkdir build
|
||||
cd build
|
||||
cmake ..
|
||||
make
|
||||
sudo apt install libgdal-dev libeigen3-dev python-matplotlib libyaml-cpp-dev libcereal-dev python2.7-dev
|
||||
```
|
||||
|
||||
## Workflow
|
||||
Steps needed to do inference on tkDNN with a custom neural network.
|
||||
* Build and train a NN model with your favorite framework.
|
||||
* Export weights and bias for each layer and save them in a binary file (one for layer).
|
||||
* Export outputs for each layer and save them in a binary file (one for layer).
|
||||
* Create a new test and define the network, layer by layer using the weights extracted and the output to check the results.
|
||||
* Do inference.
|
||||
|
||||
## How to export weights
|
||||
|
||||
Weights are essential for any network to run inference. For each test a folder organized as follow is needed (in the build folder):
|
||||
```
|
||||
test_nn
|
||||
|---- layers/ (folder containing a binary file for each layer with the corresponding wieghts and bias)
|
||||
|---- debug/ (folder containing a binary file for each layer with the corresponding outputs)
|
||||
```
|
||||
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://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://git.hipert.unimore.it/fgatti/darknet.git
|
||||
cd darknet
|
||||
make
|
||||
mkdir layers debug
|
||||
./darknet export <path-to-cfg-file> <path-to-weights> layers
|
||||
```
|
||||
N.b. Use compilation with CPU (leave GPU=0 in Makefile) if you also want debug.
|
||||
|
||||
### 2)Export weights for DLA34 and ResNet101
|
||||
To get weights and outputs needed to run the tests dla34 and resnet101 use the Python script and the Anaconda environment included in the repository.
|
||||
|
||||
Create Anaconda environment and activate it:
|
||||
```
|
||||
conda env create -f file_name.yml
|
||||
source activate env_name
|
||||
python <script name>
|
||||
```
|
||||
### 3)Export weights for CenterNet
|
||||
To get the weights needed to run Centernet tests use [this](https://github.com/sapienzadavide/CenterNet.git) fork of the original Centernet.
|
||||
```
|
||||
git clone https://github.com/sapienzadavide/CenterNet.git
|
||||
```
|
||||
* follow the instruction in the README.md and INSTALL.md
|
||||
|
||||
```
|
||||
python demo.py --input_res 512 --arch resdcn_101 ctdet --demo /path/to/image/or/folder/or/video/or/webcam --load_model ../models/ctdet_coco_resdcn101.pth --exp_wo --exp_wo_dim 512
|
||||
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.
|
||||
|
||||
```
|
||||
git clone https://github.com/mive93/pytorch-ssd
|
||||
cd pytorch-ssd
|
||||
conda env create -f env_mobv2ssd.yml
|
||||
python run_ssd_live_demo.py mb2-ssd-lite <pth-model-fil> <labels-file>
|
||||
```
|
||||
|
||||
## Darknet Parser
|
||||
tkDNN implement and easy parser for darknet cfg files, a network can be converted with *tk::dnn::darknetParser*:
|
||||
```
|
||||
// example of parsing yolo4
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser("yolov4.cfg", "yolov4/layers", "coco.names");
|
||||
net->print();
|
||||
```
|
||||
All models from darknet are now parsed directly from cfg, you still need to export the weights with the descripted tools in the previus section.
|
||||
<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:
|
||||
```
|
||||
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 succesfully created your rt file, run the demo:
|
||||
```
|
||||
./demo yolo4_fp32.rt ../demo/yolo_test.mp4 y
|
||||
```
|
||||
In general the demo program takes 6 parameters:
|
||||
```
|
||||
./demo <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)
|
||||
|
||||
N.b. By default it is used FP32 inference
|
||||
|
||||
|
||||

|
||||
|
||||
### FP16 inference
|
||||
|
||||
To run the an object detection demo with FP16 inference follow these steps (example with yolov3):
|
||||
```
|
||||
export TKDNN_MODE=FP16 # set the half floating point optimization
|
||||
rm yolo3_fp16.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo3 # run the yolo test (is slow)
|
||||
./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 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)
|
||||
```
|
||||
bash scripts/download_validation.sh COCO
|
||||
```
|
||||
to automatically download COCO2017 validation (inside demo folder) and create those needed file. Use BDD insted of COCO to download BDD validation.
|
||||
|
||||
Then a complete example using yolo3 and COCO dataset would be:
|
||||
```
|
||||
export TKDNN_MODE=INT8
|
||||
export TKDNN_CALIB_LABEL_PATH=../demo/COCO_val2017/all_labels.txt
|
||||
export TKDNN_CALIB_IMG_PATH=../demo/COCO_val2017/all_images.txt
|
||||
rm yolo3_int8.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo3 # run the yolo test (is slow)
|
||||
./demo yolo3_int8.rt ../demo/yolo_test.mp4 y
|
||||
```
|
||||
N.B.
|
||||
* Using INT8 inference will lead to some errors in the results.
|
||||
* 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 desidered **max** batch size.
|
||||
The test will still run with a batch of 1, but the created tensorRT can manage the desidered batch size.
|
||||
|
||||
### Test batch Inference
|
||||
This will test the network with random input and check if the output of each batch is the same.
|
||||
```
|
||||
./test_rtinference <network-rt-file> <number-of-batches>
|
||||
# <number-of-batches> should be less or equal to the max batch size of the <network-rt-file>
|
||||
|
||||
# example
|
||||
export TKDNN_BATCHSIZE=4 # set max batch size
|
||||
rm yolo3_fp32.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo3 # build RT file
|
||||
./test_rtinference yolo3_fp32.rt 4 # test with a batch size of 4
|
||||
```
|
||||
|
||||
## mAP demo
|
||||
|
||||
To compute mAP, precision, recall and f1score, run the map_demo.
|
||||
|
||||
A validation set is needed.
|
||||
To download COCO_val2017 (80 classes) run (form the root folder):
|
||||
```
|
||||
bash scripts/download_validation.sh COCO
|
||||
```
|
||||
To download Berkeley_val (10 classes) run (form the root folder):
|
||||
```
|
||||
bash scripts/download_validation.sh BDD
|
||||
```
|
||||
|
||||
To compute the map, the following parameters are needed:
|
||||
```
|
||||
./map_demo <network rt> <network type [y|c|m]> <labels file path> <config file path>
|
||||
```
|
||||
where
|
||||
* ```<network rt>```: rt file of a chosen network on which compute the mAP.
|
||||
* ```<network type [y|c|m]>```: type of network. Right now only y(yolo), c(centernet) and m(mobilenet) are allowed
|
||||
* ```<labels file path>```: path to a text file containing all the paths of the ground-truth labels. It is important that all the labels of the ground-truth are in a folder called 'labels'. In the folder containing the folder 'labels' there should be also a folder 'images', containing all the ground-truth images having the same same as the labels. To better understand, if there is a label path/to/labels/000001.txt there should be a corresponding image path/to/images/000001.jpg.
|
||||
* ```<config file path>```: path to a yaml file with the parameters needed for the mAP computation, similar to demo/config.yaml
|
||||
|
||||
Example:
|
||||
The recommended workflow follow these step:
|
||||
* Build and train a model in Keras (on any PC)
|
||||
* Export weights and bias
|
||||
* Define the model on tkDNN
|
||||
* Do inference (on TK1)
|
||||
|
||||
## Compile the library
|
||||
Build with cmake
|
||||
```
|
||||
mkdir build
|
||||
cd build
|
||||
./map_demo dla34_cnet_FP32.rt c ../demo/COCO_val2017/all_labels.txt ../demo/config.yaml
|
||||
cmake ..
|
||||
# use -DTEST_DATA=False to skip dataset download
|
||||
make
|
||||
```
|
||||
during the cmake configuration it will be dowloaded the weights needed for running
|
||||
the tests
|
||||
|
||||
This demo also creates a json file named ```net_name_COCO_res.json``` containing all the detections computed. The detections are in COCO format, the correct format to subit the results to [CodaLab COCO detection challenge](https://competitions.codalab.org/competitions/20794#participate).
|
||||
## Test
|
||||
Assumiung you have correctly builded the library these are the test ready to exec:
|
||||
* test_simple: a simple convolutional and dense network (CUDNN only)
|
||||
* test_mnist: the famous mnist netwok (CUDNN and TENSORRT)
|
||||
* test_mnistRT: the mnist network hardcoded in using tensorRT apis (TENSORRT only)
|
||||
* test_yolo: YOLO detection network (CUDNN and TENSORRT)
|
||||
* test_yolo_tiny: smaller version of YOLO (CUDNN and TENSRRT)
|
||||
* test_yolo3_berkeley: our yolo3 version trained with BDD100K dateset
|
||||
|
||||
## Existing tests and supported networks
|
||||
|
||||
| Test Name | Network | Dataset | N Classes | Input size | Weights |
|
||||
| :---------------- | :-------------------------------------------- | :-----------------------------------------------------------: | :-------: | :-----------: | :------------------------------------------------------------------------ |
|
||||
| yolo | YOLO v2<sup>1</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 608x608 | [weights](https://cloud.hipert.unimore.it/s/nf4PJ3k8bxBETwL/download) |
|
||||
| yolo_224 | YOLO v2<sup>1</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 224x224 | weights |
|
||||
| yolo_berkeley | YOLO v2<sup>1</sup> | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 416x736 | weights |
|
||||
| yolo_relu | YOLO v2 (with ReLU, not Leaky)<sup>1</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | weights |
|
||||
| yolo_tiny | YOLO v2 tiny<sup>1</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/m3orfJr8pGrN5mQ/download) |
|
||||
| yolo_voc | YOLO v2<sup>1</sup> | [VOC ](http://host.robots.ox.ac.uk/pascal/VOC/) | 21 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/DJC5Fi2pEjfNDP9/download) |
|
||||
| yolo3 | YOLO v3<sup>2</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/jPXmHyptpLoNdNR/download) |
|
||||
| yolo3_512 | YOLO v3<sup>2</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/RGecMeGLD4cXEWL/download) |
|
||||
| yolo3_berkeley | YOLO v3<sup>2</sup> | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 320x544 | [weights](https://cloud.hipert.unimore.it/s/o5cHa4AjTKS64oD/download) |
|
||||
| yolo3_coco4 | YOLO v3<sup>2</sup> | [COCO 2014](http://cocodataset.org/) | 4 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/o27NDzSAartbyc4/download) |
|
||||
| yolo3_flir | YOLO v3<sup>2</sup> | [FREE FLIR](https://www.flir.com/oem/adas/adas-dataset-form/) | 3 | 320x544 | [weights](https://cloud.hipert.unimore.it/s/62DECncmF6bMMiH/download) |
|
||||
| yolo3_tiny | YOLO v3 tiny<sup>2</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/LMcSHtWaLeps8yN/download) |
|
||||
| yolo3_tiny512 | YOLO v3 tiny<sup>2</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/8Zt6bHwHADqP4JC/download) |
|
||||
| dla34 | Deep Leayer Aggreagtion (DLA) 34<sup>3</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 224x224 | weights |
|
||||
| dla34_cnet | Centernet (DLA34 backend)<sup>4</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/KRZBbCQsKAtQwpZ/download) |
|
||||
| mobilenetv2ssd | Mobilnet v2 SSD Lite<sup>5</sup> | [VOC ](http://host.robots.ox.ac.uk/pascal/VOC/) | 21 | 300x300 | [weights](https://cloud.hipert.unimore.it/s/x4ZfxBKN23zAJQp/download) |
|
||||
| mobilenetv2ssd512 | Mobilnet v2 SSD Lite<sup>5</sup> | [COCO 2017](http://cocodataset.org/) | 81 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/pdCw2dYyHMJrcEM/download) |
|
||||
| resnet101 | Resnet 101<sup>6</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 224x224 | weights |
|
||||
| resnet101_cnet | Centernet (Resnet101 backend)<sup>4</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/5BTjHMWBcJk8g3i/download) |
|
||||
| csresnext50-panet-spp | Cross Stage Partial Network <sup>7</sup> | [COCO 2014](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/Kcs4xBozwY4wFx8/download) |
|
||||
| yolo4 | Yolov4 <sup>8</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) |
|
||||
| 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 | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download) |
|
||||
|
||||
|
||||
## References
|
||||
|
||||
1. Redmon, Joseph, and Ali Farhadi. "YOLO9000: better, faster, stronger." Proceedings of the IEEE conference on computer vision and pattern recognition. 2017.
|
||||
2. Redmon, Joseph, and Ali Farhadi. "Yolov3: An incremental improvement." arXiv preprint arXiv:1804.02767 (2018).
|
||||
3. Yu, Fisher, et al. "Deep layer aggregation." Proceedings of the IEEE conference on computer vision and pattern recognition. 2018.
|
||||
4. Zhou, Xingyi, Dequan Wang, and Philipp Krähenbühl. "Objects as points." arXiv preprint arXiv:1904.07850 (2019).
|
||||
5. Sandler, Mark, et al. "Mobilenetv2: Inverted residuals and linear bottlenecks." Proceedings of the IEEE conference on computer vision and pattern recognition. 2018.
|
||||
6. He, Kaiming, et al. "Deep residual learning for image recognition." Proceedings of the IEEE conference on computer vision and pattern recognition. 2016.
|
||||
7. Wang, Chien-Yao, et al. "CSPNet: A New Backbone that can Enhance Learning Capability of CNN." arXiv preprint arXiv:1911.11929 (2019).
|
||||
8. Bochkovskiy, Alexey, Chien-Yao Wang, and Hong-Yuan Mark Liao. "YOLOv4: Optimal Speed and Accuracy of Object Detection." arXiv preprint arXiv:2004.10934 (2020).
|
||||
## yolo3 berkeley demo detection
|
||||
For the live detection you need to precompile the tensorRT file by luncing the desidered network test, this is the recommended process:
|
||||
```
|
||||
export TKDNN_MODE=FP16 # set the half floating point optimization
|
||||
rm yolo3_berkeley.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_yolo3_berkeley # run the yolo test (is slow)
|
||||
# with f16 inference the result will be a bit incorrect
|
||||
```
|
||||
this will genereate a yolo3_berkeley.rt file that can be used for live detection:
|
||||
```
|
||||
./yolo3_demo # launch detection on a demo video
|
||||
./yolo3_demo yolo3_berkeley.rt /dev/video0 # launch detection on device 0
|
||||
```
|
||||

|
||||
|
||||
@@ -1,66 +1,33 @@
|
||||
# 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 the header files
|
||||
|
||||
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
|
||||
find_path(CUDNN_INCLUDE_DIR
|
||||
${CMAKE_SYSROOT}/usr/local/include
|
||||
${CMAKE_SYSROOT}/usr/include
|
||||
/usr/local/nvidia/tensorrt/include/
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
|
||||
if(CUDNN_FOUND)
|
||||
set(CUDNN_LIBRARIES ${CUDNN_LIBRARY} ${NVINFER_LIBRARY})
|
||||
set(CUDNN_INCLUDE_DIRS ${CUDNN_INCLUDE_DIR} ${NVINFER_INCLUDE_DIR})
|
||||
endif()
|
||||
set(OLD_ROOT ${CMAKE_FIND_ROOT_PATH})
|
||||
list(APPEND CMAKE_FIND_ROOT_PATH /)
|
||||
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.7)
|
||||
list(APPEND CMAKE_FIND_LIBRARY_SUFFIXES .so.5)
|
||||
find_library(CUDNN_LIB
|
||||
NAMES cudnn
|
||||
PATHS
|
||||
/usr/local/driveworks/targets/${CMAKE_SYSTEM_PROCESSOR}-Linux/lib
|
||||
/usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
find_library(CUDNN_NVLIB
|
||||
NAMES "nvinfer"
|
||||
PATHS
|
||||
/usr/local/driveworks/targets/${CMAKE_SYSTEM_PROCESSOR}-Linux/lib
|
||||
/usr/lib/${CMAKE_SYSTEM_PROCESSOR}-linux-gnu/
|
||||
NO_DEFAULT_PATH
|
||||
)
|
||||
set(CMAKE_FIND_ROOT_PATH ${OLD_ROOT})
|
||||
|
||||
set(CUDNN_FOUND true)
|
||||
set(CUDNN_LIBRARIES ${CUDNN_LIB} ${CUDNN_NVLIB})
|
||||
message("-- Found CUDNN: " ${CUDNN_LIB})
|
||||
message("-- Found NVINFER: " ${CUDNN_NVLIB})
|
||||
set(CUDNN_FOUND true)
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
classes : 80 #number of classes
|
||||
map_points : 101 #number of recall points (0 for all, 101 for COCO, 11 PascalVOC)
|
||||
map_levels : 10 #number of IoU step for the AP
|
||||
map_step : 0.05 #step of IoU
|
||||
IoU_thresh : 0.5 #starting IoU threshold
|
||||
conf_thresh : 0.0 #threshold on the condifence of the bbox
|
||||
verbose : false #print on screen information
|
||||
@@ -1,7 +0,0 @@
|
||||
classes : 3 #number of classes
|
||||
map_points : 101 #number of recall points (0 for all, 101 for COCO, 11 PascalVOC)
|
||||
map_levels : 10 #number of IoU step for the AP
|
||||
map_step : 0.05 #step of IoU
|
||||
IoU_thresh : 0.5 #starting IoU threshold
|
||||
conf_thresh : 0.0 #threshold on the condifence of the bbox
|
||||
verbose : false #print on screen information
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Mon 06 May 2019 11:32:13 PM CEST"
|
||||
image_width: 1920
|
||||
image_height: 1080
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 1.6158690952190570e+03, 0., 9.4702812371722337e+02, 0.,
|
||||
1.6123979985757153e+03, 5.1995630055718266e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -4.0971199964304100e-01, 1.8755404192050384e-01,
|
||||
-5.3059322427743867e-03, -1.0380603625304912e-03, 0. ]
|
||||
avg_reprojection_error: 3.4351035832972515e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 10:32:53 AM CEST"
|
||||
image_width: 3072
|
||||
image_height: 1728
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 4.7264390181579711e+03, 0., 1.5059850098280642e+03, 0.,
|
||||
4.6793092340700096e+03, 6.7300681982359868e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -4.2669569210605879e-01, 6.6337608795749903e-01,
|
||||
-1.3881256269106437e-03, 5.2468063845700682e-03, 0. ]
|
||||
avg_reprojection_error: 3.1312290189919406e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 10:14:44 AM CEST"
|
||||
image_width: 1920
|
||||
image_height: 1080
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 1.6902498656747011e+03, 0., 9.7959318966703324e+02, 0.,
|
||||
1.7552884617253583e+03, 5.3327953707582492e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -5.4891909767312119e-01, 2.5555919841568631e-01,
|
||||
-4.3831358875660656e-03, -1.3934378903760349e-02, 0. ]
|
||||
avg_reprojection_error: 1.1758482932800183e+00
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Mon 06 May 2019 11:32:13 PM CEST"
|
||||
image_width: 1920
|
||||
image_height: 1080
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 1.6158690952190570e+03, 0., 9.4702812371722337e+02, 0.,
|
||||
1.6123979985757153e+03, 5.1995630055718266e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -4.0971199964304100e-01, 1.8755404192050384e-01,
|
||||
-5.3059322427743867e-03, -1.0380603625304912e-03, 0. ]
|
||||
avg_reprojection_error: 3.4351035832972515e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 09:56:50 AM CEST"
|
||||
image_width: 1920
|
||||
image_height: 1080
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 1.6229477302581809e+03, 0., 1.0277357980566628e+03, 0.,
|
||||
1.6485741394129034e+03, 5.5596919291027621e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -3.7853584845653426e-01, 7.8553352913896368e-02,
|
||||
-6.5552938633907229e-03, -1.6436824648695104e-02, 0. ]
|
||||
avg_reprojection_error: 8.4629096638637347e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Fri 03 May 2019 11:56:13 PM CEST"
|
||||
image_width: 3072
|
||||
image_height: 1728
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 5.8796921906556563e+03, 0., 1.3036708932691290e+03, 0.,
|
||||
5.9435402023228071e+03, 8.1110067822514861e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -5.4688862790206871e-01, 5.1913397860290666e-01,
|
||||
-2.1076612628273591e-03, 1.6869796115416984e-02, 0. ]
|
||||
avg_reprojection_error: 6.7667474319420251e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Sat 04 May 2019 12:00:38 AM CEST"
|
||||
image_width: 3072
|
||||
image_height: 1728
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 4.6903033136815602e+03, 0., 1.6303445000881884e+03, 0.,
|
||||
4.7582671272189546e+03, 4.3596515032334111e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -3.4366857232996317e-01, 2.2799325522263861e-01,
|
||||
2.0765840315530557e-02, -4.0088654509745098e-03, 0. ]
|
||||
avg_reprojection_error: 3.9811872397860709e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 10:20:53 AM CEST"
|
||||
image_width: 3072
|
||||
image_height: 1728
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 2.5005410461483498e+03, 0., 1.5319405824251596e+03, 0.,
|
||||
2.5001544574623872e+03, 7.8267345299919543e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -3.7379752112038928e-01, 1.6246299444310250e-01,
|
||||
8.0371978716752837e-04, -9.6108499236087584e-04, 0. ]
|
||||
avg_reprojection_error: 3.6334262234685299e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 10:37:47 AM CEST"
|
||||
image_width: 960
|
||||
image_height: 720
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 5.0439587680799593e+02, 0., 4.8997081391816727e+02, 0.,
|
||||
5.0714582349015507e+02, 3.5481348085748095e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -2.7916140864065331e-01, 6.5465070220501562e-02,
|
||||
-1.9231901334709591e-03, -2.6191562264760264e-03, 0. ]
|
||||
avg_reprojection_error: 5.7283635087126605e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 10:41:12 AM CEST"
|
||||
image_width: 960
|
||||
image_height: 720
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 5.1663651913150818e+02, 0., 4.7267297458218127e+02, 0.,
|
||||
5.1291090124818436e+02, 3.8505850298928243e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -2.8051872523046845e-01, 6.0895269981008610e-02,
|
||||
-9.7920840355269542e-03, -4.9804820350633240e-04, 0. ]
|
||||
avg_reprojection_error: 5.4967308787122626e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 10:50:02 AM CEST"
|
||||
image_width: 960
|
||||
image_height: 720
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 4.9724079419911664e+02, 0., 4.9277930193807083e+02, 0.,
|
||||
4.9700744926387819e+02, 3.6581239154403062e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -2.7582961261093608e-01, 6.6908017283259263e-02,
|
||||
-2.1580546593114500e-03, -1.7921711595441153e-03, 0. ]
|
||||
avg_reprojection_error: 3.7129088933918375e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 10:53:27 AM CEST"
|
||||
image_width: 960
|
||||
image_height: 720
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 4.9372152821507876e+02, 0., 4.7585791077351445e+02, 0.,
|
||||
4.9644139996881893e+02, 3.5961856724726260e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -2.9023109325424973e-01, 8.3150964750672046e-02,
|
||||
-6.1378621304345154e-04, 8.4481910933416999e-04, 0. ]
|
||||
avg_reprojection_error: 3.4691001942524069e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Sat 04 May 2019 12:35:58 AM CEST"
|
||||
image_width: 3840
|
||||
image_height: 2160
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 2.1723071272381276e+03, 0., 1.9718118689531000e+03, 0.,
|
||||
2.2377541672328439e+03, 9.3157209524899565e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -3.8516162509048857e-01, 1.8961757063227327e-01,
|
||||
1.8297248985443184e-02, -8.9166274086698288e-03, 0. ]
|
||||
avg_reprojection_error: 9.9886914863900311e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Sun 05 May 2019 08:52:13 PM CEST"
|
||||
image_width: 3072
|
||||
image_height: 1728
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 2.9841357325808735e+03, 0., 1.5379802472694901e+03, 0.,
|
||||
2.9784613885271938e+03, 8.9330228722164566e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -5.1096356919758967e-01, 1.4543132746407733e-01,
|
||||
-3.1254001577433334e-02, -1.4769334036191385e-02, 0. ]
|
||||
avg_reprojection_error: 9.3544537534095662e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Sun 05 May 2019 09:24:33 PM CEST"
|
||||
image_width: 3072
|
||||
image_height: 1728
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 2.4796388675592771e+03, 0., 1.5358283835422017e+03, 0.,
|
||||
2.4440198814655632e+03, 8.9911455540136217e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -3.9478938399374452e-01, 1.6288159087710818e-01,
|
||||
-1.8565610712959927e-02, -7.0112574756757643e-03, 0. ]
|
||||
avg_reprojection_error: 4.5805459213906724e-01
|
||||
@@ -0,0 +1,22 @@
|
||||
%YAML:1.0
|
||||
---
|
||||
calibration_time: "Tue 07 May 2019 10:03:44 AM CEST"
|
||||
image_width: 3072
|
||||
image_height: 1728
|
||||
board_width: 8
|
||||
board_height: 6
|
||||
square_size: 2.4799999237060547e+01
|
||||
flags: 0
|
||||
camera_matrix: !!opencv-matrix
|
||||
rows: 3
|
||||
cols: 3
|
||||
dt: d
|
||||
data: [ 2.6027348174982544e+03, 0., 1.4808496083807213e+03, 0.,
|
||||
2.6008830910556521e+03, 6.7577068120137187e+02, 0., 0., 1. ]
|
||||
distortion_coefficients: !!opencv-matrix
|
||||
rows: 5
|
||||
cols: 1
|
||||
dt: d
|
||||
data: [ -3.4912899377320661e-01, 1.5704840296202566e-01,
|
||||
6.4926875404798358e-03, 5.7293259996249049e-03, 0. ]
|
||||
avg_reprojection_error: 4.0040122960491076e-01
|
||||
|
After Width: | Height: | Size: 5.3 MiB |
|
After Width: | Height: | Size: 3.0 MiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 91 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 36 KiB |
|
After Width: | Height: | Size: 40 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
After Width: | Height: | Size: 37 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 97 KiB |
|
After Width: | Height: | Size: 89 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 103 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 15 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 23 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 128 KiB |
|
After Width: | Height: | Size: 142 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 82 KiB |
|
After Width: | Height: | Size: 61 KiB |
|
After Width: | Height: | Size: 86 KiB |
|
After Width: | Height: | Size: 83 KiB |
@@ -0,0 +1,3 @@
|
||||
-7.327951322519857 -89.11104695972499 9201.012307315486
|
||||
-3.2739347567332553 -42.14373356189513 3668.5149400959867
|
||||
-0.0009310035308911926 -0.010684335913469737 0.9999999999999999
|
||||
@@ -0,0 +1,3 @@
|
||||
-5.575118981764042 19.15613757077127 7116.209593619794
|
||||
-3.2016502214672586 11.087267568165238 4660.384266971425
|
||||
-0.0007553414127200226 0.002676057142671632 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
-0.6209787370656474 -57.192772931734694 6553.189887121747
|
||||
-0.655304496315561 -28.195100762686465 3423.351597211246
|
||||
-0.0001275987755308679 -0.007884524572727637 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
21.441694474392808 72.45500438933801 4652.4523150318
|
||||
9.195810184174585 36.76655098601718 1801.6321216143722
|
||||
0.0027471614789484795 0.009610371445379061 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
23.89713091621312 60.523880117656084 7778.591483347838
|
||||
11.708054761838232 41.819183783017614 1126.9348661897782
|
||||
0.0029807026524197224 0.008783281479831609 0.9999999999999999
|
||||
@@ -0,0 +1,3 @@
|
||||
-2.986713098145805 -21.641128011999868 6870.903103366085
|
||||
-2.2937864581163416 -14.410613254705751 4594.877638262097
|
||||
-0.0004752252182089383 -0.003112785793525571 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
0.797119441300711 35.495698816749574 2225.384878217832
|
||||
0.3510443326339413 59.809425152982726 1419.4212456173686
|
||||
-1.8197506232485688e-05 0.01820976131616732 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
2.213864892663308 -21.831117643802187 4060.61306610222
|
||||
0.9075230321117119 -7.525265027425343 1268.217122301812
|
||||
0.0005431549026467866 -0.0054930502425022745 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
-8.65061527352736 -23.247834477892475 4009.9545358742134
|
||||
-2.2093309523396223 -8.398154406654037 1529.4606465341913
|
||||
-0.001952580524058866 -0.006089308376531831 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
-8.665173353556622 -19.056833294770822 3827.027102449301
|
||||
-2.728678410673174 -6.695956964089541 1523.1971944608492
|
||||
-0.0020218867007343213 -0.004877696027397352 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
-0.5624066154780419 -26.36968028701744 3384.7920236393156
|
||||
-0.6590389521668137 -8.709883019993336 1162.7049573736972
|
||||
-0.00023421305979212285 -0.006824826866955653 0.9999999999999999
|
||||
@@ -0,0 +1,3 @@
|
||||
-0.9691844827251948 -16.63913290283819 3991.384826153086
|
||||
-0.47672518258283236 -11.365071723693541 1770.7201067235435
|
||||
-0.0003215600914247826 -0.005142032883105236 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
-1.5172087045737013 5.226213011053854 2493.822558690447
|
||||
-1.4892268949636678 4.265359557115566 3382.185465939972
|
||||
-0.000492856899218649 0.0016917382715537009 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
3.671630456405992 102.56885593938215 3570.381264275829
|
||||
1.5985035927893978 46.57491080817888 -1491.4874345505793
|
||||
0.0006446393888135914 0.027894339637393125 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
0.44666021794890903 -32.932455985363575 3557.76647014547
|
||||
1.0444994361599629 -37.23760709667856 4404.4517853552425
|
||||
0.00029114742043039743 -0.010721230871024154 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
0.1982518156851575 -13.22038303683631 595.3838470607648
|
||||
-0.4806350794284377 -6.567788488139482 598.1732743332492
|
||||
-0.00016595895699412456 -0.007499178419813009 1.0
|
||||
@@ -0,0 +1,3 @@
|
||||
-0.4122368700442484 -10.479982981650977 812.1821012303
|
||||
-0.6536846365005352 -4.951476039607947 512.0831604767536
|
||||
-0.00042630219831388434 -0.006003223898658603 1.0
|
||||
@@ -1,139 +1,603 @@
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include <time.h>
|
||||
|
||||
#include "CenternetDetection.h"
|
||||
#include "MobilenetDetection.h"
|
||||
#include "utils.h"
|
||||
#include "Yolo3Detection.h"
|
||||
#include "message.h"
|
||||
#include "visualization.h"
|
||||
#include "configuration.h"
|
||||
|
||||
#include "tracker.h"
|
||||
#include "../masa_protocol/include/send.hpp"
|
||||
#include "../masa_protocol/include/serialize.hpp"
|
||||
|
||||
// #include <assert.h>
|
||||
// #include <unistd.h>
|
||||
// #include <mutex>
|
||||
// #include <ctime>
|
||||
// #include <pthread.h>
|
||||
// #include <signal.h>
|
||||
// #include <chrono>
|
||||
// #include <math.h>
|
||||
// #include <typeinfo>
|
||||
// #include <iostream>
|
||||
|
||||
#define MAX_DETECT_SIZE 100
|
||||
|
||||
bool gRun;
|
||||
std::chrono::steady_clock::time_point local_clock_start;
|
||||
std::mutex mutexgRun;
|
||||
std::string obj_class[10]{"person", "car", "truck", "bus", "motor", "bike", "rider", "traffic light", "traffic sign", "train"};
|
||||
//mutex for some opencv operations
|
||||
std::mutex mutex_cv;
|
||||
Show_t updates;
|
||||
bool SAVE_RESULT = false;
|
||||
|
||||
void sig_handler(int signo) {
|
||||
std::cout<<"request gateway stop\n";
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
std::cout << "request gateway stop\n";
|
||||
mutexgRun.lock();
|
||||
gRun = false;
|
||||
mutexgRun.unlock();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
void *readVideoCapture(void *x_void_ptr)
|
||||
{
|
||||
std::cout << "readVideoCapture start...\n";
|
||||
|
||||
std::cout<<"detection\n";
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
|
||||
std::string net = "yolo3_berkeley.rt";
|
||||
if(argc > 1)
|
||||
net = argv[1];
|
||||
std::string input = "../demo/yolo_test.mp4";
|
||||
if(argc > 2)
|
||||
input = argv[2];
|
||||
char ntype = 'y';
|
||||
if(argc > 3)
|
||||
ntype = argv[3][0];
|
||||
int n_classes = 80;
|
||||
if(argc > 4)
|
||||
n_classes = atoi(argv[4]);
|
||||
int n_batch = 1;
|
||||
if(argc > 5)
|
||||
n_batch = atoi(argv[5]);
|
||||
bool show = true;
|
||||
if(argc > 6)
|
||||
show = atoi(argv[6]);
|
||||
|
||||
if(n_batch < 1 || n_batch > 64)
|
||||
FatalError("Batch dim not supported");
|
||||
|
||||
if(!show)
|
||||
SAVE_RESULT = true;
|
||||
|
||||
tk::dnn::Yolo3Detection yolo;
|
||||
tk::dnn::CenternetDetection cnet;
|
||||
tk::dnn::MobilenetDetection mbnet;
|
||||
|
||||
tk::dnn::DetectionNN *detNN;
|
||||
|
||||
switch(ntype)
|
||||
Frame_t *info_f = (Frame_t *)x_void_ptr;
|
||||
mutex_cv.lock();
|
||||
cv::VideoCapture cap(info_f->input, cv::CAP_FFMPEG);
|
||||
mutex_cv.unlock();
|
||||
cv::Mat frame_loc, frame0;
|
||||
int frame_nbr_loc = 0;
|
||||
// bool to_show = false;
|
||||
if (!cap.isOpened())
|
||||
{
|
||||
case 'y':
|
||||
detNN = &yolo;
|
||||
break;
|
||||
case 'c':
|
||||
detNN = &cnet;
|
||||
break;
|
||||
case 'm':
|
||||
detNN = &mbnet;
|
||||
n_classes++;
|
||||
break;
|
||||
default:
|
||||
FatalError("Network type not allowed (3rd parameter)\n");
|
||||
mutexgRun.lock();
|
||||
gRun = false;
|
||||
mutexgRun.unlock();
|
||||
}
|
||||
|
||||
detNN->init(net, n_classes, n_batch);
|
||||
|
||||
gRun = true;
|
||||
|
||||
cv::VideoCapture cap(input);
|
||||
if(!cap.isOpened())
|
||||
gRun = false;
|
||||
else
|
||||
std::cout<<"camera started\n";
|
||||
std::cout << "camera started\n";
|
||||
|
||||
cv::VideoWriter resultVideo;
|
||||
if(SAVE_RESULT) {
|
||||
int w = cap.get(cv::CAP_PROP_FRAME_WIDTH);
|
||||
int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
|
||||
resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h));
|
||||
// cap.set(cv::CAP_PROP_BUFFERSIZE,3);
|
||||
// std::cout<<"buf size: "<<cap.get(CV_CAP_PROP_BUFFERSIZE)<<std::endl;
|
||||
auto start_t = std::chrono::steady_clock::now();
|
||||
auto step_t = std::chrono::steady_clock::now();
|
||||
auto end_t = std::chrono::steady_clock::now();
|
||||
auto current_timestamp = std::chrono::steady_clock::now();
|
||||
|
||||
// compute fps and find camera's clock
|
||||
double shift, mean_time = 0;
|
||||
std::cout << "Frames per second using video.get(cv::CAP_PROP_FPS) : " << cap.get(cv::CAP_PROP_FPS) << std::endl;
|
||||
std::cout << "readVideoCapture computes frame rate...\n";
|
||||
// //compute frame rate
|
||||
int i = 0;
|
||||
int num_f = 120;
|
||||
// the first 20 frames are null
|
||||
while (i < 21)
|
||||
{
|
||||
cap >> frame_loc;
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
start_t = std::chrono::steady_clock::now();
|
||||
while (i < num_f)
|
||||
{
|
||||
step_t = std::chrono::steady_clock::now();
|
||||
cap >> frame_loc;
|
||||
mean_time = mean_time + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - step_t).count();
|
||||
std::cout << " step " << i << " : " << std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - step_t).count() << " ms" << std::endl;
|
||||
i++;
|
||||
}
|
||||
end_t = std::chrono::steady_clock::now();
|
||||
|
||||
std::cout << "Capturing " << num_f << " frames" << std::endl;
|
||||
std::cout << " Time taken : " << std::chrono::duration_cast<std::chrono::milliseconds>(end_t - start_t).count() << " ms" << std::endl;
|
||||
|
||||
/*
|
||||
mean_time indicates the milliseconds from a frame and the next. (frame rate)
|
||||
local_clock_sync is the camera clock.
|
||||
shift is the difference from local camera clock and local process clock.
|
||||
a frame is allowed if its local timestamp minus its local clock is less then a tollerance,
|
||||
otherwise it will be considered old.
|
||||
*/
|
||||
auto local_clock_sync = std::chrono::steady_clock::now();
|
||||
mean_time = mean_time / num_f;
|
||||
shift = ((double)std::chrono::duration_cast<std::chrono::milliseconds>(local_clock_sync - local_clock_start).count()) / mean_time;
|
||||
shift = (shift - (int)shift) * mean_time;
|
||||
std::cout << ".-------------------------------\n";
|
||||
std::cout << " mean time: " << mean_time << std::endl;
|
||||
std::cout << " shift: " << shift << std::endl;
|
||||
std::cout << " TIMEDIFFERENCE: " << std::chrono::duration_cast<std::chrono::milliseconds>(local_clock_sync - local_clock_start).count() << std::endl;
|
||||
std::cout << "\n\n\n\n";
|
||||
std::cout << "readVideoCapture start to capture...\n";
|
||||
while (gRun)
|
||||
{
|
||||
// mutex_cv.lock();
|
||||
cap >> frame_loc;
|
||||
// mutex_cv.unlock();
|
||||
current_timestamp = std::chrono::steady_clock::now();
|
||||
shift = std::chrono::duration_cast<std::chrono::milliseconds>(current_timestamp - local_clock_sync).count();
|
||||
std::cout << " RELATIVE TIMESTAMP FRAME : " << shift << " ms" << std::endl;
|
||||
shift = shift / mean_time;
|
||||
shift = (shift - (int)shift) * mean_time;
|
||||
shift = (shift - mean_time / 2 >= 0) ? -(mean_time - shift) : shift;
|
||||
std::cout << "DELAY frame_" << frame_nbr_loc << " : " << shift << " ms" << std::endl;
|
||||
// TODO: here introduce a tollerance to discard old frame
|
||||
|
||||
// std::cout<< "CV_CAP_PROP_POS_MSEC: "<< cap.get( cv::CAP_PROP_POS_MSEC) <<std::endl;
|
||||
// std::cout<< "CV_CAP_PROP_POS_FRAMES: "<< cap.get( cv::CAP_PROP_POS_FRAMES) <<std::endl; // <-- the v4l2 'sequence' field
|
||||
// std::cout<< "cv::CAP_PROP_FPS: "<< cap.get( cv::CAP_PROP_FPS)<<std::endl;
|
||||
// std::cout << "Format: " << cap.get(CV_CAP_PROP_FORMAT) << "\n";
|
||||
// CAP_PROP_POS_MSEC Current position of the video file in milliseconds or video capture timestamp.
|
||||
std::cout << "id: " << cap.get(cv::CAP_PROP_POS_MSEC) << std::endl;
|
||||
// CAP_PROP_FRAME_COUNT Number of frames in the video file.
|
||||
std::cout << "id: " << cap.get(cv::CAP_PROP_FRAME_COUNT) << std::endl;
|
||||
|
||||
if (!frame_loc.data)
|
||||
{
|
||||
usleep(1000000);
|
||||
mutex_cv.lock();
|
||||
cap.open(info_f->input);
|
||||
printf("cap reinitialize\n");
|
||||
mutex_cv.unlock();
|
||||
continue;
|
||||
}
|
||||
|
||||
end_t = std::chrono::steady_clock::now();
|
||||
std::cout << " VC-TIME 1 : " << std::chrono::duration_cast<std::chrono::milliseconds>(end_t - start_t).count() << " ms" << std::endl;
|
||||
start_t = end_t;
|
||||
|
||||
info_f->sem_vc.lock();
|
||||
info_f->frame = frame_loc.clone();
|
||||
info_f->frame_nbr = frame_nbr_loc;
|
||||
info_f->sem_vc.unlock();
|
||||
// usleep(50000);
|
||||
end_t = std::chrono::steady_clock::now();
|
||||
std::cout << " VC-TIME 2 : " << std::chrono::duration_cast<std::chrono::milliseconds>(end_t - start_t).count() << " ms" << std::endl;
|
||||
start_t = end_t;
|
||||
frame_nbr_loc++;
|
||||
}
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
void *computationTask(void *x_void_ptr)
|
||||
{
|
||||
Camera_t *camera = (Camera_t *)x_void_ptr;
|
||||
pthread_t visual, originalshow, detectionshow, topviewshow, disparityshow;
|
||||
pthread_t videocap;
|
||||
tk::dnn::Yolo3Detection yolo = *(camera->yolo);
|
||||
//create video capture thread
|
||||
Frame_t info_f;
|
||||
info_f.input = camera->input;
|
||||
if (pthread_create(&videocap, NULL, readVideoCapture, (void *)&info_f))
|
||||
{
|
||||
fprintf(stderr, "Error creating thread\n");
|
||||
return (void *)1;
|
||||
};
|
||||
|
||||
bool to_show = camera->to_show;
|
||||
double adfGeoTransform[6];
|
||||
for (int i = 0; i < 6; i++)
|
||||
adfGeoTransform[i] = camera->adfGeoTransform[i];
|
||||
|
||||
ModFrame_t info_show;
|
||||
if (to_show)
|
||||
{
|
||||
// initialize updates struct
|
||||
updates.update_o = false;
|
||||
updates.update_de = false;
|
||||
updates.update_t = false;
|
||||
updates.update_di = false;
|
||||
if (pthread_create(&visual, NULL, show_updates, (void *)NULL))
|
||||
{
|
||||
fprintf(stderr, "Error creating thread\n");
|
||||
return (void *)1;
|
||||
};
|
||||
if (pthread_create(&originalshow, NULL, originalFrame, (void *)&info_f))
|
||||
{
|
||||
fprintf(stderr, "Error creating thread\n");
|
||||
return (void *)1;
|
||||
};
|
||||
if (pthread_create(&disparityshow, NULL, disparityFrame, (void *)&info_f))
|
||||
{
|
||||
fprintf(stderr, "Error creating thread\n");
|
||||
return (void *)1;
|
||||
};
|
||||
info_show.H = cv::Mat(cv::Size(3, 3), CV_64FC1);
|
||||
if (pthread_create(&detectionshow, NULL, detectionFrame, (void *)&info_show))
|
||||
{
|
||||
fprintf(stderr, "Error creating thread\n");
|
||||
return (void *)1;
|
||||
};
|
||||
if (pthread_create(&topviewshow, NULL, topviewFrame, (void *)&info_show))
|
||||
{
|
||||
fprintf(stderr, "Error creating thread\n");
|
||||
return (void *)1;
|
||||
};
|
||||
}
|
||||
char *pmatrix = camera->pmatrix;
|
||||
/*projection matrix from camera to map*/
|
||||
cv::Mat H(cv::Size(3, 3), CV_64FC1);
|
||||
read_projection_matrix(H, pmatrix);
|
||||
assert(cv::countNonZero(H) > 0);
|
||||
// std::cout<<H<<std::endl;
|
||||
// return (void*)0;
|
||||
/*Camera calibration*/
|
||||
cv::Mat cameraMat, distCoeff;
|
||||
readCameraCalibrationYaml(camera->cameraCalib, cameraMat, distCoeff);
|
||||
std::cout << cameraMat << std::endl;
|
||||
std::cout << distCoeff << std::endl;
|
||||
|
||||
/*GPS information*/
|
||||
std::vector<ObjCoords> coords;
|
||||
|
||||
/*socket*/
|
||||
Communicator Comm(SOCK_DGRAM);
|
||||
Comm.open_client_socket((char *)"127.0.0.1", 8888);
|
||||
|
||||
Message *m = new Message;
|
||||
m->cam_idx = camera->CAM_IDX;
|
||||
m->lights.clear();
|
||||
/*Conversion for tracker, from gps to meters and viceversa*/
|
||||
// mutex_cv.lock();
|
||||
geodetic_converter::GeodeticConverter gc;
|
||||
gc.initialiseReference(44.655540, 10.934315, 0);
|
||||
// mutex_cv.unlock();
|
||||
double east, north, up;
|
||||
// double lat, lon, alt;
|
||||
/*Mask info*/
|
||||
cv::Mat mask = cv::imread(camera->maskfile, cv::IMREAD_GRAYSCALE);
|
||||
cv::Mat maskOrient = cv::imread(camera->maskFileOrient);
|
||||
// cv::Mat maskOrient = cv::imread(camera->maskFileOrient, 0);
|
||||
|
||||
/*for(int i=0; i< mask.cols; i++)
|
||||
{
|
||||
for(int j=0; j< mask.rows; j++)
|
||||
{
|
||||
std::cout<<maskOrient.at<cv::Vec3b>(i,j) <<std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return 0;*/
|
||||
/*tracker infos*/
|
||||
std::vector<Tracker> trackers;
|
||||
std::vector<Data> cur_frame;
|
||||
int initial_age = -5;
|
||||
int age_threshold = -8;
|
||||
int n_states = 5;
|
||||
float dt = 0.03;
|
||||
|
||||
int frame_nbr = 0;
|
||||
|
||||
//save video
|
||||
/*cv::VideoWriter outputVideo;
|
||||
cv::Size S = cv::Size((int)cap.get(cv::CAP_PROP_FRAME_WIDTH), //Acquire input size
|
||||
(int)cap.get(cv::CAP_PROP_FRAME_HEIGHT));
|
||||
outputVideo.open("test.avi", static_cast<int>(cap.get(cv::CAP_PROP_FOURCC)), cap.get(cv::CAP_PROP_FPS), S, true);*/
|
||||
|
||||
cv::Mat map1, map2;
|
||||
auto start_t = std::chrono::steady_clock::now();
|
||||
auto step_t = std::chrono::steady_clock::now();
|
||||
auto end_t = std::chrono::steady_clock::now();
|
||||
// auto step_t_segmentation = std::chrono::steady_clock::now();
|
||||
// auto end_t_segmentation = std::chrono::steady_clock::now();
|
||||
|
||||
//TODO: move in a thread
|
||||
// // information for the disparity map
|
||||
// std::vector <cv::Rect> pre_rois;
|
||||
// cv::Mat pre_frame;
|
||||
cv::Mat orig_frame;
|
||||
// cv::Mat canny, pre_canny, canny_RGB, pre_canny_RGB;
|
||||
// cv::Mat canny_img;
|
||||
|
||||
// box variable
|
||||
tk::dnn::box b;
|
||||
int x0, h, y1; //w, x1, y0;
|
||||
int objClass;
|
||||
std::string det_class;
|
||||
;
|
||||
// float prob;
|
||||
cv::Scalar intensity;
|
||||
|
||||
|
||||
// cv::VideoWriter resultVideo;
|
||||
// if(SAVE_RESULT) {
|
||||
// int w = cap.get(cv::CAP_PROP_FRAME_WIDTH);
|
||||
// int h = cap.get(cv::CAP_PROP_FRAME_HEIGHT);
|
||||
// resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h));
|
||||
// }
|
||||
|
||||
cv::Mat frame;
|
||||
if(show)
|
||||
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
||||
cv::Mat frame_crop;
|
||||
cv::Mat dnn_input;
|
||||
bool first_iteration = true;
|
||||
|
||||
std::vector<cv::Mat> batch_frame;
|
||||
std::vector<cv::Mat> batch_dnn_input;
|
||||
while (gRun)
|
||||
{
|
||||
TIMER_START
|
||||
start_t = std::chrono::steady_clock::now();
|
||||
step_t = start_t;
|
||||
|
||||
while(gRun) {
|
||||
batch_dnn_input.clear();
|
||||
batch_frame.clear();
|
||||
|
||||
for(int bi=0; bi< n_batch; ++bi){
|
||||
cap >> frame;
|
||||
if(!frame.data)
|
||||
break;
|
||||
|
||||
batch_frame.push_back(frame);
|
||||
info_f.sem_vc.lock();
|
||||
frame = info_f.frame.clone();
|
||||
if (info_f.frame_nbr - frame_nbr > 1)
|
||||
std::cout << "more than one - f_n (diff " << info_f.frame_nbr - frame_nbr << ")\n";
|
||||
frame_nbr = info_f.frame_nbr;
|
||||
info_f.sem_vc.unlock();
|
||||
std::cout << "f_n: " << frame_nbr << std::endl;
|
||||
// if (!frame.data)
|
||||
if (frame_nbr == 0)
|
||||
{
|
||||
usleep(1000000);
|
||||
printf("no frame received\n");
|
||||
continue;
|
||||
}
|
||||
orig_frame = frame.clone();
|
||||
// mutex_cv.lock();
|
||||
if (first_iteration)
|
||||
cv::initUndistortRectifyMap(cameraMat, distCoeff, cv::Mat(), cameraMat, frame.size(), CV_16SC2, map1, map2);
|
||||
cv::Mat temp = frame.clone();
|
||||
cv::remap(temp, frame, map1, map2, 1);
|
||||
//undistort(temp, frame, cameraMat, distCoeff);
|
||||
// mutex_cv.unlock();
|
||||
|
||||
// this will be resized to the net format
|
||||
batch_dnn_input.push_back(frame.clone());
|
||||
}
|
||||
if(!frame.data)
|
||||
break;
|
||||
|
||||
//inference
|
||||
detNN->update(batch_dnn_input, n_batch);
|
||||
detNN->draw(batch_frame);
|
||||
// this will be resized to the net format
|
||||
dnn_input = frame.clone();
|
||||
// TODO: async infer
|
||||
yolo.update(dnn_input);
|
||||
int num_detected = yolo.detected.size();
|
||||
if (num_detected > MAX_DETECT_SIZE)
|
||||
num_detected = MAX_DETECT_SIZE;
|
||||
|
||||
if(show){
|
||||
for(int bi=0; bi< n_batch; ++bi){
|
||||
cv::imshow("detection", batch_frame[bi]);
|
||||
cv::waitKey(1);
|
||||
coords.clear();
|
||||
end_t = std::chrono::steady_clock::now();
|
||||
std::cout << " TIME 1 : " << std::chrono::duration_cast<std::chrono::milliseconds>(end_t - step_t).count() << " ms" << std::endl;
|
||||
step_t = end_t;
|
||||
// draw dets
|
||||
std::cout << "camera: " << camera->CAM_IDX << " - num detected: " << num_detected << std::endl;
|
||||
|
||||
//TODO: move in a thread
|
||||
// //preprocessing frame
|
||||
// step_t_segmentation = std::chrono::steady_clock::now();
|
||||
// // src_gray
|
||||
// canny_img = img_laplacian(orig_frame,0);
|
||||
// cv::Canny(canny_img, canny, 100, 100*2 );
|
||||
// // sprintf(buf_frame_crop_name,"../demo/demo/data/img_disparity/%d_%d_canny.jpg",frame_nbr, 999);
|
||||
// // cv::imwrite(buf_frame_crop_name, canny);
|
||||
// end_t_segmentation = std::chrono::steady_clock::now();
|
||||
// std::cout << " - TIME END pre canny : "<<std::chrono::duration_cast<std::chrono::milliseconds>(end_t_segmentation - step_t_segmentation).count() << " ms"<<std::endl;
|
||||
// step_t_segmentation = end_t_segmentation;
|
||||
// // std::cout<<"o: "<<orig_frame.cols<<" - "<<orig_frame.rows<<std::endl;
|
||||
// // std::cout<<"canny: "<<canny.cols<<" - "<<canny.rows<<std::endl;
|
||||
// // std::cout<<"pre: "<<pre_canny.cols<<" - "<<pre_canny.rows<<std::endl;
|
||||
// if(!first_iteration)
|
||||
// {
|
||||
// // backtorgb = cv::cvtColor(pre_canny,cv::COLOR_GRAY2RGB)
|
||||
// cv::cvtColor(pre_canny, pre_canny_RGB, cv::COLOR_GRAY2RGB);
|
||||
// cv::cvtColor(canny, canny_RGB, cv::COLOR_GRAY2RGB);
|
||||
// disparity_frame = frame_disparity(pre_canny_RGB, canny_RGB, frame_nbr, 999, 0);
|
||||
// std::cout<<"size: "<<disparity_frame.rows<<" - "<<disparity_frame.cols<<std::endl;
|
||||
// if (disparity_frame.rows == 0 || disparity_frame.cols == 0)
|
||||
// return -1;
|
||||
// if (disparity_frame.empty())
|
||||
// { // only fools don't check...
|
||||
// std::cout << "image not loaded !" << std::endl;
|
||||
// return -1;
|
||||
// }
|
||||
// end_t_segmentation = std::chrono::steady_clock::now();
|
||||
// std::cout << " TIME canny : frame_disparity : "<<std::chrono::duration_cast<std::chrono::milliseconds>(end_t_segmentation - step_t_segmentation).count() << " ms"<<std::endl;
|
||||
// step_t_segmentation = end_t_segmentation;
|
||||
|
||||
// // //--------------------------------
|
||||
// // //frame box disparity on the original image
|
||||
// // step_t_segmentation = std::chrono::steady_clock::now();
|
||||
// // frame_box_disparity(pre_frame, frame, pre_rois, frame_nbr);
|
||||
// // // reset pre_rois for the new roi of the current frame
|
||||
// // // pre_rois.erase(pre_rois.begin(), pre_rois.end());
|
||||
// // end_t_segmentation = std::chrono::steady_clock::now();
|
||||
// // std::cout << " TIME Frame disparity : "<<std::chrono::duration_cast<std::chrono::milliseconds>(end_t_segmentation - step_t_segmentation).count() << " ms"<<std::endl;
|
||||
// // step_t_segmentation = end_t_segmentation;
|
||||
|
||||
// // //frame box disparity on the preprocessed image
|
||||
// // cv::cvtColor(pre_canny, pre_canny_RGB, cv::COLOR_GRAY2RGB);
|
||||
// // cv::cvtColor(canny, canny_RGB, cv::COLOR_GRAY2RGB);
|
||||
// // frame_box_disparity(pre_canny_RGB, canny_RGB, pre_rois, frame_nbr);
|
||||
// // // reset pre_rois for the new roi of the current frame
|
||||
// // pre_rois.erase(pre_rois.begin(), pre_rois.end());
|
||||
// // end_t_segmentation = std::chrono::steady_clock::now();
|
||||
// // std::cout << " TIME Canny Frame disparity : "<<std::chrono::duration_cast<std::chrono::milliseconds>(end_t_segmentation - step_t_segmentation).count() << " ms"<<std::endl;
|
||||
// // step_t_segmentation = end_t_segmentation;
|
||||
// // //---------------------------------
|
||||
// }
|
||||
|
||||
// compute some metrics on the whole frame
|
||||
// segmentation(pre_frame, frame, frame_nbr, 0, 0);
|
||||
|
||||
for (int i = 0; i < num_detected; i++)
|
||||
{
|
||||
b = yolo.detected[i];
|
||||
x0 = b.x;
|
||||
// w = b.w;
|
||||
// x1 = b.x + w;
|
||||
// y0 = b.y;
|
||||
h = b.h;
|
||||
y1 = b.y + h;
|
||||
objClass = b.cl;
|
||||
det_class = obj_class[b.cl];
|
||||
// prob = b.prob;
|
||||
|
||||
intensity = mask.at<uchar>(cv::Point(int(x0 + b.w / 2), y1));
|
||||
|
||||
if (intensity[0])
|
||||
{
|
||||
|
||||
if (objClass < 6)
|
||||
{
|
||||
|
||||
// find the rectangular on the frame (sub-figure)
|
||||
// roi.x = (x0 > 0)? x0 : 0;
|
||||
// roi.y = (y0 > 0)? y0 : 0;
|
||||
// // std::cout<<"x "<<roi.x<<" - y "<<roi.y<<std::endl;
|
||||
// roi.width = (roi.x+w >= frame.cols)? frame.cols-1-roi.x : w;
|
||||
// roi.height = (roi.y+h >= frame.rows)? frame.rows-1-roi.y : h;
|
||||
// std::cout<<"w "<<roi.width<<" - h "<<roi.height<<std::endl;
|
||||
// std::cout<<"wf "<<frame.cols<<" - hf "<<frame.rows<<std::endl;
|
||||
// std::cout<<"---"<<std::endl;
|
||||
// std::cout<<"x "<<roi.x<<" to "<<roi.width+roi.x<<" wf "<<frame.cols<<std::endl;
|
||||
// std::cout<<"y "<<roi.y<<" to "<<roi.height+roi.y<<" hf "<<frame.rows<<std::endl;
|
||||
//update pre_roi for the next frame
|
||||
// pre_rois.push_back(roi);
|
||||
|
||||
// segmentation(frame(roi), frame(roi), frame_nbr, i, 1);
|
||||
|
||||
/////
|
||||
convert_coords(coords, x0 + b.w / 2, y1, objClass, H, adfGeoTransform);
|
||||
|
||||
// //std::cout<<objClass<<" ("<<prob<<"): "<<x0<<" "<<y0<<" "<<x1<<" "<<y1<<"\n";
|
||||
// cv::rectangle(frame, cv::Point(x0, y0), cv::Point(x1, y1), camera->yolo.colors[objClass], 2);
|
||||
// // draw label
|
||||
// int baseline = 0;
|
||||
// float fontScale = 0.5;
|
||||
// int thickness = 2;
|
||||
// cv::Size textSize = getTextSize(det_class, cv::FONT_HERSHEY_SIMPLEX, fontScale, thickness, &baseline);
|
||||
// cv::rectangle(frame, cv::Point(x0, y0), cv::Point((x0 + textSize.width - 2), (y0 - textSize.height - 2)), camera->yolo.colors[b.cl], -1);
|
||||
// cv::putText(frame, det_class, cv::Point(x0, (y0 - (baseline / 2))), cv::FONT_HERSHEY_SIMPLEX, fontScale, cv::Scalar(255, 255, 255), thickness);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(n_batch == 1 && SAVE_RESULT)
|
||||
resultVideo << frame;
|
||||
|
||||
end_t = std::chrono::steady_clock::now();
|
||||
std::cout << " TIME 2 : " << std::chrono::duration_cast<std::chrono::milliseconds>(end_t - step_t).count() << " ms" << std::endl;
|
||||
step_t = end_t;
|
||||
//convert from latitude and longitude to meters for ekf
|
||||
cur_frame.clear();
|
||||
for (size_t i = 0; i < coords.size(); i++)
|
||||
{
|
||||
gc.geodetic2Enu(coords[i].lat_, coords[i].long_, 0, &east, &north, &up);
|
||||
cur_frame.push_back(Data(east, north, frame_nbr, coords[i].class_));
|
||||
}
|
||||
if (first_iteration)
|
||||
{
|
||||
// if there aren't detections and it is the first iteration, we can't initialize the tracker, so continue
|
||||
if (cur_frame.empty())
|
||||
continue;
|
||||
for (auto f : cur_frame)
|
||||
trackers.push_back(Tracker(f, initial_age, dt, n_states));
|
||||
}
|
||||
else
|
||||
{
|
||||
Track(cur_frame, dt, n_states, initial_age, age_threshold, trackers);
|
||||
}
|
||||
std::cout << "There are " << trackers.size() << " trackers" << std::endl;
|
||||
//prepare message with tracker info
|
||||
if (trackers.size() != 0)
|
||||
{
|
||||
// mutex_cv.lock();
|
||||
addRoadUserfromTracker(trackers, m, gc, maskOrient, adfGeoTransform, H);
|
||||
// mutex_cv.unlock();
|
||||
//prepare the message with detection info
|
||||
//prepare_message(m, coords, CAM_IDX);
|
||||
//send message
|
||||
if (!m->objects.empty())
|
||||
Comm.send_message(m);
|
||||
}
|
||||
|
||||
if (to_show)
|
||||
{
|
||||
//populate the ModFrame_t
|
||||
info_show.sem.lock();
|
||||
info_show.original_frame = frame.clone();
|
||||
// std::vector<Tracker> trackers;
|
||||
info_show.trackers = trackers;
|
||||
// geodetic_converter::GeodeticConverter gc;
|
||||
info_show.gc = gc;
|
||||
for (int i = 0; i < 6; i++)
|
||||
info_show.adfGeoTransform[i] = adfGeoTransform[i];
|
||||
// cv::Mat H;
|
||||
info_show.H = H.clone();
|
||||
info_show.yolo = yolo;
|
||||
// std::copy(camera->yolo.begin(), camera->yolo.end(), info_show.yolo.begin());
|
||||
info_show.mask = mask.clone();
|
||||
info_show.sem.unlock();
|
||||
}
|
||||
|
||||
// update pre_frame for the disparity map
|
||||
// pre_frame = orig_frame.clone();
|
||||
// pre_canny = canny.clone();
|
||||
if (first_iteration)
|
||||
first_iteration = false;
|
||||
|
||||
frame_nbr++;
|
||||
std::cout << camera->CAM_IDX << " camera thread: ";
|
||||
TIMER_STOP
|
||||
}
|
||||
|
||||
std::cout<<"detection end\n";
|
||||
double mean = 0;
|
||||
|
||||
std::cout<<COL_GREENB<<"\n\nTime stats:\n";
|
||||
std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
|
||||
std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n";
|
||||
for(int i=0; i<detNN->stats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size();
|
||||
std::cout<<"Avg: "<<mean/n_batch<<" ms\t"<<1000/(mean/n_batch)<<" FPS\n"<<COL_END;
|
||||
|
||||
|
||||
return 0;
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
std::cout << "detection\n";
|
||||
signal(SIGINT, sig_handler);
|
||||
srand(time(NULL));
|
||||
|
||||
Parameters_t par;
|
||||
|
||||
if(!read_parameters(argc, argv, &par))
|
||||
return -1;
|
||||
|
||||
tk::dnn::Yolo3Detection yolo[par.n_cameras];
|
||||
for(int i=0; i<par.n_cameras; i++)
|
||||
{
|
||||
yolo[i].init(par.net);
|
||||
yolo[i].thresh = 0.25;
|
||||
|
||||
// if(SAVE_RESULT)
|
||||
// resultVideo << frame;
|
||||
}
|
||||
// tk::dnn::Yolo3Detection yolo;
|
||||
// yolo.init(net);
|
||||
// yolo.thresh = 0.25;
|
||||
|
||||
gRun = true;
|
||||
// start the local clock. It is used to check the incoming frames (by different cameras)
|
||||
local_clock_start = std::chrono::steady_clock::now();
|
||||
|
||||
/*GPS information*/
|
||||
double *adfGeoTransform = (double *)malloc(6 * sizeof(double));
|
||||
readTiff(par.tiffile, adfGeoTransform);
|
||||
// Camera_t cameras[par.n_cameras];
|
||||
for(int i=0; i<par.n_cameras; i++)
|
||||
{
|
||||
for(int j = 0; j < 6; j++ )
|
||||
par.cameras[i].adfGeoTransform[j] = adfGeoTransform[j];
|
||||
par.cameras[i].yolo = &yolo[i];
|
||||
// par.cameras[i].yolo.init(par.net);
|
||||
// par.cameras[i].yolo.thresh = 0.25;
|
||||
// cameras[i].yolo = yolo[i];
|
||||
// cameras[i].yolo = yolo;
|
||||
|
||||
}
|
||||
pthread_t camera_task[par.n_cameras];
|
||||
for(int i=0; i<par.n_cameras; i++)
|
||||
{
|
||||
std::cout<<"creating thread\n";
|
||||
if(pthread_create(&camera_task[i], NULL, computationTask, (void*)&(par.cameras[i])))
|
||||
{
|
||||
fprintf(stderr, "error creating thread\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
for(int i=0; i<par.n_cameras; i++)
|
||||
{
|
||||
pthread_join(camera_task[i], NULL);
|
||||
}
|
||||
std::cout <<" free adfGeoT \n";
|
||||
free(adfGeoTransform);
|
||||
std::cout << "detection end\n";
|
||||
return 0;
|
||||
}
|
||||
@@ -1,235 +0,0 @@
|
||||
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include "utils.h"
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
#include "Yolo3Detection.h"
|
||||
#include "CenternetDetection.h"
|
||||
#include "MobilenetDetection.h"
|
||||
|
||||
#include "evaluation.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
void convertFilename(std::string &filename,const std::string l_folder, const std::string i_folder, const std::string l_ext,const std::string i_ext)
|
||||
{
|
||||
filename.replace(filename.find(l_folder),l_folder.length(),i_folder);
|
||||
filename.replace(filename.find(l_ext),l_ext.length(),i_ext);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char ntype = 'y';
|
||||
const char *config_filename = "../demo/config.yaml";
|
||||
const char * net = "yolo3.rt";
|
||||
const char * labels_path = "../demo/COCO_val2017/all_labels.txt";
|
||||
bool show = false;
|
||||
bool write_dets = false;
|
||||
bool write_res_on_file = true;
|
||||
bool write_coco_json = true;
|
||||
int n_images = 5000;
|
||||
|
||||
bool verbose;
|
||||
int classes, map_points, map_levels;
|
||||
float map_step, IoU_thresh, conf_thresh;
|
||||
|
||||
double vm_total = 0, rss_total = 0;
|
||||
double vm, rss;
|
||||
|
||||
//read args
|
||||
if(argc > 1)
|
||||
net = argv[1];
|
||||
if(argc > 2)
|
||||
ntype = argv[2][0];
|
||||
if(argc > 3)
|
||||
labels_path = argv[3];
|
||||
if(argc > 4)
|
||||
config_filename = argv[4];
|
||||
|
||||
//check if files needed exist
|
||||
if(!fileExist(config_filename))
|
||||
FatalError("Wrong config file path.");
|
||||
if(!fileExist(net))
|
||||
FatalError("Wrong net file path.");
|
||||
if(!fileExist(labels_path))
|
||||
FatalError("Wrong labels file path.");
|
||||
|
||||
//read mAP parameters
|
||||
tk::dnn::readmAPParams( config_filename, classes, map_points, map_levels, map_step,
|
||||
IoU_thresh, conf_thresh, verbose);
|
||||
|
||||
//extract network name from rt path
|
||||
std::string net_name;
|
||||
removePathAndExtension(net, net_name);
|
||||
std::cout<<"Network: "<<net_name<<std::endl;
|
||||
|
||||
//open files (if needed)
|
||||
std::ofstream times, memory, coco_json;
|
||||
|
||||
if(write_coco_json){
|
||||
coco_json.open(net_name+"_COCO_res.json");
|
||||
coco_json << "[\n";
|
||||
}
|
||||
|
||||
if(write_res_on_file){
|
||||
times.open("times_"+net_name+".csv");
|
||||
memory.open("memory.csv", std::ios_base::app);
|
||||
memory<<net<<";";
|
||||
}
|
||||
|
||||
// instantiate detector
|
||||
tk::dnn::Yolo3Detection yolo;
|
||||
tk::dnn::CenternetDetection cnet;
|
||||
tk::dnn::MobilenetDetection mbnet;
|
||||
tk::dnn::DetectionNN *detNN;
|
||||
int n_classes = classes;
|
||||
switch(ntype){
|
||||
case 'y':
|
||||
detNN = &yolo;
|
||||
break;
|
||||
case 'c':
|
||||
detNN = &cnet;
|
||||
break;
|
||||
case 'm':
|
||||
detNN = &mbnet;
|
||||
n_classes++;
|
||||
break;
|
||||
default:
|
||||
FatalError("Network type not allowed (3rd parameter)\n");
|
||||
}
|
||||
detNN->init(net, n_classes);
|
||||
|
||||
//read images
|
||||
std::ifstream all_labels(labels_path);
|
||||
std::string l_filename;
|
||||
std::vector<tk::dnn::Frame> images;
|
||||
std::vector<tk::dnn::box> detected_bbox;
|
||||
|
||||
std::cout<<"Reading groundtruth and generating detections"<<std::endl;
|
||||
|
||||
if(show)
|
||||
cv::namedWindow("detection", cv::WINDOW_NORMAL);
|
||||
|
||||
int images_done;
|
||||
for (images_done=0 ; std::getline(all_labels, l_filename) && images_done < n_images ; ++images_done) {
|
||||
std::cout <<COL_ORANGEB<< "Images done:\t" << images_done<< "\n"<<COL_END;
|
||||
|
||||
tk::dnn::Frame f;
|
||||
f.lFilename = l_filename;
|
||||
f.iFilename = l_filename;
|
||||
convertFilename(f.iFilename, "labels", "images", ".txt", ".jpg");
|
||||
|
||||
// read frame
|
||||
if(!fileExist(f.iFilename.c_str()))
|
||||
FatalError("Wrong image file path.");
|
||||
|
||||
cv::Mat frame = cv::imread(f.iFilename.c_str(), cv::IMREAD_COLOR);
|
||||
std::vector<cv::Mat> batch_frames;
|
||||
batch_frames.push_back(frame);
|
||||
int height = frame.rows;
|
||||
int width = frame.cols;
|
||||
|
||||
if(!frame.data)
|
||||
break;
|
||||
std::vector<cv::Mat> batch_dnn_input;
|
||||
batch_dnn_input.push_back(frame.clone());
|
||||
|
||||
//inference
|
||||
detected_bbox.clear();
|
||||
detNN->update(batch_dnn_input,1,write_res_on_file, ×, write_coco_json);
|
||||
detNN->draw(batch_frames);
|
||||
detected_bbox = detNN->detected;
|
||||
|
||||
if(write_coco_json)
|
||||
printJsonCOCOFormat(&coco_json, f.iFilename.c_str(), detected_bbox, classes, width, height);
|
||||
|
||||
std::ofstream myfile;
|
||||
if(write_dets)
|
||||
myfile.open ("det/"+f.lFilename.substr(f.lFilename.find("labels/") + 7));
|
||||
|
||||
// save detections labels
|
||||
for(auto d:detected_bbox){
|
||||
//convert detected bb in the same format as label
|
||||
//<x_center>/<image_width> <y_center>/<image_width> <width>/<image_width> <height>/<image_width>
|
||||
tk::dnn::BoundingBox b;
|
||||
b.x = (d.x + d.w/2) / width;
|
||||
b.y = (d.y + d.h/2) / height;
|
||||
b.w = d.w / width;
|
||||
b.h = d.h / height;
|
||||
b.prob = d.prob;
|
||||
b.cl = d.cl;
|
||||
f.det.push_back(b);
|
||||
|
||||
if(write_dets)
|
||||
myfile << d.cl << " "<< d.prob << " "<< b.x << " "<< b.y << " "<< b.w << " "<< b.h <<"\n";
|
||||
|
||||
if(show)// draw rectangle for detection
|
||||
cv::rectangle(batch_frames[0], cv::Point(d.x, d.y), cv::Point(d.x + d.w, d.y + d.h), cv::Scalar(0, 0, 255), 2);
|
||||
}
|
||||
|
||||
if(write_dets)
|
||||
myfile.close();
|
||||
|
||||
// read and save groundtruth labels
|
||||
if(fileExist(f.lFilename.c_str()))
|
||||
{
|
||||
std::ifstream labels(l_filename);
|
||||
for(std::string line; std::getline(labels, line); ){
|
||||
std::istringstream in(line);
|
||||
tk::dnn::BoundingBox b;
|
||||
in >> b.cl >> b.x >> b.y >> b.w >> b.h;
|
||||
b.prob = 1;
|
||||
b.truthFlag = 1;
|
||||
f.gt.push_back(b);
|
||||
|
||||
if(show)// draw rectangle for groundtruth
|
||||
cv::rectangle(batch_frames[0], cv::Point((b.x-b.w/2)*width, (b.y-b.h/2)*height), cv::Point((b.x+b.w/2)*width,(b.y+b.h/2)*height), cv::Scalar(0, 255, 0), 2);
|
||||
}
|
||||
}
|
||||
|
||||
images.push_back(f);
|
||||
|
||||
if(show){
|
||||
cv::imshow("detection", batch_frames[0]);
|
||||
cv::waitKey(0);
|
||||
}
|
||||
|
||||
getMemUsage(vm, rss);
|
||||
vm_total += vm;
|
||||
rss_total += rss;
|
||||
|
||||
|
||||
}
|
||||
|
||||
if(write_coco_json){
|
||||
coco_json.seekp (coco_json.tellp() - std::streampos(2));
|
||||
coco_json << "\n]\n";
|
||||
coco_json.close();
|
||||
}
|
||||
|
||||
std::cout << "Avg VM[MB]: " << vm_total/images_done/1024.0 << ";Avg RSS[MB]: " << rss_total/images_done/1024.0 << std::endl;
|
||||
|
||||
//compute mAP
|
||||
double AP = tk::dnn::computeMapNIoULevels(images,classes,IoU_thresh,conf_thresh, map_points, map_step, map_levels, verbose, write_res_on_file, net_name);
|
||||
std::cout<<"mAP "<<IoU_thresh<<":"<<IoU_thresh+map_step*(map_levels-1)<<" = "<<AP<<std::endl;
|
||||
|
||||
//compute average precision, recall and f1score
|
||||
tk::dnn::computeTPFPFN(images,classes,IoU_thresh,conf_thresh, verbose, write_res_on_file, net_name);
|
||||
|
||||
if(write_res_on_file){
|
||||
memory<<vm_total/images_done/1024.0<<";"<<rss_total/images_done/1024.0<<"\n";
|
||||
times.close();
|
||||
memory.close();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
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
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
|
||||
LABEL maintainer "Francesco Gatti"
|
||||
|
||||
ADD nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb /tmp/trt.deb
|
||||
RUN apt-get update && dpkg -i /tmp/trt.deb && rm /tmp/trt.deb && apt-get update
|
||||
RUN apt install -y libnvinfer7=7.0.0-1+cuda10.2 libnvinfer-dev=7.0.0-1+cuda10.2
|
||||
RUN DEBIAN_FRONTEND=noninteractive apt install -y git wget libeigen3-dev libyaml-cpp-dev
|
||||
RUN cd /tmp && \
|
||||
wget https://github.com/Kitware/CMake/releases/download/v3.17.3/cmake-3.17.3-Linux-x86_64.sh && \
|
||||
chmod +x cmake-3.17.3-Linux-x86_64.sh && \
|
||||
./cmake-3.17.3-Linux-x86_64.sh --prefix=/usr/local --exclude-subdir --skip-license && \
|
||||
rm ./cmake-3.17.3-Linux-x86_64.sh
|
||||
|
||||
RUN echo "INSTALL OPENCV"
|
||||
RUN apt-get install -y build-essential \
|
||||
unzip \
|
||||
pkg-config \
|
||||
libjpeg-dev \
|
||||
libpng-dev \
|
||||
libtiff-dev \
|
||||
libavcodec-dev \
|
||||
libavformat-dev \
|
||||
libswscale-dev \
|
||||
libv4l-dev \
|
||||
libxvidcore-dev \
|
||||
libx264-dev \
|
||||
libgtk-3-dev \
|
||||
libatlas-base-dev \
|
||||
gfortran \
|
||||
libgstreamer1.0-dev \
|
||||
libgstreamer-plugins-base1.0-dev \
|
||||
libdc1394-22-dev \
|
||||
libavresample-dev
|
||||
RUN cd && wget https://github.com/opencv/opencv/archive/4.3.0.tar.gz && tar -xf 4.3.0.tar.gz && rm *.tar.gz
|
||||
RUN cd && wget https://github.com/opencv/opencv_contrib/archive/4.3.0.tar.gz && tar -xf 4.3.0.tar.gz && rm *.tar.gz
|
||||
RUN cd && \
|
||||
cd opencv-4.3.0 && mkdir build && cd build && \
|
||||
cmake -D CMAKE_BUILD_TYPE=RELEASE \
|
||||
-D CMAKE_INSTALL_PREFIX=/usr/local \
|
||||
-D INSTALL_PYTHON_EXAMPLES=OFF \
|
||||
-D INSTALL_C_EXAMPLES=OFF \
|
||||
-D OPENCV_EXTRA_MODULES_PATH='~/opencv_contrib-4.3.0/modules' \
|
||||
-D BUILD_EXAMPLES=OFF \
|
||||
-D WITH_CUDA=ON \
|
||||
-D CUDA_ARCH_BIN=7.2 \
|
||||
-D CUDA_ARCH_PTX="" \
|
||||
-D ENABLE_FAST_MATH=ON \
|
||||
-D CUDA_FAST_MATH=ON \
|
||||
-D WITH_CUBLAS=ON \
|
||||
-D WITH_LIBV4L=ON \
|
||||
-D WITH_GSTREAMER=ON \
|
||||
-D WITH_GSTREAMER_0_10=OFF \
|
||||
-D WITH_TBB=ON \
|
||||
../ && make -j12 && make install
|
||||
RUN apt clean
|
||||
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
# Use the prebuilt image
|
||||
```
|
||||
# build image
|
||||
docker build -t tkdnn:build -f Dockerfile .
|
||||
```
|
||||
|
||||
# Build Base Docker image
|
||||
```
|
||||
# make nvidia docker working
|
||||
# follow this guide: https://github.com/NVIDIA/nvidia-docker
|
||||
|
||||
# dowload tensorrt
|
||||
# from: https://developer.nvidia.com/compute/machine-learning/tensorrt/secure/7.0/7.0.0.11/local_repo/nv-tensorrt-repo-ubuntu1804-cuda10.2-trt7.0.0.11-ga-20191216_1-1_amd64.deb
|
||||
|
||||
# build image
|
||||
docker build -t ceccocats/tkdnn:latest -f Dockerfile.base .
|
||||
|
||||
# run image
|
||||
docker run -ti --gpus all --rm ceccocats/tkdnn:latest bash
|
||||
```
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <stdlib.h>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <time.h>
|
||||
#include <chrono>
|
||||
|
||||
#include "cuda.h"
|
||||
#include "cuda_runtime_api.h"
|
||||
#include <cublas_v2.h>
|
||||
#include <cudnn.h>
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
//saliency
|
||||
#include <opencv2/core/utility.hpp>
|
||||
//#include <opencv2/saliency.hpp>
|
||||
#include <opencv2/highgui.hpp>
|
||||
|
||||
#define SAVE false
|
||||
#define SAVE_TO(name, fn, i, var) {sprintf(buf_frame_crop_name,name,fn,i);\
|
||||
cv::imwrite(buf_frame_crop_name, var);}
|
||||
|
||||
|
||||
|
||||
// cv::Mat img_threshold(cv::Mat frame_crop);
|
||||
// cv::Mat img_background(cv::Mat frame_crop);
|
||||
// cv::Mat img_dist_transform(cv::Mat frame_crop);
|
||||
// cv::Mat img_watershed(cv::Mat frame_crop);
|
||||
void image_segmentation(cv::Mat frame_crop, int frame_nbr, int i);
|
||||
void image_gradients(cv::Mat frame_crop, int frame_nbr, int i);
|
||||
void image_find_contours(cv::Mat frame_crop, int frame_nbr, int i);
|
||||
void image_saliency(cv::Mat frame_crop, int frame_nbr, int i);
|
||||
void frame_box_disparity(cv::Mat pre_frame, cv::Mat frame, std::vector <cv::Rect> pre_rois, int frame_nbr);
|
||||
void segmentation(cv::Mat pre_frame, cv::Mat frame_crop, int frame_nbr, int i, int mode);
|
||||
|
||||
//canny
|
||||
cv::Mat img_laplacian(cv::Mat frame_crop, int ret);
|
||||
cv::Mat frame_disparity(cv::Mat pre_frame, cv::Mat frame, int frame_nbr, int i, int ret);
|
||||
@@ -0,0 +1,32 @@
|
||||
#ifndef CALIBRATION_H
|
||||
#define CALIBRATION_H
|
||||
|
||||
#include "gdal.h"
|
||||
#include <gdal_priv.h>
|
||||
#include <gdal/gdal.h>
|
||||
#include "gdal/gdal_priv.h"
|
||||
#include "gdal/cpl_conv.h"
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
#include <opencv2/calib3d.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
struct ObjCoords
|
||||
{
|
||||
double lat_;
|
||||
double long_;
|
||||
int class_;
|
||||
};
|
||||
|
||||
void readTiff(char *filename, double *adfGeoTransform);
|
||||
void readCameraCalibrationYaml(const std::string &cameraCalib, cv::Mat &cameraMat, cv::Mat &distCoeff);
|
||||
void pixel2coord(int x, int y, double &lat, double &lon, double *adfGeoTransform);
|
||||
void coord2pixel(double lat, double lon, int &x, int &y, double *adfGeoTransform);
|
||||
void fillMatrix(cv::Mat &H, double *matrix, bool show = false);
|
||||
void read_projection_matrix(cv::Mat &H, char *path);
|
||||
void convert_coords(std::vector<ObjCoords> &coords, int x, int y, int detected_class, cv::Mat H, double *adfGeoTransform);
|
||||
|
||||
#endif /*CALIBRATION_H*/
|
||||
@@ -0,0 +1,45 @@
|
||||
#ifndef CAMERAUTILS_H
|
||||
#define CAMERAUTILS_H
|
||||
|
||||
#include <vector>
|
||||
#include <mutex>
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include "tracker.h"
|
||||
#include "Yolo3Detection.h"
|
||||
|
||||
struct Camera_t
|
||||
{
|
||||
int CAM_IDX;
|
||||
char *input;
|
||||
char *pmatrix;
|
||||
char *maskfile;
|
||||
char *cameraCalib;
|
||||
char *maskFileOrient;
|
||||
bool to_show;
|
||||
tk::dnn::Yolo3Detection *yolo;
|
||||
double adfGeoTransform[6];
|
||||
};
|
||||
|
||||
struct Frame_t
|
||||
{
|
||||
char *input;
|
||||
cv::Mat frame;
|
||||
int frame_nbr;
|
||||
// sem_vc for mainthread, videocapturethread, originalthread and disparitythread
|
||||
std::mutex sem_vc;
|
||||
};
|
||||
|
||||
struct ModFrame_t
|
||||
{
|
||||
std::vector<Tracker> trackers;
|
||||
geodetic_converter::GeodeticConverter gc;
|
||||
double adfGeoTransform[6];
|
||||
cv::Mat H;
|
||||
cv::Mat original_frame;
|
||||
tk::dnn::Yolo3Detection yolo;
|
||||
cv::Mat mask;
|
||||
// sem for mainthread, detectionthread and topviewthread
|
||||
std::mutex sem;
|
||||
};
|
||||
|
||||
#endif /*CAMERAUTILS_H*/
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef CONFIGURATION_H
|
||||
#define CONFIGURATION_H
|
||||
|
||||
#include "cameraUtils.h"
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
struct Parameters_t
|
||||
{
|
||||
char *net;
|
||||
char *tiffile;
|
||||
int n_cameras;
|
||||
Camera_t *cameras;
|
||||
};
|
||||
|
||||
void readCamerasParametersYaml(const std::string &camerasParams, Parameters_t *par);
|
||||
bool read_parameters(int argc, char *argv[], Parameters_t *par);
|
||||
|
||||
#endif /*CONFIGURATION_H*/
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef MESSAGE_H
|
||||
#define MESSAGE_H
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <opencv2/calib3d.hpp>
|
||||
#include <opencv2/core.hpp>
|
||||
// #include <sys/socket.h> //socket
|
||||
// #include <arpa/inet.h> //inet_addr
|
||||
// #include <unistd.h> //write
|
||||
|
||||
#include "tracker.h"
|
||||
|
||||
#include "../masa_protocol/include/send.hpp"
|
||||
#include "../masa_protocol/include/serialize.hpp"
|
||||
|
||||
unsigned long long time_in_ms();
|
||||
|
||||
void addRoadUserfromTracker(const std::vector<Tracker> &trackers, Message *m, geodetic_converter::GeodeticConverter &gc, const cv::Mat &maskOrient, double *adfGeoTransform, cv::Mat H);
|
||||
|
||||
#endif /*MESSAGE_H*/
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef BOUNDINGBOX_H
|
||||
#define BOUNDINGBOX_H
|
||||
|
||||
#include <iostream>
|
||||
#include "tkdnn.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
class BoundingBox : public tk::dnn::box
|
||||
{
|
||||
float overlap(const float p1, const float l1, const float p2, const float l22);
|
||||
float boxesIntersection(const BoundingBox &b);
|
||||
float boxesUnion(const BoundingBox &b);
|
||||
|
||||
public:
|
||||
|
||||
int uniqueTruthIndex = -1;
|
||||
int truthFlag = 0;
|
||||
float maxIoU = 0;
|
||||
|
||||
float IoU(const BoundingBox &b);
|
||||
void clear();
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& os, const BoundingBox& bb);
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const BoundingBox& bb);
|
||||
bool boxComparison (const BoundingBox& a,const BoundingBox& b) ;
|
||||
|
||||
}}
|
||||
#endif /*BOUNDINGBOX_H*/
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
#ifndef CENTERNETDETECTION_H
|
||||
#define CENTERNETDETECTION_H
|
||||
|
||||
#include "kernels.h"
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include "opencv2/opencv.hpp"
|
||||
#include <time.h>
|
||||
#include <vector>
|
||||
#include <numeric> // std::iota
|
||||
#include <algorithm> // std::sort
|
||||
|
||||
#include "DetectionNN.h"
|
||||
|
||||
#include "kernelsThrust.h"
|
||||
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
class CenternetDetection : public DetectionNN
|
||||
{
|
||||
private:
|
||||
tk::dnn::dataDim_t dim;
|
||||
tk::dnn::dataDim_t dim2;
|
||||
tk::dnn::dataDim_t dim_hm;
|
||||
tk::dnn::dataDim_t dim_wh;
|
||||
tk::dnn::dataDim_t dim_reg;
|
||||
float *topk_scores;
|
||||
int *topk_inds_;
|
||||
float *topk_ys_;
|
||||
float *topk_xs_;
|
||||
int *ids_d, *ids_, *ids_2, *ids_2d;
|
||||
|
||||
float *scores, *scores_d;
|
||||
int *clses, *clses_d;
|
||||
int *topk_inds_d;
|
||||
float *topk_ys_d;
|
||||
float *topk_xs_d;
|
||||
int *inttopk_xs_d, *inttopk_ys_d;
|
||||
|
||||
|
||||
float *bbx0, *bby0, *bbx1, *bby1;
|
||||
float *bbx0_d, *bby0_d, *bbx1_d, *bby1_d;
|
||||
|
||||
float *target_coords;
|
||||
|
||||
#ifdef OPENCV_CUDACONTRIB
|
||||
float *mean_d;
|
||||
float *stddev_d;
|
||||
#else
|
||||
cv::Vec<float, 3> mean;
|
||||
cv::Vec<float, 3> stddev;
|
||||
dnnType *input;
|
||||
#endif
|
||||
|
||||
float *d_ptrs;
|
||||
|
||||
cv::Mat src;
|
||||
cv::Mat dst;
|
||||
cv::Mat dst2;
|
||||
cv::Mat trans, trans2;
|
||||
//processing
|
||||
float toll = 0.000001;
|
||||
int K = 100;
|
||||
int width = 128;//56; // TODO
|
||||
|
||||
// pointer used in the kernels
|
||||
float *src_out;
|
||||
int *ids_out;
|
||||
|
||||
struct threshold op;
|
||||
|
||||
public:
|
||||
CenternetDetection() {};
|
||||
~CenternetDetection() {};
|
||||
|
||||
bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
|
||||
} // namespace dnn
|
||||
} // namespace tk
|
||||
|
||||
|
||||
#endif /*CENTERNETDETECTION_H*/
|
||||
@@ -1,48 +0,0 @@
|
||||
#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;
|
||||
float scale_xy = 1;
|
||||
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);
|
||||
|
||||
}}
|
||||
@@ -1,183 +0,0 @@
|
||||
#ifndef DETECTIONNN_H
|
||||
#define DETECTIONNN_H
|
||||
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include "utils.h"
|
||||
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
#include "tkdnn.h"
|
||||
|
||||
// #define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib.
|
||||
|
||||
#ifdef OPENCV_CUDACONTRIB
|
||||
#include <opencv2/cudawarping.hpp>
|
||||
#include <opencv2/cudaarithm.hpp>
|
||||
#endif
|
||||
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
class DetectionNN {
|
||||
|
||||
protected:
|
||||
tk::dnn::NetworkRT *netRT = nullptr;
|
||||
dnnType *input_d;
|
||||
|
||||
std::vector<cv::Size> originalSize;
|
||||
|
||||
cv::Scalar colors[256];
|
||||
|
||||
int nBatches = 1;
|
||||
|
||||
#ifdef OPENCV_CUDACONTRIB
|
||||
cv::cuda::GpuMat bgr[3];
|
||||
cv::cuda::GpuMat imagePreproc;
|
||||
#else
|
||||
cv::Mat bgr[3];
|
||||
cv::Mat imagePreproc;
|
||||
dnnType *input;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* 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, const int bi=0) = 0;
|
||||
|
||||
/**
|
||||
* This method postprocess the output of the NN to obtain the correct
|
||||
* boundig boxes.
|
||||
*
|
||||
* @param bi batch index
|
||||
* @param mAP set to true only if all the probabilities for a bounding
|
||||
* box are needed, as in some cases for the mAP calculation
|
||||
*/
|
||||
virtual void postprocess(const 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;
|
||||
|
||||
DetectionNN() {};
|
||||
~DetectionNN(){};
|
||||
|
||||
/**
|
||||
* Method used to inialize the class, allocate memory and compute
|
||||
* needed data.
|
||||
*
|
||||
* @param tensor_path path to the rt file og 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, const int n_batches=1) = 0;
|
||||
|
||||
/**
|
||||
* This method performs the whole detection of the NN.
|
||||
*
|
||||
* @param frames frames to run detection on.
|
||||
* @param cur_batches number of batches to use in inference
|
||||
* @param save_times if set to true, preprocess, inference and postprocess times
|
||||
* are saved on a csv file, otherwise not.
|
||||
* @param times pointer to the output stream where to write times
|
||||
* @param mAP set to true only if all the probabilities for a bounding
|
||||
* box are needed, as in some cases for the mAP calculation
|
||||
*/
|
||||
void update(std::vector<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.clear();
|
||||
if(TKDNN_VERBOSE) printCenteredTitle(" TENSORRT detection ", '=', 30);
|
||||
{
|
||||
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;
|
||||
{
|
||||
if(TKDNN_VERBOSE) dim.print();
|
||||
TKDNN_TSTART
|
||||
netRT->infer(dim, input_d);
|
||||
TKDNN_TSTOP
|
||||
if(TKDNN_VERBOSE) dim.print();
|
||||
stats.push_back(t_ns);
|
||||
if(save_times) *times<<t_ns<<";";
|
||||
}
|
||||
|
||||
batchDetected.clear();
|
||||
{
|
||||
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.
|
||||
*
|
||||
* @param frames orginal frame to draw bounding box on.
|
||||
*/
|
||||
void draw(std::vector<cv::Mat>& frames) {
|
||||
tk::dnn::box b;
|
||||
int x0, w, x1, y0, h, y1;
|
||||
int objClass;
|
||||
std::string det_class;
|
||||
|
||||
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<batchDetected[bi].size(); i++) {
|
||||
b = batchDetected[bi][i];
|
||||
x0 = b.x;
|
||||
x1 = b.x + b.w;
|
||||
y0 = b.y;
|
||||
y1 = b.y + b.h;
|
||||
det_class = classesNames[b.cl];
|
||||
|
||||
// draw rectangle
|
||||
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(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif /* DETECTIONNN_H*/
|
||||
@@ -1,161 +0,0 @@
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include <Eigen/Dense>
|
||||
#include "utils.h"
|
||||
#include "tkdnn.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Gatti
|
||||
*/
|
||||
class ImuOdom {
|
||||
|
||||
public:
|
||||
tk::dnn::Network *net = nullptr;
|
||||
|
||||
// Network input dim
|
||||
tk::dnn::dataDim_t dim0;
|
||||
tk::dnn::dataDim_t dim1;
|
||||
tk::dnn::dataDim_t dim2;
|
||||
|
||||
// Network output dim
|
||||
tk::dnn::dataDim_t odim0;
|
||||
tk::dnn::dataDim_t odim1;
|
||||
|
||||
// input pointers
|
||||
dnnType *i0_d, *i1_d, *i2_d;
|
||||
// output pointers
|
||||
dnnType *o0_d, *o1_d;
|
||||
|
||||
// output eigen CPU
|
||||
Eigen::MatrixXf deltaP, deltaQ;
|
||||
|
||||
Eigen::MatrixXd odomPOS, odomEULER;
|
||||
Eigen::Matrix3d odomROT;
|
||||
Eigen::Isometry3f tf = Eigen::Isometry3f::Identity();
|
||||
|
||||
ImuOdom() {}
|
||||
|
||||
virtual ~ImuOdom() {}
|
||||
|
||||
/**
|
||||
* Method used for inizialize the class
|
||||
*
|
||||
* @return Success of the initialization
|
||||
*/
|
||||
bool init(std::string layers_path) {
|
||||
|
||||
dim0 = tk::dnn::dataDim_t(1, 4, 1, 100);
|
||||
dim1 = tk::dnn::dataDim_t(1, 3, 1, 100);
|
||||
dim2 = tk::dnn::dataDim_t(1, 3, 1, 100);
|
||||
|
||||
checkCuda( cudaMalloc(&i0_d, dim0.tot()*sizeof(dnnType)) );
|
||||
checkCuda( cudaMalloc(&i1_d, dim1.tot()*sizeof(dnnType)) );
|
||||
checkCuda( cudaMalloc(&i2_d, dim2.tot()*sizeof(dnnType)) );
|
||||
|
||||
std::string c0_bin = layers_path + "/conv1d_7.bin";
|
||||
std::string c1_bin = layers_path + "/conv1d_8.bin";
|
||||
std::string c2_bin = layers_path + "/conv1d_9.bin";
|
||||
std::string c3_bin = layers_path + "/conv1d_10.bin";
|
||||
std::string c4_bin = layers_path + "/conv1d_11.bin";
|
||||
std::string c5_bin = layers_path + "/conv1d_12.bin";
|
||||
std::string l0_bin = layers_path + "/bidirectional_3.bin";
|
||||
std::string l1_bin = layers_path + "/bidirectional_4.bin";
|
||||
std::string d0_bin = layers_path + "/dense_3.bin";
|
||||
std::string d1_bin = layers_path + "/dense_4.bin";
|
||||
|
||||
net = new tk::dnn::Network(dim0);
|
||||
tk::dnn::Input *x0 = new tk::dnn::Input (net, dim0, i0_d);
|
||||
tk::dnn::Conv2d *x0_0 = new tk::dnn::Conv2d (net, 128, 1, 11, 1, 1, 0, 0, c0_bin);
|
||||
tk::dnn::Conv2d *x0_1 = new tk::dnn::Conv2d (net, 128, 1, 11, 1, 1, 0, 0, c1_bin);
|
||||
tk::dnn::Pooling *x0_2 = new tk::dnn::Pooling(net, 1, 3, 1, 3 ,0, 0, tk::dnn::tkdnnPoolingMode_t::POOLING_MAX);
|
||||
|
||||
tk::dnn::Input *x1 = new tk::dnn::Input (net, dim1, i1_d);
|
||||
tk::dnn::Conv2d *x1_0 = new tk::dnn::Conv2d (net, 128, 1, 11, 1, 1, 0, 0, c2_bin);
|
||||
tk::dnn::Conv2d *x1_1 = new tk::dnn::Conv2d (net, 128, 1, 11, 1, 1, 0, 0, c3_bin);
|
||||
tk::dnn::Pooling *x1_2 = new tk::dnn::Pooling(net, 1, 3, 1, 3, 0, 0, tk::dnn::tkdnnPoolingMode_t::POOLING_MAX);
|
||||
|
||||
tk::dnn::Input *x2 = new tk::dnn::Input (net, dim2, i2_d);
|
||||
tk::dnn::Conv2d *x2_0 = new tk::dnn::Conv2d (net, 128, 1, 11, 1, 1, 0, 0, c4_bin);
|
||||
tk::dnn::Conv2d *x2_1 = new tk::dnn::Conv2d (net, 128, 1, 11, 1, 1, 0, 0, c5_bin);
|
||||
tk::dnn::Pooling *x2_2 = new tk::dnn::Pooling(net, 1, 3, 1, 3, 0, 0, tk::dnn::tkdnnPoolingMode_t::POOLING_MAX);
|
||||
|
||||
tk::dnn::Layer *concat_l[3] = { x0_2, x1_2, x2_2 };
|
||||
tk::dnn::Route *concat = new tk::dnn::Route(net, concat_l, 3);
|
||||
|
||||
tk::dnn::LSTM *lstm0 = new tk::dnn::LSTM(net, 128, true, l0_bin);
|
||||
tk::dnn::LSTM *lstm1 = new tk::dnn::LSTM(net, 128, false, l1_bin);
|
||||
|
||||
tk::dnn::Dense *d0 = new tk::dnn::Dense(net, 3, d0_bin);
|
||||
|
||||
tk::dnn::Layer *lstm1_l[1] = { lstm1 };
|
||||
tk::dnn::Route *lstm1_link = new tk::dnn::Route(net, lstm1_l, 1);
|
||||
tk::dnn::Dense *d1 = new tk::dnn::Dense(net, 4, d1_bin);
|
||||
|
||||
net->print();
|
||||
|
||||
// output data
|
||||
o0_d = d0->dstData;
|
||||
o1_d = d1->dstData;
|
||||
odim0 = d0->output_dim;
|
||||
odim1 = d1->output_dim;
|
||||
|
||||
deltaP.resize(odim0.tot(), 1);
|
||||
deltaQ.resize(odim1.tot(), 1);
|
||||
|
||||
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) );
|
||||
checkCuda( cudaMemcpy(i1_d, x1, dim1.tot()*sizeof(dnnType), cudaMemcpyHostToDevice) );
|
||||
checkCuda( cudaMemcpy(i2_d, x2, dim2.tot()*sizeof(dnnType), cudaMemcpyHostToDevice) );
|
||||
|
||||
// Inference
|
||||
tk::dnn::dataDim_t dim;
|
||||
net->infer(dim, nullptr);
|
||||
|
||||
checkCuda( cudaMemcpy(deltaP.data(), o0_d, odim0.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost) );
|
||||
checkCuda( cudaMemcpy(deltaQ.data(), o1_d, odim1.tot()*sizeof(dnnType), cudaMemcpyDeviceToHost) );
|
||||
|
||||
// compute odom
|
||||
Eigen::Quaterniond q;
|
||||
q.w() = deltaQ(0);
|
||||
q.x() = deltaQ(1);
|
||||
q.y() = deltaQ(2);
|
||||
q.z() = deltaQ(3);
|
||||
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>();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}}
|
||||
@@ -1,69 +0,0 @@
|
||||
#ifndef INT8BATCHSTREAM_H
|
||||
#define INT8BATCHSTREAM_H
|
||||
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "NvInfer.h"
|
||||
#include "utils.h"
|
||||
#include "tkdnn.h"
|
||||
|
||||
/*
|
||||
* BatchStream implements the stream for the INT8 calibrator.
|
||||
* It reads the two files .txt with the list of image file names
|
||||
* and the list of label file names.
|
||||
* It then iterates on images and labels.
|
||||
*/
|
||||
class BatchStream {
|
||||
public:
|
||||
BatchStream(tk::dnn::dataDim_t dim, int batchSize, int maxBatches, const std::string& fileimglist, const std::string& filelabellist);
|
||||
virtual ~BatchStream() { }
|
||||
void reset(int firstBatch);
|
||||
bool next();
|
||||
void skip(int skipCount);
|
||||
float *getBatch() { return mBatch.data(); }
|
||||
float *getLabels() { return mLabels.data(); }
|
||||
int getBatchesRead() const { return mBatchCount; }
|
||||
int getBatchSize() const { return mBatchSize; }
|
||||
nvinfer1::DimsNCHW getDims() const { return mDims; }
|
||||
float* getFileBatch() { return &mFileBatch[0]; }
|
||||
float* getFileLabels() { return &mFileLabels[0]; }
|
||||
void readInListFile(const std::string& dataFilePath, std::vector<std::string>& mListIn);
|
||||
void readCVimage(std::string inputFileName, std::vector<float>& res, bool fixshape = true);
|
||||
void readLabels(std::string inputFileName ,std::vector<float>& ris);
|
||||
bool update();
|
||||
|
||||
private:
|
||||
int mBatchSize{ 0 };
|
||||
int mMaxBatches{ 0 };
|
||||
int mBatchCount{ 0 };
|
||||
int mFileCount{ 0 };
|
||||
int mFileBatchPos{ 0 };
|
||||
int mImageSize{ 0 };
|
||||
|
||||
nvinfer1::DimsNCHW mDims;
|
||||
std::vector<float> mBatch;
|
||||
std::vector<float> mLabels;
|
||||
std::vector<float> mFileBatch;
|
||||
std::vector<float> mFileLabels;
|
||||
|
||||
int mHeight;
|
||||
int mWidth;
|
||||
std::string mFileImgList;
|
||||
std::vector<std::string> mListImg;
|
||||
std::string mFileLabelList;
|
||||
std::vector<std::string> mListLabel;
|
||||
};
|
||||
|
||||
#endif //INT8BATCHSTREAM
|
||||
@@ -1,49 +0,0 @@
|
||||
#ifndef INT8CALIBRATOR_H
|
||||
#define INT8CALIBRATOR_H
|
||||
|
||||
#include <vector>
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <stdint.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "NvInfer.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iomanip>
|
||||
|
||||
#include "Int8BatchStream.h"
|
||||
|
||||
#include "tkdnn.h"
|
||||
#include "utils.h"
|
||||
|
||||
/*
|
||||
* Int8EntropyCalibrator implements the INT8 calibrator to achieve the
|
||||
* INT8 quantization. It uses a BatchStream stream to scroll through
|
||||
* images data. It also implements the calibration cache, a way to
|
||||
* save the calibration process results to reduce the running time:
|
||||
* the calibration process takes a long time.
|
||||
*/
|
||||
class Int8EntropyCalibrator : public nvinfer1::IInt8EntropyCalibrator {
|
||||
public:
|
||||
Int8EntropyCalibrator(BatchStream& stream, int firstBatch, const std::string& calibTableFilePath,
|
||||
const std::string& inputBlobName, bool readCache = true);
|
||||
virtual ~Int8EntropyCalibrator() { checkCuda(cudaFree(mDeviceInput)); }
|
||||
int getBatchSize() const override { return mStream.getBatchSize(); }
|
||||
bool getBatch(void* bindings[], const char* names[], int nbBindings) override;
|
||||
const void* readCalibrationCache(size_t& length) override;
|
||||
void writeCalibrationCache(const void* cache, size_t length) override;
|
||||
|
||||
private:
|
||||
BatchStream mStream;
|
||||
const std::string mCalibTableFilePath{ nullptr };
|
||||
const std::string mInputBlobName;
|
||||
bool mReadCache{ true };
|
||||
|
||||
size_t mInputCount;
|
||||
void* mDeviceInput{ nullptr };
|
||||
std::vector<char> mCalibrationCache;
|
||||
};
|
||||
|
||||
#endif //INT8CALIBRATOR_H
|
||||
@@ -6,21 +6,18 @@
|
||||
#include "utils.h"
|
||||
#include "Network.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
namespace tk
|
||||
{
|
||||
namespace dnn
|
||||
{
|
||||
|
||||
enum layerType_t {
|
||||
LAYER_INPUT,
|
||||
LAYER_DENSE,
|
||||
LAYER_CONV2D,
|
||||
LAYER_DECONV2D,
|
||||
LAYER_DEFORMCONV2D,
|
||||
LAYER_LSTM,
|
||||
LAYER_ACTIVATION,
|
||||
LAYER_ACTIVATION_CRELU,
|
||||
LAYER_ACTIVATION_LEAKY,
|
||||
LAYER_ACTIVATION_MISH,
|
||||
LAYER_FLATTEN,
|
||||
LAYER_RESHAPE,
|
||||
LAYER_MULADD,
|
||||
LAYER_POOLING,
|
||||
LAYER_SOFTMAX,
|
||||
@@ -37,67 +34,60 @@ enum layerType_t {
|
||||
/**
|
||||
Simple layer Father class
|
||||
*/
|
||||
class Layer {
|
||||
class Layer
|
||||
{
|
||||
|
||||
public:
|
||||
Layer(Network *net);
|
||||
virtual ~Layer();
|
||||
virtual layerType_t getLayerType() = 0;
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData) {
|
||||
std::cout<<"No infer action for this layer\n";
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData)
|
||||
{
|
||||
std::cout << "No infer action for this layer\n";
|
||||
return NULL;
|
||||
}
|
||||
void setFinal() { this->final = true; }
|
||||
|
||||
dataDim_t input_dim, output_dim;
|
||||
dnnType *dstData = nullptr; //where results will be putted
|
||||
dnnType *dstData; //where results will be putted
|
||||
|
||||
int id = 0;
|
||||
bool final; //if the layer is the final one
|
||||
|
||||
std::string getLayerName() {
|
||||
std::string getLayerName()
|
||||
{
|
||||
layerType_t type = getLayerType();
|
||||
switch(type) {
|
||||
case LAYER_INPUT: return "Input";
|
||||
case LAYER_DENSE: return "Dense";
|
||||
case LAYER_CONV2D: return "Conv2d";
|
||||
case LAYER_DECONV2D: return "DeConv2d";
|
||||
case LAYER_DEFORMCONV2D: return "DeformConv2d";
|
||||
case LAYER_LSTM: return "LSTM";
|
||||
case LAYER_ACTIVATION: return "Activation";
|
||||
case LAYER_ACTIVATION_CRELU: return "ActivationCReLU";
|
||||
case LAYER_ACTIVATION_LEAKY: return "ActivationLeaky";
|
||||
case LAYER_ACTIVATION_MISH: return "ActivationMish";
|
||||
case LAYER_FLATTEN: return "Flatten";
|
||||
case LAYER_RESHAPE: return "Reshape";
|
||||
case LAYER_MULADD: return "MulAdd";
|
||||
case LAYER_POOLING: return "Pooling";
|
||||
case LAYER_SOFTMAX: return "Softmax";
|
||||
case LAYER_ROUTE: return "Route";
|
||||
case LAYER_REORG: return "Reorg";
|
||||
case LAYER_SHORTCUT: return "Shortcut";
|
||||
case LAYER_UPSAMPLE: return "Upsample";
|
||||
case LAYER_REGION: return "Region";
|
||||
case LAYER_YOLO: return "Yolo";
|
||||
default: return "unknown";
|
||||
case LAYER_INPUT: return "Input";
|
||||
case LAYER_DENSE: return "Dense";
|
||||
case LAYER_CONV2D: return "Conv2d";
|
||||
case LAYER_LSTM: return "LSTM";
|
||||
case LAYER_ACTIVATION: return "Activation";
|
||||
case LAYER_FLATTEN: return "Flatten";
|
||||
case LAYER_MULADD: return "MulAdd";
|
||||
case LAYER_POOLING: return "Pooling";
|
||||
case LAYER_SOFTMAX: return "Softmax";
|
||||
case LAYER_ROUTE: return "Route";
|
||||
case LAYER_REORG: return "Reorg";
|
||||
case LAYER_SHORTCUT: return "Shortcut";
|
||||
case LAYER_UPSAMPLE: return "Upsample";
|
||||
case LAYER_REGION: return "Region";
|
||||
case LAYER_YOLO: return "Yolo";
|
||||
default: return "unknown";
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
Network *net;
|
||||
cudnnTensorDescriptor_t srcTensorDesc, dstTensorDesc;
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Father class of all layer that need to load trained weights
|
||||
*/
|
||||
class LayerWgs : public Layer {
|
||||
class LayerWgs : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
LayerWgs(Network *net, int inputs, int outputs, int kh, int kw, int kt,
|
||||
std::string fname_weights, bool batchnorm = false, bool additional_bias = false, bool deConv = false, int groups = 1);
|
||||
LayerWgs(Network *net, int inputs, int outputs, int kh, int kw, int kt,
|
||||
std::string fname_weights, bool batchnorm = false);
|
||||
virtual ~LayerWgs();
|
||||
|
||||
int inputs, outputs;
|
||||
@@ -106,70 +96,23 @@ public:
|
||||
dnnType *data_h, *data_d;
|
||||
dnnType *bias_h, *bias_d;
|
||||
|
||||
// additional bias for DCN
|
||||
bool additional_bias;
|
||||
dnnType *bias2_h = nullptr, *bias2_d = nullptr;
|
||||
|
||||
//batchnorm
|
||||
bool batchnorm;
|
||||
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;
|
||||
dnnType *power_h;
|
||||
dnnType *scales_h, *scales_d;
|
||||
dnnType *mean_h, *mean_d;
|
||||
dnnType *variance_h, *variance_d;
|
||||
|
||||
//fp16
|
||||
__half *data16_h = nullptr, *bias16_h = nullptr;
|
||||
__half *data16_d = nullptr, *bias16_d = nullptr;
|
||||
__half *bias216_h = nullptr, *bias216_d = nullptr;
|
||||
__half *data16_h, *bias16_h;
|
||||
__half *data16_d, *bias16_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; }
|
||||
}
|
||||
}
|
||||
__half *power16_h, *power16_d;
|
||||
__half *scales16_h, *scales16_d;
|
||||
__half *mean16_h, *mean16_d;
|
||||
__half *variance16_h, *variance16_d;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Input layer (it doesnt need weigths)
|
||||
*/
|
||||
@@ -186,7 +129,6 @@ public:
|
||||
virtual layerType_t getLayerType() { return LAYER_INPUT; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData) {
|
||||
dim = output_dim;
|
||||
return dstData;
|
||||
}
|
||||
};
|
||||
@@ -195,55 +137,45 @@ public:
|
||||
/**
|
||||
Dense (full interconnection) layer
|
||||
*/
|
||||
class Dense : public LayerWgs {
|
||||
class Dense : public LayerWgs
|
||||
{
|
||||
|
||||
public:
|
||||
Dense(Network *net, int out_ch, std::string fname_weights);
|
||||
virtual ~Dense();
|
||||
virtual layerType_t getLayerType() { return LAYER_DENSE; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Avaible activation functions
|
||||
*/
|
||||
typedef enum {
|
||||
ACTIVATION_ELU = 100,
|
||||
ACTIVATION_LEAKY = 101,
|
||||
ACTIVATION_MISH = 102
|
||||
typedef enum
|
||||
{
|
||||
ACTIVATION_ELU = 100,
|
||||
ACTIVATION_LEAKY = 101
|
||||
} tkdnnActivationMode_t;
|
||||
|
||||
/**
|
||||
Activation layer (it doesnt need weigths)
|
||||
*/
|
||||
class Activation : public Layer {
|
||||
class Activation : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
int act_mode;
|
||||
float ceiling;
|
||||
|
||||
Activation(Network *net, int act_mode, const float ceiling=0.0);
|
||||
Activation(Network *net, int act_mode);
|
||||
virtual ~Activation();
|
||||
virtual layerType_t getLayerType() {
|
||||
if(act_mode == CUDNN_ACTIVATION_CLIPPED_RELU)
|
||||
return LAYER_ACTIVATION_CRELU;
|
||||
else if (act_mode == ACTIVATION_LEAKY)
|
||||
return LAYER_ACTIVATION_LEAKY;
|
||||
else if (act_mode == ACTIVATION_MISH)
|
||||
return LAYER_ACTIVATION_MISH;
|
||||
else
|
||||
return LAYER_ACTIVATION;
|
||||
};
|
||||
virtual layerType_t getLayerType() { return LAYER_ACTIVATION; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
|
||||
protected:
|
||||
cudnnActivationDescriptor_t activDesc;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Convolutional 2D layer
|
||||
|
||||
@@ -255,31 +187,27 @@ protected:
|
||||
means: OUTCH
|
||||
variance: OUTCH
|
||||
*/
|
||||
class Conv2d : public LayerWgs {
|
||||
class Conv2d : public LayerWgs
|
||||
{
|
||||
|
||||
public:
|
||||
Conv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
||||
int strideH, int strideW, int paddingH, int paddingW,
|
||||
std::string fname_weights, bool batchnorm = false, bool deConv = false, int groups = 1, bool additional_bias=false);
|
||||
std::string fname_weights, bool batchnorm = false);
|
||||
virtual ~Conv2d();
|
||||
virtual layerType_t getLayerType() { return LAYER_CONV2D; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
|
||||
int kernelH, kernelW, strideH, strideW, paddingH, paddingW;
|
||||
bool deConv, additional_bias;
|
||||
int groups;
|
||||
|
||||
protected:
|
||||
cudnnFilterDescriptor_t filterDesc;
|
||||
cudnnConvolutionDescriptor_t convDesc;
|
||||
cudnnConvolutionFwdAlgoPerf_t algo;
|
||||
cudnnConvolutionBwdDataAlgoPerf_t bwAlgo;
|
||||
cudnnConvolutionFwdAlgo_t algo;
|
||||
cudnnTensorDescriptor_t biasTensorDesc;
|
||||
|
||||
void initCUDNN(bool back = false);
|
||||
void inferCUDNN(dnnType* srcData, bool back = false);
|
||||
void* workSpace;
|
||||
void *workSpace;
|
||||
size_t ws_sizeInBytes;
|
||||
};
|
||||
|
||||
@@ -349,140 +277,72 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Convolutional 2D layer
|
||||
*/
|
||||
class DeConv2d : public Conv2d {
|
||||
|
||||
public:
|
||||
DeConv2d( Network *net, int out_ch, int kernelH, int kernelW,
|
||||
int strideH, int strideW, int paddingH, int paddingW,
|
||||
std::string fname_weights, bool batchnorm = false, int groups = 1) :
|
||||
Conv2d(net, out_ch, kernelH, kernelW, strideH, strideW, paddingH, paddingW, fname_weights, batchnorm, true, groups) {}
|
||||
virtual ~DeConv2d() {}
|
||||
virtual layerType_t getLayerType() { return LAYER_DECONV2D; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Deformable Convolutionl 2d layer
|
||||
*/
|
||||
class DeformConv2d : public LayerWgs {
|
||||
|
||||
public:
|
||||
DeformConv2d( Network *net, int out_ch, int deformable_group, int kernelH, int kernelW,
|
||||
int strideH, int strideW, int paddingH, int paddingW,
|
||||
std::string d_fname_weights, std::string fname_weights, bool batchnorm);
|
||||
virtual ~DeformConv2d();
|
||||
virtual layerType_t getLayerType() { return LAYER_DEFORMCONV2D; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
tk::dnn::Conv2d *preconv;
|
||||
int out_ch;
|
||||
int deformableGroup;
|
||||
int kernelH, kernelW, strideH, strideW, paddingH, paddingW;
|
||||
dnnType *ones_d1;
|
||||
dnnType *ones_d2;
|
||||
int chunk_dim;
|
||||
dnnType *offset, *mask;
|
||||
dnnType *output_conv;
|
||||
|
||||
cublasStatus_t stat;
|
||||
cublasHandle_t handle;
|
||||
|
||||
protected:
|
||||
|
||||
cudnnTensorDescriptor_t biasTensorDesc;
|
||||
void initCUDNN();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
Flatten layer
|
||||
is actually a matrix transposition
|
||||
*/
|
||||
class Flatten : public Layer {
|
||||
class Flatten : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
Flatten(Network *net);
|
||||
Flatten(Network *net);
|
||||
virtual ~Flatten();
|
||||
virtual layerType_t getLayerType() { return LAYER_FLATTEN; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
};
|
||||
|
||||
/**
|
||||
Reshape layer
|
||||
*/
|
||||
class Reshape : public Layer {
|
||||
|
||||
public:
|
||||
Reshape(Network *net, dataDim_t new_dim);
|
||||
virtual ~Reshape();
|
||||
virtual layerType_t getLayerType() { return LAYER_RESHAPE; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
MulAdd layer
|
||||
apply a multiplication and then an addition for each data
|
||||
*/
|
||||
class MulAdd : public Layer {
|
||||
class MulAdd : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
MulAdd(Network *net, dnnType mul, dnnType add);
|
||||
MulAdd(Network *net, dnnType mul, dnnType add);
|
||||
virtual ~MulAdd();
|
||||
virtual layerType_t getLayerType() { return LAYER_MULADD; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
|
||||
protected:
|
||||
dnnType mul, add;
|
||||
dnnType *add_vector;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Avaible pooling functions (padding on tkDNN is not supported)
|
||||
*/
|
||||
typedef enum {
|
||||
POOLING_MAX = 0,
|
||||
POOLING_AVERAGE = 1, // count for average includes padded values
|
||||
POOLING_AVERAGE_EXCLUDE_PADDING = 2, // count for average does not include padded values
|
||||
POOLING_MAX_FIXEDSIZE = 100 // max pool darknet fashion
|
||||
typedef enum
|
||||
{
|
||||
POOLING_MAX = 0,
|
||||
POOLING_AVERAGE = 1, // count for average includes padded values
|
||||
POOLING_AVERAGE_EXCLUDE_PADDING = 2 // count for average does not include padded values
|
||||
} tkdnnPoolingMode_t;
|
||||
|
||||
/**
|
||||
Pooling layer
|
||||
currenty supported only 2d pooing (also on 3d input)
|
||||
*/
|
||||
class Pooling : public Layer {
|
||||
class Pooling : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
int winH, winW;
|
||||
int strideH, strideW;
|
||||
int paddingH, paddingW;
|
||||
bool size;
|
||||
tkdnnPoolingMode_t pool_mode;
|
||||
|
||||
Pooling(Network *net, int winH, int winW,
|
||||
int strideH, int strideW,
|
||||
int paddingH, int paddingW,
|
||||
tkdnnPoolingMode_t pool_mode);
|
||||
Pooling(Network *net, int winH, int winW,
|
||||
int strideH, int strideW, tkdnnPoolingMode_t pool_mode);
|
||||
virtual ~Pooling();
|
||||
virtual layerType_t getLayerType() { return LAYER_POOLING; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
|
||||
protected:
|
||||
|
||||
cudnnPoolingDescriptor_t poolingDesc;
|
||||
tkdnnPoolingMode_t pool_mode;
|
||||
dnnType *tmpInputData, *tmpOutputData;
|
||||
bool poolOn3d;
|
||||
};
|
||||
@@ -490,52 +350,49 @@ protected:
|
||||
/**
|
||||
Softmax layer
|
||||
*/
|
||||
class Softmax : public Layer {
|
||||
class Softmax : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
Softmax(Network *net, const tk::dnn::dataDim_t* dim=nullptr, const cudnnSoftmaxMode_t mode=CUDNN_SOFTMAX_MODE_CHANNEL);
|
||||
Softmax(Network *net);
|
||||
virtual ~Softmax();
|
||||
virtual layerType_t getLayerType() { return LAYER_SOFTMAX; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
dataDim_t dim;
|
||||
cudnnSoftmaxMode_t mode;
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
};
|
||||
|
||||
/**
|
||||
Route layer
|
||||
Merge a list of layers
|
||||
*/
|
||||
class Route : public Layer {
|
||||
class Route : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
Route(Network *net, Layer **layers, int layers_n, int groups = 1, int group_id = 0);
|
||||
Route(Network *net, Layer **layers, int layers_n);
|
||||
virtual ~Route();
|
||||
virtual layerType_t getLayerType() { return LAYER_ROUTE; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
|
||||
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;
|
||||
Layer **layers; //ids of layers to be merged
|
||||
int layers_n; //number of layers
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Reorg layer
|
||||
Mantain same dimension but change C*H*W distribution
|
||||
*/
|
||||
class Reorg : public Layer {
|
||||
class Reorg : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
Reorg(Network *net, int stride);
|
||||
virtual ~Reorg();
|
||||
virtual layerType_t getLayerType() { return LAYER_REORG; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
|
||||
int stride;
|
||||
};
|
||||
@@ -544,14 +401,15 @@ public:
|
||||
Shortcut layer
|
||||
sum with stride another layer
|
||||
*/
|
||||
class Shortcut : public Layer {
|
||||
class Shortcut : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
Shortcut(Network *net, Layer *backLayer);
|
||||
Shortcut(Network *net, Layer *backLayer);
|
||||
virtual ~Shortcut();
|
||||
virtual layerType_t getLayerType() { return LAYER_SHORTCUT; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
|
||||
public:
|
||||
Layer *backLayer;
|
||||
@@ -561,31 +419,28 @@ public:
|
||||
Upsample layer
|
||||
Mantain same dimension but change C*H*W distribution
|
||||
*/
|
||||
class Upsample : public Layer {
|
||||
class Upsample : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
Upsample(Network *net, int stride);
|
||||
virtual ~Upsample();
|
||||
virtual layerType_t getLayerType() { return LAYER_UPSAMPLE; };
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
|
||||
int stride;
|
||||
bool reverse;
|
||||
};
|
||||
|
||||
struct box {
|
||||
struct box
|
||||
{
|
||||
int cl;
|
||||
float x, y, w, h;
|
||||
float prob;
|
||||
std::vector<float> probs;
|
||||
|
||||
void print()
|
||||
{
|
||||
std::cout<<"x: "<<x<<"\ty: "<<y<<"\tw: "<<w<<"\th: "<<h<<"\tcl: "<<cl<<"\tprob: "<<prob<<std::endl;
|
||||
}
|
||||
};
|
||||
struct sortable_bbox {
|
||||
struct sortable_bbox
|
||||
{
|
||||
int index;
|
||||
int cl;
|
||||
float **probs;
|
||||
@@ -594,14 +449,17 @@ struct sortable_bbox {
|
||||
/**
|
||||
Yolo3 layer
|
||||
*/
|
||||
class Yolo : public Layer {
|
||||
class Yolo : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
struct box {
|
||||
struct box
|
||||
{
|
||||
float x, y, w, h;
|
||||
};
|
||||
|
||||
struct detection{
|
||||
struct detection
|
||||
{
|
||||
Yolo::box bbox;
|
||||
int classes;
|
||||
float *prob;
|
||||
@@ -610,30 +468,30 @@ public:
|
||||
int sort_class;
|
||||
};
|
||||
|
||||
Yolo(Network *net, int classes, int num, std::string fname_weights,int n_masks=3, float scale_xy=1);
|
||||
Yolo(Network *net, int classes, int num, std::string fname_weights);
|
||||
virtual ~Yolo();
|
||||
virtual layerType_t getLayerType() { return LAYER_YOLO; };
|
||||
|
||||
int classes, num, n_masks;
|
||||
int classes, num;
|
||||
dnnType *mask_h, *mask_d; //anchors
|
||||
dnnType *bias_h, *bias_d; //anchors
|
||||
float scaleXY;
|
||||
std::vector<std::string> classesNames;
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
int computeDetections(Yolo::detection *dets, int &ndets, int netw, int neth, float thresh);
|
||||
|
||||
dnnType *predictions;
|
||||
|
||||
static const int MAX_DETECTIONS = 8192;
|
||||
static const int MAX_DETECTIONS = 256;
|
||||
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);
|
||||
};
|
||||
|
||||
/**
|
||||
Region layer
|
||||
*/
|
||||
class Region : public Layer {
|
||||
class Region : public Layer
|
||||
{
|
||||
|
||||
public:
|
||||
Region(Network *net, int classes, int coords, int num);
|
||||
@@ -641,11 +499,12 @@ public:
|
||||
virtual layerType_t getLayerType() { return LAYER_REGION; };
|
||||
|
||||
int classes, coords, num;
|
||||
|
||||
virtual dnnType* infer(dataDim_t &dim, dnnType* srcData);
|
||||
|
||||
virtual dnnType *infer(dataDim_t &dim, dnnType *srcData);
|
||||
};
|
||||
|
||||
class RegionInterpret {
|
||||
class RegionInterpret
|
||||
{
|
||||
|
||||
public:
|
||||
RegionInterpret(dataDim_t input_dim, dataDim_t output_dim,
|
||||
@@ -657,7 +516,6 @@ public:
|
||||
int classes, coords, num;
|
||||
float thresh;
|
||||
|
||||
|
||||
box *boxes;
|
||||
float **probs;
|
||||
sortable_bbox *s;
|
||||
@@ -665,9 +523,9 @@ public:
|
||||
int res_boxes_n;
|
||||
|
||||
box get_region_box(float *x, float *biases, int n, int index, int i, int j, int w, int h, int stride);
|
||||
void get_region_boxes( float *input, int w, int h, int netw, int neth, float thresh,
|
||||
float **probs, box *boxes, int only_objectness,
|
||||
int *map, float tree_thresh, int relative);
|
||||
void get_region_boxes(float *input, int w, int h, int netw, int neth, float thresh,
|
||||
float **probs, box *boxes, int only_objectness,
|
||||
int *map, float tree_thresh, int relative);
|
||||
void correct_region_boxes(box *boxes, int n, int w, int h, int netw, int neth, int relative);
|
||||
void interpretData(dnnType *data_h, int imageW = 0, int imageH = 0);
|
||||
void showImageResult(dnnType *input_h);
|
||||
@@ -675,5 +533,6 @@ public:
|
||||
static float box_iou(box a, box b);
|
||||
};
|
||||
|
||||
}}
|
||||
} // namespace dnn
|
||||
} // namespace tk
|
||||
#endif //LAYER_H
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
#ifndef MOBILENETDETECTION_H
|
||||
#define MOBILENETDETECTION_H
|
||||
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include "opencv2/opencv.hpp"
|
||||
|
||||
#include "DetectionNN.h"
|
||||
|
||||
#define N_COORDS 4
|
||||
#define N_SSDSPEC 6
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
struct SSDSpec
|
||||
{
|
||||
int featureSize = 0;
|
||||
int shrinkage = 0;
|
||||
int boxWidth = 0;
|
||||
int boxHeight = 0;
|
||||
int ratio1 = 0;
|
||||
int ratio2 = 0;
|
||||
|
||||
SSDSpec() {}
|
||||
SSDSpec(int feature_size, int shrinkage, int box_width, int box_height, int ratio1, int ratio2) :
|
||||
featureSize(feature_size), shrinkage(shrinkage), boxWidth(box_width),
|
||||
boxHeight(box_height), ratio1(ratio1), ratio2(ratio2) {}
|
||||
void setAll(int feature_size, int shrinkage, int box_width, int box_height, int ratio1, int ratio2)
|
||||
{
|
||||
this->featureSize = feature_size;
|
||||
this->shrinkage = shrinkage;
|
||||
this->boxWidth = box_width;
|
||||
this->boxHeight = box_height;
|
||||
this->ratio1 = ratio1;
|
||||
this->ratio2 = ratio2;
|
||||
}
|
||||
void print()
|
||||
{
|
||||
std::cout << "fsize: " << featureSize << "\tshrinkage: " << shrinkage <<
|
||||
"\t box W:" << boxWidth << "\tbox H: " << boxHeight <<
|
||||
"\t x ratio:" << ratio1 << "\t y ratio:" << ratio2 << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
class MobilenetDetection : public DetectionNN
|
||||
{
|
||||
private:
|
||||
float IoUThreshold = 0.45;
|
||||
float centerVariance = 0.1;
|
||||
float sizeVariance = 0.2;
|
||||
int imageSize;
|
||||
|
||||
float *priors = nullptr;
|
||||
int nPriors = 0;
|
||||
float *locations_h, *confidences_h;
|
||||
|
||||
|
||||
|
||||
void generate_ssd_priors(const SSDSpec *specs, const int n_specs, bool clamp = true);
|
||||
void convert_locatios_to_boxes_and_center();
|
||||
float iou(const tk::dnn::box &a, const tk::dnn::box &b);
|
||||
|
||||
|
||||
|
||||
public:
|
||||
MobilenetDetection() {};
|
||||
~MobilenetDetection() {};
|
||||
|
||||
bool init(const std::string& tensor_path, const int n_classes, const int n_batches=1);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
|
||||
} // namespace dnn
|
||||
} // namespace tk
|
||||
|
||||
#endif /*MOBILENETDETECTION_H*/
|
||||
@@ -1,10 +1,12 @@
|
||||
#ifndef NETWORK_H
|
||||
#define NETWORK_H
|
||||
|
||||
#include <string>
|
||||
#include "utils.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
namespace tk
|
||||
{
|
||||
namespace dnn
|
||||
{
|
||||
|
||||
/**
|
||||
Data rapresentation beetween layers
|
||||
@@ -14,63 +16,58 @@ namespace tk { namespace dnn {
|
||||
w = width (rows)
|
||||
l = lenght (3rd dimension)
|
||||
*/
|
||||
struct dataDim_t {
|
||||
struct dataDim_t
|
||||
{
|
||||
|
||||
int n, c, h, w, l;
|
||||
|
||||
dataDim_t() : n(1), c(1), h(1), w(1), l(1) {};
|
||||
dataDim_t() : n(1), c(1), h(1), w(1), l(1){};
|
||||
|
||||
dataDim_t(int _n, int _c, int _h, int _w, int _l = 1) :
|
||||
n(_n), c(_c), h(_h), w(_w), l(_l) {};
|
||||
dataDim_t(int _n, int _c, int _h, int _w, int _l = 1) : n(_n), c(_c), h(_h), w(_w), l(_l){};
|
||||
|
||||
void print() {
|
||||
std::cout<<"Data dim: "<<n<<" "<<c<<" "<<h<<" "<<w<<" "<<l<<"\n";
|
||||
void print()
|
||||
{
|
||||
std::cout << "Data dim: " << n << " " << c << " " << h << " " << w << " " << l << "\n";
|
||||
}
|
||||
|
||||
int tot() {
|
||||
return n*c*h*w*l;
|
||||
int tot()
|
||||
{
|
||||
return n * c * h * w * l;
|
||||
}
|
||||
};
|
||||
|
||||
class Layer;
|
||||
const int MAX_LAYERS = 512;
|
||||
const int MAX_LAYERS = 256;
|
||||
|
||||
class Network {
|
||||
class Network
|
||||
{
|
||||
|
||||
public:
|
||||
Network(dataDim_t input_dim);
|
||||
virtual ~Network();
|
||||
void releaseLayers();
|
||||
|
||||
/**
|
||||
Do inferece for every added layer
|
||||
*/
|
||||
dnnType* infer(dataDim_t &dim, dnnType* data);
|
||||
dnnType *infer(dataDim_t &dim, dnnType *data);
|
||||
|
||||
bool addLayer(Layer *l);
|
||||
void print();
|
||||
const char *getNetworkRTName(const char *network_name);
|
||||
|
||||
cudnnDataType_t dataType;
|
||||
cudnnTensorFormat_t tensorFormat;
|
||||
cudnnHandle_t cudnnHandle;
|
||||
cublasHandle_t cublasHandle;
|
||||
|
||||
Layer* layers[MAX_LAYERS]; //contains layers of the net
|
||||
int num_layers; //current number of layers
|
||||
Layer *layers[MAX_LAYERS]; //contains layers of the net
|
||||
int num_layers; //current number of layers
|
||||
|
||||
dataDim_t input_dim;
|
||||
dataDim_t getOutputDim();
|
||||
|
||||
bool fp16, dla, int8;
|
||||
int maxBatchSize;
|
||||
bool dontLoadWeights;
|
||||
std::string fileImgList;
|
||||
std::string fileLabelList;
|
||||
std::string networkName;
|
||||
std::string networkNameRT;
|
||||
|
||||
bool fp16, dla;
|
||||
};
|
||||
|
||||
}}
|
||||
} // namespace dnn
|
||||
} // namespace tk
|
||||
#endif //NETWORK_H
|
||||
|
||||
@@ -7,36 +7,35 @@
|
||||
#include "Layer.h"
|
||||
#include "NvInfer.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
template<typename T> void writeBUF(char*& buffer, const T& val)
|
||||
namespace tk
|
||||
{
|
||||
*reinterpret_cast<T*>(buffer) = val;
|
||||
namespace dnn
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
void writeBUF(char *&buffer, const T &val)
|
||||
{
|
||||
*reinterpret_cast<T *>(buffer) = val;
|
||||
buffer += sizeof(T);
|
||||
}
|
||||
|
||||
template<typename T> T readBUF(const char*& buffer)
|
||||
template <typename T>
|
||||
T readBUF(const char *&buffer)
|
||||
{
|
||||
T val = *reinterpret_cast<const T*>(buffer);
|
||||
T val = *reinterpret_cast<const T *>(buffer);
|
||||
buffer += sizeof(T);
|
||||
return val;
|
||||
}
|
||||
|
||||
using namespace nvinfer1;
|
||||
#include "pluginsRT/ActivationLeakyRT.h"
|
||||
#include "pluginsRT/ActivationReLUCeilingRT.h"
|
||||
#include "pluginsRT/ActivationMishRT.h"
|
||||
#include "pluginsRT/ReorgRT.h"
|
||||
#include "pluginsRT/RegionRT.h"
|
||||
#include "pluginsRT/RouteRT.h"
|
||||
//#include "pluginsRT/RouteRT.h"
|
||||
#include "pluginsRT/ShortcutRT.h"
|
||||
#include "pluginsRT/YoloRT.h"
|
||||
#include "pluginsRT/UpsampleRT.h"
|
||||
#include "pluginsRT/ResizeLayerRT.h"
|
||||
#include "pluginsRT/DeformableConvRT.h"
|
||||
#include "pluginsRT/FlattenConcatRT.h"
|
||||
#include "pluginsRT/ReshapeRT.h"
|
||||
#include "pluginsRT/MaxPoolingFixedSizeRT.h"
|
||||
//#include "pluginsRT/Int8Calibrator.h"
|
||||
|
||||
class PluginFactory : IPluginFactory
|
||||
{
|
||||
@@ -44,27 +43,23 @@ public:
|
||||
YoloRT *yolos[16];
|
||||
int n_yolos;
|
||||
|
||||
virtual IPlugin* createPlugin(const char* layerName, const void* serialData, size_t serialLength);
|
||||
virtual IPlugin *createPlugin(const char *layerName, const void *serialData, size_t serialLength);
|
||||
};
|
||||
|
||||
|
||||
|
||||
class NetworkRT {
|
||||
class NetworkRT
|
||||
{
|
||||
|
||||
public:
|
||||
nvinfer1::DataType dtRT;
|
||||
nvinfer1::IBuilder *builderRT;
|
||||
nvinfer1::IRuntime *runtimeRT;
|
||||
nvinfer1::INetworkDefinition *networkRT;
|
||||
#if NV_TENSORRT_MAJOR >= 6
|
||||
nvinfer1::IBuilderConfig *configRT;
|
||||
#endif
|
||||
nvinfer1::INetworkDefinition *networkRT;
|
||||
|
||||
nvinfer1::ICudaEngine *engineRT;
|
||||
nvinfer1::IExecutionContext *contextRT;
|
||||
|
||||
const static int MAX_BUFFERS_RT = 10;
|
||||
void* buffersRT[MAX_BUFFERS_RT];
|
||||
dataDim_t buffersDIM[MAX_BUFFERS_RT];
|
||||
void *buffersRT[MAX_BUFFERS_RT];
|
||||
int buf_input_idx, buf_output_idx;
|
||||
|
||||
dataDim_t input_dim, output_dim;
|
||||
@@ -76,45 +71,29 @@ public:
|
||||
NetworkRT(Network *net, const char *name);
|
||||
virtual ~NetworkRT();
|
||||
|
||||
int getMaxBatchSize() {
|
||||
if(engineRT != nullptr)
|
||||
return engineRT->getMaxBatchSize();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
int getBuffersN() {
|
||||
if(engineRT != nullptr)
|
||||
return engineRT->getNbBindings();
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
Do inferece
|
||||
*/
|
||||
dnnType* infer(dataDim_t &dim, dnnType* data);
|
||||
void enqueue(int batchSize = 1);
|
||||
dnnType *infer(dataDim_t &dim, dnnType *data);
|
||||
void enqueue();
|
||||
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Layer *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Conv2d *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Activation *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Dense *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Pooling *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Softmax *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Route *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Flatten *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Reshape *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Reorg *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Region *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Shortcut *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Yolo *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, Upsample *l);
|
||||
nvinfer1::ILayer* convert_layer(nvinfer1::ITensor *input, DeformConv2d *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Layer *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Conv2d *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Activation *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Dense *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Pooling *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Softmax *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Route *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Reorg *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Region *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Shortcut *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Yolo *l);
|
||||
nvinfer1::ILayer *convert_layer(nvinfer1::ITensor *input, Upsample *l);
|
||||
|
||||
bool serialize(const char *filename);
|
||||
bool deserialize(const char *filename);
|
||||
};
|
||||
|
||||
}}
|
||||
} // namespace dnn
|
||||
} // namespace tk
|
||||
#endif //NETWORKRT_H
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
#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);
|
||||
|
||||
}}
|
||||
@@ -1,36 +1,78 @@
|
||||
#ifndef Yolo3Detection_H
|
||||
#define Yolo3Detection_H
|
||||
#include <opencv2/videoio.hpp>
|
||||
#include "opencv2/opencv.hpp"
|
||||
#ifndef YOLO3DDETECTION_H
|
||||
#define YOLO3DDETECTION_H
|
||||
|
||||
#include "DetectionNN.h"
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
#include <unistd.h>
|
||||
#include <mutex>
|
||||
#include "utils.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
#include <opencv2/core/core.hpp>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
class Yolo3Detection : public DetectionNN
|
||||
#include "tkdnn.h"
|
||||
|
||||
namespace tk
|
||||
{
|
||||
namespace dnn
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Francesco Gatti
|
||||
*/
|
||||
class Yolo3Detection
|
||||
{
|
||||
|
||||
private:
|
||||
int num = 0;
|
||||
int nMasks = 0;
|
||||
int nDets = 0;
|
||||
tk::dnn::NetworkRT *netRT = nullptr;
|
||||
tk::dnn::Yolo *yolo[3];
|
||||
dnnType *input, *input_d;
|
||||
|
||||
int ndets = 0;
|
||||
tk::dnn::Yolo::detection *dets = nullptr;
|
||||
tk::dnn::Yolo* yolo[3];
|
||||
|
||||
tk::dnn::Yolo* getYoloLayer(int n=0);
|
||||
cv::Mat imageF;
|
||||
cv::Mat bgr[3];
|
||||
|
||||
cv::Mat bgr_h;
|
||||
|
||||
public:
|
||||
Yolo3Detection() {};
|
||||
~Yolo3Detection() {};
|
||||
int classes = 0;
|
||||
int num = 0;
|
||||
float thresh = 0.3;
|
||||
cv::Scalar colors[256];
|
||||
|
||||
// this is filled with results
|
||||
std::vector<tk::dnn::box> detected;
|
||||
|
||||
// keep track of inference times (ms)
|
||||
std::vector<double> stats;
|
||||
|
||||
Yolo3Detection() {}
|
||||
|
||||
virtual ~Yolo3Detection() {}
|
||||
|
||||
/**
|
||||
* Method used to inizialize the class
|
||||
*
|
||||
* @return Success of the initialization
|
||||
*/
|
||||
bool init(std::string tensor_path);
|
||||
void addBorders(cv::Mat &imageORIG, cv::Mat &imageWBorders, int &top, int &left);
|
||||
void update(cv::Mat &frame);
|
||||
|
||||
|
||||
tk::dnn::Yolo* getYoloLayer(int n=0) {
|
||||
if(n<3)
|
||||
return yolo[n];
|
||||
else
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
|
||||
} // namespace dnn
|
||||
} // namespace tk
|
||||
|
||||
#endif /* Yolo3Detection_H*/
|
||||
#endif /*YOLO3DDETECTION_H*/
|
||||
@@ -1,116 +0,0 @@
|
||||
#ifndef EVALUATION_H
|
||||
#define EVALUATION_H
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
#include "tkdnn.h"
|
||||
#include "BoundingBox.h"
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
struct Frame
|
||||
{
|
||||
std::string lFilename;
|
||||
std::string iFilename;
|
||||
std::vector<BoundingBox> gt;
|
||||
std::vector<BoundingBox> det;
|
||||
|
||||
void print() const;
|
||||
};
|
||||
|
||||
struct PR
|
||||
{
|
||||
double precision = 0;
|
||||
double recall = 0;
|
||||
int tp = 0, fp = 0, fn = 0;
|
||||
|
||||
void print();
|
||||
};
|
||||
|
||||
void readmAPParams( const char* config_filename, int& classes, int& map_points,
|
||||
int& map_levels, float& map_step, float& IoU_thresh,
|
||||
float& conf_thresh, bool& verbose);
|
||||
|
||||
/**
|
||||
* This method computes the mean Average Precision for a set of detections and
|
||||
* groundtruths. It returns the mAP for a given IoU threshold, and a given
|
||||
* confidence threshold over all the classes.
|
||||
*
|
||||
* @param images collection of frames on which to compute the metrics
|
||||
* @param classes number of classes of the considered dataset
|
||||
* @param IoU_thresh threshold used to compute Intersection over Union
|
||||
* @param conf_thresh threshold used to filter bounding boxes based on their
|
||||
* confidence (or probability)
|
||||
* @param map_points number of point used to compute the mAP. if 0 is given,
|
||||
* all the recall levels are evaluated, otherwise only
|
||||
* map_point recall levels are used. For COCO evaluation
|
||||
* 101 points are used.
|
||||
* @param verbose is set to true, prints on screen additional info
|
||||
*
|
||||
* @return mAP computed
|
||||
*/
|
||||
double computeMap( std::vector<Frame> &images,const int classes,
|
||||
const float IoU_thresh, const float conf_thresh=0.3,
|
||||
const int map_points=101, const bool verbose=false);
|
||||
|
||||
|
||||
/**
|
||||
* This method computes the mean Average Precision for a set of detections and
|
||||
* groundtruths on several IoU thresholds. It is used to compute, for example,
|
||||
* the most used metric in Object Detection, namely the mAP 0.5:0.95, which is
|
||||
* the average among the mAP for IoU level from 0.5 to 0.95 with a step of 0.05.
|
||||
*
|
||||
* @param images collection of frames on which to compute the metrics
|
||||
* @param classes number of classes of the considered dataset
|
||||
* @param IoU_thresh starting threshold used to compute Intersection over Union
|
||||
* @param conf_thresh threshold used to filter bounding boxes based on their
|
||||
* confidence (or probability)
|
||||
* @param map_points number of point used to compute the mAP. if 0 is given,
|
||||
* 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_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
|
||||
*
|
||||
* @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)
|
||||
*/
|
||||
double computeMapNIoULevels(std::vector<Frame> &images,const int classes,
|
||||
const float i_IoU_thresh=0.5, const float conf_thresh=0.3,
|
||||
const int map_points=101, const float map_step=0.05,
|
||||
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),
|
||||
* False Negative (FN), precision, recall and f1-score.
|
||||
* Those values are computer over all the detections, over all the classes.
|
||||
*
|
||||
* @param images collection of frames on which to compute the metrics
|
||||
* @param classes number of classes of the considered dataset
|
||||
* @param IoU_thresh threshold used to compute Intersection over Union
|
||||
* @param conf_thresh threshold used to filter bounding boxes based on their
|
||||
* confidence (or probability)
|
||||
* @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
|
||||
*/
|
||||
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*/
|
||||
|
||||