diff --git a/.gitignore b/.gitignore index b56526f..c1d362c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,5 +12,11 @@ build/ *.hdf5 *.pk *.table +cmake-build-release/ demo/COCO_val2017 -demo/BDD100K_val \ No newline at end of file +demo/BDD100K_val +/.vs +cmake-build-minsizerel/* +scripts/COCO_val2017/* +scripts/COCO_val2017.zip +scripts/all_labels.txt \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c8619d..d3a89f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,14 @@ cmake_minimum_required(VERSION 3.5) project (tkDNN) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wno-deprecated-declarations -Wno-unused-variable") +if(UNIX) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC -Wno-deprecated-declarations -Wno-unused-variable ") +endif() +if(WIN32) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_FLAGS "/O2 /FS /EHsc") +set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) +endif(WIN32) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include/tkDNN) # project specific flags @@ -18,7 +25,7 @@ add_definitions(-DTKDNN_PATH="${CMAKE_CURRENT_SOURCE_DIR}") find_package(CUDA 9.0 REQUIRED) SET(CUDA_SEPARABLE_COMPILATION ON) #set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -arch=sm_30 --compiler-options '-fPIC'") -set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32) +set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} --maxrregcount=32 -arch=sm_61 ) find_package(CUDNN REQUIRED) include_directories(${CUDNN_INCLUDE_DIR}) @@ -28,6 +35,7 @@ include_directories(${CUDNN_INCLUDE_DIR}) file(GLOB tkdnn_CUSRC "src/kernels/*.cu" "src/sorting.cu") cuda_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${CUDNN_INCLUDE_DIRS}) cuda_add_library(kernels SHARED ${tkdnn_CUSRC}) +target_link_libraries(kernels ${CUDA_CUBLAS_LIBRARIES}) #------------------------------------------------------------------------------- @@ -40,7 +48,7 @@ find_package(OpenCV REQUIRED) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV") # gives problems in cross-compiling, probably malformed cmake config -#find_package(yaml-cpp REQUIRED) +find_package(yaml-cpp REQUIRED) #------------------------------------------------------------------------------- # Build Libraries @@ -48,7 +56,7 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENCV") file(GLOB tkdnn_SRC "src/*.cpp") set(tkdnn_LIBS kernels ${CUDA_LIBRARIES} ${CUDA_CUBLAS_LIBRARIES} ${CUDNN_LIBRARIES} ${OpenCV_LIBS} yaml-cpp) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include ${CUDA_INCLUDE_DIRS} ${OPENCV_INCLUDE_DIRS} ${NVINFER_INCLUDES}) add_library(tkDNN SHARED ${tkdnn_SRC}) target_link_libraries(tkDNN ${tkdnn_LIBS}) diff --git a/Issues.md b/Issues.md new file mode 100644 index 0000000..4875b13 --- /dev/null +++ b/Issues.md @@ -0,0 +1 @@ +1)error C2131 @ Yolo3Detection.cpp(97) -> expression doesnt evaluate to a constant caused to read of variable outside its lifetime \ No newline at end of file diff --git a/README.md b/README.md index 84e0037..7fb389b 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,14 @@ Results for COCO val 2017 (5k images), on RTX 2080Ti, with conf threshold=0.001 - [mAP demo](#map-demo) - [Existing tests and supported networks](#existing-tests-and-supported-networks) - [References](#references) + - [tkDNN on Windows 10 (experimental)](#tkdnn-on-windows-10-experimental) + - [Dependencies-Windows](#dependencies-windows) + - [Compiling tkDNN on Windows](#compiling-tkdnn-on-windows) + - [Run the demo on Windows](#run-the-demo-on-windows) + - [FP16 inference windows](#fp16-inference-windows) + - [INT8 inference windows](#int8-inference-windows) + - [Known issues with tkDNN on Windows](#known-issues-with-tkdnn-on-windows) + @@ -355,6 +363,94 @@ This demo also creates a json file named ```net_name_COCO_res.json``` containing | 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/) | 80 | 672x672 | [weights](https://cloud.hipert.unimore.it/s/BLPpiAigZJLorQD/download) | +### tkDNN on Windows 10 (experimental) + +### Dependencies-Windows +This branch should work on every NVIDIA GPU supported in windows with the following dependencies: + +* WINDOWS 10 1803 or HIGHER +* CUDA 10.0 (Recommended CUDA 11.2 ) +* CUDNN 7.6 (Recommended CUDNN 8.1.1 ) +* TENSORRT 6.0.1 (Recommended TENSORRT 7.2.3.4 ) +* OPENCV 3.4 (Recommended OPENCV 4.2.0 ) +* MSVC 16.7 +* YAML-CPP +* EIGEN3 +* 7ZIP (ADD TO PATH) +* NINJA 1.10 + + +All the above mentioned dependencies except 7ZIP can be installed using Microsoft's [VCPKG](https://github.com/microsoft/vcpkg.git) . +After bootstrapping VCPKG the dependencies can be built and installed using the following command : + +``` +opencv4(normal) - vcpkg.exe install opencv4[tbb,jpeg,tiff,opengl,openmp,png,ffmpeg,eigen]:x64-windows yaml-cpp:x64-windows eigen3:x64-windows --x-install-root=C:\opt --x-buildtrees-root=C:\temp_vcpkg_build + +opencv4(cuda) - vcpkg.exe install opencv4[cuda,nonfree,contrib,eigen,tbb,jpeg,tiff,opengl,openmp,png,ffmpeg]:x64-windows yaml-cpp:x64-windows eigen3:x64-windows --x-install-root=C:\opt --x-buildtrees-root=C:\temp_vcpkg_build +``` +To build opencv4 with cuda and cudnn version corresponding to your cuda version,vcpkg's cudnn portfile needs to be modified by adding ```$ENV{CUDA_PATH}``` at lines 16 and 17 in the portfile.cmake + +After VCPKG finishes building and installing all the packages delete C:\temp_vcpkg_build and add C:\opt\x64-windows\bin and C:\opt\x64-windows\debug\bin to path + +### Compiling tkDNN on Windows + +tkDNN is built with cmake(3.15+) on windows along with ninja.Msbuild and NMake Makefiles are drastically slower when compiling the library compared to windows +``` +git clone https://github.com/ceccocats/tkDNN.git +cd tkdnn-windows +mkdir build +cd build +cmake -DCMAKE_BUILD_TYPE=Release -G"Ninja" .. +ninja -j4 +``` + +### Run the demo on Windows + +This example uses yolo4_tiny.\ +To run the object detection file create .rt file bu running: +``` +.\test_yolo4tiny.exe +``` + +Once the rt file has been successfully create,run the demo using the following command: +``` +.\demo.exe yolo4tiny_fp32.rt ..\demo\yolo_test.mp4 y +``` + For general info on more demo paramters,check Run the demo section on top + To run the test_all_tests.sh on windows,use git bash or msys2 + +### FP16 inference windows + +This is an untested feature on windows.To run the object detection demo with FP16 interference follow the below steps(example with yolo4tiny): +``` +set TKDNN_MODE=FP16 +del /f yolo4tiny_fp16.rt +.\test_yolo4tiny.exe +.\demo.exe yolo4tiny_fp16.rt ..\demo\yolo_test.mp4 +``` + +### INT8 inference windows +To run object detection demo with INT8 (example with yolo4tiny): +``` +set TKDNN_MODE=INT8 +set TKDNN_CALIB_LABEL_PATH=..\demo\COCO_val2017\all_labels.txt +set TKDNN_CALIB_IMG_PATH=..\demo\COCO_val2017\all_images.txt +del /f yolo4tiny_int8.rt # be sure to delete(or move) old tensorRT files +.\test_yolo4tiny.exe # run the yolo test (is slow) +.\demo.exe yolo4tiny_int8.rt ..\demo\yolo_test.mp4 y + +``` + +### Known issues with tkDNN on Windows + +Mobilenet and Centernet demos work properly only when built with msvc 16.7 in Release Mode,when built in debug mode for the mentioned networks one might encounter opencv assert errors + +All Darknet models work properly with demo using MSVC version(16.7-16.9) + +It is recommended to use Nvidia Driver(465+),Cuda unknown errors have been observed when using older drivers on pascal(SM 61) devices. + + + ## References diff --git a/demo/demo/demo.cpp b/demo/demo/demo.cpp index 9f50d0b..317a574 100644 --- a/demo/demo/demo.cpp +++ b/demo/demo/demo.cpp @@ -1,7 +1,7 @@ #include #include #include /* srand, rand */ -#include +//#include #include #include "CenternetDetection.h" @@ -22,10 +22,15 @@ int main(int argc, char *argv[]) { signal(SIGINT, sig_handler); - std::string net = "yolo3_berkeley.rt"; + std::string net = "yolo4tiny_fp32.rt"; if(argc > 1) net = argv[1]; - std::string input = "../demo/yolo_test.mp4"; + #ifdef __linux__ + std::string input = "../demo/yolo_test.mp4"; + #elif _WIN32 + std::string input = "..\\..\\..\\demo\\yolo_test.mp4"; + #endif + if(argc > 2) input = argv[2]; char ntype = 'y'; @@ -131,7 +136,7 @@ int main(int argc, char *argv[]) { double mean = 0; std::cout<stats.begin(), detNN->stats.end())/n_batch<<" ms\n"; + std::cout<<"Min: "<<*std::min_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n"; std::cout<<"Max: "<<*std::max_element(detNN->stats.begin(), detNN->stats.end())/n_batch<<" ms\n"; for(int i=0; istats.size(); i++) mean += detNN->stats[i]; mean /= detNN->stats.size(); std::cout<<"Avg: "< #include #include /* srand, rand */ +#ifdef __linux__ #include +#endif + #include #include "utils.h" diff --git a/include/tkDNN/DetectionNN.h b/include/tkDNN/DetectionNN.h index 0498d41..a8c81f7 100644 --- a/include/tkDNN/DetectionNN.h +++ b/include/tkDNN/DetectionNN.h @@ -4,7 +4,10 @@ #include #include #include +#ifdef __linux__ #include +#endif + #include #include "utils.h" @@ -14,7 +17,7 @@ #include "tkdnn.h" -// #define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. +//#define OPENCV_CUDACONTRIB //if OPENCV has been compiled with CUDA and contrib. #ifdef OPENCV_CUDACONTRIB #include @@ -150,7 +153,6 @@ class DetectionNN { int x0, w, x1, y0, h, y1; int objClass; std::string det_class; - int baseline = 0; float font_scale = 0.5; int thickness = 2; diff --git a/include/tkDNN/ImuOdom.h b/include/tkDNN/ImuOdom.h index 6d8d4cb..d5429a8 100644 --- a/include/tkDNN/ImuOdom.h +++ b/include/tkDNN/ImuOdom.h @@ -1,7 +1,14 @@ #include #include #include /* srand, rand */ + +#ifdef __linux__ #include +#elif _WIN32 +#define _USE_MATH_DEFINES +#include +#endif + #include #include #include "utils.h" diff --git a/include/tkDNN/Int8BatchStream.h b/include/tkDNN/Int8BatchStream.h index 4349c1f..c39a11c 100644 --- a/include/tkDNN/Int8BatchStream.h +++ b/include/tkDNN/Int8BatchStream.h @@ -11,8 +11,11 @@ #include #include #include -#include +#include +#ifdef __linux__ #include +#endif + #include #include "NvInfer.h" diff --git a/include/tkDNN/Layer.h b/include/tkDNN/Layer.h index 25c4565..e097372 100644 --- a/include/tkDNN/Layer.h +++ b/include/tkDNN/Layer.h @@ -19,6 +19,7 @@ enum layerType_t { LAYER_ACTIVATION_CRELU, LAYER_ACTIVATION_LEAKY, LAYER_ACTIVATION_MISH, + LAYER_ACTIVATION_LOGISTIC, LAYER_FLATTEN, LAYER_RESHAPE, LAYER_MULADD, @@ -68,6 +69,7 @@ public: case LAYER_ACTIVATION_CRELU: return "ActivationCReLU"; case LAYER_ACTIVATION_LEAKY: return "ActivationLeaky"; case LAYER_ACTIVATION_MISH: return "ActivationMish"; + case LAYER_ACTIVATION_LOGISTIC: return "ActivationLogistic"; case LAYER_FLATTEN: return "Flatten"; case LAYER_RESHAPE: return "Reshape"; case LAYER_MULADD: return "MulAdd"; @@ -212,7 +214,8 @@ public: typedef enum { ACTIVATION_ELU = 100, ACTIVATION_LEAKY = 101, - ACTIVATION_MISH = 102 + ACTIVATION_MISH = 102, + ACTIVATION_LOGISTIC = 103 } tkdnnActivationMode_t; /** @@ -233,6 +236,8 @@ public: return LAYER_ACTIVATION_LEAKY; else if (act_mode == ACTIVATION_MISH) return LAYER_ACTIVATION_MISH; + else if (act_mode == ACTIVATION_LOGISTIC) + return LAYER_ACTIVATION_LOGISTIC; else return LAYER_ACTIVATION; }; diff --git a/include/tkDNN/NetworkRT.h b/include/tkDNN/NetworkRT.h index 4c6c816..66892f5 100644 --- a/include/tkDNN/NetworkRT.h +++ b/include/tkDNN/NetworkRT.h @@ -6,6 +6,7 @@ #include "Network.h" #include "Layer.h" #include "NvInfer.h" +#include namespace tk { namespace dnn { @@ -26,6 +27,7 @@ using namespace nvinfer1; #include "pluginsRT/ActivationLeakyRT.h" #include "pluginsRT/ActivationReLUCeilingRT.h" #include "pluginsRT/ActivationMishRT.h" +#include "pluginsRT/ActivationLogisticRT.h" #include "pluginsRT/ReorgRT.h" #include "pluginsRT/RegionRT.h" #include "pluginsRT/RouteRT.h" @@ -59,6 +61,7 @@ public: #if NV_TENSORRT_MAJOR >= 6 nvinfer1::IBuilderConfig *configRT; #endif + nvinfer1::ICudaEngine *engineRT; nvinfer1::IExecutionContext *contextRT; @@ -114,6 +117,9 @@ public: bool serialize(const char *filename); bool deserialize(const char *filename); + + + }; }} diff --git a/include/tkDNN/pluginsRT/ActivationLeakyRT.h b/include/tkDNN/pluginsRT/ActivationLeakyRT.h index d3f66fb..9e26b2b 100644 --- a/include/tkDNN/pluginsRT/ActivationLeakyRT.h +++ b/include/tkDNN/pluginsRT/ActivationLeakyRT.h @@ -52,8 +52,9 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, size); + assert(buf == a + getSerializationSize()); } int size; diff --git a/include/tkDNN/pluginsRT/ActivationLogisticRT.h b/include/tkDNN/pluginsRT/ActivationLogisticRT.h new file mode 100644 index 0000000..83f62ff --- /dev/null +++ b/include/tkDNN/pluginsRT/ActivationLogisticRT.h @@ -0,0 +1,60 @@ +#include +#include "../kernels.h" + +class ActivationLogisticRT : public IPlugin { + +public: + ActivationLogisticRT() { + + + } + + ~ActivationLogisticRT(){ + + } + + int getNbOutputs() const override { + return 1; + } + + Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) override { + return inputs[0]; + } + + void configure(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, int maxBatchSize) override { + size = 1; + for(int i=0; i(inputs[0]), + reinterpret_cast(outputs[0]), batchSize*size, stream); + return 0; + } + + + virtual size_t getSerializationSize() override { + return 1*sizeof(int); + } + + virtual void serialize(void* buffer) override { + char *buf = reinterpret_cast(buffer); + tk::dnn::writeBUF(buf, size); + } + + int size; +}; \ No newline at end of file diff --git a/include/tkDNN/pluginsRT/ActivationMishRT.h b/include/tkDNN/pluginsRT/ActivationMishRT.h index 1744ab0..5d660af 100644 --- a/include/tkDNN/pluginsRT/ActivationMishRT.h +++ b/include/tkDNN/pluginsRT/ActivationMishRT.h @@ -52,8 +52,9 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, size); + assert(buf == a + getSerializationSize()); } int size; diff --git a/include/tkDNN/pluginsRT/ActivationReLUCeilingRT.h b/include/tkDNN/pluginsRT/ActivationReLUCeilingRT.h index 286f22e..50ceb81 100644 --- a/include/tkDNN/pluginsRT/ActivationReLUCeilingRT.h +++ b/include/tkDNN/pluginsRT/ActivationReLUCeilingRT.h @@ -51,9 +51,10 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, ceiling); tk::dnn::writeBUF(buf, size); + assert(buf = a + getSerializationSize()); } diff --git a/include/tkDNN/pluginsRT/ActivationSigmoidRT.h b/include/tkDNN/pluginsRT/ActivationSigmoidRT.h index 1d47136..bcc58c7 100644 --- a/include/tkDNN/pluginsRT/ActivationSigmoidRT.h +++ b/include/tkDNN/pluginsRT/ActivationSigmoidRT.h @@ -52,8 +52,9 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, size); + assert(buf == a + getSerializationSize()); } int size; diff --git a/include/tkDNN/pluginsRT/DeformableConvRT.h b/include/tkDNN/pluginsRT/DeformableConvRT.h index 225a24e..5cb2bab 100644 --- a/include/tkDNN/pluginsRT/DeformableConvRT.h +++ b/include/tkDNN/pluginsRT/DeformableConvRT.h @@ -116,7 +116,7 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, chunk_dim); tk::dnn::writeBUF(buf, kh); tk::dnn::writeBUF(buf, kw); @@ -163,6 +163,7 @@ public: for(int i=0; i(buffer); + char *buf = reinterpret_cast(buffer),*a = buf; tk::dnn::writeBUF(buf, c); tk::dnn::writeBUF(buf, h); tk::dnn::writeBUF(buf, w); tk::dnn::writeBUF(buf, rows); tk::dnn::writeBUF(buf, cols); + assert(buf == a + getSerializationSize()); } int c, h, w; diff --git a/include/tkDNN/pluginsRT/MaxPoolingFixedSizeRT.h b/include/tkDNN/pluginsRT/MaxPoolingFixedSizeRT.h index 911fca2..0899a34 100644 --- a/include/tkDNN/pluginsRT/MaxPoolingFixedSizeRT.h +++ b/include/tkDNN/pluginsRT/MaxPoolingFixedSizeRT.h @@ -55,7 +55,7 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, this->c); tk::dnn::writeBUF(buf, this->h); @@ -65,6 +65,7 @@ public: tk::dnn::writeBUF(buf, this->stride_W); tk::dnn::writeBUF(buf, this->winSize); tk::dnn::writeBUF(buf, this->padding); + assert(buf == a + getSerializationSize()); } int n, c, h, w; diff --git a/include/tkDNN/pluginsRT/RegionRT.h b/include/tkDNN/pluginsRT/RegionRT.h index f0d127e..8487652 100644 --- a/include/tkDNN/pluginsRT/RegionRT.h +++ b/include/tkDNN/pluginsRT/RegionRT.h @@ -73,13 +73,14 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, classes); tk::dnn::writeBUF(buf, coords); tk::dnn::writeBUF(buf, num); tk::dnn::writeBUF(buf, c); tk::dnn::writeBUF(buf, h); tk::dnn::writeBUF(buf, w); + assert(buf == a + getSerializationSize()); } int c, h, w; diff --git a/include/tkDNN/pluginsRT/ReorgRT.h b/include/tkDNN/pluginsRT/ReorgRT.h index ee85718..c1b529a 100644 --- a/include/tkDNN/pluginsRT/ReorgRT.h +++ b/include/tkDNN/pluginsRT/ReorgRT.h @@ -52,11 +52,12 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, stride); tk::dnn::writeBUF(buf, c); tk::dnn::writeBUF(buf, h); tk::dnn::writeBUF(buf, w); + assert(buf == a + getSerializationSize()); } int c, h, w, stride; diff --git a/include/tkDNN/pluginsRT/ReshapeRT.h b/include/tkDNN/pluginsRT/ReshapeRT.h index 97030db..37017c7 100644 --- a/include/tkDNN/pluginsRT/ReshapeRT.h +++ b/include/tkDNN/pluginsRT/ReshapeRT.h @@ -50,11 +50,12 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a = buf; tk::dnn::writeBUF(buf, n); tk::dnn::writeBUF(buf, c); tk::dnn::writeBUF(buf, h); tk::dnn::writeBUF(buf, w); + assert(buf == a + getSerializationSize()); } int n, c, h, w; diff --git a/include/tkDNN/pluginsRT/ResizeLayerRT.h b/include/tkDNN/pluginsRT/ResizeLayerRT.h index ae87dbf..cde52bf 100644 --- a/include/tkDNN/pluginsRT/ResizeLayerRT.h +++ b/include/tkDNN/pluginsRT/ResizeLayerRT.h @@ -52,7 +52,7 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, o_c); tk::dnn::writeBUF(buf, o_h); @@ -61,6 +61,7 @@ public: tk::dnn::writeBUF(buf, i_c); tk::dnn::writeBUF(buf, i_h); tk::dnn::writeBUF(buf, i_w); + assert(buf == a + getSerializationSize()); } int i_c, i_h, i_w, o_c, o_h, o_w; diff --git a/include/tkDNN/pluginsRT/RouteRT.h b/include/tkDNN/pluginsRT/RouteRT.h index 23f30b7..5a8c170 100644 --- a/include/tkDNN/pluginsRT/RouteRT.h +++ b/include/tkDNN/pluginsRT/RouteRT.h @@ -75,7 +75,7 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, groups); tk::dnn::writeBUF(buf, group_id); tk::dnn::writeBUF(buf, in); @@ -85,6 +85,7 @@ public: tk::dnn::writeBUF(buf, c); tk::dnn::writeBUF(buf, h); tk::dnn::writeBUF(buf, w); + assert(buf == a + getSerializationSize()); } static const int MAX_INPUTS = 4; diff --git a/include/tkDNN/pluginsRT/ShortcutRT.h b/include/tkDNN/pluginsRT/ShortcutRT.h index 3eadd3f..17f050f 100644 --- a/include/tkDNN/pluginsRT/ShortcutRT.h +++ b/include/tkDNN/pluginsRT/ShortcutRT.h @@ -59,13 +59,14 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, bc); tk::dnn::writeBUF(buf, bh); tk::dnn::writeBUF(buf, bw); tk::dnn::writeBUF(buf, c); tk::dnn::writeBUF(buf, h); tk::dnn::writeBUF(buf, w); + assert(buf == a + getSerializationSize()); } diff --git a/include/tkDNN/pluginsRT/UpsampleRT.h b/include/tkDNN/pluginsRT/UpsampleRT.h index 7a62abc..a11d7b4 100644 --- a/include/tkDNN/pluginsRT/UpsampleRT.h +++ b/include/tkDNN/pluginsRT/UpsampleRT.h @@ -54,11 +54,12 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); + char *buf = reinterpret_cast(buffer),*a=buf; tk::dnn::writeBUF(buf, stride); tk::dnn::writeBUF(buf, c); tk::dnn::writeBUF(buf, h); tk::dnn::writeBUF(buf, w); + assert(buf == a + getSerializationSize()); } int c, h, w, stride; diff --git a/include/tkDNN/pluginsRT/YoloRT.h b/include/tkDNN/pluginsRT/YoloRT.h index 9af8587..2911869 100644 --- a/include/tkDNN/pluginsRT/YoloRT.h +++ b/include/tkDNN/pluginsRT/YoloRT.h @@ -64,20 +64,23 @@ public: checkCuda( cudaMemcpyAsync(dstData, srcData, batchSize*c*h*w*sizeof(dnnType), cudaMemcpyDeviceToDevice, stream)); - for (int b = 0; b < batchSize; ++b){ - for(int n = 0; n < n_masks; ++n){ - int index = entry_index(b, n*w*h, 0); - if (new_coords == 1) - activationLOGISTICForward(srcData + index, dstData + index, 4*w*h, stream); //x,y,w,h - else - activationLOGISTICForward(srcData + index, dstData + index, 2*w*h, stream); //x,y - if (this->scaleXY != 1) scalAdd(dstData + index, 2 * w*h, this->scaleXY, -0.5*(this->scaleXY - 1), 1); - - index = entry_index(b, n*w*h, 4); - activationLOGISTICForward(srcData + index, dstData + index, (1+classes)*w*h, stream); - } - } + for (int b = 0; b < batchSize; ++b){ + for(int n = 0; n < n_masks; ++n){ + int index = entry_index(b, n*w*h, 0); + if (new_coords == 1){ + if (this->scaleXY != 1) scalAdd(dstData + index, 2 * w*h, this->scaleXY, -0.5*(this->scaleXY - 1), 1); + } + else{ + activationLOGISTICForward(srcData + index, dstData + index, 2*w*h, stream); //x,y + + if (this->scaleXY != 1) scalAdd(dstData + index, 2 * w*h, this->scaleXY, -0.5*(this->scaleXY - 1), 1); + + index = entry_index(b, n*w*h, 4); + activationLOGISTICForward(srcData + index, dstData + index, (1+classes)*w*h, stream); + } + } + } //std::cout<<"YOLO END\n"; return 0; @@ -89,21 +92,25 @@ public: } virtual void serialize(void* buffer) override { - char *buf = reinterpret_cast(buffer); - tk::dnn::writeBUF(buf, classes); - tk::dnn::writeBUF(buf, num); - tk::dnn::writeBUF(buf, n_masks); - tk::dnn::writeBUF(buf, scaleXY); - tk::dnn::writeBUF(buf, nms_thresh); - tk::dnn::writeBUF(buf, nms_kind); - tk::dnn::writeBUF(buf, new_coords); - tk::dnn::writeBUF(buf, c); - tk::dnn::writeBUF(buf, h); - tk::dnn::writeBUF(buf, w); - for(int i=0; i(buffer),*a=buf; + tk::dnn::writeBUF(buf, classes); std::cout << "Classes :" << classes << std::endl; + tk::dnn::writeBUF(buf, num); std::cout << "Num : " << num << std::endl; + tk::dnn::writeBUF(buf, n_masks); std::cout << "N_Masks" << n_masks << std::endl; + tk::dnn::writeBUF(buf, scaleXY); std::cout << "ScaleXY :" << scaleXY << std::endl; + tk::dnn::writeBUF(buf, nms_thresh); std::cout << "nms_thresh :" << nms_thresh << std::endl; + tk::dnn::writeBUF(buf, nms_kind); std::cout << "nms_kind : " << nms_kind << std::endl; + tk::dnn::writeBUF(buf, new_coords); std::cout << "new_coords : " << new_coords << std::endl; + tk::dnn::writeBUF(buf, c); std::cout << "C : " << c << std::endl; + tk::dnn::writeBUF(buf, h); std::cout << "H : " << h << std::endl; + tk::dnn::writeBUF(buf, w); std::cout << "C : " << c << std::endl; + for (int i = 0; i < n_masks; i++) + { + tk::dnn::writeBUF(buf, mask[i]); std::cout << "mask[i] : " << mask[i] << std::endl; + } + for (int i = 0; i < n_masks * 2 * num; i++) + { + tk::dnn::writeBUF(buf, bias[i]); std::cout << "bias[i] : " << bias[i] << std::endl; + } // save classes names for(int i=0; i input_bins, std::vector readBinaryFile(input_bins[0], net->input_dim.tot(), &input_h, &data); // outputs - dnnType *cudnn_out[outputs.size()], *rt_out[outputs.size()]; + //dnnType *cudnn_out[outputs.size()], *rt_out[outputs.size()]; + std::vector cudnn_out,rt_out; tk::dnn::dataDim_t dim1 = net->input_dim; //input dim printCenteredTitle(" CUDNN inference ", '=', 30); { @@ -39,7 +40,7 @@ int testInference(std::vector input_bins, std::vector TKDNN_TSTOP dim1.print(); } - for(int i=0; idstData; + for(int i=0; idstData); if(netRT != nullptr) { tk::dnn::dataDim_t dim2 = net->input_dim; @@ -50,7 +51,7 @@ int testInference(std::vector input_bins, std::vector TKDNN_TSTOP dim2.print(); } - for(int i=0; ibuffersRT[i+1]; + for(int i=0; ibuffersRT[i+1]); } int ret_cudnn = 0, ret_tensorrt = 0, ret_cudnn_tensorrt = 0; diff --git a/include/tkDNN/utils.h b/include/tkDNN/utils.h index 538a3f3..eeef3c2 100644 --- a/include/tkDNN/utils.h +++ b/include/tkDNN/utils.h @@ -12,8 +12,12 @@ #include #include +#ifdef __linux__ #include +#endif + #include +#include #define dnnType float @@ -39,6 +43,7 @@ #define TKDNN_VERBOSE 0 // Simple Timer +#ifdef __linux__ #define TKDNN_TSTART timespec start, end; \ clock_gettime(CLOCK_MONOTONIC, &start); @@ -48,6 +53,14 @@ if(show) std::cout< duration = stop -start; \ +auto time_ms = std::chrono::duration_cast(duration);\ +double t_ns = time_ms.count(); +#endif + /******************************************************** * Prints the error message, and exits diff --git a/scripts/download_validation.py b/scripts/download_validation.py new file mode 100644 index 0000000..0e3b1d4 --- /dev/null +++ b/scripts/download_validation.py @@ -0,0 +1,39 @@ +import os +import urllib.request as dowReq +import zipfile + +val = input("Enter BDD or COCO :") +if(val == "COCO"): + url = "https://cloud.hipert.unimore.it/s/LNxBDk4wzqXPL8c/download" + lib = "..\demo\COCO_val2017" + lib_zip = "COCO_val2017.zip" +elif(val == "BDD"): + url = "https://cloud.hipert.unimore.it/s/bikqk3FzCq2tg4D/download" + lib = "..\demo\BDD100k_val" + lib_zip = "BDD100k_val.zip" + +dowReq.urlretrieve(url,lib_zip) + +with zipfile.ZipFile(lib_zip,'r') as zip_ref: + zip_ref.extractall(lib) + +labelFolder = lib + "\labels" +imageFolder = lib + "\images" + +file1 = open(".\\..\\demo\\all_labels.txt","a") +path1 = os.path.realpath(labelFolder) +for file in os.listdir(labelFolder): + valTemp = path1 + "\\" + file + valTemp = valTemp + '\n' + file1.write(valTemp) +file1.close() + +file2 = open(".\\..\\demo\\all_images.txt","a") +path2 = os.path.realpath(imageFolder) +for file in os.listdir(imageFolder): + pathtemp = path2 + "\\" + file + pathtemp = pathtemp + '\n' + file2.write(pathtemp) +file2.close() + +print("Completed") diff --git a/src/Activation.cpp b/src/Activation.cpp index 28c7624..4219271 100644 --- a/src/Activation.cpp +++ b/src/Activation.cpp @@ -52,7 +52,11 @@ dnnType* Activation::infer(dataDim_t &dim, dnnType* srcData) { else if(act_mode == ACTIVATION_MISH) { activationMishForward(srcData, dstData, dim.tot()); - } else { + } + else if(act_mode == ACTIVATION_LOGISTIC) { + activationLOGISTICForward(srcData, dstData, dim.tot()); + + }else { dnnType alpha = dnnType(1); dnnType beta = dnnType(0); checkCUDNN( cudnnActivationForward(net->cudnnHandle, diff --git a/src/DarknetParser.cpp b/src/DarknetParser.cpp index 7b5410c..69b6b29 100644 --- a/src/DarknetParser.cpp +++ b/src/DarknetParser.cpp @@ -187,6 +187,7 @@ namespace tk { namespace dnn { if(f.activation == "relu") act = tkdnnActivationMode_t(CUDNN_ACTIVATION_RELU); else if(f.activation == "leaky") act = tk::dnn::ACTIVATION_LEAKY; else if(f.activation == "mish") act = tk::dnn::ACTIVATION_MISH; + else if(f.activation == "logistic") act = tk::dnn::ACTIVATION_LOGISTIC; else { FatalError("activation not supported: " + f.activation); } netLayers[netLayers.size()-1] = new tk::dnn::Activation(net, act); }; diff --git a/src/LSTM.cpp b/src/LSTM.cpp index 7b87711..d0429e0 100644 --- a/src/LSTM.cpp +++ b/src/LSTM.cpp @@ -87,17 +87,22 @@ LSTM::LSTM( Network *net, int hiddensize, bool returnSeq, std::string fname_weig checkCUDNN(cudnnCreateRNNDescriptor(&rnnDesc)); #if CUDNN_MAJOR > 7 - checkCUDNN(cudnnSetRNNDescriptor_v6(net->cudnnHandle, + checkCUDNN(cudnnSetRNNDescriptor_v6(net->cudnnHandle,rnnDesc, stateSize, numLayers, dropoutDesc, + cudnnRNNInputMode_t::CUDNN_LINEAR_INPUT, + //(bidirectional ? cudnnDirectionMode_t::CUDNN_BIDIRECTIONAL : cudnnDirectionMode_t::CUDNN_UNIDIRECTIONAL), + cudnnDirectionMode_t::CUDNN_UNIDIRECTIONAL, + cudnnRNNMode_t::CUDNN_LSTM, + cudnnRNNAlgo_t::CUDNN_RNN_ALGO_STANDARD, + net->dataType)); #else - checkCUDNN(cudnnSetRNNDescriptor(net->cudnnHandle, -#endif - rnnDesc, stateSize, numLayers, dropoutDesc, + checkCUDNN(cudnnSetRNNDescriptor(net->cudnnHandle,rnnDesc, stateSize, numLayers, dropoutDesc, cudnnRNNInputMode_t::CUDNN_LINEAR_INPUT, //(bidirectional ? cudnnDirectionMode_t::CUDNN_BIDIRECTIONAL : cudnnDirectionMode_t::CUDNN_UNIDIRECTIONAL), cudnnDirectionMode_t::CUDNN_UNIDIRECTIONAL, cudnnRNNMode_t::CUDNN_LSTM, cudnnRNNAlgo_t::CUDNN_RNN_ALGO_STANDARD, net->dataType)); +#endif // Get temp space sizes diff --git a/src/NetworkRT.cpp b/src/NetworkRT.cpp index 501ade4..5dc8ee0 100644 --- a/src/NetworkRT.cpp +++ b/src/NetworkRT.cpp @@ -139,7 +139,8 @@ NetworkRT::NetworkRT(Network *net, const char *name) { #if NV_TENSORRT_MAJOR >= 6 engineRT = builderRT->buildEngineWithConfig(*networkRT, *configRT); #else - engineRT = builderRT->buildCudaEngine(*networkRT); + //engineRT = builderRT->buildCudaEngine(*networkRT); + engineRT = std::shared_ptr(builderRT->buildCudaEngine(*networkRT)); #endif if(engineRT == nullptr) FatalError("cloud not build cuda engine") @@ -226,7 +227,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Layer *l) { return convert_layer(input, (Conv2d*) l); if(type == LAYER_POOLING) return convert_layer(input, (Pooling*) l); - if(type == LAYER_ACTIVATION || type == LAYER_ACTIVATION_CRELU || type == LAYER_ACTIVATION_LEAKY || type == LAYER_ACTIVATION_MISH) + if(type == LAYER_ACTIVATION || type == LAYER_ACTIVATION_CRELU || type == LAYER_ACTIVATION_LEAKY || type == LAYER_ACTIVATION_MISH || type == LAYER_ACTIVATION_LOGISTIC) return convert_layer(input, (Activation*) l); if(type == LAYER_SOFTMAX) return convert_layer(input, (Softmax*) l); @@ -421,6 +422,12 @@ ILayer* NetworkRT::convert_layer(ITensor *input, Activation *l) { checkNULL(lRT); return lRT; } + else if(l->act_mode == ACTIVATION_LOGISTIC) { + IPlugin *plugin = new ActivationLogisticRT(); + IPluginLayer *lRT = networkRT->addPlugin(&input, 1, *plugin); + checkNULL(lRT); + return lRT; + } else { FatalError("this Activation mode is not yet implemented"); return NULL; @@ -561,7 +568,7 @@ ILayer* NetworkRT::convert_layer(ITensor *input, DeformConv2d *l) { IPluginLayer *lRT = networkRT->addPlugin(inputs, 2, *plugin); checkNULL(lRT); lRT->setName( ("Deformable" + std::to_string(l->id)).c_str() ); - delete(inputs); + delete[](inputs); // batchnorm void *bias_b, *power_b, *mean_b, *variance_b, *scales_b; if(dtRT == DataType::kHALF) { @@ -638,7 +645,7 @@ bool NetworkRT::deserialize(const char *filename) { IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialData, size_t serialLength) { - const char * buf = reinterpret_cast(serialData); + const char * buf = reinterpret_cast(serialData),*bufCheck = buf; std::string name(layerName); //std::cout<size = readBUF(buf); + assert(buf == bufCheck + serialLength); return a; } if(name.find("ActivationMish") == 0) { ActivationMishRT *a = new ActivationMishRT(); a->size = readBUF(buf); + assert(buf == bufCheck + serialLength); + return a; + } + if(name.find("ActivationLogistic") == 0) { + ActivationLogisticRT *a = new ActivationLogisticRT(); + a->size = readBUF(buf); return a; } if(name.find("ActivationCReLU") == 0) { - ActivationReLUCeiling *a = new ActivationReLUCeiling(readBUF(buf)); + float activationReluTemp = readBUF(buf); + ActivationReLUCeiling* a = new ActivationReLUCeiling(activationReluTemp); a->size = readBUF(buf); + assert(buf == bufCheck + serialLength); return a; } if(name.find("Region") == 0) { - RegionRT *r = new RegionRT(readBUF(buf), //classes - readBUF(buf), //coords - readBUF(buf)); //num + int classesTemp = readBUF(buf); + int coordsTemp = readBUF(buf); + int numTemp = readBUF(buf); + RegionRT* r = new RegionRT(classesTemp, coordsTemp, numTemp); r->c = readBUF(buf); r->h = readBUF(buf); r->w = readBUF(buf); + assert(buf == bufCheck + serialLength); return r; } if(name.find("Reorg") == 0) { - ReorgRT *r = new ReorgRT(readBUF(buf)); //stride + int strideTemp = readBUF(buf); + ReorgRT *r = new ReorgRT(strideTemp); r->c = readBUF(buf); r->h = readBUF(buf); r->w = readBUF(buf); + assert(buf == bufCheck + serialLength); return r; } @@ -690,27 +710,34 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa r->h = readBUF(buf); r->w = readBUF(buf); return r; + assert(buf == bufCheck + serialLength); } if(name.find("Pooling") == 0) { - MaxPoolFixedSizeRT *r = new MaxPoolFixedSizeRT( readBUF(buf), //c - readBUF(buf), //h - readBUF(buf), //w - readBUF(buf), //n - readBUF(buf), //strideH - readBUF(buf), //strideW - readBUF(buf), //winSize - readBUF(buf)); //padding + int cTemp = readBUF(buf); + int hTemp = readBUF(buf); + int wTemp = readBUF(buf); + int nTemp = readBUF(buf); + int strideHTemp = readBUF(buf); + int strideWTemp = readBUF(buf); + int winSizeTemp = readBUF(buf); + int paddingTemp = readBUF(buf); + + MaxPoolFixedSizeRT* r = new MaxPoolFixedSizeRT(cTemp, hTemp, wTemp, nTemp, strideHTemp, strideWTemp, winSizeTemp, paddingTemp); + assert(buf == bufCheck + serialLength); return r; } if(name.find("Resize") == 0) { - ResizeLayerRT *r = new ResizeLayerRT(readBUF(buf), //o_c - readBUF(buf), //o_h - readBUF(buf)); //o_w + int o_cTemp = readBUF(buf); + int o_hTemp = readBUF(buf); + int o_wTemp = readBUF(buf); + ResizeLayerRT* r = new ResizeLayerRT(o_cTemp, o_hTemp, o_wTemp); + r->i_c = readBUF(buf); r->i_h = readBUF(buf); r->i_w = readBUF(buf); + assert(buf == bufCheck + serialLength); return r; } @@ -721,6 +748,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa r->w = readBUF(buf); r->rows = readBUF(buf); r->cols = readBUF(buf); + assert(buf == bufCheck + serialLength); return r; } @@ -732,20 +760,25 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa new_dim.h = readBUF(buf); new_dim.w = readBUF(buf); ReshapeRT *r = new ReshapeRT(new_dim); + assert(buf == bufCheck + serialLength); return r; } if(name.find("Yolo") == 0) { - YoloRT *r = new YoloRT(readBUF(buf), //classes - readBUF(buf), //num - nullptr, //yolo - readBUF(buf), //n_masks - readBUF(buf), //scale_xy - readBUF(buf), //nms_thresh - readBUF(buf), //nms_kind - readBUF(buf) //new_coords - ); + + int classes_temp = readBUF(buf); + int num_temp = readBUF(buf); + int n_masks_temp = readBUF(buf); + float scale_xy_temp = readBUF(buf); + float nms_thresh_temp = readBUF(buf); + int nms_kind_temp = readBUF(buf); + int new_coords_temp = readBUF(buf); + + YoloRT *r = new YoloRT(classes_temp,num_temp,nullptr,n_masks_temp,scale_xy_temp,nms_thresh_temp,nms_kind_temp,new_coords_temp); + + + r->c = readBUF(buf); r->h = readBUF(buf); r->w = readBUF(buf); @@ -762,36 +795,54 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa tmp[j] = readBUF(buf); r->classesNames[i] = std::string(tmp); } + assert(buf == bufCheck + serialLength); yolos[n_yolos++] = r; return r; } if(name.find("Upsample") == 0) { - UpsampleRT *r = new UpsampleRT(readBUF(buf)); //stride + int strideTemp = readBUF(buf); + UpsampleRT* r = new UpsampleRT(strideTemp); r->c = readBUF(buf); r->h = readBUF(buf); r->w = readBUF(buf); + assert(buf == bufCheck + serialLength); return r; } if(name.find("Route") == 0) { - RouteRT *r = new RouteRT(readBUF(buf),readBUF(buf)); + int groupsTemp = readBUF(buf); + int group_idTemp = readBUF(buf); + RouteRT* r = new RouteRT(groupsTemp, group_idTemp); r->in = readBUF(buf); for(int i=0; ic_in[i] = readBUF(buf); r->c = readBUF(buf); r->h = readBUF(buf); r->w = readBUF(buf); + assert(buf == bufCheck + serialLength); return r; } if(name.find("Deformable") == 0) { - DeformableConvRT *r = new DeformableConvRT(readBUF(buf), readBUF(buf), readBUF(buf), - readBUF(buf), readBUF(buf), readBUF(buf), - readBUF(buf), readBUF(buf), - readBUF(buf),readBUF(buf),readBUF(buf),readBUF(buf), - readBUF(buf),readBUF(buf),readBUF(buf),readBUF(buf), - nullptr); + int chuck_dimTemp = readBUF(buf); + int khTemp = readBUF(buf); + int kwTemp = readBUF(buf); + int shTemp = readBUF(buf); + int swTemp = readBUF(buf); + int phTemp = readBUF(buf); + int pwTemp = readBUF(buf); + int deformableGroupTemp = readBUF(buf); + int i_nTemp = readBUF(buf); + int i_cTemp = readBUF(buf); + int i_hTemp = readBUF(buf); + int i_wTemp = readBUF(buf); + int o_nTemp = readBUF(buf); + int o_cTemp = readBUF(buf); + int o_hTemp = readBUF(buf); + int o_wTemp = readBUF(buf); + + DeformableConvRT* r = new DeformableConvRT(chuck_dimTemp, khTemp, kwTemp, shTemp, swTemp, phTemp, pwTemp, deformableGroupTemp, i_nTemp, i_cTemp, i_hTemp, i_wTemp, o_nTemp, o_cTemp, o_hTemp, o_wTemp, nullptr); dnnType *aus = new dnnType[r->chunk_dim*2]; for(int i=0; ichunk_dim*2; i++) aus[i] = readBUF(buf); @@ -822,6 +873,7 @@ IPlugin* PluginFactory::createPlugin(const char* layerName, const void* serialDa aus[i] = readBUF(buf); checkCuda( cudaMemcpy(r->ones_d2, aus, sizeof(dnnType)*r->dim_ones, cudaMemcpyHostToDevice) ); free(aus); + assert(buf == bufCheck + serialLength); return r; } diff --git a/src/Yolo.cpp b/src/Yolo.cpp index 9737e74..1eb7843 100644 --- a/src/Yolo.cpp +++ b/src/Yolo.cpp @@ -9,6 +9,7 @@ #include "Layer.h" #include "kernels.h" + namespace tk { namespace dnn { Yolo::Yolo(Network *net, int classes, int num, std::string fname_weights, int n_masks, float scale_xy, double nms_thresh, nmsKind_t nsm_kind, int new_coords) : @@ -72,8 +73,8 @@ Yolo::box get_yolo_box(float *x, float *biases, int n, int index, int i, int j, b.h = exp(x[index + 3*stride]) * biases[2*n+1] / h; } else{ - b.x = (i + x[index + 0 * stride] * 2 - 0.5) / lw; - b.y = (j + x[index + 1 * stride] * 2 - 0.5) / lh; + b.x = (i + x[index + 0 * stride] ) / lw; + b.y = (j + x[index + 1 * stride] ) / lh; b.w = x[index + 2 * stride] * x[index + 2 * stride] * 4 * biases[2 * n] / w; b.h = x[index + 3 * stride] * x[index + 3 * stride] * 4 * biases[2 * n + 1] / h; } @@ -87,15 +88,18 @@ dnnType* Yolo::infer(dataDim_t &dim, dnnType* srcData) { for (int b = 0; b < dim.n; ++b){ for(int n = 0; n < n_masks; ++n){ int index = entry_index(b, n*dim.w*dim.h, 0, classes, input_dim, output_dim); - if (new_coords == 1) - activationLOGISTICForward(srcData + index, dstData + index, 4*dim.w*dim.h); - else + std::cout<<"new_coords"<scaleXY != 1) scalAdd(dstData + index, 2 * dim.w*dim.h, this->scaleXY, -0.5*(this->scaleXY - 1), 1); + } + else{ activationLOGISTICForward(srcData + index, dstData + index, 2*dim.w*dim.h); - if (this->scaleXY != 1) scalAdd(dstData + index, 2 * dim.w*dim.h, this->scaleXY, -0.5*(this->scaleXY - 1), 1); - - index = entry_index(b, n*dim.w*dim.h, 4, classes, input_dim, output_dim); - activationLOGISTICForward(srcData + index, dstData + index, (1+classes)*dim.w*dim.h); + if (this->scaleXY != 1) scalAdd(dstData + index, 2 * dim.w*dim.h, this->scaleXY, -0.5*(this->scaleXY - 1), 1); + + index = entry_index(b, n*dim.w*dim.h, 4, classes, input_dim, output_dim); + activationLOGISTICForward(srcData + index, dstData + index, (1+classes)*dim.w*dim.h); + } } } @@ -209,10 +213,10 @@ float yolo_box_iou(Yolo::box a, Yolo::box b) } void box_c(const Yolo::box a, const Yolo::box b, float& top, float& bot, float& left, float& right) { - top = std::min(a.y - a.h / 2, b.y - b.h / 2); - bot = std::max(a.y + a.h / 2, b.y + b.h / 2); - left = std::min(a.x - a.w / 2, b.x - b.w / 2); - right = std::max(a.x + a.w / 2, b.x + b.w / 2); + top = (std::min)(a.y - a.h / 2, b.y - b.h / 2); + bot = (std::max)(a.y + a.h / 2, b.y + b.h / 2); + left = (std::min)(a.x - a.w / 2, b.x - b.w / 2); + right = (std::max)(a.x + a.w / 2, b.x + b.w / 2); } // https://github.com/Zzh-tju/DIoU-darknet diff --git a/src/Yolo3Detection.cpp b/src/Yolo3Detection.cpp index b94eea9..0c638e6 100644 --- a/src/Yolo3Detection.cpp +++ b/src/Yolo3Detection.cpp @@ -94,9 +94,10 @@ void Yolo3Detection::preprocess(cv::Mat &frame, const int bi){ void Yolo3Detection::postprocess(const int bi, const bool mAP){ //get yolo outputs - dnnType *rt_out[netRT->pluginFactory->n_yolos]; - for(int i=0; ipluginFactory->n_yolos; i++) - rt_out[i] = (dnnType*)netRT->buffersRT[i+1] + netRT->buffersDIM[i+1].tot()*bi; + std::vector rt_out; + //dnnType *rt_out[netRT->pluginFactory->n_yolos]; + for(int i=0; ipluginFactory->n_yolos; 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); float y_ratio = float(originalSize[bi].height) / float(netRT->input_dim.h); diff --git a/src/kernels/deformable_conv.cu b/src/kernels/deformable_conv.cu index 592c538..4dbc552 100644 --- a/src/kernels/deformable_conv.cu +++ b/src/kernels/deformable_conv.cu @@ -18,7 +18,7 @@ inline int GET_BLOCKS(const int N) } -__device__ float dmcn_im2col_bilinear(const float *bottom_data, const int data_width, +__device__ __host__ float dmcn_im2col_bilinear(const float *bottom_data, const int data_width, const int height, const int width, float h, float w) { int h_low = floor(h); int w_low = floor(w); diff --git a/src/utils.cpp b/src/utils.cpp index 65030f0..fa6458f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -23,14 +23,23 @@ bool fileExist(const char *fname) { void downloadWeightsifDoNotExist(const std::string& input_bin, const std::string& test_folder, const std::string& weights_url){ if(!fileExist(input_bin.c_str())){ std::string mkdir_cmd = "mkdir " + test_folder; - std::string wget_cmd = "wget " + weights_url + " -O " + test_folder + "/weights.zip"; + std::string wget_cmd = "curl " + weights_url + " --output " + test_folder + "/weights.zip"; +#ifdef __linux__ std::string unzip_cmd = "unzip " + test_folder + "/weights.zip -d" + test_folder; std::string rm_cmd = "rm " + test_folder + "/weights.zip"; + +#elif _WIN32 + + std::string unzip_cmd = "7z x " + test_folder + "/weights.zip -o" + test_folder; +#endif int err = 0; err = system(mkdir_cmd.c_str()); err = system(wget_cmd.c_str()); err = system(unzip_cmd.c_str()); +#ifdef __linux__ err = system(rm_cmd.c_str()); +#endif + } } @@ -191,8 +200,12 @@ void getMemUsage(double& vm_usage_kb, double& resident_set_kb){ >> O >> itrealvalue >> starttime >> vsize >> rss; stat_stream.close(); - +#ifdef __linux__ long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages +#elif _WIN32 + long page_size_kb = 4096/1024; +#endif + vm_usage_kb = vsize / 1024.0; resident_set_kb = rss * page_size_kb; } diff --git a/tests/darknet/cfg/yolo4-csp.cfg b/tests/darknet/cfg/yolo4-csp.cfg new file mode 100644 index 0000000..887898e --- /dev/null +++ b/tests/darknet/cfg/yolo4-csp.cfg @@ -0,0 +1,1279 @@ +[net] +# Testing +#batch=1 +#subdivisions=1 +# Training +batch=64 +subdivisions=8 +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 = 500500 +policy=steps +steps=400000,450000 +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=255 +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=80 +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=255 +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=80 +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=255 +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=80 +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 \ No newline at end of file diff --git a/tests/darknet/cfg/yolo4x.cfg b/tests/darknet/cfg/yolo4x.cfg index 89f2564..f6604f6 100644 --- a/tests/darknet/cfg/yolo4x.cfg +++ b/tests/darknet/cfg/yolo4x.cfg @@ -5,8 +5,8 @@ # Training batch=64 subdivisions=8 -width=672 -height=672 +width=640 +height=640 channels=3 momentum=0.949 decay=0.0005 @@ -15,7 +15,7 @@ saturation = 1.5 exposure = 1.5 hue=.1 -learning_rate=0.00261 +learning_rate=0.001 burn_in=1000 max_batches = 500500 policy=steps @@ -26,6 +26,8 @@ mosaic=1 letter_box=1 +#optimized_memory=1 + [convolutional] batch_normalize=1 filters=32 @@ -1131,6 +1133,7 @@ size=1 stride=1 pad=1 activation=mish +stopbackward=800 ########################## @@ -1147,7 +1150,7 @@ size=1 stride=1 pad=1 filters=255 -activation=linear +activation=logistic [yolo] @@ -1156,6 +1159,7 @@ anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 4 classes=80 num=9 jitter=.1 +scale_x_y = 2.0 objectness_smooth=0 ignore_thresh = .7 truth_thresh = 1 @@ -1169,6 +1173,7 @@ iou_loss=ciou nms_kind=diounms beta_nms=0.6 new_coords=1 +max_delta=5 [route] layers = -4 @@ -1275,7 +1280,7 @@ size=1 stride=1 pad=1 filters=255 -activation=linear +activation=logistic [yolo] @@ -1284,6 +1289,7 @@ anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 4 classes=80 num=9 jitter=.1 +scale_x_y = 2.0 objectness_smooth=1 ignore_thresh = .7 truth_thresh = 1 @@ -1297,6 +1303,7 @@ iou_loss=ciou nms_kind=diounms beta_nms=0.6 new_coords=1 +max_delta=5 [route] layers = -4 @@ -1403,7 +1410,7 @@ size=1 stride=1 pad=1 filters=255 -activation=linear +activation=logistic [yolo] @@ -1412,6 +1419,7 @@ anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 4 classes=80 num=9 jitter=.1 +scale_x_y = 2.0 objectness_smooth=1 ignore_thresh = .7 truth_thresh = 1 @@ -1425,3 +1433,4 @@ iou_loss=ciou nms_kind=diounms beta_nms=0.6 new_coords=1 +max_delta=2 \ No newline at end of file diff --git a/tests/darknet/yolo4-csp.cpp b/tests/darknet/yolo4-csp.cpp new file mode 100644 index 0000000..3802a9a --- /dev/null +++ b/tests/darknet/yolo4-csp.cpp @@ -0,0 +1,36 @@ +#include +#include +#include "tkdnn.h" +#include "test.h" +#include "DarknetParser.h" + +int main() { + std::string bin_path = "yolo4-csp"; + 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.cfg"; + std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/AfzHE4BfTeEm2gH/download"); + + + + // parse darknet network + tk::dnn::Network *net = tk::dnn::darknetParser(cfg_path, wgs_path, name_path); + net->print(); + + //convert network to tensorRT + tk::dnn::NetworkRT *netRT = new tk::dnn::NetworkRT(net, net->getNetworkRTName(bin_path.c_str())); + + int ret = testInference(input_bins, output_bins, net, netRT); + net->releaseLayers(); + delete net; + delete netRT; + return ret; +} \ No newline at end of file diff --git a/tests/darknet/yolo4x.cpp b/tests/darknet/yolo4x.cpp index b9ad003..8df1aef 100644 --- a/tests/darknet/yolo4x.cpp +++ b/tests/darknet/yolo4x.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/yolo4x.cfg"; std::string name_path = std::string(TKDNN_PATH) + "/tests/darknet/names/coco.names"; - downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/BLPpiAigZJLorQD/download"); + downloadWeightsifDoNotExist(input_bins[0], bin_path, "https://cloud.hipert.unimore.it/s/5MFjtNtgbDGdJEo/download");