Merge pull request #13 from ceccocats/master
ceccocats/tkdnn:master -> perseusdg/tkdnn:tensorrt8
This commit is contained in:
+10
-2
@@ -5,6 +5,10 @@ set(CMAKE_CXX_STANDARD 14)
|
||||
|
||||
option(ENABLE_OPENCV_CUDA_CONTRIB "Enable OpenCV CUDA Contrib" OFF )
|
||||
|
||||
if(NOT CMAKE_BUILD_TYPE)
|
||||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "default build" FORCE)
|
||||
endif(NOT CMAKE_BUILD_TYPE)
|
||||
|
||||
find_package(CUDA 9.0 REQUIRED)
|
||||
if (CUDA_FOUND)
|
||||
set(OUTPUTFILE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cuda_script) # No suffix required
|
||||
@@ -78,8 +82,7 @@ endif()
|
||||
#-------------------------------------------------------------------------------
|
||||
# CUDA
|
||||
#-------------------------------------------------------------------------------
|
||||
|
||||
#set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_30 --compiler-options '-fPIC'")
|
||||
set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}" --compiler-options '-fPIC')
|
||||
|
||||
|
||||
find_package(CUDNN REQUIRED)
|
||||
@@ -203,12 +206,17 @@ target_link_libraries(test_shelfnet_berkeley tkDNN)
|
||||
add_executable(test_shelfnet_mapillary tests/shelfnet/shelfnet_mapillary.cpp)
|
||||
target_link_libraries(test_shelfnet_mapillary tkDNN)
|
||||
|
||||
add_executable(test_shelfnet_coco tests/shelfnet/shelfnet_coco.cpp)
|
||||
target_link_libraries(test_shelfnet_coco tkDNN)
|
||||
|
||||
# MONODEPTH2
|
||||
add_executable(test_monodepth2_640 tests/monodepth2/monodepth2_640.cpp)
|
||||
target_link_libraries(test_monodepth2_640 tkDNN)
|
||||
|
||||
add_executable(test_monodepth2_1024 tests/monodepth2/monodepth2_1024.cpp)
|
||||
target_link_libraries(test_monodepth2_1024 tkDNN)
|
||||
|
||||
|
||||
# DEMOS
|
||||
add_executable(test_rtinference tests/test_rtinference/rtinference.cpp)
|
||||
target_link_libraries(test_rtinference tkDNN)
|
||||
|
||||
@@ -23,9 +23,11 @@ If you use tkDNN in your research, please cite the [following paper](https://iee
|
||||
- [x] Support 2D/3D Object Detection and Tracking [README](docs/README_2d3dtracking.md)
|
||||
#### 24 November 2021
|
||||
- [x] Support to sematic segmentation on cuda 11
|
||||
- [x] Support to TensorRT8.
|
||||
- [x] Support to TensorRT8. (thanks to [Harshvardhan Chandirasekar](https://github.com/perseusdg))
|
||||
#### 30 March 2022
|
||||
- [x] Support to monocular depth esitmation [README](docs/README_depth.md) (thanks to [Harshvardhan Chandirasekar](https://github.com/perseusdg))
|
||||
|
||||
|
||||
TensorRT8 (and therefore Jetpack 4.6) is currently supported only on the branch tensort8 due to [performance issue with TensorRT8](https://docs.nvidia.com/deeplearning/tensorrt/release-notes/tensorrt-8.html)). We will merge it to the master as soon as those issues are fixed (probably in future minor releases).
|
||||
|
||||
## FPS Results
|
||||
Inference FPS of yolov4 with tkDNN, average of 1200 images with the same dimension as the input size, on
|
||||
@@ -117,8 +119,8 @@ git clone https://github.com/ceccocats/tkDNN
|
||||
cd tkDNN
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_BUILD_TYPE=Release -G"Ninja" ..
|
||||
ninja
|
||||
cmake -DCMAKE_BUILD_TYPE=Release ..
|
||||
make
|
||||
```
|
||||
|
||||
## Workflow
|
||||
@@ -138,6 +140,7 @@ For specific details on how to export weights see [HERE](./docs/exporting_weight
|
||||
For specific details on how to run:
|
||||
- 2D object detection demos, details on FP16, INT8 and batching see [HERE](./docs/demo.md).
|
||||
- segmentation demos see [HERE](./docs/README_seg.md).
|
||||
- monocular depth estimation see [HERE](./docs/README_depth.md).
|
||||
- 2D/3D object detection and tracking demos see [HERE](./docs/README_2d3dtracking.md).
|
||||
- mAP demo to evaluate 2D object detectors see [HERE](./docs/mAP_demo.md).
|
||||
|
||||
@@ -175,16 +178,17 @@ For specific details on how to run tkDNN on Windows 10/11 see [HERE](./docs/wind
|
||||
| yolo4_320 | Yolov4 <sup>8</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 320x320 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) |
|
||||
| yolo4_512 | Yolov4 <sup>8</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) |
|
||||
| yolo4_608 | Yolov4 <sup>8</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 608x608 | [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) |
|
||||
| yolo4_berkeley | Yolov4 <sup>8</sup> | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 544x320 | [weights](https://cloud.hipert.unimore.it/s/nkWFa5fgb4NTdnB/download) |
|
||||
| yolo4tiny | Yolov4 tiny <sup>9</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download) |
|
||||
| yolo4x | Yolov4x-mish <sup>9</sup> | [COCO 2017](http://cocodataset.org/) |
|
||||
| yolo4x | Yolov4x-mish <sup>9</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 640x640 | [weights](https://cloud.hipert.unimore.it/s/5MFjtNtgbDGdJEo/download) |
|
||||
| yolo4tiny_512 | Yolov4 tiny <sup>9</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download) |
|
||||
80 | 640x640 | [weights](https://cloud.hipert.unimore.it/s/5MFjtNtgbDGdJEo/download) |
|
||||
| yolo4x-cps | Scaled Yolov4 <sup>10</sup> | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/AfzHE4BfTeEm2gH/download) |
|
||||
| shelfnet | ShelfNet18_realtime<sup>11</sup> | [Cityscapes](https://www.cityscapes-dataset.com/) | 19 | 1024x1024 | [weights](https://cloud.hipert.unimore.it/s/mEDZMRJaGCFWSJF/download) |
|
||||
| shelfnet_berkeley | ShelfNet18_realtime<sup>11</sup> | [DeepDrive](https://bdd-data.berkeley.edu/) | 20 | 1024x1024 | [weights](https://cloud.hipert.unimore.it/s/m92e7QdD9gYMF7f/download) |
|
||||
| dla34_cnet3d | Centernet3D (DLA34 backend)<sup>4</sup> | [KITTI 2017](http://www.cvlibs.net/datasets/kitti/eval_object.php?obj_benchmark=3d) | 1 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/2MDyWGzQsTKMjmR/download) |
|
||||
| dla34_ctrack | CenterTrack (DLA34 backend)<sup>12</sup> | [NuScenes 3D](https://www.nuscenes.org/) | 7 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/rjNfgGL9FtAXLHp/download) |
|
||||
| monodepth2 | Monodepth2 <sup>13</sup> | [KITTI DEPTH](http://www.cvlibs.net/datasets/kitti/raw_data.php) | - | 640x192 | [weights-mono](https://cloud.hipert.unimore.it/s/iYw9QwgP6CsqxLR/download) |
|
||||
| monodepth2 | Monodepth2 <sup>13</sup> | [KITTI DEPTH](http://www.cvlibs.net/datasets/kitti/raw_data.php) | - | 640x192 | [weights-stereo](https://cloud.hipert.unimore.it/s/XmwbWNXDfqyQ4EL/download) |
|
||||
|
||||
|
||||
## References
|
||||
@@ -201,3 +205,11 @@ For specific details on how to run tkDNN on Windows 10/11 see [HERE](./docs/wind
|
||||
10. Wang, Chien-Yao, Alexey Bochkovskiy, and Hong-Yuan Mark Liao. "Scaled-YOLOv4: Scaling Cross Stage Partial Network." arXiv preprint arXiv:2011.08036 (2020).
|
||||
11. Zhuang, Juntang, et al. "ShelfNet for fast semantic segmentation." Proceedings of the IEEE International Conference on Computer Vision Workshops. 2019.
|
||||
12. Zhou, Xingyi, Vladlen Koltun, and Philipp Krähenbühl. "Tracking objects as points." European Conference on Computer Vision. Springer, Cham, 2020.
|
||||
13. Godard, Clément, et al. "Digging into self-supervised monocular depth estimation." Proceedings of the IEEE/CVF International Conference on Computer Vision. 2019.
|
||||
|
||||
## Contributors
|
||||
The main contibutors, in chronological order, are:
|
||||
- [Francesco Gatti](https://github.com/ceccocats), francesco.gatti@hipert.it
|
||||
- [Micaela Verucchi](https://github.com/mive93), micaela.verucchi@unimore.it
|
||||
- [Davide Sapienza](https://github.com/sapienzadavide), davide.sapienza@unimore.it
|
||||
- [Harshvardhan Chandirasekar](https://github.com/perseusdg), f20180523@goa.bits-pilani.ac.in
|
||||
|
||||
+33
-45
@@ -9,7 +9,6 @@
|
||||
#include "Yolo3Detection.h"
|
||||
|
||||
bool gRun;
|
||||
bool SAVE_RESULT = false;
|
||||
|
||||
void sig_handler(int signo) {
|
||||
std::cout<<"request gateway stop\n";
|
||||
@@ -20,44 +19,37 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
#ifdef __linux__
|
||||
std::string config_file = "../demo/demoConfig.yaml";
|
||||
#elif _WIN32
|
||||
std::string config_file = "..\\..\\..\\demo\\demoConfig.yaml";
|
||||
#endif
|
||||
|
||||
if(argc > 1){
|
||||
config_file = argv[1];
|
||||
}
|
||||
|
||||
YAML::Node conf = YAMLloadConf(config_file);
|
||||
if(!conf){
|
||||
// get config file path and read it
|
||||
#ifdef __linux__
|
||||
std::string config_file = "../demo/demoConfig.yaml";
|
||||
#elif _WIN32
|
||||
std::string config_file = "..\\..\\..\\demo\\demoConfig.yaml";
|
||||
#endif
|
||||
if(argc > 1)
|
||||
config_file = argv[1];
|
||||
|
||||
YAML::Node conf = YAMLloadConf(config_file);
|
||||
if(!conf)
|
||||
FatalError("Problem with config file");
|
||||
}
|
||||
|
||||
|
||||
std::string net = YAMLgetConf<std::string>(conf,"net","yolo4tiny_fp32.rt");
|
||||
if(!fileExist(net.c_str())) {
|
||||
// read settings from config file
|
||||
std::string net = YAMLgetConf<std::string>(conf, "net", "yolo4tiny_fp32.rt");
|
||||
if(!fileExist(net.c_str()))
|
||||
FatalError("The given network does not exist. Create the rt first.");
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
std::string input = YAMLgetConf<std::string>(conf, "input", "../demo/yolo_test.mp4");
|
||||
std::string cfgPath = YAMLgetConf<std::string>(conf,"cfg_input", "../tests/darknet/cfg/yolo4tiny.cfg");
|
||||
std::string namePath = YAMLgetConf<std::string>(conf,"name_input","../tests/darknet/names/coco.names");
|
||||
#elif _WIN32
|
||||
std::string input = YAMLgetConf<std::string>(conf, "win_input", "..\\..\\..\\demo\\yolo_test.mp4");
|
||||
std::string cfgPath = YAMLgetConf<std::string>(conf,"cfg_win_input","..\\..\\..\\tests\\darknet\\cfg\\yolo4tiny.cfg");
|
||||
std::string namePath = YAMLgetConf<std::string>(conf,"name_win_input","..\\..\\..\\tests\\darknet\\names\\coco.names");
|
||||
#endif
|
||||
if(!fileExist(input.c_str()))
|
||||
FatalError("The given input video does not exist.");
|
||||
#ifdef __linux__
|
||||
std::string input = YAMLgetConf<std::string>(conf, "input", "../demo/yolo_test.mp4");
|
||||
#elif _WIN32
|
||||
std::string input = YAMLgetConf<std::string>(conf, "win_input", "..\\..\\..\\demo\\yolo_test.mp4");
|
||||
#endif
|
||||
if(!fileExist(input.c_str()))
|
||||
FatalError("The given input video does not exist.");
|
||||
|
||||
char ntype = YAMLgetConf<char>(conf, "ntype", 'y');
|
||||
int n_classes = YAMLgetConf<int>(conf, "n_classes", 80);
|
||||
int n_batch = YAMLgetConf<int>(conf, "n_batch", 1);
|
||||
if(n_batch < 1 || n_batch > 64)
|
||||
FatalError("Batch dim not supported");
|
||||
FatalError("Batch dim not supported");
|
||||
float conf_thresh = YAMLgetConf<float>(conf, "conf_thresh", 0.3);
|
||||
bool show = YAMLgetConf<bool>(conf, "show", true);
|
||||
bool save = YAMLgetConf<bool>(conf, "save", false);
|
||||
@@ -70,7 +62,8 @@ int main(int argc, char *argv[]) {
|
||||
std::cout <<"Demo settings - input: "<< input
|
||||
<<", show: "<< show
|
||||
<<", save: "<< save<<"\n\n";
|
||||
|
||||
|
||||
// create detection network
|
||||
tk::dnn::Yolo3Detection yolo;
|
||||
tk::dnn::CenternetDetection cnet;
|
||||
tk::dnn::MobilenetDetection mbnet;
|
||||
@@ -93,15 +86,9 @@ int main(int argc, char *argv[]) {
|
||||
FatalError("Network type not allowed (3rd parameter)\n");
|
||||
}
|
||||
|
||||
if(ntype == 'c' || ntype == 'm'){
|
||||
cfgPath = "";
|
||||
namePath = "";
|
||||
}
|
||||
|
||||
detNN->init(net,cfgPath,namePath,n_classes,n_batch,conf_thresh);
|
||||
|
||||
gRun = true;
|
||||
detNN->init(net,n_classes,n_batch,conf_thresh);
|
||||
|
||||
// open video stream
|
||||
cv::VideoCapture cap(input);
|
||||
if(!cap.isOpened())
|
||||
gRun = false;
|
||||
@@ -115,13 +102,15 @@ int main(int argc, char *argv[]) {
|
||||
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;
|
||||
std::vector<cv::Mat> batch_frame;
|
||||
std::vector<cv::Mat> batch_dnn_input;
|
||||
|
||||
// start detection loop
|
||||
gRun = true;
|
||||
while(gRun) {
|
||||
batch_dnn_input.clear();
|
||||
batch_frame.clear();
|
||||
@@ -154,14 +143,13 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
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";
|
||||
std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())<<" ms\n";
|
||||
std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())<<" ms\n";
|
||||
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;
|
||||
|
||||
std::cout<<"Avg: "<<mean<<" ms\t"<<1000/(mean)<<" FPS\n"<<COL_END;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ int main(int argc, char *argv[]) {
|
||||
if(save) {
|
||||
int w = depthNN.output_w;
|
||||
int h = depthNN.output_h;
|
||||
resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','J','P','G'), 30, cv::Size(w, h));
|
||||
resultVideo.open("result.mp4", cv::VideoWriter::fourcc('M','P','4','V'), 30, cv::Size(w, h));
|
||||
}
|
||||
|
||||
if(show)
|
||||
|
||||
+5
-11
@@ -45,8 +45,6 @@ int main(int argc, char *argv[])
|
||||
bool verbose;
|
||||
int classes, map_points, map_levels;
|
||||
float map_step, IoU_thresh, conf_thresh;
|
||||
std::string cfg_path = "../tests/darknet/cfg/yolo4tiny.cfg";
|
||||
std::string name_path = "../tests/darknet/names/coco.names";
|
||||
double vm_total = 0, rss_total = 0;
|
||||
double vm, rss;
|
||||
|
||||
@@ -56,17 +54,13 @@ int main(int argc, char *argv[])
|
||||
if(argc > 2)
|
||||
ntype = argv[2][0];
|
||||
if(argc > 3)
|
||||
cfg_path = argv[3];
|
||||
labels_path = argv[3];
|
||||
if(argc > 4)
|
||||
name_path = argv[4];
|
||||
config_filename = argv[4];
|
||||
if(argc > 5)
|
||||
labels_path = argv[5];
|
||||
n_batches = atoi(argv[5]);
|
||||
if(argc > 6)
|
||||
config_filename = argv[6];
|
||||
if(argc > 7)
|
||||
n_batches = atoi(argv[7]);
|
||||
if(argc > 8)
|
||||
confidence_thresh = atof(argv[8]);
|
||||
confidence_thresh = atof(argv[6]);
|
||||
|
||||
std::cout<<"conf t: "<<confidence_thresh<<std::endl;
|
||||
|
||||
@@ -121,7 +115,7 @@ int main(int argc, char *argv[])
|
||||
default:
|
||||
FatalError("Network type not allowed (3rd parameter)\n");
|
||||
}
|
||||
detNN->init(net,cfg_path,name_path,n_classes, 1, conf_thresh);
|
||||
detNN->init(net,n_classes, 1, conf_thresh);
|
||||
|
||||
//read images
|
||||
std::ifstream all_labels(labels_path);
|
||||
|
||||
+2
-10
@@ -2,16 +2,8 @@
|
||||
input : "../demo/yolo_test.mp4"
|
||||
win_input : "..\\..\\..\\demo\\yolo_test.mp4"
|
||||
|
||||
#cfg input
|
||||
cfg_input : "../tests/darknet/cfg/yolo4tiny.cfg"
|
||||
cfg_win_input : "..\\..\\..\\tests\\darknet\\cfg\\yolo4tiny.cfg"
|
||||
|
||||
#name input
|
||||
name_input : "../tests/darknet/names/coco.names"
|
||||
name_win_input : "..\\..\\..\\tests\\darknet\\names\\coco.names"
|
||||
|
||||
# network config
|
||||
net : "yolo4tiny_fp32.rt"
|
||||
net : "yolo4_berkeley_fp32.rt"
|
||||
ntype : 'y'
|
||||
n_classes : 80
|
||||
n_batch : 1
|
||||
@@ -19,4 +11,4 @@ conf_thresh : 0.3
|
||||
|
||||
# demo config
|
||||
show : true
|
||||
save : false
|
||||
save : false
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
# Monocular depth estimation with tkDNN
|
||||
|
||||
Currently tkDNN supports only Monodepth2 as monocular depth esitmation network.
|
||||
|
||||
|
||||
## Run the demo
|
||||
|
||||
To run the depth estimation demo follow these steps (example with monodepth2):
|
||||
```
|
||||
rm monodepth2_fp32.rt # be sure to delete(or move) old tensorRT files
|
||||
./test_monodepth2 # run the yolo test (is slow)
|
||||
./demoDepth monodepth2_fp32.rt ../demo/yolo_test.mp4
|
||||
```
|
||||
In general the demo program takes the following parameters:
|
||||
```
|
||||
./demoDepth <network-rt-file> <path-to-video> <show-flag> <save-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
|
||||
* ```<show-flag>``` if set to 0 the demo will not show the visualization, it will otherwise (default=1)
|
||||
* ```<save-flag>``` if set to 1 the demo will save the video into result.mp4, it won't otherwise (default=1)
|
||||
|
||||
NB) By default it is used FP32 inference
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
<!-- ## FPS Results
|
||||
|
||||
Inference FPS of shelfnet with tkDNN, average of 1200 images 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 );
|
||||
|
||||
| Platform | Test | Phase | FP32, ms | FP32, FPS | FP16, ms | FP16, FPS | INT8, ms | INT8, FPS |
|
||||
| :------: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: | :-----: |
|
||||
| RTX 2080Ti | shelfnet 1024x1024 (B=1) | pre | 6.11863 | 163.435 | 5.81465 | 171.979 | 5.88699 | 169.866 |
|
||||
| RTX 2080Ti | shelfnet 1024x1024 (B=1) | inf | 11.5464 | 86.6074 | 7.35396 | 135.981 | 6.37623 | 156.832 |
|
||||
| RTX 2080Ti | shelfnet 1024x1024 (B=1) | post | 4.09058 | 244.464 | 3.91961 | 255.128 | 4.07343 | 245.493 |
|
||||
| RTX 2080Ti | shelfnet 1024x1024 (B=1) | tot | 21.7556 | 45.9652 | 17.0882 | 58.5199 | 16.3366 | 61.2121 |
|
||||
| RTX 2080Ti | shelfnet 2048x2048 (B=4) | pre | 25.435 | 39.3158 | 25.2953 | 39.5331 | 25.9303 | 38.565 |
|
||||
| RTX 2080Ti | shelfnet 2048x2048 (B=4) | inf | 36.5015 | 27.3961 | 17.0534 | 58.6395 | 15.6061 | 64.0773 |
|
||||
| RTX 2080Ti | shelfnet 2048x2048 (B=4) | post | 17.3917 | 57.4985 | 17.1649 | 58.2583 | 17.5539 | 56.9675 |
|
||||
| RTX 2080Ti | shelfnet 2048x2048 (B=4) | tot | 79.3283 | 12.6058 | 59.5136 | 16.8029 | 59.0903 | 16.9233 |
|
||||
| AGX Xavier | shelfnet 1024x1024 (B=1) | pre | 8.0174 | 124.729 | 7.5117 | 133.126 | 7.47333 | 133.809 |
|
||||
| AGX Xavier | shelfnet 1024x1024 (B=1) | inf | 72.4173 | 13.8089 | 37.505 | 26.6631 | 31.3286 | 31.9197 |
|
||||
| AGX Xavier | shelfnet 1024x1024 (B=1) | post | 8.89958 | 112.365 | 8.83576 | 113.176 | 9.42655 | 106.083 |
|
||||
| AGX Xavier | shelfnet 1024x1024 (B=1) | tot | 89.3342 | 11.1939 | 53.8525 | 18.5692 | 48.2285 | 20.7346 |
|
||||
| AGX Xavier | shelfnet 2048x2048 (B=4) | pre | 47.1454 | 21.211 | 21.6475 | 46.1947 | 21.4201 | 46.6851 |
|
||||
| AGX Xavier | shelfnet 2048x2048 (B=4) | inf | 266.537 | 3.75183 | 128.321 | 7.79293 | 107.621 | 9.29185 |
|
||||
| AGX Xavier | shelfnet 2048x2048 (B=4) | post | 44.0711 | 22.6906 | 40.1732 | 24.8922 | 39.873 | 25.0796 |
|
||||
| AGX Xavier | shelfnet 2048x2048 (B=4) | tot | 357.753 | 2.79522 | 190.142 | 5.25922 | 168.914 | 5.92016 | -->
|
||||
|
||||
@@ -46,8 +46,6 @@ The config file is a yaml file with the following attributes:
|
||||
* ```conf_thresh``` confidence threshold for the detector. Only bounding boxes with threshold greater than conf-thresh will be displayed.
|
||||
* ```show``` if set to 0 the demo will not show the visualization (if n-batches ==1)
|
||||
* ```save``` if set to 1 the demo will save the video of the demo into result.mp4 (if n-batches ==1)
|
||||
* ```cfg_input``` (for linux) \ ```cfg_win_input``` (for windows) is the location of the cfg path of the network for mobilenet and centernet networks use ```" "```
|
||||
* ```name_input``` (for linux) \ ```name_win_input``` (for windows) is the location of the name path of the network for mobilenet and centernet networks use ```" "```
|
||||
|
||||
N.B. By default it is used FP32 inference
|
||||
|
||||
|
||||
@@ -86,6 +86,18 @@ mkdir layer debug
|
||||
python export.py
|
||||
```
|
||||
|
||||
### 6)Export weights for monodepth2
|
||||
To get the weights needed to run Shelfnet tests use [this](https://github.com/perseusdg/monodepth2) fork of a Pytorch implementation of monodepth2 network.
|
||||
|
||||
```
|
||||
git clone https://github.com/perseusdg/monodepth2
|
||||
cd monodepth2
|
||||
mkdir models # Download the official weights and put depth.pth and encorder.pth inside this new folder
|
||||
conda env create --file monodepth.yaml
|
||||
conda activate monodepth2
|
||||
python exporter.py # you will find the weights inside the tkDNN_bin folder
|
||||
```
|
||||
|
||||
## Darknet Parser
|
||||
tkDNN implement and easy parser for darknet cfg files, a network can be converted with *tk::dnn::darknetParser*:
|
||||
```
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
CenternetDetection() {};
|
||||
~CenternetDetection() {};
|
||||
|
||||
bool init(const std::string& tensor_path,const std::string& cfg_path,const std::string& name_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3);
|
||||
bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
@@ -87,7 +87,7 @@ class DetectionNN {
|
||||
* @param n_batches maximum number of batches to use in inference
|
||||
* @return true if everything is correct, false otherwise.
|
||||
*/
|
||||
virtual bool init(const std::string& tensor_path,const std::string& cfg_path,const std::string& name_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3) = 0;
|
||||
virtual bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3) = 0;
|
||||
|
||||
/**
|
||||
* This method performs the whole detection of the NN.
|
||||
|
||||
@@ -65,7 +65,7 @@ public:
|
||||
MobilenetDetection() {};
|
||||
~MobilenetDetection() {};
|
||||
|
||||
bool init(const std::string& tensor_path, const std::string& cfg_path,const std::string& name_path,const int n_classes, const int n_batches=1, const float conf_thresh=0.3);
|
||||
bool init(const std::string& tensor_path,const int n_classes, const int n_batches=1, const float conf_thresh=0.3);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
@@ -30,10 +30,6 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
using namespace nvinfer1;
|
||||
|
||||
|
||||
|
||||
class NetworkRT {
|
||||
|
||||
public:
|
||||
@@ -57,6 +53,7 @@ public:
|
||||
dnnType *output;
|
||||
cudaStream_t stream;
|
||||
|
||||
std::vector<nvinfer1::YoloRT*> yolo_plugins; // yolo layers in network
|
||||
|
||||
NetworkRT(Network *net, const char *name);
|
||||
virtual ~NetworkRT();
|
||||
|
||||
@@ -185,6 +185,7 @@ class SegmentationNN {
|
||||
checkCuda(cudaMemcpyAsync(stddev_d, stddev.data(), stddev.size() * sizeof(float), cudaMemcpyHostToDevice, netRT->stream));
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,13 +19,12 @@ private:
|
||||
tk::dnn::Yolo* getYoloLayer(int n=0);
|
||||
|
||||
cv::Mat bgr_h;
|
||||
std::vector<int> noYolos;
|
||||
|
||||
public:
|
||||
Yolo3Detection() {};
|
||||
~Yolo3Detection() {};
|
||||
|
||||
bool init(const std::string& tensor_path,const std::string& cfg_path,const std::string& name_path,const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3);
|
||||
bool init(const std::string& tensor_path, const int n_classes=80, const int n_batches=1, const float conf_thresh=0.3);
|
||||
void preprocess(cv::Mat &frame, const int bi=0);
|
||||
void postprocess(const int bi=0,const bool mAP=false);
|
||||
};
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <NvInfer.h>
|
||||
#include <vector>
|
||||
#include <tkdnn.h>
|
||||
using namespace tk::dnn;
|
||||
|
||||
|
||||
namespace nvinfer1 {
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <vector>
|
||||
#include "../kernels.h"
|
||||
#include <NvInfer.h>
|
||||
#include <tkdnn.h>
|
||||
|
||||
#define YOLORT_CLASSNAME_W 256
|
||||
|
||||
@@ -80,8 +79,10 @@ namespace nvinfer1 {
|
||||
float nms_thresh;
|
||||
int nms_kind;
|
||||
int new_coords;
|
||||
int NUM = 0;
|
||||
|
||||
std::vector<std::string> classesNames;
|
||||
std::vector<dnnType> mask;
|
||||
std::vector<dnnType> bias;
|
||||
|
||||
|
||||
int entry_index(int batch, int location, int entry) {
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
#include "Layer.h"
|
||||
#include "NetworkRT.h"
|
||||
|
||||
#define TKDNN_VERSION 500
|
||||
#define TKDNN_VERSION 700
|
||||
|
||||
@@ -23,13 +23,16 @@
|
||||
#include <ios>
|
||||
#include <chrono>
|
||||
|
||||
#include <yaml-cpp/yaml.h>
|
||||
|
||||
|
||||
|
||||
#if NV_TENSORRT_MAJOR > 7
|
||||
#define NOEXCEPT noexcept
|
||||
#else
|
||||
#define NOEXCEPT
|
||||
#ifndef NOEXCEPT
|
||||
#if NV_TENSORRT_MAJOR > 7
|
||||
#define NOEXCEPT noexcept
|
||||
#else
|
||||
#define NOEXCEPT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@@ -176,5 +179,4 @@ inline T YAMLgetConf(YAML::Node conf, std::string key, T defaultVal) {
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
#endif //UTILS_H
|
||||
|
||||
+43
-39
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
|
||||
cd build
|
||||
#cd build
|
||||
|
||||
RED='\033[1;31m'
|
||||
GREEN='\033[1;32m'
|
||||
@@ -29,24 +29,28 @@ function print_output {
|
||||
|
||||
}
|
||||
|
||||
out_dir=results
|
||||
out_file=results.log
|
||||
rm $out_file
|
||||
rm -rf $out_dir/
|
||||
mkdir -p $out_dir
|
||||
|
||||
function test_net {
|
||||
./test_$1 &>> $out_file
|
||||
./test_$1 &> $out_dir/$1_${TKDNN_MODE}_build_$out_file
|
||||
print_output $? $1
|
||||
./test_rtinference $1*.rt $TKDNN_BATCHSIZE &>> $out_file
|
||||
./test_rtinference $1*.rt 1 &> $out_dir/$1_${TKDNN_MODE}_inference_batch1_$out_file
|
||||
print_output $? "infer $1"
|
||||
./test_rtinference $1*.rt $TKDNN_BATCHSIZE &> $out_dir/$1_${TKDNN_MODE}_inference_batch${TKDNN_BATCHSIZE}_$out_file
|
||||
print_output $? "batched $1"
|
||||
}
|
||||
|
||||
|
||||
modes=( 1 ) # only FP32
|
||||
# modes=( 1 2 ) # FP32 and FP16
|
||||
# modes=( 1 ) # only FP32
|
||||
modes=( 1 2 ) # FP32 and FP16
|
||||
# modes=( 1 2 3 ) # FP32, FP16 and INT8
|
||||
|
||||
for i in "${modes[@]}"
|
||||
do
|
||||
rm *rt
|
||||
rm -f *rt
|
||||
if [ $i -eq 1 ]
|
||||
then
|
||||
export TKDNN_MODE=FP32
|
||||
@@ -73,37 +77,37 @@ do
|
||||
# print_output $? imuodom
|
||||
|
||||
test_net yolo4
|
||||
test_net yolo4_320
|
||||
test_net yolo4_320_coco2
|
||||
test_net yolo4_512
|
||||
test_net yolo4_608
|
||||
test_net yolo4-csp
|
||||
test_net yolo4x
|
||||
test_net yolo4_berkeley
|
||||
test_net yolo4_berkeley_f1
|
||||
test_net yolo4tiny
|
||||
test_net yolo4tiny_512
|
||||
test_net yolo3
|
||||
test_net yolo3_berkeley
|
||||
test_net yolo3_coco4
|
||||
test_net yolo3_flir
|
||||
test_net yolo3_512
|
||||
test_net yolo3tiny
|
||||
test_net yolo3tiny_512
|
||||
test_net yolo2
|
||||
test_net yolo2_voc
|
||||
#test_net yolo2tiny
|
||||
test_net csresnext50-panet-spp
|
||||
#test_net csresnext50-panet-spp_berkeley
|
||||
test_net resnet101_cnet
|
||||
test_net dla34_cnet
|
||||
test_net dla34_cnet3d
|
||||
test_net mobilenetv2ssd
|
||||
test_net mobilenetv2ssd512
|
||||
test_net bdd-mobilenetv2ssd
|
||||
test_net dla34_ctrack
|
||||
test_net shelfnet
|
||||
test_net shelfnet_berkeley
|
||||
# test_net yolo4_320
|
||||
# test_net yolo4_320_coco2
|
||||
# test_net yolo4_512
|
||||
# test_net yolo4_608
|
||||
# test_net yolo4-csp
|
||||
# test_net yolo4x
|
||||
# test_net yolo4_berkeley
|
||||
# test_net yolo4_berkeley_f1
|
||||
# test_net yolo4tiny
|
||||
# test_net yolo4tiny_512
|
||||
# test_net yolo3
|
||||
# test_net yolo3_berkeley
|
||||
# test_net yolo3_coco4
|
||||
# test_net yolo3_flir
|
||||
# test_net yolo3_512
|
||||
# test_net yolo3tiny
|
||||
# test_net yolo3tiny_512
|
||||
# test_net yolo2
|
||||
# test_net yolo2_voc
|
||||
# test_net yolo2tiny
|
||||
# test_net csresnext50-panet-spp
|
||||
# test_net csresnext50-panet-spp_berkeley
|
||||
# test_net resnet101_cnet
|
||||
# test_net dla34_cnet
|
||||
# test_net dla34_cnet3d
|
||||
# test_net mobilenetv2ssd
|
||||
# test_net mobilenetv2ssd512
|
||||
# test_net bdd-mobilenetv2ssd
|
||||
# test_net dla34_ctrack
|
||||
# test_net shelfnet
|
||||
# test_net shelfnet_berkeley
|
||||
done
|
||||
|
||||
echo "If errors occured, check logfile $out_file"
|
||||
echo "If errors occured, check logfiles in directory: $out_dir"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
bool CenternetDetection::init(const std::string& tensor_path, const std::string& cfg_path,const std::string& name_path,const int n_classes, const int n_batches, const float conf_thresh){
|
||||
bool CenternetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh){
|
||||
std::cout<<(tensor_path).c_str()<<"\n";
|
||||
netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str() );
|
||||
classes = n_classes;
|
||||
@@ -120,6 +120,7 @@ bool CenternetDetection::init(const std::string& tensor_path, const std::string&
|
||||
dst2.at<float>(2,1)=dst2.at<float>(1,1) + (dst2.at<float>(0,0)-dst2.at<float>(1,0) );
|
||||
return true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ float MobilenetDetection::iou(const tk::dnn::box &a, const tk::dnn::box &b){
|
||||
return iou;
|
||||
}
|
||||
|
||||
bool MobilenetDetection::init(const std::string& tensor_path, const std::string& cfg_path,const std::string& name_path,const int n_classes, const int n_batches, const float conf_thresh){
|
||||
bool MobilenetDetection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh){
|
||||
std::cout<<(tensor_path).c_str()<<"\n";
|
||||
netRT = new tk::dnn::NetworkRT(NULL, (tensor_path).c_str());
|
||||
imageSize = netRT->input_dim.h;
|
||||
@@ -198,7 +198,7 @@ bool MobilenetDetection::init(const std::string& tensor_path, const std::string&
|
||||
"bottle" , "wine glass" , "cup" , "fork" , "knife" , "spoon" , "bowl" , "banana" ,
|
||||
"apple" , "sandwich" , "orange" , "broccoli" , "carrot" , "hot dog" , "pizza" ,
|
||||
"donut" , "cake" , "chair" , "sofa" , "pottedplant" , "bed" , "diningtable" ,
|
||||
"toilet" , "tvmonitor" , "laptop" , "mouse" , "remote" , "keyboard" ,
|
||||
"toilet" , "tvmonitor" , "laptop" , "mouse" , "remote" , "keyboard" ,
|
||||
"cell phone" , "microwave" , "oven" , "toaster" , "sink" , "refrigerator" ,
|
||||
"book" , "clock" , "vase" , "scissors" , "teddy bear" , "hair drier" , "toothbrush"};
|
||||
classesNames = std::vector<std::string>(classes_names_, std::end(classes_names_));
|
||||
@@ -207,7 +207,7 @@ bool MobilenetDetection::init(const std::string& tensor_path, const std::string&
|
||||
else{
|
||||
FatalError("Number of classes not supported for mobilenet");
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void MobilenetDetection::preprocess(cv::Mat &frame, const int bi){
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
|
||||
using namespace nvinfer1;
|
||||
|
||||
extern std::mutex gYoloPlugins_mutex;
|
||||
extern std::vector<YoloRT*> gYoloPlugins;
|
||||
|
||||
// Logger for info/warning/errors
|
||||
class Logger : public ILogger {
|
||||
void log(Severity severity, const char* msg) NOEXCEPT override {
|
||||
@@ -826,6 +829,12 @@ IPluginV2Layer* NetworkRT::convert_layer(ITensor *input, Yolo *l) {
|
||||
mPluginAttributes.emplace_back(PluginField("nms_thresh",&l->nms_thresh,PluginFieldType::kFLOAT32,1));
|
||||
mPluginAttributes.emplace_back(PluginField("nms_kins",&l->nsm_kind,PluginFieldType::kINT32,1));
|
||||
mPluginAttributes.emplace_back(PluginField("new_coords",&l->new_coords,PluginFieldType::kINT32,1));
|
||||
mPluginAttributes.emplace_back(PluginField("mask",l->mask_h,PluginFieldType::kFLOAT32,l->n_masks));
|
||||
mPluginAttributes.emplace_back(PluginField("bias",l->bias_h,PluginFieldType::kFLOAT32,l->n_masks*2*l->num));
|
||||
for(int i=0; i<l->classes; i++) {
|
||||
mPluginAttributes.emplace_back(PluginField("class_name",l->classesNames[i].data(),PluginFieldType::kCHAR,l->classesNames[i].size()));
|
||||
}
|
||||
|
||||
mFC.nbFields = mPluginAttributes.size();
|
||||
mFC.fields = mPluginAttributes.data();
|
||||
auto *plugin = creator->createPlugin(l->getLayerName().c_str(),&mFC);
|
||||
@@ -1001,7 +1010,14 @@ bool NetworkRT::deserialize(const char *filename) {
|
||||
}
|
||||
|
||||
runtimeRT = createInferRuntime(loggerRT);
|
||||
|
||||
gYoloPlugins_mutex.lock();
|
||||
gYoloPlugins.clear();
|
||||
engineRT = runtimeRT->deserializeCudaEngine(gieModelStream, size);
|
||||
yolo_plugins = gYoloPlugins;
|
||||
gYoloPlugins.clear();
|
||||
gYoloPlugins_mutex.unlock();
|
||||
|
||||
std::cout<<size<<std::endl;
|
||||
//if (gieModelStream) delete [] gieModelStream;
|
||||
|
||||
|
||||
+3
-2
@@ -278,6 +278,7 @@ void Yolo::mergeDetections(Yolo::detection *dets, int ndets, int classes, double
|
||||
}
|
||||
total = k+1;
|
||||
|
||||
float thresh = 0.45f;
|
||||
for(k = 0; k < classes; ++k){
|
||||
for(i = 0; i < total; ++i){
|
||||
dets[i].sort_class = k;
|
||||
@@ -288,9 +289,9 @@ void Yolo::mergeDetections(Yolo::detection *dets, int ndets, int classes, double
|
||||
box a = dets[i].bbox;
|
||||
for(j = i+1; j < total; ++j){
|
||||
box b = dets[j].bbox;
|
||||
if (nsm_kind == GREEDY_NMS && yolo_box_iou(a, b) > nms_thresh)
|
||||
if (nsm_kind == GREEDY_NMS && yolo_box_iou(a, b) > thresh)
|
||||
dets[j].prob[k] = 0;
|
||||
else if (nsm_kind == DIOU_NMS && yolo_box_diou(a, b, nms_thresh) > nms_thresh)
|
||||
else if (nsm_kind == DIOU_NMS && yolo_box_diou(a, b, nms_thresh) > thresh)
|
||||
dets[j].prob[k] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
+17
-33
@@ -3,7 +3,7 @@
|
||||
|
||||
namespace tk { namespace dnn {
|
||||
|
||||
bool Yolo3Detection::init(const std::string& tensor_path,const std::string& cfg_path,const std::string& name_path,const int n_classes, const int n_batches, const float conf_thresh) {
|
||||
bool Yolo3Detection::init(const std::string& tensor_path, const int n_classes, const int n_batches, const float conf_thresh) {
|
||||
|
||||
//convert network to tensorRT
|
||||
std::cout<<(tensor_path).c_str()<<"\n";
|
||||
@@ -14,43 +14,27 @@ namespace tk { namespace dnn {
|
||||
tk::dnn::dataDim_t idim = netRT->input_dim;
|
||||
idim.n = nBatches;
|
||||
|
||||
std::vector<int> yolosLine = noYolosLine(cfg_path);
|
||||
noYolos = yolosLine;
|
||||
int channels,height,width;
|
||||
loadYoloInitInfo(channels,width,height,cfg_path);
|
||||
|
||||
|
||||
|
||||
if(yolosLine.size() < 2 ) {
|
||||
if(netRT->yolo_plugins.size() < 2 ) {
|
||||
FatalError("this is not yolo3");
|
||||
}
|
||||
|
||||
for(int i=0; i<netRT->yolo_plugins.size(); i++) {
|
||||
nvinfer1::YoloRT *yRT = netRT->yolo_plugins[i];
|
||||
classes = yRT->classes;
|
||||
num = yRT->num;
|
||||
nMasks = yRT->n_masks;
|
||||
|
||||
for(int i=0; i<noYolos.size(); i++) {
|
||||
std::vector<float> maskTemp,anchorsTemp;
|
||||
std::vector<std::string> classNamesTemp;
|
||||
int nms_kind,coords,numTemp;
|
||||
float nmsthresh;
|
||||
loadYoloInfo(cfg_path,yolosLine[i],maskTemp,anchorsTemp,numTemp,classes,nmsthresh,nms_kind,coords);
|
||||
classNamesTemp = darknetReadNames(name_path);
|
||||
num = numTemp/maskTemp.size();
|
||||
nMasks = maskTemp.size();
|
||||
dnnType* maskTempF;
|
||||
dnnType* biasTempF;
|
||||
maskTempF = maskTemp.data();
|
||||
biasTempF = anchorsTemp.data();
|
||||
// make a yolo layer to interpret predictions
|
||||
yolo[i] = new tk::dnn::Yolo(nullptr, classes, nMasks, ""); // yolo without input and bias
|
||||
yolo[i]->mask_h = new dnnType[nMasks];
|
||||
yolo[i]->bias_h = new dnnType[num*nMasks*2];
|
||||
memcpy(yolo[i]->mask_h, maskTempF, sizeof(dnnType)*nMasks);
|
||||
memcpy(yolo[i]->bias_h, biasTempF, sizeof(dnnType)*num*nMasks*2);
|
||||
auto dim = netRT->engineRT->getBindingDimensions(i+1);
|
||||
yolo[i]->input_dim = yolo[i]->output_dim = tk::dnn::dataDim_t(1, dim.d[0], dim.d[1], dim.d[2]);
|
||||
yolo[i]->classesNames = classNamesTemp;
|
||||
yolo[i]->nms_thresh = nmsthresh;
|
||||
yolo[i]->nsm_kind = (tk::dnn::Yolo::nmsKind_t) nms_kind;
|
||||
yolo[i]->new_coords = coords;
|
||||
memcpy(yolo[i]->mask_h, yRT->mask.data(), sizeof(dnnType)*nMasks);
|
||||
memcpy(yolo[i]->bias_h, yRT->bias.data(), sizeof(dnnType)*num*nMasks*2);
|
||||
yolo[i]->input_dim = yolo[i]->output_dim = tk::dnn::dataDim_t(1, yRT->c, yRT->h, yRT->w);
|
||||
yolo[i]->classesNames = yRT->classesNames;
|
||||
yolo[i]->nms_thresh = yRT->nms_thresh;
|
||||
yolo[i]->nsm_kind = (tk::dnn::Yolo::nmsKind_t) yRT->nms_kind;
|
||||
yolo[i]->new_coords = yRT->new_coords;
|
||||
}
|
||||
|
||||
dets = tk::dnn::Yolo::allocateDetections(tk::dnn::Yolo::MAX_DETECTIONS, classes);
|
||||
@@ -112,12 +96,12 @@ void Yolo3Detection::postprocess(const int bi, const bool mAP){
|
||||
|
||||
|
||||
//get yolo outputs
|
||||
if(noYolos.size() < 2){
|
||||
if(netRT->yolo_plugins.size() < 2){
|
||||
FatalError("YOLOS WRONG!!");
|
||||
}
|
||||
std::vector<float *> rt_out;
|
||||
//dnnType *rt_out[netRT->pluginFactory->n_yolos];
|
||||
for(int i=0; i<noYolos.size(); i++)
|
||||
for(int i=0; i<netRT->yolo_plugins.size(); i++)
|
||||
rt_out.push_back((dnnType*)netRT->buffersRT[i+1] + netRT->buffersDIM[i+1].tot()*bi);
|
||||
|
||||
float x_ratio = float(originalSize[bi].width) / float(netRT->input_dim.w);
|
||||
@@ -125,7 +109,7 @@ void Yolo3Detection::postprocess(const int bi, const bool mAP){
|
||||
|
||||
// compute dets
|
||||
nDets = 0;
|
||||
for(int i=0; i<noYolos.size(); i++) {
|
||||
for(int i=0; i<netRT->yolo_plugins.size(); i++) {
|
||||
yolo[i]->dstData = rt_out[i];
|
||||
yolo[i]->computeDetections(dets, nDets, netRT->input_dim.w, netRT->input_dim.h, confThreshold, yolo[i]->new_coords);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
#include <tkDNN/pluginsRT/YoloRT.h>
|
||||
|
||||
#include <utility>
|
||||
#include <mutex>
|
||||
using namespace nvinfer1;
|
||||
|
||||
// used to retrive Yolo plugin during network deserialization
|
||||
std::mutex gYoloPlugins_mutex;
|
||||
std::vector<YoloRT*> gYoloPlugins;
|
||||
|
||||
std::vector<PluginField> YoloRTPluginCreator::mPluginAttributes;
|
||||
PluginFieldCollection YoloRTPluginCreator::mFC{};
|
||||
|
||||
@@ -22,6 +27,10 @@ YoloRT::YoloRT(int classes, int num, int c,int h,int w,int n_masks, float scale_
|
||||
this->nms_thresh = nms_thresh;
|
||||
this->nms_kind = nms_kind;
|
||||
this->new_coords = new_coords;
|
||||
|
||||
bias.clear();
|
||||
mask.clear();
|
||||
classesNames.clear();
|
||||
}
|
||||
|
||||
YoloRT::YoloRT(const void *data, size_t length) {
|
||||
@@ -36,7 +45,24 @@ YoloRT::YoloRT(const void *data, size_t length) {
|
||||
c = readBUF<int>(buf);
|
||||
h = readBUF<int>(buf);
|
||||
w = readBUF<int>(buf);
|
||||
|
||||
mask.resize(n_masks);
|
||||
for(int i=0; i<n_masks; i++)
|
||||
mask[i] = readBUF<dnnType>(buf);
|
||||
bias.resize(n_masks*2*num);
|
||||
for(int i=0; i<n_masks*2*num; i++)
|
||||
bias[i] = readBUF<dnnType>(buf);
|
||||
|
||||
// save classes names
|
||||
classesNames.resize(classes);
|
||||
for(int i=0; i<classes; i++) {
|
||||
char tmp[YOLORT_CLASSNAME_W];
|
||||
for(int j=0; j<YOLORT_CLASSNAME_W; j++)
|
||||
tmp[j] = readBUF<char>(buf);
|
||||
classesNames[i] = std::string(tmp);
|
||||
}
|
||||
assert(buf == bufCheck + length);
|
||||
gYoloPlugins.push_back(this);
|
||||
}
|
||||
|
||||
YoloRT::~YoloRT() {}
|
||||
@@ -126,7 +152,7 @@ int32_t YoloRT::enqueue(int32_t batchSize, const void *const *inputs, void **out
|
||||
|
||||
|
||||
size_t YoloRT::getSerializationSize() const NOEXCEPT {
|
||||
return 8 * sizeof(int) + 2 * sizeof(float) ;
|
||||
return 8 * sizeof(int) + 2 * sizeof(float) + n_masks*sizeof(dnnType) + num*n_masks*2*sizeof(dnnType) + YOLORT_CLASSNAME_W*classes*sizeof(char);
|
||||
}
|
||||
|
||||
bool YoloRT::supportsFormat(DataType type, PluginFormat format) const NOEXCEPT {
|
||||
@@ -145,6 +171,19 @@ void YoloRT::serialize(void *buffer) const NOEXCEPT {
|
||||
writeBUF(buf, c); //std::cout << "C : " << c << std::endl;
|
||||
writeBUF(buf, h); //std::cout << "H : " << h << std::endl;
|
||||
writeBUF(buf, w); //std::cout << "C : " << c << std::endl;
|
||||
for (int i = 0; i < n_masks; i++)
|
||||
writeBUF(buf, mask[i]); //std::cout << "mask[i] : " << mask[i] << std::endl;
|
||||
for (int i = 0; i < n_masks * 2 * num; i++)
|
||||
writeBUF(buf, bias[i]); //std::cout << "bias[i] : " << bias[i] << std::endl;
|
||||
|
||||
// save classes names
|
||||
for(int i=0; i<classes; i++) {
|
||||
char tmp[YOLORT_CLASSNAME_W];
|
||||
strcpy(tmp, classesNames[i].c_str());
|
||||
for(int j=0; j<YOLORT_CLASSNAME_W; j++) {
|
||||
writeBUF(buf, tmp[j]);
|
||||
}
|
||||
}
|
||||
|
||||
assert(buf == a + getSerializationSize());
|
||||
}
|
||||
@@ -171,6 +210,9 @@ void YoloRT::setPluginNamespace(const char *pluginNamespace) NOEXCEPT {
|
||||
|
||||
IPluginV2Ext *YoloRT::clone() const NOEXCEPT {
|
||||
auto *p = new YoloRT(classes, num,c,h,w,n_masks, scaleXY, nms_thresh, nms_kind, new_coords);
|
||||
p->mask = mask;
|
||||
p->bias = bias;
|
||||
p->classesNames = classesNames;
|
||||
p->setPluginNamespace(mPluginNamespace.c_str());
|
||||
return p;
|
||||
}
|
||||
@@ -235,6 +277,17 @@ IPluginV2Ext *YoloRTPluginCreator::createPlugin(const char *name, const PluginFi
|
||||
int nms_kind = *(static_cast<const int*>(fields[8].data));
|
||||
int new_coords = *(static_cast<const int*>(fields[9].data));
|
||||
auto *pluginObj = new YoloRT(classes,num,c,h,w,n_masks,scaleXY,nmsThresh,nms_kind,new_coords);
|
||||
|
||||
// fill additional data
|
||||
pluginObj->mask.resize(fields[10].length*sizeof(float));
|
||||
memcpy(pluginObj->mask.data(), fields[10].data, fields[10].length*sizeof(float));
|
||||
pluginObj->bias.resize(fields[11].length*sizeof(float));
|
||||
memcpy(pluginObj->bias.data(), fields[11].data, fields[11].length*sizeof(float));
|
||||
pluginObj->classesNames.resize(classes);
|
||||
for(int i=0; i<classes; i++) {
|
||||
pluginObj->classesNames[i].resize(fields[12+i].length);
|
||||
memcpy(&pluginObj->classesNames[i][0], fields[12+i].data, fields[12+i].length*sizeof(char));
|
||||
}
|
||||
return pluginObj;
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
||||
person
|
||||
head
|
||||
@@ -0,0 +1,34 @@
|
||||
#include<iostream>
|
||||
#include<vector>
|
||||
#include "tkdnn.h"
|
||||
#include "test.h"
|
||||
#include "DarknetParser.h"
|
||||
|
||||
int main() {
|
||||
std::string bin_path = "yolo4-csp_crowd";
|
||||
std::vector<std::string> input_bins = {
|
||||
bin_path + "/layers/input.bin"
|
||||
};
|
||||
std::vector<std::string> output_bins = {
|
||||
bin_path + "/debug/layer144_out.bin",
|
||||
bin_path + "/debug/layer159_out.bin",
|
||||
bin_path + "/debug/layer174_out.bin"
|
||||
};
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4-csp_crowd.cfg";
|
||||
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/crowdhuman.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/RKWfWNmWXfJigsK/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
net->print();
|
||||
|
||||
//convert network to tensorRT
|
||||
tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str()));
|
||||
|
||||
int ret = testInference(input_bins, output_bins, net, netRT);
|
||||
net->releaseLayers();
|
||||
delete net;
|
||||
delete netRT;
|
||||
return ret;
|
||||
}
|
||||
@@ -17,7 +17,7 @@ int main() {
|
||||
std::string wgs_path = bin_path + "/layers";
|
||||
std::string cfg_path = std::string(TKDNN_PATH) + "/tests/darknet/cfg/yolo4_berkeley.cfg";
|
||||
std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/berkeley.names";
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/M7WJdGoGDaDACnN/download");
|
||||
downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/q9dwoqQ5YQqEi7s/download");
|
||||
|
||||
// parse darknet network
|
||||
tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path);
|
||||
|
||||
@@ -0,0 +1,295 @@
|
||||
#include <iostream>
|
||||
#include <opencv2/highgui/highgui.hpp>
|
||||
#include <opencv2/imgproc/imgproc.hpp>
|
||||
|
||||
#include "tkdnn.h"
|
||||
#include "NetworkViz.h"
|
||||
|
||||
|
||||
const char *input_bin = "shelfnet_coco/debug/input.bin";
|
||||
|
||||
const char *backbone[] = {
|
||||
"shelfnet_coco/layers/backbone-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer1-0-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer1-0-conv2.bin",
|
||||
"shelfnet_coco/layers/backbone-layer1-1-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer1-1-conv2.bin",
|
||||
"shelfnet_coco/layers/backbone-layer2-0-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer2-0-conv2.bin",
|
||||
"shelfnet_coco/layers/backbone-layer2-0-downsample-0.bin",
|
||||
"shelfnet_coco/layers/backbone-layer2-1-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer2-1-conv2.bin",
|
||||
"shelfnet_coco/layers/backbone-layer3-0-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer3-0-conv2.bin",
|
||||
"shelfnet_coco/layers/backbone-layer3-0-downsample-0.bin",
|
||||
"shelfnet_coco/layers/backbone-layer3-1-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer3-1-conv2.bin",
|
||||
"shelfnet_coco/layers/backbone-layer4-0-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer4-0-conv2.bin",
|
||||
"shelfnet_coco/layers/backbone-layer4-0-downsample-0.bin",
|
||||
"shelfnet_coco/layers/backbone-layer4-1-conv1.bin",
|
||||
"shelfnet_coco/layers/backbone-layer4-1-conv2.bin"};
|
||||
|
||||
const char *conv_out[] = {
|
||||
"shelfnet_coco/layers/conv_out-conv-conv.bin",
|
||||
"shelfnet_coco/layers/conv_out-conv_out.bin",
|
||||
"shelfnet_coco/layers/conv_out16-conv-conv.bin",
|
||||
"shelfnet_coco/layers/conv_out16-conv_out.bin",
|
||||
"shelfnet_coco/layers/conv_out32-conv-conv.bin",
|
||||
"shelfnet_coco/layers/conv_out32-conv_out.bin"
|
||||
};
|
||||
|
||||
const char *decoder[] = {
|
||||
"shelfnet_coco/layers/decoder-bottom-conv1.bin",
|
||||
"shelfnet_coco/layers/decoder-bottom-conv12.bin",
|
||||
"shelfnet_coco/layers/decoder-up_conv_list-0-conv-conv.bin",
|
||||
"shelfnet_coco/layers/decoder-up_conv_list-0-conv_atten.bin",
|
||||
"shelfnet_coco/layers/decoder-up_dense_list-0-conv.bin",
|
||||
"shelfnet_coco/layers/decoder-up_conv_list-1-conv-conv.bin",
|
||||
"shelfnet_coco/layers/decoder-up_conv_list-1-conv_atten.bin",
|
||||
"shelfnet_coco/layers/decoder-up_dense_list-1-conv.bin"
|
||||
};
|
||||
|
||||
|
||||
const char *ladder[] = {
|
||||
"shelfnet_coco/layers/ladder-inconv-conv1.bin",
|
||||
"shelfnet_coco/layers/ladder-inconv-conv12.bin",
|
||||
"shelfnet_coco/layers/ladder-down_module_list-0-conv1.bin",
|
||||
"shelfnet_coco/layers/ladder-down_module_list-0-conv12.bin",
|
||||
"shelfnet_coco/layers/ladder-down_conv_list-0.bin",
|
||||
|
||||
"shelfnet_coco/layers/ladder-down_module_list-1-conv1.bin",
|
||||
"shelfnet_coco/layers/ladder-down_module_list-1-conv12.bin",
|
||||
"shelfnet_coco/layers/ladder-down_conv_list-1.bin",
|
||||
|
||||
"shelfnet_coco/layers/ladder-bottom-conv1.bin",
|
||||
"shelfnet_coco/layers/ladder-bottom-conv12.bin",
|
||||
|
||||
|
||||
|
||||
"shelfnet_coco/layers/ladder-up_conv_list-0-conv-conv.bin",
|
||||
"shelfnet_coco/layers/ladder-up_conv_list-0-conv_atten.bin",
|
||||
"shelfnet_coco/layers/ladder-up_dense_list-0-conv.bin",
|
||||
|
||||
|
||||
"shelfnet_coco/layers/ladder-up_conv_list-1-conv-conv.bin",
|
||||
"shelfnet_coco/layers/ladder-up_conv_list-1-conv_atten.bin",
|
||||
"shelfnet_coco/layers/ladder-up_dense_list-1-conv.bin"};
|
||||
|
||||
const char *trans[] = {
|
||||
"shelfnet_coco/layers/trans1-conv.bin",
|
||||
"shelfnet_coco/layers/trans2-conv.bin",
|
||||
"shelfnet_coco/layers/trans3-conv.bin"};
|
||||
int main()
|
||||
{
|
||||
|
||||
downloadWeightsifDoNotExist(input_bin, "shelfnet_coco", "https://cloud.hipert.unimore.it/s/KfQ9fGJQsgzNbiW/download");
|
||||
|
||||
int classes = 183;
|
||||
|
||||
// Network layout
|
||||
tk::dnn::dataDim_t dim(1, 3, 1024, 1024, 1);
|
||||
tk::dnn::Network net(dim);
|
||||
|
||||
int bi = 0, di = 0, li = 0, ci = 0;
|
||||
new tk::dnn::Conv2d(&net, 64, 7, 7, 2, 2, 3, 3, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
tk::dnn::Layer* last = new tk::dnn::Pooling (&net, 3, 3, 2, 2, 1, 1, tk::dnn::POOLING_MAX);
|
||||
|
||||
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
}
|
||||
|
||||
std::vector<tk::dnn::Layer*> features;
|
||||
for(int i=0;i<3;++i){
|
||||
int out_channel = pow(2,7+i);
|
||||
std::cout<<out_channel<<std::endl;
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 2, 2, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
tk::dnn::Layer* bn2 = new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 2, 2, 0, 0, backbone[bi++], true);
|
||||
new tk::dnn::Shortcut(&net, bn2);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, backbone[bi++], true);
|
||||
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
features.push_back(last);
|
||||
}
|
||||
|
||||
for(int i=0; i<features.size(); ++i){
|
||||
new tk::dnn::Route(&net, &features[i], 1);
|
||||
int out_channel = pow(2,6+i);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, trans[i], true);
|
||||
features[i] = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
}
|
||||
|
||||
//DECODER
|
||||
|
||||
last = features[2];
|
||||
std::vector<tk::dnn::Layer*> up_out;
|
||||
//bottom
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, decoder[di++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, decoder[di++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
up_out.push_back(last);
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
int out_channel = pow(2,7-i);
|
||||
//up-conv
|
||||
std::cout<<out_channel<<std::endl;
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, decoder[di++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
|
||||
new tk::dnn::Pooling(&net, last->output_dim.w, last->output_dim.h, last->output_dim.w, last->output_dim.h, 0, 0, tk::dnn::POOLING_AVERAGE);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, decoder[di++], true);
|
||||
|
||||
tk::dnn::Layer* act = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_SIGMOID);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Shortcut(&net, act, true);
|
||||
|
||||
//interpolate
|
||||
new tk::dnn::Resize(&net, 1,2,2);
|
||||
new tk::dnn::Shortcut(&net, features[1-i]);
|
||||
|
||||
//up-dense
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, decoder[di++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
up_out.push_back(last);
|
||||
}
|
||||
|
||||
//LADDER
|
||||
|
||||
std::vector<tk::dnn::Layer*> down_out;
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
|
||||
for(int i=0; i<2;++i){
|
||||
int out_channel = pow(2,6+i);
|
||||
tk::dnn::Layer* l_last = new tk::dnn::Shortcut(&net, up_out[2-i]);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, l_last);
|
||||
l_last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
down_out.push_back(l_last);
|
||||
|
||||
new tk::dnn::Conv2d (&net, out_channel*2, 3, 3, 2, 2, 1, 1, ladder[li++], false);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.0f); //should be ReLU
|
||||
}
|
||||
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, 256, 3, 3, 1, 1, 1, 1, ladder[li++], true, false, 1, true);
|
||||
new tk::dnn::Shortcut(&net, last);
|
||||
last = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_RELU);
|
||||
up_out.clear();
|
||||
up_out.push_back(last);
|
||||
|
||||
for(int i=0; i<2; ++i){
|
||||
int out_channel = pow(2,7-i);
|
||||
//up-conv
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
|
||||
new tk::dnn::Pooling(&net, last->output_dim.w, last->output_dim.h, last->output_dim.w, last->output_dim.h, 0, 0, tk::dnn::POOLING_AVERAGE);
|
||||
new tk::dnn::Conv2d (&net, out_channel, 1, 1, 1, 1, 0, 0, ladder[li++], true);
|
||||
|
||||
tk::dnn::Layer* act = new tk::dnn::Activation (&net, CUDNN_ACTIVATION_SIGMOID);
|
||||
new tk::dnn::Route(&net, &last, 1);
|
||||
new tk::dnn::Shortcut(&net, act, true);
|
||||
|
||||
//interpolate
|
||||
new tk::dnn::Resize(&net, 1,2,2);
|
||||
new tk::dnn::Shortcut(&net, down_out[1-i]);
|
||||
|
||||
// //up-dense
|
||||
new tk::dnn::Conv2d (&net, out_channel, 3, 3, 1, 1, 1, 1, ladder[li++], true);
|
||||
last = new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
up_out.push_back(last);
|
||||
}
|
||||
|
||||
|
||||
// for(int i=2;i>=0;--i){
|
||||
// new tk::dnn::Route(&net, &up_out[i], 1);
|
||||
new tk::dnn::Conv2d (&net, 64, 3, 3, 1, 1, 1, 1, conv_out[ci++], true);
|
||||
new tk::dnn::Activation (&net, tk::dnn::ACTIVATION_LEAKY, 0.0f, 0.01);
|
||||
new tk::dnn::Conv2d (&net, classes, 3, 3, 1, 1, 1, 1, conv_out[ci++], false);
|
||||
/*up_out[i] =*/ new tk::dnn::Resize(&net, classes, net.input_dim.h, net.input_dim.w, true, tk::dnn::ResizeMode_t::LINEAR);
|
||||
// // }
|
||||
|
||||
new tk::dnn::Softmax(&net);
|
||||
|
||||
const char *output_bin = "shelfnet_coco/debug/softmax.bin";
|
||||
|
||||
// Load input
|
||||
dnnType *data;
|
||||
dnnType *input_h;
|
||||
readBinaryFile(input_bin, dim.tot(), &input_h, &data);
|
||||
std::cout<<"Input:"<<std::endl;
|
||||
|
||||
//print network model
|
||||
net.print();
|
||||
|
||||
// // convert network to tensorRT
|
||||
tk::dnn::NetworkRT netRT(&net, net.getNetworkRTName("shelfnet_coco"));
|
||||
|
||||
tk::dnn::dataDim_t dim1 = dim; //input dim
|
||||
dnnType *cudnn_out = nullptr;
|
||||
printCenteredTitle(" CUDNN inference ", '=', 30);
|
||||
{
|
||||
dim1.print();
|
||||
TKDNN_TSTART
|
||||
cudnn_out = net.infer(dim1, data);
|
||||
TKDNN_TSTOP
|
||||
dim1.print();
|
||||
}
|
||||
|
||||
tk::dnn::dataDim_t dim2 = dim;
|
||||
printCenteredTitle(" TENSORRT inference ", '=', 30);
|
||||
{
|
||||
dim2.print();
|
||||
TKDNN_TSTART
|
||||
netRT.infer(dim2, data);
|
||||
TKDNN_TSTOP
|
||||
dim2.print();
|
||||
}
|
||||
|
||||
dnnType *rt_out1 = (dnnType *)netRT.buffersRT[1];
|
||||
|
||||
printCenteredTitle(std::string(" CHECK RESULTS ").c_str(), '=', 30);
|
||||
dnnType *out1, *out1_h;
|
||||
int odim1 = dim1.tot();
|
||||
readBinaryFile(output_bin, odim1, &out1_h, &out1);
|
||||
|
||||
int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0;
|
||||
// std::cout << "CUDNN vs correct" << std::endl;
|
||||
// ret_cudnn |= checkResult(odim1, cudnn_out, out1, true, 20) == 0 ? 0 : ERROR_CUDNN;
|
||||
|
||||
std::cout << "TRT vs correct" << std::endl;
|
||||
ret_tensorrt |=checkResult(odim1, rt_out1, out1) == 0 ? 0 : ERROR_TENSORRT;
|
||||
|
||||
std::cout << "CUDNN vs TRT " << std::endl;
|
||||
ret_cudnn_tensorrt |= checkResult(odim1, cudnn_out, rt_out1) == 0 ? 0 : ERROR_CUDNNvsTENSORRT;
|
||||
|
||||
cv::Mat viz = vizLayer2Mat(&net, net.num_layers-1);
|
||||
cv::imwrite("test.png", viz);
|
||||
|
||||
return ret_cudnn | ret_tensorrt | ret_cudnn_tensorrt;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include<iostream>
|
||||
#include<algorithm>
|
||||
#include "tkdnn.h"
|
||||
#include "tkDNN/tkdnn.h"
|
||||
#include <stdlib.h> /* srand, rand */
|
||||
|
||||
|
||||
@@ -66,11 +66,11 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
double min = *std::min_element(stats.begin(), stats.end())/BATCH_SIZE;
|
||||
double max = *std::max_element(stats.begin(), stats.end())/BATCH_SIZE;
|
||||
double min = *std::min_element(stats.begin(), stats.end()); ///BATCH_SIZE;
|
||||
double max = *std::max_element(stats.begin(), stats.end()); ///BATCH_SIZE;
|
||||
double mean =0;
|
||||
for(int i=0; i<stats.size(); i++) mean += stats[i]; mean /= stats.size();
|
||||
mean /=BATCH_SIZE;
|
||||
//mean /=BATCH_SIZE;
|
||||
|
||||
std::cout<<"Min: "<<min<<" ms\n";
|
||||
std::cout<<"Max: "<<max<<" ms\n";
|
||||
|
||||
Reference in New Issue
Block a user