diff --git a/CMakeLists.txt b/CMakeLists.txt index 13db7b5..c29e987 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -202,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) diff --git a/README.md b/README.md index fa00681..825c00b 100644 --- a/README.md +++ b/README.md @@ -23,12 +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 (tensort8 branch). - +- [x] Support to TensorRT8. (thanks to [Harshvardhan Chandirasekar](https://github.com/perseusdg)) #### 30 March 2022 -- [x] Support to monocular depth esitmation (tensort8 branch) [README](docs/README_depth.md) +- [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 @@ -120,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 @@ -179,11 +178,10 @@ For specific details on how to run tkDNN on Windows 10/11 see [HERE](./docs/wind | yolo4_320 | Yolov4 8 | [COCO 2017](http://cocodataset.org/) | 80 | 320x320 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) | | yolo4_512 | Yolov4 8 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) | | yolo4_608 | Yolov4 8 | [COCO 2017](http://cocodataset.org/) | 80 | 608x608 | [weights](https://cloud.hipert.unimore.it/s/d97CFzYqCPCp5Hg/download) | -| yolo4_berkeley | Yolov4 8 | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 540x320 | [weights](https://cloud.hipert.unimore.it/s/nkWFa5fgb4NTdnB/download) | +| yolo4_berkeley | Yolov4 8 | [BDD100K ](https://bair.berkeley.edu/blog/2018/05/30/bdd/) | 10 | 544x320 | [weights](https://cloud.hipert.unimore.it/s/nkWFa5fgb4NTdnB/download) | | yolo4tiny | Yolov4 tiny 9 | [COCO 2017](http://cocodataset.org/) | 80 | 416x416 | [weights](https://cloud.hipert.unimore.it/s/iRnc4pSqmx78gJs/download) | -| yolo4x | Yolov4x-mish 9 | [COCO 2017](http://cocodataset.org/) | +| yolo4x | Yolov4x-mish 9 | [COCO 2017](http://cocodataset.org/) | 80 | 640x640 | [weights](https://cloud.hipert.unimore.it/s/5MFjtNtgbDGdJEo/download) | | yolo4tiny_512 | Yolov4 tiny 9 | [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 10 | [COCO 2017](http://cocodataset.org/) | 80 | 512x512 | [weights](https://cloud.hipert.unimore.it/s/AfzHE4BfTeEm2gH/download) | | shelfnet | ShelfNet18_realtime11 | [Cityscapes](https://www.cityscapes-dataset.com/) | 19 | 1024x1024 | [weights](https://cloud.hipert.unimore.it/s/mEDZMRJaGCFWSJF/download) | | shelfnet_berkeley | ShelfNet18_realtime11 | [DeepDrive](https://bdd-data.berkeley.edu/) | 20 | 1024x1024 | [weights](https://cloud.hipert.unimore.it/s/m92e7QdD9gYMF7f/download) | diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index f46ca80..c857086 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -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,41 @@ 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(conf,"net","yolo4tiny_fp32.rt"); - if(!fileExist(net.c_str())) { + // read settings from config file + std::string net = YAMLgetConf(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(conf, "input", "../demo/yolo_test.mp4"); - std::string cfgPath = YAMLgetConf(conf,"cfg_input", "../tests/darknet/cfg/yolo4tiny.cfg"); - std::string namePath = YAMLgetConf(conf,"name_input","../tests/darknet/names/coco.names"); -#elif _WIN32 - std::string input = YAMLgetConf(conf, "win_input", "..\\..\\..\\demo\\yolo_test.mp4"); - std::string cfgPath = YAMLgetConf(conf,"cfg_win_input","..\\..\\..\\tests\\darknet\\cfg\\yolo4tiny.cfg"); - std::string namePath = YAMLgetConf(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(conf, "input", "../demo/yolo_test.mp4"); + std::string cfgPath = YAMLgetConf(conf,"cfg_input", "../tests/darknet/cfg/yolo4tiny.cfg"); + std::string namePath = YAMLgetConf(conf,"name_input","../tests/darknet/names/coco.names"); + #elif _WIN32 + std::string input = YAMLgetConf(conf, "win_input", "..\\..\\..\\demo\\yolo_test.mp4"); + std::string cfgPath = YAMLgetConf(conf,"cfg_win_input","..\\..\\..\\tests\\darknet\\cfg\\yolo4tiny.cfg"); + std::string namePath = YAMLgetConf(conf,"name_win_input","..\\..\\..\\tests\\darknet\\names\\coco.names"); + #endif + if(!fileExist(input.c_str())) + FatalError("The given input video does not exist."); char ntype = YAMLgetConf(conf, "ntype", 'y'); int n_classes = YAMLgetConf(conf, "n_classes", 80); int n_batch = YAMLgetConf(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(conf, "conf_thresh", 0.3); bool show = YAMLgetConf(conf, "show", true); bool save = YAMLgetConf(conf, "save", false); @@ -70,7 +66,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; @@ -100,8 +97,7 @@ int main(int argc, char *argv[]) { detNN->init(net,cfgPath,namePath,n_classes,n_batch,conf_thresh); - gRun = true; - + // open video stream cv::VideoCapture cap(input); if(!cap.isOpened()) gRun = false; @@ -115,13 +111,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 batch_frame; std::vector batch_dnn_input; + // start detection loop + gRun = true; while(gRun) { batch_dnn_input.clear(); batch_frame.clear(); @@ -154,14 +152,13 @@ int main(int argc, char *argv[]) { } std::cout<<"detection end\n"; + double mean = 0; - std::cout<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; istats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size(); - std::cout<<"Avg: "<stream)); return true; + return true; } /** diff --git a/include/tkDNN/utils.h b/include/tkDNN/utils.h index a1a1f1c..055ea67 100644 --- a/include/tkDNN/utils.h +++ b/include/tkDNN/utils.h @@ -23,6 +23,7 @@ #include #include +#include @@ -176,5 +177,4 @@ inline T YAMLgetConf(YAML::Node conf, std::string key, T defaultVal) { return val; } - #endif //UTILS_H diff --git a/scripts/test_all_tests.sh b/scripts/test_all_tests.sh index 0da9b6b..e44f7e8 100644 --- a/scripts/test_all_tests.sh +++ b/scripts/test_all_tests.sh @@ -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" diff --git a/src/CenternetDetection.cpp b/src/CenternetDetection.cpp index 133c682..eba8ce4 100644 --- a/src/CenternetDetection.cpp +++ b/src/CenternetDetection.cpp @@ -120,6 +120,7 @@ bool CenternetDetection::init(const std::string& tensor_path, const std::string& dst2.at(2,1)=dst2.at(1,1) + (dst2.at(0,0)-dst2.at(1,0) ); return true; + return true; } diff --git a/src/MobilenetDetection.cpp b/src/MobilenetDetection.cpp index 1d3832d..94c90c7 100644 --- a/src/MobilenetDetection.cpp +++ b/src/MobilenetDetection.cpp @@ -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(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){ diff --git a/src/Yolo.cpp b/src/Yolo.cpp index e6fb8ab..b68e1f6 100644 --- a/src/Yolo.cpp +++ b/src/Yolo.cpp @@ -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; } } diff --git a/tests/darknet/cfg/yolo4-csp_crowd.cfg b/tests/darknet/cfg/yolo4-csp_crowd.cfg new file mode 100644 index 0000000..4c50f4d --- /dev/null +++ b/tests/darknet/cfg/yolo4-csp_crowd.cfg @@ -0,0 +1,1279 @@ +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=16 +width=512 +height=512 +channels=3 +momentum=0.949 +decay=0.0005 +angle=0 +saturation = 1.5 +exposure = 1.5 +hue=.1 + +learning_rate=0.001 +burn_in=1000 +max_batches = 8000 +policy=steps +steps=6400,7200 +scales=.1,.1 + +mosaic=1 + +letter_box=1 + +ema_alpha=0.9998 + +#optimized_memory=1 + +#23:104x104 54:52x52 85:26x26 104:13x13 for 416 + + + +[convolutional] +batch_normalize=1 +filters=32 +size=3 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=2 +pad=1 +activation=mish + +#[convolutional] +#batch_normalize=1 +#filters=64 +#size=1 +#stride=1 +#pad=1 +#activation=mish + +#[route] +#layers = -2 + +#[convolutional] +#batch_normalize=1 +#filters=64 +#size=1 +#stride=1 +#pad=1 +#activation=mish + +[convolutional] +batch_normalize=1 +filters=32 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +#[convolutional] +#batch_normalize=1 +#filters=64 +#size=1 +#stride=1 +#pad=1 +#activation=mish + +#[route] +#layers = -1,-7 + +#[convolutional] +#batch_normalize=1 +#filters=64 +#size=1 +#stride=1 +#pad=1 +#activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=64 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=64 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-10 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-28 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +# Downsample + +[convolutional] +batch_normalize=1 +filters=1024 +size=3 +stride=2 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=3 +stride=1 +pad=1 +activation=mish + +[shortcut] +from=-3 +activation=linear + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1,-16 + +[convolutional] +batch_normalize=1 +filters=1024 +size=1 +stride=1 +pad=1 +activation=mish + +########################## + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +### SPP ### +[maxpool] +stride=1 +size=5 + +[route] +layers=-2 + +[maxpool] +stride=1 +size=9 + +[route] +layers=-4 + +[maxpool] +stride=1 +size=13 + +[route] +layers=-1,-3,-5,-6 +### End SPP ### + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[route] +layers = -1, -13 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 79 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[route] +layers = -1, -6 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[upsample] +stride=2 + +[route] +layers = 48 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -1, -3 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=mish + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=128 +activation=mish + +[route] +layers = -1, -6 + +[convolutional] +batch_normalize=1 +filters=128 +size=1 +stride=1 +pad=1 +activation=mish + +########################## + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=21 +activation=logistic + + +[yolo] +mask = 0,1,2 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=2 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=0 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=4.0 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=5 + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=256 +activation=mish + +[route] +layers = -1, -20 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=256 +activation=mish + +[route] +layers = -1,-6 + +[convolutional] +batch_normalize=1 +filters=256 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=21 +activation=logistic + + +[yolo] +mask = 3,4,5 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=2 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=1.0 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=5 + +[route] +layers = -4 + +[convolutional] +batch_normalize=1 +size=3 +stride=2 +pad=1 +filters=512 +activation=mish + +[route] +layers = -1, -49 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[route] +layers = -2 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=512 +activation=mish + +[route] +layers = -1,-6 + +[convolutional] +batch_normalize=1 +filters=512 +size=1 +stride=1 +pad=1 +activation=mish + +[convolutional] +batch_normalize=1 +size=3 +stride=1 +pad=1 +filters=1024 +activation=mish + +[convolutional] +size=1 +stride=1 +pad=1 +filters=21 +activation=logistic + + +[yolo] +mask = 6,7,8 +anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401 +classes=2 +num=9 +jitter=.1 +scale_x_y = 2.0 +objectness_smooth=1 +ignore_thresh = .7 +truth_thresh = 1 +#random=1 +resize=1.5 +iou_thresh=0.2 +iou_normalizer=0.05 +cls_normalizer=0.5 +obj_normalizer=0.4 +iou_loss=ciou +nms_kind=diounms +beta_nms=0.6 +new_coords=1 +max_delta=2 diff --git a/tests/darknet/names/crowdhuman.names b/tests/darknet/names/crowdhuman.names new file mode 100644 index 0000000..5ba1275 --- /dev/null +++ b/tests/darknet/names/crowdhuman.names @@ -0,0 +1,2 @@ +person +head \ No newline at end of file diff --git a/tests/darknet/yolo4-csp_crowd.cpp b/tests/darknet/yolo4-csp_crowd.cpp new file mode 100644 index 0000000..b8f0e6b --- /dev/null +++ b/tests/darknet/yolo4-csp_crowd.cpp @@ -0,0 +1,34 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4-csp_crowd"; + std::vector input_bins = { + bin_path + "/layers/input.bin" + }; + std::vector 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; +} \ No newline at end of file diff --git a/tests/darknet/yolo4_berkeley_f1.cpp b/tests/darknet/yolo4_berkeley_f1.cpp index f6f4e62..7d830c3 100644 --- a/tests/darknet/yolo4_berkeley_f1.cpp +++ b/tests/darknet/yolo4_berkeley_f1.cpp @@ -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); diff --git a/tests/shelfnet/shelfnet_coco.cpp b/tests/shelfnet/shelfnet_coco.cpp new file mode 100644 index 0000000..276a09d --- /dev/null +++ b/tests/shelfnet/shelfnet_coco.cpp @@ -0,0 +1,295 @@ +#include +#include +#include + +#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 features; + for(int i=0;i<3;++i){ + int out_channel = pow(2,7+i); + std::cout< 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<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 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:"<