├── configs
├── yolov5-2.0
│ ├── .gitkeep
│ ├── yolov5l.yaml
│ ├── yolov5m.yaml
│ ├── yolov5s.yaml
│ ├── yolov5x.yaml
│ ├── yolov5m.cfg
│ ├── yolov5l.cfg
│ ├── yolov5s.cfg
│ └── yolov5x.cfg
├── yolov5-3.0
│ ├── .gitkeep
│ ├── yolov5l.yaml
│ ├── yolov5m.yaml
│ ├── yolov5s.yaml
│ ├── yolov5x.yaml
│ ├── yolov5l.cfg
│ ├── yolov5m.cfg
│ ├── yolov5s.cfg
│ └── yolov5x.cfg
├── dog.jpg
├── person.jpg
├── result.jpg
├── qq_group.png
├── qrcode.jpeg
├── yolo-trt.png
├── yolov5-4.0
│ ├── yolov5l.yaml
│ ├── yolov5m.yaml
│ ├── yolov5s.yaml
│ ├── yolov5x.yaml
│ ├── yolov5l.cfg
│ ├── yolov5m.cfg
│ ├── yolov5s.cfg
│ └── yolov5x.cfg
├── yolov5-5.0
│ ├── yolov5l.yaml
│ ├── yolov5m.yaml
│ ├── yolov5s.yaml
│ ├── yolov5x.yaml
│ ├── yolov5l.cfg
│ ├── yolov5m.cfg
│ ├── yolov5s.cfg
│ ├── yolov5x.cfg
│ ├── yolov5l6.yaml
│ ├── yolov5m6.yaml
│ ├── yolov5s6.yaml
│ ├── yolov5x6.yaml
│ ├── yolov5l6.cfg
│ ├── yolov5s6.cfg
│ ├── yolov5m6.cfg
│ └── yolov5x6.cfg
├── yolov5-6.0
│ ├── yolov5l.yaml
│ ├── yolov5m.yaml
│ ├── yolov5n.yaml
│ ├── yolov5s.yaml
│ ├── yolov5x.yaml
│ ├── yolov5l.cfg
│ ├── yolov5s.cfg
│ ├── yolov5m.cfg
│ ├── yolov5n.cfg
│ └── yolov5x.cfg
├── yolov3-tiny.cfg
└── yolov4-tiny.cfg
├── modules
├── decodeTensorCUDA.h
├── yolov4.h
├── class_detector.cpp
├── yolov5.h
├── class_detector.h
├── yolov5.cpp
├── yolov3.h
├── yolov2.h
├── yolo_config_parser.h
├── yolov4.cpp
├── ds_image.h
├── calibrator.h
├── kernel.cu
├── yoloplugin_lib.h
├── chunk.h
├── yolov3.cpp
├── yolov2.cpp
├── decodeTensorCUDA.cu
├── hardswish.h
├── mish.h
├── detect.h
├── class_yolo_detector.hpp
├── calibrator.cpp
└── hardswish.cu
├── extra
├── API.h
└── class_timer.hpp
├── .gitignore
├── sln
├── test_dll
│ ├── test_dll.vcxproj.user
│ ├── test_dll.vcxproj.filters
│ └── test_dll.vcxproj
├── dll_detector
│ ├── dll_detector.vcxproj.user
│ ├── TensorRT-8.0.1.6_cuda-10.2.cudnn8.2.props
│ └── dll_detector.vcxproj.filters
├── props
│ ├── opencv412_release_x64.props
│ ├── TensorRT-8.0.1.6_cuda-11.3_cudnn8.2.props
│ ├── cuda100_x64_release.props
│ ├── cuda11_x64_release.props
│ ├── gflags_x64_release.props
│ ├── TensorRT-5.1.5.0_cuda-10.0_cudnn-7.5.props
│ ├── opencv330_release_x64.props
│ ├── TensorRT-7.1.3.4_cuda-11.0_cudnn8.0.props
│ ├── TensorRT-7.2.1.6_cuda-11.0.cudnn8.0.props
│ ├── TensorRT-7.2.3.4_cuda-11.1.cudnn8.1.props
│ ├── dll_debug_release_x64.props
│ ├── console_debug_release_x64 .props
│ └── opencv412_release_x64_vs2017.props
└── sln.sln
├── scripts
├── CMakeLists.txt
├── download.py
└── yaml2cfg.py
├── LICENSE
├── CMakeLists.txt
├── samples
└── sample_detector.cpp
└── README.md
/configs/yolov5-2.0/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/.gitkeep:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/configs/dog.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enazoe/yolo-tensorrt/HEAD/configs/dog.jpg
--------------------------------------------------------------------------------
/configs/person.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enazoe/yolo-tensorrt/HEAD/configs/person.jpg
--------------------------------------------------------------------------------
/configs/result.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enazoe/yolo-tensorrt/HEAD/configs/result.jpg
--------------------------------------------------------------------------------
/configs/qq_group.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enazoe/yolo-tensorrt/HEAD/configs/qq_group.png
--------------------------------------------------------------------------------
/configs/qrcode.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enazoe/yolo-tensorrt/HEAD/configs/qrcode.jpeg
--------------------------------------------------------------------------------
/configs/yolo-trt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/enazoe/yolo-tensorrt/HEAD/configs/yolo-trt.png
--------------------------------------------------------------------------------
/modules/decodeTensorCUDA.h:
--------------------------------------------------------------------------------
1 | #ifndef DECODETENSORCUDA_H_
2 | #define DECODETENSORCUDA_H_
3 | #include "yolo.h"
4 |
5 | float* decodeTensorCUDA(const int imageIdx, const TensorInfo& tensor);
6 | #endif
--------------------------------------------------------------------------------
/extra/API.h:
--------------------------------------------------------------------------------
1 | #ifdef API_EXPORTS
2 |
3 | #if defined(_MSC_VER)
4 | #define API __declspec(dllexport)
5 | #else
6 | #define API __attribute__((visibility("default")))
7 | #endif
8 |
9 | #else
10 |
11 | #if defined(_MSC_VER)
12 | #define API __declspec(dllimport)
13 | #else
14 | #define API
15 | #endif
16 |
17 | #endif
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | build/
2 | *.weights
3 | *.engine
4 | *.pdb
5 | x64/
6 | ipch/
7 | data/
8 | *.sdf
9 | *.opensdf
10 | *.exp
11 | *.db
12 | *.ipdb
13 | *.dll
14 | *.lib
15 | *.table
16 | api/
17 | *.iobj
18 | *.opendb
19 | *.exe
20 | .vs/
21 | .vscode/
22 | *.log
23 | *.pt
24 | *.onnx
25 | .ipynb_checkpoints
26 | *.idea
27 | Dockerfile
28 |
--------------------------------------------------------------------------------
/sln/test_dll/test_dll.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(SolutionDir)
5 | WindowsLocalDebugger
6 |
7 |
--------------------------------------------------------------------------------
/modules/yolov4.h:
--------------------------------------------------------------------------------
1 | #ifndef CLASS_YOLOV4_H_
2 | #define CLASS_YOLOV4_H_
3 | #include "yolo.h"
4 | class YoloV4 :public Yolo
5 | {
6 | public:
7 | YoloV4(
8 | const NetworkInfo &network_info_,
9 | const InferParams &infer_params_);
10 | private:
11 | std::vector decodeTensor(const int imageIdx,
12 | const int imageH,
13 | const int imageW,
14 | const TensorInfo& tensor) override;
15 | };
16 |
17 | #endif
18 |
--------------------------------------------------------------------------------
/sln/dll_detector/dll_detector.vcxproj.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(SolutionDir)
5 | WindowsLocalDebugger
6 |
7 |
--------------------------------------------------------------------------------
/modules/class_detector.cpp:
--------------------------------------------------------------------------------
1 | #include "class_detector.h"
2 | #include "class_yolo_detector.hpp"
3 |
4 | class Detector::Impl
5 | {
6 | public:
7 | Impl() {}
8 |
9 | ~Impl(){}
10 |
11 | YoloDectector _detector;
12 | };
13 |
14 | Detector::Detector()
15 | {
16 | _impl = new Impl();
17 | }
18 |
19 | Detector::~Detector()
20 | {
21 | if (_impl)
22 | {
23 | delete _impl;
24 | _impl = nullptr;
25 | }
26 | }
27 |
28 | void Detector::init(const Config &config)
29 | {
30 | _impl->_detector.init(config);
31 | }
32 |
33 | void Detector::detect(const std::vector &mat_image, std::vector &vec_batch_result)
34 | {
35 | _impl->_detector.detect(mat_image, vec_batch_result);
36 | }
37 |
--------------------------------------------------------------------------------
/sln/props/opencv412_release_x64.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | D:\dependency\OPENCV412\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | D:\dependency\OPENCV412\x64\vc14\lib;%(AdditionalLibraryDirectories)
12 | opencv_world412.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/extra/class_timer.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 | #include
5 | #include
6 |
7 | class Timer
8 | {
9 | public:
10 | Timer() : beg_(clock_::now())
11 | {}
12 | void reset()
13 | {
14 | beg_ = clock_::now();
15 | }
16 |
17 | double elapsed() const
18 | {
19 | return std::chrono::duration_cast(clock_::now() - beg_).count();
20 | }
21 |
22 | void out(std::string message = "")
23 | {
24 | double t = elapsed();
25 | std::cout << message << " elasped time:" << t << "ms" << std::endl;
26 | reset();
27 | }
28 |
29 | double get_duration()const
30 | {
31 | return elapsed();
32 | }
33 | private:
34 | using clock_ = std::chrono::high_resolution_clock;
35 | using second_ = std::chrono::duration;
36 | std::chrono::time_point beg_;
37 | };
38 |
--------------------------------------------------------------------------------
/sln/props/TensorRT-8.0.1.6_cuda-11.3_cudnn8.2.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | D:\dependency\TensorRT-8.0.1.6_cuda-11.3_cudnn8.2\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | D:\dependency\TensorRT-8.0.1.6_cuda-11.3_cudnn8.2\lib;%(AdditionalLibraryDirectories)
12 | nvinfer.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sln/props/cuda100_x64_release.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.0\lib\x64;%(AdditionalLibraryDirectories)
12 | cudart_static.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sln/props/cuda11_x64_release.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.0\lib\x64;%(AdditionalLibraryDirectories)
12 | cudart_static.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/scripts/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.1) # setting this is required
2 | project(yolov3-trt) # this sets the project name
3 |
4 |
5 |
6 | add_executable(yolov3-trt samples/sample_detector.cpp)
7 |
8 |
9 | set(CMAKE_CXX_COMPILIER "/usr/bin/g++")
10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wno-write-strings")
11 |
12 | LINK_DIRECTORIES(${CMAKE_BINARY_DIR})
13 | message(STATUS "${CMAKE_BINARY_DIR}")
14 | message(STATUS "${CMAKE_SOURCE_DIR}")
15 |
16 | add_library(detector SHARED IMPORTED)
17 | set_target_properties(detector PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/lib/libdetector.so)
18 |
19 | find_package(OpenCV REQUIRED)
20 |
21 |
22 | target_include_directories(yolov3-trt PRIVATE modules/ ./)
23 |
24 | target_link_libraries(yolov3-trt detector opencv_core opencv_calib3d opencv_dnn)
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/scripts/download.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | import requests
4 | print("download cfg file from https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3.cfg ...")
5 | url = 'https://raw.githubusercontent.com/pjreddie/darknet/master/cfg/yolov3.cfg'
6 | r = requests.get(url)
7 |
8 | with open('../configs/yolov3.cfg', 'wb') as f:
9 | f.write(r.content)
10 | print("done!")
11 | print("download weights file from https://pjreddie.com/media/files/yolov3.weights ...")
12 |
13 | url = 'https://pjreddie.com/media/files/yolov3.weights'
14 | r = requests.get(url)
15 |
16 | with open('../configs/yolov3.weights', 'wb') as f:
17 | f.write(r.content)
18 | print("done!")
19 |
20 | url = 'https://raw.githubusercontent.com/pjreddie/darknet/master/data/dog.jpg'
21 | r = requests.get(url)
22 |
23 | with open('../configs/dog.jpg', 'wb') as f:
24 | f.write(r.content)
25 | print("complete !")
--------------------------------------------------------------------------------
/sln/props/gflags_x64_release.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | <_PropertySheetDisplayName>gflag_x64_release
7 |
8 |
9 |
10 | D:\dependency\gflag\include;%(AdditionalIncludeDirectories)
11 |
12 |
13 | D:\dependency\gflag\lib;%(AdditionalLibraryDirectories)
14 | gflags_static.lib;gflags.lib;%(AdditionalDependencies)
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sln/props/TensorRT-5.1.5.0_cuda-10.0_cudnn-7.5.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | D:\dependency\TensorRT-5.1.5.0_cuda-10.0_cudnn-7.5\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | D:\dependency\TensorRT-5.1.5.0_cuda-10.0_cudnn-7.5\lib;%(AdditionalLibraryDirectories)
12 | nvinfer.lib;nvinfer_plugin.lib;nvonnxparser.lib;nvparsers.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sln/props/opencv330_release_x64.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | <_PropertySheetDisplayName>opencv330_release_x64
7 |
8 |
9 |
10 | D:\dependency\OPENCV330\include;%(AdditionalIncludeDirectories)
11 |
12 |
13 | D:\dependency\OPENCV330\x64\vc12\lib;%(AdditionalLibraryDirectories)
14 | opencv_world330.lib;%(AdditionalDependencies)
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/sln/props/TensorRT-7.1.3.4_cuda-11.0_cudnn8.0.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | D:\dependency\TensorRT-7.1.3.4_cuda-11.0.cudnn8.0\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | D:\dependency\TensorRT-7.1.3.4_cuda-11.0.cudnn8.0\lib;%(AdditionalLibraryDirectories)
12 | nvinfer.lib;nvinfer_plugin.lib;nvonnxparser.lib;nvparsers.lib;myelin64_1.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sln/props/TensorRT-7.2.1.6_cuda-11.0.cudnn8.0.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | D:\dependency\TensorRT-7.2.1.6_cuda-11.0.cudnn8.0\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | D:\dependency\TensorRT-7.2.1.6_cuda-11.0.cudnn8.0\lib;%(AdditionalLibraryDirectories)
12 | myelin64_1.lib;nvinfer.lib;nvinfer_plugin.lib;nvonnxparser.lib;nvparsers.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sln/props/TensorRT-7.2.3.4_cuda-11.1.cudnn8.1.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | D:\dependency\TensorRT-7.2.3.4.Windows10.x86_64.cuda-11.1.cudnn8.1\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | D:\dependency\TensorRT-7.2.3.4.Windows10.x86_64.cuda-11.1.cudnn8.1\lib;%(AdditionalLibraryDirectories)
12 | myelin64_1.lib;nvinfer.lib;nvinfer_plugin.lib;nvonnxparser.lib;nvparsers.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sln/dll_detector/TensorRT-8.0.1.6_cuda-10.2.cudnn8.2.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | D:\dependency\TensorRT-8.0.1.6\include;%(AdditionalIncludeDirectories)
9 |
10 |
11 | D:\dependency\TensorRT-8.0.1.6\lib;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2\lib\x64;%(AdditionalLibraryDirectories)
12 | nvinfer.lib;nvinfer_plugin.lib;nvonnxparser.lib;nvparsers.lib;cudart.lib;cuda.lib;cudnn.lib;cublas.lib;%(AdditionalDependencies)
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/sln/props/dll_debug_release_x64.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | <_PropertySheetDisplayName>linx_dll_debug_release_x64
7 | $(SolutionDir)
8 | $(SolutionDir)$(Platform)\
9 |
10 |
11 |
12 | ..\..\modules;..\..\extra;%(AdditionalIncludeDirectories)
13 | API_EXPORTS;%(PreprocessorDefinitions)
14 |
15 |
16 | $(SolutionDir)$(Configuration)\;%(AdditionalLibraryDirectories)
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/modules/yolov5.h:
--------------------------------------------------------------------------------
1 | #ifndef CLASS_YOLOV5_H_
2 | #define CLASS_YOLOV5_H_
3 | #include "yolo.h"
4 | class YoloV5 :public Yolo
5 | {
6 | public:
7 | YoloV5(
8 | const NetworkInfo &network_info_,
9 | const InferParams &infer_params_);
10 |
11 | BBox convert_bbox_res(const float& bx, const float& by, const float& bw, const float& bh,
12 | const uint32_t& stride_h_, const uint32_t& stride_w_, const uint32_t& netW, const uint32_t& netH)
13 | {
14 | BBox b;
15 | // Restore coordinates to network input resolution
16 | float x = bx * stride_w_;
17 | float y = by * stride_h_;
18 |
19 | b.x1 = x - bw / 2;
20 | b.x2 = x + bw / 2;
21 |
22 | b.y1 = y - bh / 2;
23 | b.y2 = y + bh / 2;
24 |
25 | b.x1 = clamp(b.x1, 0, netW);
26 | b.x2 = clamp(b.x2, 0, netW);
27 | b.y1 = clamp(b.y1, 0, netH);
28 | b.y2 = clamp(b.y2, 0, netH);
29 |
30 | return b;
31 | }
32 |
33 |
34 | private:
35 | std::vector decodeTensor(const int imageIdx,
36 | const int imageH,
37 | const int imageW,
38 | const TensorInfo& tensor) override;
39 | };
40 |
41 | #endif
--------------------------------------------------------------------------------
/sln/props/console_debug_release_x64 .props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | <_PropertySheetDisplayName>linx_console_debug_release_x64
7 | $(SolutionDir)
8 | $(SolutionDir)$(Platform)
9 |
10 |
11 |
12 | ..\..\modules;..\..\extra\linx;..\..\extra\linx_timer;%(AdditionalIncludeDirectories)
13 | _CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
14 |
15 |
16 | $(SolutionDir)$(Configuration)\;..\..\libs;$(SolutionDir);%(AdditionalLibraryDirectories)
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2020 enazoe
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.1)
2 | project(yolo-trt VERSION 1.0)
3 | enable_language(CUDA)
4 |
5 | set(CMAKE_CXX_COMPILIER "/usr/bin/g++")
6 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3 -Wno-write-strings")
7 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath -Wl,$ORIGIN")
8 |
9 | #cuda
10 | #export PATH=/usr/local/cuda-11.0/bin:$PATH
11 | #include_directories(/usr/local/cuda/include)
12 | #link_directories(/usr/local/cuda/lib64)
13 | find_package(CUDA REQUIRED)
14 |
15 | #opencv
16 | #set(OpenCV_DIR /opt/opencv-4.1.2/share/OpenCV)
17 | find_package(OpenCV REQUIRED)
18 |
19 | #detector lib (cuda)
20 | file(GLOB_RECURSE sources modules/*.hpp modules/*.cpp modules/*.h modules/*.cu extra/*.h)
21 | add_library(detector SHARED ${sources})
22 | target_include_directories(detector PRIVATE extra/ modules/ ${OpenCV_INCLUDE_DIRS} ${CUDA_TOOLKIT_ROOT_DIR}/include)
23 | target_link_libraries(detector nvinfer nvinfer_plugin nvparsers "stdc++fs")
24 |
25 | #sample
26 | add_executable(yolo-trt samples/sample_detector.cpp)
27 | target_include_directories(yolo-trt PRIVATE modules/ extra/)
28 | target_link_libraries(yolo-trt detector ${OpenCV_LIBS})
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/sln/test_dll/test_dll.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Source Files
20 |
21 |
22 |
23 |
24 | Header Files
25 |
26 |
27 |
--------------------------------------------------------------------------------
/modules/class_detector.h:
--------------------------------------------------------------------------------
1 | #ifndef CLASS_DETECTOR_H_
2 | #define CLASS_DETECTOR_H_
3 |
4 | #include "API.h"
5 | #include
6 | #include
7 |
8 | struct Result
9 | {
10 | int id = -1;
11 | float prob = 0.f;
12 | cv::Rect rect;
13 | };
14 |
15 | using BatchResult = std::vector;
16 |
17 | enum ModelType
18 | {
19 | YOLOV3,
20 | YOLOV4,
21 | YOLOV5
22 | };
23 |
24 | enum Precision
25 | {
26 | INT8 = 0,
27 | FP16,
28 | FP32
29 | };
30 |
31 | struct Config
32 | {
33 | std::string file_model_cfg = "configs/yolov4.cfg";
34 |
35 | std::string file_model_weights = "configs/yolov4.weights";
36 |
37 | float detect_thresh = 0.9;
38 |
39 | ModelType net_type = YOLOV4;
40 |
41 | Precision inference_precison = FP32;
42 |
43 | int gpu_id = 0;
44 |
45 | std::string calibration_image_list_file_txt = "configs/calibration_images.txt";
46 |
47 | };
48 |
49 | class API Detector
50 | {
51 | public:
52 | explicit Detector();
53 |
54 | ~Detector();
55 |
56 | void init(const Config &config);
57 |
58 | void detect(const std::vector &mat_image, std::vector &vec_batch_result);
59 |
60 | private:
61 |
62 | Detector(const Detector &);
63 | const Detector &operator =(const Detector &);
64 | class Impl;
65 | Impl *_impl;
66 | };
67 |
68 | #endif // !CLASS_QH_DETECTOR_H_
--------------------------------------------------------------------------------
/sln/props/opencv412_release_x64_vs2017.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | D:\dependency\OpenCV412\x64\vc15\bin;D:\dependency\OpenCV412\include;$(VC_IncludePath);$(WindowsSDK_IncludePath);$(IncludePath)
7 | D:\dependency\OpenCV412\x64\vc15\lib;$(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64;$(LibraryPath)
8 | $(VC_ExecutablePath_x64);$(WindowsSDK_ExecutablePath);$(VS_ExecutablePath);$(MSBuild_ExecutablePath);$(FxCopDir);$(PATH);
9 | <_PropertySheetDisplayName>OpenCV412_release_x64_vs2017
10 |
11 |
12 |
13 | opencv_world412.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
14 | D:\dependency\OpenCV412\x64\vc15\lib;%(AdditionalLibraryDirectories)
15 |
16 |
17 |
18 | 64
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/configs/yolov5-4.0/yolov5l.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, C3, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5l.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, C3, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-4.0/yolov5m.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.67 # model depth multiple
4 | width_multiple: 0.75 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, C3, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-4.0/yolov5s.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.33 # model depth multiple
4 | width_multiple: 0.50 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, C3, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-4.0/yolov5x.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.33 # model depth multiple
4 | width_multiple: 1.25 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, C3, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5m.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.67 # model depth multiple
4 | width_multiple: 0.75 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, C3, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5s.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.33 # model depth multiple
4 | width_multiple: 0.50 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, C3, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5x.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.33 # model depth multiple
4 | width_multiple: 1.25 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, C3, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5l.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.0 # model depth multiple
6 | width_multiple: 1.0 # layer channel multiple
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 6, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 3, C3, [1024]],
24 | [-1, 1, SPPF, [1024, 5]], # 9
25 | ]
26 |
27 | # YOLOv5 v6.0 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5m.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.67 # model depth multiple
6 | width_multiple: 0.75 # layer channel multiple
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 6, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 3, C3, [1024]],
24 | [-1, 1, SPPF, [1024, 5]], # 9
25 | ]
26 |
27 | # YOLOv5 v6.0 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5n.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.25 # layer channel multiple
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 6, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 3, C3, [1024]],
24 | [-1, 1, SPPF, [1024, 5]], # 9
25 | ]
26 |
27 | # YOLOv5 v6.0 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5s.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 0.33 # model depth multiple
6 | width_multiple: 0.50 # layer channel multiple
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 6, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 3, C3, [1024]],
24 | [-1, 1, SPPF, [1024, 5]], # 9
25 | ]
26 |
27 | # YOLOv5 v6.0 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5x.yaml:
--------------------------------------------------------------------------------
1 | # YOLOv5 🚀 by Ultralytics, GPL-3.0 license
2 |
3 | # Parameters
4 | nc: 80 # number of classes
5 | depth_multiple: 1.33 # model depth multiple
6 | width_multiple: 1.25 # layer channel multiple
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 v6.0 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, C3, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 6, C3, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, C3, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 3, C3, [1024]],
24 | [-1, 1, SPPF, [1024, 5]], # 9
25 | ]
26 |
27 | # YOLOv5 v6.0 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, C3, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, C3, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, C3, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, C3, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-2.0/yolov5l.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, BottleneckCSP, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, BottleneckCSP, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, BottleneckCSP, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, BottleneckCSP, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, BottleneckCSP, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-2.0/yolov5m.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.67 # model depth multiple
4 | width_multiple: 0.75 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, BottleneckCSP, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, BottleneckCSP, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, BottleneckCSP, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, BottleneckCSP, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, BottleneckCSP, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-2.0/yolov5s.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.33 # model depth multiple
4 | width_multiple: 0.50 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, BottleneckCSP, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, BottleneckCSP, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, BottleneckCSP, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, BottleneckCSP, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, BottleneckCSP, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-2.0/yolov5x.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.33 # model depth multiple
4 | width_multiple: 1.25 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, BottleneckCSP, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, BottleneckCSP, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, BottleneckCSP, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, BottleneckCSP, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, BottleneckCSP, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/yolov5l.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, BottleneckCSP, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, BottleneckCSP, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, BottleneckCSP, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, BottleneckCSP, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, BottleneckCSP, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/yolov5m.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.67 # model depth multiple
4 | width_multiple: 0.75 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, BottleneckCSP, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, BottleneckCSP, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, BottleneckCSP, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, BottleneckCSP, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, BottleneckCSP, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/yolov5s.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.33 # model depth multiple
4 | width_multiple: 0.50 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, BottleneckCSP, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, BottleneckCSP, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, BottleneckCSP, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, BottleneckCSP, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, BottleneckCSP, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/yolov5x.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.33 # model depth multiple
4 | width_multiple: 1.25 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv5 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Focus, [64, 3]], # 0-P1/2
16 | [-1, 1, Conv, [128, 3, 2]], # 1-P2/4
17 | [-1, 3, BottleneckCSP, [128]],
18 | [-1, 1, Conv, [256, 3, 2]], # 3-P3/8
19 | [-1, 9, BottleneckCSP, [256]],
20 | [-1, 1, Conv, [512, 3, 2]], # 5-P4/16
21 | [-1, 9, BottleneckCSP, [512]],
22 | [-1, 1, Conv, [1024, 3, 2]], # 7-P5/32
23 | [-1, 1, SPP, [1024, [5, 9, 13]]],
24 | [-1, 3, BottleneckCSP, [1024, False]], # 9
25 | ]
26 |
27 | # YOLOv5 head
28 | head:
29 | [[-1, 1, Conv, [512, 1, 1]],
30 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
31 | [[-1, 6], 1, Concat, [1]], # cat backbone P4
32 | [-1, 3, BottleneckCSP, [512, False]], # 13
33 |
34 | [-1, 1, Conv, [256, 1, 1]],
35 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
36 | [[-1, 4], 1, Concat, [1]], # cat backbone P3
37 | [-1, 3, BottleneckCSP, [256, False]], # 17 (P3/8-small)
38 |
39 | [-1, 1, Conv, [256, 3, 2]],
40 | [[-1, 14], 1, Concat, [1]], # cat head P4
41 | [-1, 3, BottleneckCSP, [512, False]], # 20 (P4/16-medium)
42 |
43 | [-1, 1, Conv, [512, 3, 2]],
44 | [[-1, 10], 1, Concat, [1]], # cat head P5
45 | [-1, 3, BottleneckCSP, [1024, False]], # 23 (P5/32-large)
46 |
47 | [[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
48 | ]
49 |
--------------------------------------------------------------------------------
/modules/yolov5.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "yolov5.h"
3 | #include "decodeTensorCUDA.h"
4 |
5 | YoloV5::YoloV5(
6 | const NetworkInfo &network_info_,
7 | const InferParams &infer_params_) :
8 | Yolo( network_info_, infer_params_) {}
9 | std::vector YoloV5::decodeTensor(const int imageIdx, const int imageH, const int imageW, const TensorInfo& tensor)
10 | {
11 | float scale_h = 1.f;
12 | float scale_w = 1.f;
13 | int xOffset = 0;
14 | int yOffset = 0;
15 | calcuate_letterbox_message(m_InputH, m_InputW, imageH, imageW, scale_h, scale_w, xOffset, yOffset);
16 | std::vector binfo;
17 |
18 | // decode output (x,y,w,h,maxProb,maxIndex)
19 | float* boxes = decodeTensorCUDA(imageIdx, tensor);
20 |
21 | // Ergodic result
22 | for (uint32_t y = 0; y < tensor.grid_h; ++y)
23 | {
24 | for (uint32_t x = 0; x < tensor.grid_w; ++x)
25 | {
26 | for (uint32_t b = 0; b < tensor.numBBoxes; ++b)
27 | {
28 | const int bbindex = y * tensor.grid_w+ x;
29 | const float bx
30 | = boxes[18 * bbindex + 6*b + 0];
31 |
32 | const float by
33 | = boxes[18 * bbindex + 6*b + 1];
34 |
35 | const float bw
36 | = boxes[18 * bbindex + 6*b + 2];
37 |
38 | const float bh
39 | = boxes[18 * bbindex + 6*b + 3];
40 |
41 | const float maxProb
42 | = boxes[18 * bbindex + 6*b + 4];
43 |
44 | const int maxIndex
45 | = (int) boxes[18 * bbindex + 6*b + 5];
46 |
47 | if (maxProb > m_ProbThresh)
48 | {
49 | add_bbox_proposal(bx, by, bw, bh, tensor.stride_h, tensor.stride_w, scale_h, scale_w, xOffset, yOffset, maxIndex, maxProb, imageW, imageH, binfo);
50 | }
51 |
52 | }
53 | }
54 | }
55 | return binfo;
56 | }
57 |
--------------------------------------------------------------------------------
/modules/yolov3.h:
--------------------------------------------------------------------------------
1 | /**
2 | MIT License
3 |
4 | Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | *
24 | */
25 |
26 | #ifndef _YOLO_V3_
27 | #define _YOLO_V3_
28 |
29 | #include "yolo.h"
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | class YoloV3 : public Yolo
36 | {
37 | public:
38 | YoloV3(const NetworkInfo& networkInfo, const InferParams& inferParams);
39 |
40 | private:
41 | std::vector decodeTensor(const int imageIdx, const int imageH, const int imageW,
42 | const TensorInfo& tensor) override;
43 | };
44 |
45 | #endif // _YOLO_V3_
--------------------------------------------------------------------------------
/modules/yolov2.h:
--------------------------------------------------------------------------------
1 | /**
2 | MIT License
3 |
4 | Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | *
24 | */
25 |
26 | #ifndef _YOLO_V2_
27 | #define _YOLO_V2_
28 |
29 | #include "yolo.h"
30 |
31 | #include
32 | #include
33 | #include
34 |
35 | class YoloV2 : public Yolo
36 | {
37 | public:
38 | YoloV2( const NetworkInfo& networkInfo, const InferParams& inferParams);
39 |
40 | private:
41 | std::vector decodeTensor(const int imageIdx, const int imageH, const int imageW,
42 | const TensorInfo& tensor) override;
43 | };
44 |
45 | #endif // _YOLO_V2_
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5l.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.0
9 | width_multiple=1.0
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Conv]
13 | from=-1
14 | number=1
15 | args=64, 6, 2, 2
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=6
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [C3]
53 | from=-1
54 | number=3
55 | args=1024
56 |
57 | [SPPF]
58 | from=-1
59 | number=1
60 | args=1024, 5
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5s.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=0.33
9 | width_multiple=0.5
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Conv]
13 | from=-1
14 | number=1
15 | args=64, 6, 2, 2
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=6
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [C3]
53 | from=-1
54 | number=3
55 | args=1024
56 |
57 | [SPPF]
58 | from=-1
59 | number=1
60 | args=1024, 5
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5m.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=0.67
9 | width_multiple=0.75
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Conv]
13 | from=-1
14 | number=1
15 | args=64, 6, 2, 2
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=6
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [C3]
53 | from=-1
54 | number=3
55 | args=1024
56 |
57 | [SPPF]
58 | from=-1
59 | number=1
60 | args=1024, 5
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5n.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=0.33
9 | width_multiple=0.25
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Conv]
13 | from=-1
14 | number=1
15 | args=64, 6, 2, 2
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=6
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [C3]
53 | from=-1
54 | number=3
55 | args=1024
56 |
57 | [SPPF]
58 | from=-1
59 | number=1
60 | args=1024, 5
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-6.0/yolov5x.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.33
9 | width_multiple=1.25
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Conv]
13 | from=-1
14 | number=1
15 | args=64, 6, 2, 2
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=6
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [C3]
53 | from=-1
54 | number=3
55 | args=1024
56 |
57 | [SPPF]
58 | from=-1
59 | number=1
60 | args=1024, 5
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-4.0/yolov5l.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.0
9 | width_multiple=1.0
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [C3]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5l.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.0
9 | width_multiple=1.0
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [C3]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-4.0/yolov5m.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=0.67
9 | width_multiple=0.75
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [C3]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-4.0/yolov5s.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch= 2
7 | nc=80
8 | depth_multiple=0.33
9 | width_multiple=0.5
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [C3]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-4.0/yolov5x.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.33
9 | width_multiple=1.25
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [C3]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5m.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=0.67
9 | width_multiple=0.75
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [C3]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5s.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch= 1
7 | nc=80
8 | depth_multiple=0.33
9 | width_multiple=0.5
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [C3]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5x.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.33
9 | width_multiple=1.25
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [C3]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [C3]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [C3]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [C3]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [C3]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [C3]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [C3]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [C3]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/modules/yolo_config_parser.h:
--------------------------------------------------------------------------------
1 | /**
2 | MIT License
3 |
4 | Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | *
24 | */
25 |
26 | #ifndef _YOLO_CONFIG_PARSER_
27 | #define _YOLO_CONFIG_PARSER_
28 |
29 | #include "yolo.h"
30 |
31 | #include
32 | //#include
33 |
34 | // Init to be called at the very beginning to verify all config params are valid
35 | //void yoloConfigParserInit(int argc, char** argv);
36 |
37 | //NetworkInfo getYoloNetworkInfo();
38 | //InferParams getYoloInferParams();
39 | //uint64_t getSeed();
40 | //std::string getNetworkType();
41 | //std::string getPrecision();
42 | //std::string getTestImages();
43 | //std::string getTestImagesPath();
44 | //bool getDecode();
45 | //bool getDoBenchmark();
46 | //bool getViewDetections();
47 | //bool getSaveDetections();
48 | //std::string getSaveDetectionsPath();
49 | //uint32_t getBatchSize();
50 | //bool getShuffleTestSet();
51 |
52 | #endif //_YOLO_CONFIG_PARSER_
--------------------------------------------------------------------------------
/configs/yolov5-2.0/yolov5m.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=320
5 | channels=3
6 | nc=80
7 | depth_multiple=0.67
8 | width_multiple=0.75
9 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
10 |
11 | [Focus]
12 | from=-1
13 | number=1
14 | args=64, 3
15 |
16 | [Conv]
17 | from=-1
18 | number=1
19 | args=128, 3, 2
20 |
21 | [BottleneckCSP]
22 | from=-1
23 | number=3
24 | args=128
25 |
26 | [Conv]
27 | from=-1
28 | number=1
29 | args=256, 3, 2
30 |
31 | [BottleneckCSP]
32 | from=-1
33 | number=9
34 | args=256
35 |
36 | [Conv]
37 | from=-1
38 | number=1
39 | args=512, 3, 2
40 |
41 | [BottleneckCSP]
42 | from=-1
43 | number=9
44 | args=512
45 |
46 | [Conv]
47 | from=-1
48 | number=1
49 | args=1024, 3, 2
50 |
51 | [SPP]
52 | from=-1
53 | number=1
54 | args=1024, [5, 9, 13]
55 |
56 | [BottleneckCSP]
57 | from=-1
58 | number=3
59 | args=1024, False
60 |
61 | [Conv]
62 | from=-1
63 | number=1
64 | args=512, 1, 1
65 |
66 | [nn.Upsample]
67 | from=-1
68 | number=1
69 | args='None', 2, 'nearest'
70 |
71 | [Concat]
72 | from=-1, 6
73 | number=1
74 | args=1
75 |
76 | [BottleneckCSP]
77 | from=-1
78 | number=3
79 | args=512, False
80 |
81 | [Conv]
82 | from=-1
83 | number=1
84 | args=256, 1, 1
85 |
86 | [nn.Upsample]
87 | from=-1
88 | number=1
89 | args='None', 2, 'nearest'
90 |
91 | [Concat]
92 | from=-1, 4
93 | number=1
94 | args=1
95 |
96 | [BottleneckCSP]
97 | from=-1
98 | number=3
99 | args=256, False
100 |
101 | [Conv]
102 | from=-1
103 | number=1
104 | args=256, 3, 2
105 |
106 | [Concat]
107 | from=-1, 14
108 | number=1
109 | args=1
110 |
111 | [BottleneckCSP]
112 | from=-1
113 | number=3
114 | args=512, False
115 |
116 | [Conv]
117 | from=-1
118 | number=1
119 | args=512, 3, 2
120 |
121 | [Concat]
122 | from=-1, 10
123 | number=1
124 | args=1
125 |
126 | [BottleneckCSP]
127 | from=-1
128 | number=3
129 | args=1024, False
130 |
131 | [Detect]
132 | from=17, 20, 23
133 | number=1
134 | args='nc', 'anchors'
135 |
--------------------------------------------------------------------------------
/configs/yolov5-2.0/yolov5l.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=320
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.0
9 | width_multiple=1.0
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [BottleneckCSP]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [BottleneckCSP]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [BottleneckCSP]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [BottleneckCSP]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [BottleneckCSP]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [BottleneckCSP]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [BottleneckCSP]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [BottleneckCSP]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-2.0/yolov5s.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=320
4 | height=320
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=0.33
9 | width_multiple=0.5
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [BottleneckCSP]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [BottleneckCSP]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [BottleneckCSP]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [BottleneckCSP]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [BottleneckCSP]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [BottleneckCSP]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [BottleneckCSP]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [BottleneckCSP]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-2.0/yolov5x.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=320
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.33
9 | width_multiple=1.25
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [BottleneckCSP]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [BottleneckCSP]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [BottleneckCSP]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [BottleneckCSP]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [BottleneckCSP]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [BottleneckCSP]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [BottleneckCSP]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [BottleneckCSP]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/yolov5l.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.0
9 | width_multiple=1.0
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [BottleneckCSP]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [BottleneckCSP]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [BottleneckCSP]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [BottleneckCSP]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [BottleneckCSP]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [BottleneckCSP]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [BottleneckCSP]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [BottleneckCSP]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/yolov5m.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=0.67
9 | width_multiple=0.75
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [BottleneckCSP]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [BottleneckCSP]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [BottleneckCSP]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [BottleneckCSP]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [BottleneckCSP]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [BottleneckCSP]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [BottleneckCSP]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [BottleneckCSP]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/yolov5s.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=0.33
9 | width_multiple=0.5
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [BottleneckCSP]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [BottleneckCSP]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [BottleneckCSP]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [BottleneckCSP]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [BottleneckCSP]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [BottleneckCSP]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [BottleneckCSP]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [BottleneckCSP]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/configs/yolov5-3.0/yolov5x.cfg:
--------------------------------------------------------------------------------
1 |
2 | [net]
3 | width=640
4 | height=640
5 | channels=3
6 | batch=1
7 | nc=80
8 | depth_multiple=1.33
9 | width_multiple=1.25
10 | anchors=10, 13, 16, 30, 33, 23, 30, 61, 62, 45, 59, 119, 116, 90, 156, 198, 373, 326
11 |
12 | [Focus]
13 | from=-1
14 | number=1
15 | args=64, 3
16 |
17 | [Conv]
18 | from=-1
19 | number=1
20 | args=128, 3, 2
21 |
22 | [BottleneckCSP]
23 | from=-1
24 | number=3
25 | args=128
26 |
27 | [Conv]
28 | from=-1
29 | number=1
30 | args=256, 3, 2
31 |
32 | [BottleneckCSP]
33 | from=-1
34 | number=9
35 | args=256
36 |
37 | [Conv]
38 | from=-1
39 | number=1
40 | args=512, 3, 2
41 |
42 | [BottleneckCSP]
43 | from=-1
44 | number=9
45 | args=512
46 |
47 | [Conv]
48 | from=-1
49 | number=1
50 | args=1024, 3, 2
51 |
52 | [SPP]
53 | from=-1
54 | number=1
55 | args=1024, [5, 9, 13]
56 |
57 | [BottleneckCSP]
58 | from=-1
59 | number=3
60 | args=1024, False
61 |
62 | [Conv]
63 | from=-1
64 | number=1
65 | args=512, 1, 1
66 |
67 | [nn.Upsample]
68 | from=-1
69 | number=1
70 | args='None', 2, 'nearest'
71 |
72 | [Concat]
73 | from=-1, 6
74 | number=1
75 | args=1
76 |
77 | [BottleneckCSP]
78 | from=-1
79 | number=3
80 | args=512, False
81 |
82 | [Conv]
83 | from=-1
84 | number=1
85 | args=256, 1, 1
86 |
87 | [nn.Upsample]
88 | from=-1
89 | number=1
90 | args='None', 2, 'nearest'
91 |
92 | [Concat]
93 | from=-1, 4
94 | number=1
95 | args=1
96 |
97 | [BottleneckCSP]
98 | from=-1
99 | number=3
100 | args=256, False
101 |
102 | [Conv]
103 | from=-1
104 | number=1
105 | args=256, 3, 2
106 |
107 | [Concat]
108 | from=-1, 14
109 | number=1
110 | args=1
111 |
112 | [BottleneckCSP]
113 | from=-1
114 | number=3
115 | args=512, False
116 |
117 | [Conv]
118 | from=-1
119 | number=1
120 | args=512, 3, 2
121 |
122 | [Concat]
123 | from=-1, 10
124 | number=1
125 | args=1
126 |
127 | [BottleneckCSP]
128 | from=-1
129 | number=3
130 | args=1024, False
131 |
132 | [Detect]
133 | from=17, 20, 23
134 | number=1
135 | args='nc', 'anchors'
136 |
--------------------------------------------------------------------------------
/sln/sln.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.25420.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dll_detector", "dll_detector\dll_detector.vcxproj", "{AE246A73-03C7-4A8E-B978-DA5CE9C73B97}"
7 | EndProject
8 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_dll", "test_dll\test_dll.vcxproj", "{AE9921FC-C594-4C41-925A-5582896BD2A8}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|x64 = Debug|x64
13 | Debug|x86 = Debug|x86
14 | Release|x64 = Release|x64
15 | Release|x86 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
18 | {AE246A73-03C7-4A8E-B978-DA5CE9C73B97}.Debug|x64.ActiveCfg = Debug|x64
19 | {AE246A73-03C7-4A8E-B978-DA5CE9C73B97}.Debug|x64.Build.0 = Debug|x64
20 | {AE246A73-03C7-4A8E-B978-DA5CE9C73B97}.Debug|x86.ActiveCfg = Debug|Win32
21 | {AE246A73-03C7-4A8E-B978-DA5CE9C73B97}.Debug|x86.Build.0 = Debug|Win32
22 | {AE246A73-03C7-4A8E-B978-DA5CE9C73B97}.Release|x64.ActiveCfg = Release|x64
23 | {AE246A73-03C7-4A8E-B978-DA5CE9C73B97}.Release|x64.Build.0 = Release|x64
24 | {AE246A73-03C7-4A8E-B978-DA5CE9C73B97}.Release|x86.ActiveCfg = Release|Win32
25 | {AE246A73-03C7-4A8E-B978-DA5CE9C73B97}.Release|x86.Build.0 = Release|Win32
26 | {AE9921FC-C594-4C41-925A-5582896BD2A8}.Debug|x64.ActiveCfg = Debug|x64
27 | {AE9921FC-C594-4C41-925A-5582896BD2A8}.Debug|x64.Build.0 = Debug|x64
28 | {AE9921FC-C594-4C41-925A-5582896BD2A8}.Debug|x86.ActiveCfg = Debug|Win32
29 | {AE9921FC-C594-4C41-925A-5582896BD2A8}.Debug|x86.Build.0 = Debug|Win32
30 | {AE9921FC-C594-4C41-925A-5582896BD2A8}.Release|x64.ActiveCfg = Release|x64
31 | {AE9921FC-C594-4C41-925A-5582896BD2A8}.Release|x64.Build.0 = Release|x64
32 | {AE9921FC-C594-4C41-925A-5582896BD2A8}.Release|x86.ActiveCfg = Release|Win32
33 | {AE9921FC-C594-4C41-925A-5582896BD2A8}.Release|x86.Build.0 = Release|Win32
34 | EndGlobalSection
35 | GlobalSection(SolutionProperties) = preSolution
36 | HideSolutionNode = FALSE
37 | EndGlobalSection
38 | EndGlobal
39 |
--------------------------------------------------------------------------------
/modules/yolov4.cpp:
--------------------------------------------------------------------------------
1 |
2 | #include "yolov4.h"
3 |
4 | YoloV4::YoloV4( const NetworkInfo &network_info_,
5 | const InferParams &infer_params_) :
6 | Yolo(network_info_, infer_params_) {}
7 |
8 | std::vector YoloV4::decodeTensor(const int imageIdx, const int imageH, const int imageW, const TensorInfo& tensor)
9 | {
10 | float scale_h = 1.f;
11 | float scale_w = 1.f;
12 | int xOffset = 0;
13 | int yOffset = 0;
14 |
15 | const float* detections = &tensor.hostBuffer[imageIdx * tensor.volume];
16 |
17 | std::vector binfo;
18 | for (uint32_t y = 0; y < tensor.grid_h; ++y)
19 | {
20 | for (uint32_t x = 0; x < tensor.grid_w; ++x)
21 | {
22 | for (uint32_t b = 0; b < tensor.numBBoxes; ++b)
23 | {
24 | const float pw = tensor.anchors[tensor.masks[b] * 2];
25 | const float ph = tensor.anchors[tensor.masks[b] * 2 + 1];
26 |
27 | const int numGridCells = tensor.grid_h * tensor.grid_w;
28 | const int bbindex = y * tensor.grid_w + x;
29 | const float bx
30 | = x + detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 0)];
31 | const float by
32 | = y + detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 1)];
33 | const float bw
34 | = pw * detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 2)];
35 | const float bh
36 | = ph * detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 3)];
37 |
38 | const float objectness
39 | = detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 4)];
40 |
41 | float maxProb = 0.0f;
42 | int maxIndex = -1;
43 |
44 | for (uint32_t i = 0; i < tensor.numClasses; ++i)
45 | {
46 | float prob
47 | = (detections[bbindex
48 | + numGridCells * (b * (5 + tensor.numClasses) + (5 + i))]);
49 |
50 | if (prob > maxProb)
51 | {
52 | maxProb = prob;
53 | maxIndex = i;
54 | }
55 | }
56 | maxProb = objectness * maxProb;
57 |
58 | if (maxProb > m_ProbThresh)
59 | {
60 | add_bbox_proposal(bx, by, bw, bh, tensor.stride_h, tensor.stride_w, scale_h, scale_w, xOffset, yOffset, maxIndex, maxProb, imageW, imageH, binfo);
61 | }
62 | }
63 | }
64 | }
65 | return binfo;
66 | }
67 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5l6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # YOLOv5 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [ [ -1, 1, Focus, [ 64, 3 ] ], # 0-P1/2
17 | [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4
18 | [ -1, 3, C3, [ 128 ] ],
19 | [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8
20 | [ -1, 9, C3, [ 256 ] ],
21 | [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16
22 | [ -1, 9, C3, [ 512 ] ],
23 | [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32
24 | [ -1, 3, C3, [ 768 ] ],
25 | [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64
26 | [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ],
27 | [ -1, 3, C3, [ 1024, False ] ], # 11
28 | ]
29 |
30 | # YOLOv5 head
31 | head:
32 | [ [ -1, 1, Conv, [ 768, 1, 1 ] ],
33 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
34 | [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5
35 | [ -1, 3, C3, [ 768, False ] ], # 15
36 |
37 | [ -1, 1, Conv, [ 512, 1, 1 ] ],
38 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
39 | [ [ -1, 6 ], 1, Concat, [ 1 ] ], # cat backbone P4
40 | [ -1, 3, C3, [ 512, False ] ], # 19
41 |
42 | [ -1, 1, Conv, [ 256, 1, 1 ] ],
43 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
44 | [ [ -1, 4 ], 1, Concat, [ 1 ] ], # cat backbone P3
45 | [ -1, 3, C3, [ 256, False ] ], # 23 (P3/8-small)
46 |
47 | [ -1, 1, Conv, [ 256, 3, 2 ] ],
48 | [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4
49 | [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium)
50 |
51 | [ -1, 1, Conv, [ 512, 3, 2 ] ],
52 | [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5
53 | [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large)
54 |
55 | [ -1, 1, Conv, [ 768, 3, 2 ] ],
56 | [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6
57 | [ -1, 3, C3, [ 1024, False ] ], # 32 (P6/64-xlarge)
58 |
59 | [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6)
60 | ]
61 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5m6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.67 # model depth multiple
4 | width_multiple: 0.75 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # YOLOv5 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [ [ -1, 1, Focus, [ 64, 3 ] ], # 0-P1/2
17 | [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4
18 | [ -1, 3, C3, [ 128 ] ],
19 | [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8
20 | [ -1, 9, C3, [ 256 ] ],
21 | [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16
22 | [ -1, 9, C3, [ 512 ] ],
23 | [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32
24 | [ -1, 3, C3, [ 768 ] ],
25 | [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64
26 | [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ],
27 | [ -1, 3, C3, [ 1024, False ] ], # 11
28 | ]
29 |
30 | # YOLOv5 head
31 | head:
32 | [ [ -1, 1, Conv, [ 768, 1, 1 ] ],
33 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
34 | [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5
35 | [ -1, 3, C3, [ 768, False ] ], # 15
36 |
37 | [ -1, 1, Conv, [ 512, 1, 1 ] ],
38 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
39 | [ [ -1, 6 ], 1, Concat, [ 1 ] ], # cat backbone P4
40 | [ -1, 3, C3, [ 512, False ] ], # 19
41 |
42 | [ -1, 1, Conv, [ 256, 1, 1 ] ],
43 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
44 | [ [ -1, 4 ], 1, Concat, [ 1 ] ], # cat backbone P3
45 | [ -1, 3, C3, [ 256, False ] ], # 23 (P3/8-small)
46 |
47 | [ -1, 1, Conv, [ 256, 3, 2 ] ],
48 | [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4
49 | [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium)
50 |
51 | [ -1, 1, Conv, [ 512, 3, 2 ] ],
52 | [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5
53 | [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large)
54 |
55 | [ -1, 1, Conv, [ 768, 3, 2 ] ],
56 | [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6
57 | [ -1, 3, C3, [ 1024, False ] ], # 32 (P6/64-xlarge)
58 |
59 | [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6)
60 | ]
61 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5s6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 0.33 # model depth multiple
4 | width_multiple: 0.50 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # YOLOv5 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [ [ -1, 1, Focus, [ 64, 3 ] ], # 0-P1/2
17 | [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4
18 | [ -1, 3, C3, [ 128 ] ],
19 | [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8
20 | [ -1, 9, C3, [ 256 ] ],
21 | [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16
22 | [ -1, 9, C3, [ 512 ] ],
23 | [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32
24 | [ -1, 3, C3, [ 768 ] ],
25 | [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64
26 | [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ],
27 | [ -1, 3, C3, [ 1024, False ] ], # 11
28 | ]
29 |
30 | # YOLOv5 head
31 | head:
32 | [ [ -1, 1, Conv, [ 768, 1, 1 ] ],
33 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
34 | [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5
35 | [ -1, 3, C3, [ 768, False ] ], # 15
36 |
37 | [ -1, 1, Conv, [ 512, 1, 1 ] ],
38 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
39 | [ [ -1, 6 ], 1, Concat, [ 1 ] ], # cat backbone P4
40 | [ -1, 3, C3, [ 512, False ] ], # 19
41 |
42 | [ -1, 1, Conv, [ 256, 1, 1 ] ],
43 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
44 | [ [ -1, 4 ], 1, Concat, [ 1 ] ], # cat backbone P3
45 | [ -1, 3, C3, [ 256, False ] ], # 23 (P3/8-small)
46 |
47 | [ -1, 1, Conv, [ 256, 3, 2 ] ],
48 | [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4
49 | [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium)
50 |
51 | [ -1, 1, Conv, [ 512, 3, 2 ] ],
52 | [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5
53 | [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large)
54 |
55 | [ -1, 1, Conv, [ 768, 3, 2 ] ],
56 | [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6
57 | [ -1, 3, C3, [ 1024, False ] ], # 32 (P6/64-xlarge)
58 |
59 | [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6)
60 | ]
61 |
--------------------------------------------------------------------------------
/configs/yolov5-5.0/yolov5x6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.33 # model depth multiple
4 | width_multiple: 1.25 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # YOLOv5 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [ [ -1, 1, Focus, [ 64, 3 ] ], # 0-P1/2
17 | [ -1, 1, Conv, [ 128, 3, 2 ] ], # 1-P2/4
18 | [ -1, 3, C3, [ 128 ] ],
19 | [ -1, 1, Conv, [ 256, 3, 2 ] ], # 3-P3/8
20 | [ -1, 9, C3, [ 256 ] ],
21 | [ -1, 1, Conv, [ 512, 3, 2 ] ], # 5-P4/16
22 | [ -1, 9, C3, [ 512 ] ],
23 | [ -1, 1, Conv, [ 768, 3, 2 ] ], # 7-P5/32
24 | [ -1, 3, C3, [ 768 ] ],
25 | [ -1, 1, Conv, [ 1024, 3, 2 ] ], # 9-P6/64
26 | [ -1, 1, SPP, [ 1024, [ 3, 5, 7 ] ] ],
27 | [ -1, 3, C3, [ 1024, False ] ], # 11
28 | ]
29 |
30 | # YOLOv5 head
31 | head:
32 | [ [ -1, 1, Conv, [ 768, 1, 1 ] ],
33 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
34 | [ [ -1, 8 ], 1, Concat, [ 1 ] ], # cat backbone P5
35 | [ -1, 3, C3, [ 768, False ] ], # 15
36 |
37 | [ -1, 1, Conv, [ 512, 1, 1 ] ],
38 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
39 | [ [ -1, 6 ], 1, Concat, [ 1 ] ], # cat backbone P4
40 | [ -1, 3, C3, [ 512, False ] ], # 19
41 |
42 | [ -1, 1, Conv, [ 256, 1, 1 ] ],
43 | [ -1, 1, nn.Upsample, [ None, 2, 'nearest' ] ],
44 | [ [ -1, 4 ], 1, Concat, [ 1 ] ], # cat backbone P3
45 | [ -1, 3, C3, [ 256, False ] ], # 23 (P3/8-small)
46 |
47 | [ -1, 1, Conv, [ 256, 3, 2 ] ],
48 | [ [ -1, 20 ], 1, Concat, [ 1 ] ], # cat head P4
49 | [ -1, 3, C3, [ 512, False ] ], # 26 (P4/16-medium)
50 |
51 | [ -1, 1, Conv, [ 512, 3, 2 ] ],
52 | [ [ -1, 16 ], 1, Concat, [ 1 ] ], # cat head P5
53 | [ -1, 3, C3, [ 768, False ] ], # 29 (P5/32-large)
54 |
55 | [ -1, 1, Conv, [ 768, 3, 2 ] ],
56 | [ [ -1, 12 ], 1, Concat, [ 1 ] ], # cat head P6
57 | [ -1, 3, C3, [ 1024, False ] ], # 32 (P6/64-xlarge)
58 |
59 | [ [ 23, 26, 29, 32 ], 1, Detect, [ nc, anchors ] ], # Detect(P3, P4, P5, P6)
60 | ]
61 |
--------------------------------------------------------------------------------
/samples/sample_detector.cpp:
--------------------------------------------------------------------------------
1 | #include "class_timer.hpp"
2 | #include "class_detector.h"
3 |
4 | #include
5 | #include
6 |
7 |
8 | int main()
9 | {
10 | Config config_v3;
11 | config_v3.net_type = YOLOV3;
12 | config_v3.file_model_cfg = "../configs/yolov3.cfg";
13 | config_v3.file_model_weights = "../configs/yolov3.weights";
14 | config_v3.calibration_image_list_file_txt = "../configs/calibration_images.txt";
15 | config_v3.inference_precison =FP32;
16 | config_v3.detect_thresh = 0.5;
17 |
18 | Config config_v4;
19 | config_v4.net_type = YOLOV4;
20 | config_v4.file_model_cfg = "../configs/yolov4.cfg";
21 | config_v4.file_model_weights = "../configs/yolov4.weights";
22 | config_v4.calibration_image_list_file_txt = "../configs/calibration_images.txt";
23 | config_v4.inference_precison = FP32;
24 | config_v4.detect_thresh = 0.5;
25 |
26 | Config config_v5;
27 | config_v5.net_type = YOLOV5;
28 | config_v5.detect_thresh = 0.5;
29 | config_v5.file_model_cfg = "../configs/yolov5-6.0/yolov5n.cfg";
30 | config_v5.file_model_weights = "../configs/yolov5-6.0/yolov5n.weights";
31 | config_v5.calibration_image_list_file_txt = "../configs/calibration_images.txt";
32 | config_v5.inference_precison = FP32;
33 |
34 | std::unique_ptr detector(new Detector());
35 | detector->init(config_v5);
36 | cv::Mat image0 = cv::imread("../configs/dog.jpg", cv::IMREAD_UNCHANGED);
37 | cv::Mat image1 = cv::imread("../configs/person.jpg", cv::IMREAD_UNCHANGED);
38 | std::vector batch_res;
39 | Timer timer;
40 | for (;;)
41 | {
42 | //prepare batch data
43 | std::vector batch_img;
44 | cv::Mat temp0 = image0.clone();
45 | cv::Mat temp1 = image1.clone();
46 | batch_img.push_back(temp0);
47 | //batch_img.push_back(temp1);
48 |
49 | //detect
50 | timer.reset();
51 | detector->detect(batch_img, batch_res);
52 | timer.out("detect");
53 |
54 | //disp
55 | for (int i=0;i m_Bboxes;
58 |
59 | // unaltered original Image
60 | cv::Mat m_OrigImage;
61 | // letterboxed Image given to the network as input
62 | cv::Mat m_LetterboxImage;
63 | // final image marked with the bounding boxes
64 | cv::Mat m_MarkedImage;
65 | };
66 |
67 | #endif
68 |
--------------------------------------------------------------------------------
/modules/calibrator.h:
--------------------------------------------------------------------------------
1 | /**
2 | MIT License
3 |
4 | Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | *
24 | */
25 | #ifndef _CALIBRATOR_H_
26 | #define _CALIBRATOR_H_
27 |
28 | #include "NvInfer.h"
29 | #include "ds_image.h"
30 | #include "trt_utils.h"
31 |
32 | class Int8EntropyCalibrator : public nvinfer1::IInt8EntropyCalibrator2
33 | {
34 | public:
35 | Int8EntropyCalibrator(const uint32_t& batchSize, const std::string& calibImages,
36 | const std::string& calibImagesPath, const std::string& calibTableFilePath,
37 | const uint64_t& inputSize, const uint32_t& inputH, const uint32_t& inputW,
38 | const std::string& inputBlobName,const std::string &s_net_type_);
39 | virtual ~Int8EntropyCalibrator();
40 |
41 | int getBatchSize() const noexcept override { return m_BatchSize; }
42 | bool getBatch(void* bindings[], const char* names[], int nbBindings) noexcept override;
43 | const void* readCalibrationCache(size_t& length) noexcept override;
44 | void writeCalibrationCache(const void* cache, size_t length) noexcept override;
45 |
46 | private:
47 | const uint32_t m_BatchSize;
48 | const uint32_t m_InputH;
49 | const uint32_t m_InputW;
50 | const uint64_t m_InputSize;
51 | const uint64_t m_InputCount;
52 | const std::string m_InputBlobName;
53 | const std::string _s_net_type;
54 | const std::string m_CalibTableFilePath{nullptr};
55 | uint32_t m_ImageIndex;
56 | bool m_ReadCache{true};
57 | void* m_DeviceInput{nullptr};
58 | std::vector m_ImageList;
59 | std::vector m_CalibrationCache;
60 | };
61 |
62 | #endif
--------------------------------------------------------------------------------
/configs/yolov3-tiny.cfg:
--------------------------------------------------------------------------------
1 | [net]
2 | # Testing
3 | batch=1
4 | subdivisions=1
5 | # Training
6 | # batch=64
7 | # subdivisions=2
8 | width=416
9 | height=416
10 | channels=3
11 | momentum=0.9
12 | decay=0.0005
13 | angle=0
14 | saturation = 1.5
15 | exposure = 1.5
16 | hue=.1
17 |
18 | learning_rate=0.001
19 | burn_in=1000
20 | max_batches = 500200
21 | policy=steps
22 | steps=400000,450000
23 | scales=.1,.1
24 |
25 | [convolutional]
26 | batch_normalize=1
27 | filters=16
28 | size=3
29 | stride=1
30 | pad=1
31 | activation=leaky
32 |
33 | [maxpool]
34 | size=2
35 | stride=2
36 |
37 | [convolutional]
38 | batch_normalize=1
39 | filters=32
40 | size=3
41 | stride=1
42 | pad=1
43 | activation=leaky
44 |
45 | [maxpool]
46 | size=2
47 | stride=2
48 |
49 | [convolutional]
50 | batch_normalize=1
51 | filters=64
52 | size=3
53 | stride=1
54 | pad=1
55 | activation=leaky
56 |
57 | [maxpool]
58 | size=2
59 | stride=2
60 |
61 | [convolutional]
62 | batch_normalize=1
63 | filters=128
64 | size=3
65 | stride=1
66 | pad=1
67 | activation=leaky
68 |
69 | [maxpool]
70 | size=2
71 | stride=2
72 |
73 | [convolutional]
74 | batch_normalize=1
75 | filters=256
76 | size=3
77 | stride=1
78 | pad=1
79 | activation=leaky
80 |
81 | [maxpool]
82 | size=2
83 | stride=2
84 |
85 | [convolutional]
86 | batch_normalize=1
87 | filters=512
88 | size=3
89 | stride=1
90 | pad=1
91 | activation=leaky
92 |
93 | [maxpool]
94 | size=2
95 | stride=1
96 |
97 | [convolutional]
98 | batch_normalize=1
99 | filters=1024
100 | size=3
101 | stride=1
102 | pad=1
103 | activation=leaky
104 |
105 | ###########
106 |
107 | [convolutional]
108 | batch_normalize=1
109 | filters=256
110 | size=1
111 | stride=1
112 | pad=1
113 | activation=leaky
114 |
115 | [convolutional]
116 | batch_normalize=1
117 | filters=512
118 | size=3
119 | stride=1
120 | pad=1
121 | activation=leaky
122 |
123 | [convolutional]
124 | size=1
125 | stride=1
126 | pad=1
127 | filters=255
128 | activation=linear
129 |
130 |
131 |
132 | [yolo]
133 | mask = 3,4,5
134 | anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
135 | classes=80
136 | num=6
137 | jitter=.3
138 | ignore_thresh = .7
139 | truth_thresh = 1
140 | random=1
141 |
142 | [route]
143 | layers = -4
144 |
145 | [convolutional]
146 | batch_normalize=1
147 | filters=128
148 | size=1
149 | stride=1
150 | pad=1
151 | activation=leaky
152 |
153 | [upsample]
154 | stride=2
155 |
156 | [route]
157 | layers = -1, 8
158 |
159 | [convolutional]
160 | batch_normalize=1
161 | filters=256
162 | size=3
163 | stride=1
164 | pad=1
165 | activation=leaky
166 |
167 | [convolutional]
168 | size=1
169 | stride=1
170 | pad=1
171 | filters=255
172 | activation=linear
173 |
174 | [yolo]
175 | mask = 0,1,2
176 | anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
177 | classes=80
178 | num=6
179 | jitter=.3
180 | ignore_thresh = .7
181 | truth_thresh = 1
182 | random=1
183 |
--------------------------------------------------------------------------------
/modules/kernel.cu:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | inline __device__ float sigmoidGPU(const float& x) { return 1.0f / (1.0f + __expf(-x)); }
9 |
10 | __global__ void gpuYoloLayerV3(const float* input, float* output, const uint32_t grid_h_,
11 | const uint32_t grid_w_, const uint32_t numOutputClasses,
12 | const uint32_t numBBoxes)
13 | {
14 | uint32_t x_id = blockIdx.x * blockDim.x + threadIdx.x;
15 | uint32_t y_id = blockIdx.y * blockDim.y + threadIdx.y;
16 | uint32_t z_id = blockIdx.z * blockDim.z + threadIdx.z;
17 |
18 | if ((x_id >= grid_w_) || (y_id >= grid_h_) || (z_id >= numBBoxes))
19 | {
20 | return;
21 | }
22 |
23 | const int numGridCells = grid_h_ * grid_w_;
24 | const int bbindex = y_id * grid_w_ + x_id;
25 |
26 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]
27 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 0)]);
28 |
29 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]
30 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 1)]);
31 |
32 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]
33 | = __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 2)]);
34 |
35 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]
36 | = __expf(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 3)]);
37 |
38 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]
39 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + 4)]);
40 |
41 | for (uint32_t i = 0; i < numOutputClasses; ++i)
42 | {
43 | output[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]
44 | = sigmoidGPU(input[bbindex + numGridCells * (z_id * (5 + numOutputClasses) + (5 + i))]);
45 | }
46 | }
47 |
48 | cudaError_t cudaYoloLayerV3(const void* input, void* output, const uint32_t& batchSize,
49 | const uint32_t& n_grid_h_,const uint32_t& n_grid_w_,
50 | const uint32_t& numOutputClasses, const uint32_t& numBBoxes,
51 | uint64_t outputSize, cudaStream_t stream)
52 | {
53 | dim3 threads_per_block(16, 16, 4);
54 | dim3 number_of_blocks((n_grid_w_ / threads_per_block.x) + 1,
55 | (n_grid_h_ / threads_per_block.y) + 1,
56 | (numBBoxes / threads_per_block.z) + 1);
57 | for (int batch = 0; batch < batchSize; ++batch)
58 | {
59 | gpuYoloLayerV3<<>>(
60 | reinterpret_cast(input) + (batch * outputSize),
61 | reinterpret_cast(output) + (batch * outputSize), n_grid_h_, n_grid_w_, numOutputClasses,
62 | numBBoxes);
63 | }
64 | return cudaGetLastError();
65 | }
--------------------------------------------------------------------------------
/modules/yoloplugin_lib.h:
--------------------------------------------------------------------------------
1 | /**
2 | MIT License
3 |
4 | Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | *
24 | */
25 | #ifndef __YOLOPLUGIN_LIB__
26 | #define __YOLOPLUGIN_LIB__
27 |
28 | //#include
29 |
30 | #include "calibrator.h"
31 | #include "trt_utils.h"
32 | #include "yolo.h"
33 |
34 | //#ifdef __cplusplus
35 | //extern "C" {
36 | //#endif
37 |
38 | #define MAX_OBJECTS_PER_FRAME 32
39 | typedef struct YoloPluginCtx YoloPluginCtx;
40 | typedef struct YoloPluginOutput YoloPluginOutput;
41 | // Init parameters structure as input, required for instantiating yoloplugin_lib
42 | typedef struct
43 | {
44 | // Width at which frame/object will be scaled
45 | int processingWidth;
46 | // height at which frame/object will be scaled
47 | int processingHeight;
48 | // Flag to indicate whether operating on crops of full frame
49 | int fullFrame;
50 | // Plugin config file
51 | std::string configFilePath;
52 | } YoloPluginInitParams;
53 |
54 | struct YoloPluginCtx
55 | {
56 | YoloPluginInitParams initParams;
57 | NetworkInfo networkInfo;
58 | InferParams inferParams;
59 | Yolo* inferenceNetwork;
60 |
61 | // perf vars
62 | float inferTime = 0.0, preTime = 0.0, postTime = 0.0;
63 | uint32_t batchSize = 0;
64 | uint64_t imageCount = 0;
65 | };
66 |
67 | // Detected/Labelled object structure, stores bounding box info along with label
68 | typedef struct
69 | {
70 | int left;
71 | int top;
72 | int width;
73 | int height;
74 | char label[64];
75 | } YoloPluginObject;
76 |
77 | // Output data returned after processing
78 | struct YoloPluginOutput
79 | {
80 | int numObjects;
81 | YoloPluginObject object[MAX_OBJECTS_PER_FRAME];
82 | };
83 |
84 | // Initialize library context
85 | YoloPluginCtx* YoloPluginCtxInit(YoloPluginInitParams* initParams, size_t batchSize);
86 |
87 | // Dequeue processed output
88 | std::vector YoloPluginProcess(YoloPluginCtx* ctx, std::vector& cvmats);
89 |
90 | // Deinitialize library context
91 | void YoloPluginCtxDeinit(YoloPluginCtx* ctx);
92 |
93 | //#ifdef __cplusplus
94 | //}
95 | //#endif
96 |
97 | #endif
98 |
--------------------------------------------------------------------------------
/sln/dll_detector/dll_detector.vcxproj.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Source Files
23 |
24 |
25 | Source Files
26 |
27 |
28 |
29 |
30 | Source Files
31 |
32 |
33 | Source Files
34 |
35 |
36 | Source Files
37 |
38 |
39 | Source Files
40 |
41 |
42 | Source Files
43 |
44 |
45 | Source Files
46 |
47 |
48 | Source Files
49 |
50 |
51 | Source Files
52 |
53 |
54 | Source Files
55 |
56 |
57 | Source Files
58 |
59 |
60 | Source Files
61 |
62 |
63 |
64 |
65 | Source Files
66 |
67 |
68 | Source Files
69 |
70 |
71 | Source Files
72 |
73 |
74 | Source Files
75 |
76 |
77 | Source Files
78 |
79 |
80 |
--------------------------------------------------------------------------------
/modules/chunk.h:
--------------------------------------------------------------------------------
1 | #ifndef CHUNK_H_
2 | #define CHUNK_H_
3 |
4 | //#include "NvInfer.h"
5 | //#include "NvInferPlugin.h"
6 | //#include "NvInferRuntimeCommon.h"
7 | //#include
8 | //#include
9 | //#include
10 | //#include
11 | //#include
12 | //#include
13 | //#include
14 |
15 | #include
16 | #include
17 | #include "NvInfer.h"
18 |
19 | namespace nvinfer1
20 | {
21 | class Chunk : public IPluginV2
22 | {
23 | public:
24 | Chunk();
25 | Chunk(const void* buffer, size_t length);
26 | ~Chunk();
27 | int getNbOutputs()const noexcept override;
28 | Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims)noexcept override;
29 | int initialize()noexcept override;
30 | void terminate()noexcept override;
31 | size_t getWorkspaceSize(int maxBatchSize) const noexcept override;
32 | // int enqueue(int batchSize, const void* const* inputs, void** outputs, void* workspace, cudaStream_t stream)noexcept override;
33 |
34 | int enqueue(int batchSize, const void* const* inputs, void* const* outputs, void* workspace,
35 | cudaStream_t stream) noexcept override;
36 |
37 | size_t getSerializationSize() const noexcept override;
38 | void serialize(void* buffer) const noexcept override;
39 | const char* getPluginType() const noexcept override;
40 | const char* getPluginVersion() const noexcept override;
41 | void destroy()noexcept override;
42 | void setPluginNamespace(const char* pluginNamespace)noexcept override;
43 | const char* getPluginNamespace() const noexcept override;
44 | DataType getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const noexcept;
45 | bool isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const noexcept;
46 | bool canBroadcastInputAcrossBatch(int inputIndex) const noexcept;
47 | void attachToContext(
48 | cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator);
49 | void configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput);
50 | void detachFromContext();
51 | bool supportsFormatCombination(int pos, const PluginTensorDesc* inOut, int nbInputs, int nbOutputs) const
52 | {
53 | return inOut[pos].format == TensorFormat::kLINEAR && inOut[pos].type == DataType::kFLOAT;
54 | }
55 | IPluginV2* clone() const noexcept override;
56 | bool supportsFormat(DataType type, PluginFormat format) const noexcept override;
57 | void configureWithFormat(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, DataType type, PluginFormat format, int maxBatchSize) noexcept override;
58 |
59 | private:
60 | std::string _s_plugin_namespace;
61 | int _n_size_split;
62 | };
63 |
64 | class ChunkPluginCreator : public IPluginCreator
65 | {
66 | public:
67 | ChunkPluginCreator();
68 | ~ChunkPluginCreator() override = default;
69 | const char* getPluginName()const noexcept override;
70 | const char* getPluginVersion() const noexcept override;
71 | const PluginFieldCollection* getFieldNames()noexcept override;
72 | IPluginV2* createPlugin(const char* name, const PluginFieldCollection* fc)noexcept override;
73 | IPluginV2* deserializePlugin(const char* name, const void* serialData, size_t serialLength)noexcept override;
74 | void setPluginNamespace(const char* libNamespace)noexcept override;
75 | const char* getPluginNamespace() const noexcept override;
76 | private:
77 | std::string _s_name_space;
78 | static PluginFieldCollection _fc;
79 | static std::vector _vec_plugin_attributes;
80 | };
81 |
82 | }//nampespace nvinfer1
83 |
84 |
85 | #endif
86 |
87 |
88 |
--------------------------------------------------------------------------------
/scripts/yaml2cfg.py:
--------------------------------------------------------------------------------
1 | import torch
2 | import argparse
3 | from utils.downloads import *
4 | import struct
5 | import yaml
6 |
7 | def yaml2cfg(opt):
8 | with open(opt.yaml,'r') as f:
9 | with open(opt.yaml.split(".")[0]+".cfg", 'w') as cfg:
10 | f = yaml.load(f,Loader=yaml.FullLoader)
11 | net = 0
12 | for k in f:
13 | if ((k != 'anchors')and(k !='backbone')and(k !='head')):
14 | if net == 0:
15 | cfg.write('\n[net]\n')
16 | cfg.write("width={}\n".format(opt.net_w))
17 | cfg.write("height={}\n".format(opt.net_h))
18 | cfg.write("channels={}\n".format(3))
19 | cfg.write("batch={}\n".format(opt.batch))
20 | net =1
21 | cfg.write("{}={}\n".format(k,f[k]))
22 | elif (k == 'anchors'):
23 | anchors = []
24 | for v in f[k]:
25 | anchors.extend(v)
26 | cfg.write("anchors={}\n".format(str(anchors)[1:-1]))
27 | elif((k == 'backbone') or (k =='head')):
28 | for vector in f[k]:
29 | #net type
30 | cfg.write('\n[{}]\n'.format(vector[2]))
31 | #from
32 | if type(vector[0]) == int:
33 | cfg.write("from={}\n".format(str(vector[0])))
34 | elif type(vector[0]) == list:
35 | cfg.write("from={}\n".format(str(vector[0])[1:-1]))
36 | #number
37 | if type(vector[1]) == int:
38 | cfg.write("number={}\n".format(str(vector[1])))
39 | elif type(vector[1]) == list:
40 | cfg.write("number={}\n".format(str(vector[1])[1:-1]))
41 | #params
42 | if type(vector[3]) == int:
43 | cfg.write("args={}\n".format(str(vector[3])))
44 | elif type(vector[3]) == list:
45 | cfg.write("args={}\n".format(str(vector[3])[1:-1]))
46 |
47 | def pt2weight(weights):
48 | model = torch.load(weights, map_location="cpu")['model'].eval().float()
49 | with open(weights.split(".")[0]+".weights",'w') as f:
50 | for k,v in model.state_dict().items():
51 | list_data = list(v.reshape(-1).numpy())
52 | f.write('{}'.format(k))
53 | for value in list_data:
54 | f.write(" ")
55 | f.write(struct.pack('>f',float(value)).hex())
56 | f.write('\n')
57 |
58 |
59 | if __name__ == '__main__':
60 | parser = argparse.ArgumentParser()
61 | parser.add_argument('--weights', type=str, default='weights/yolov5s.pt', help='model.pt path')
62 | parser.add_argument('--yaml', type=str, default='models/yolov5s.yaml', help='model.yaml path')
63 | parser.add_argument('--net_w', type=int, default=640, help='net width (pixels)')
64 | parser.add_argument('--net_h', type=int, default=320, help='net height (pixels)')
65 | parser.add_argument('--batch', type=int, default=1, help='inference batch size')
66 | parser.add_argument('--classes', type=int,default=80, help='filter by class: --class 0, or --class 0 2 3')
67 | opt = parser.parse_args()
68 | print(opt)
69 | attempt_download(opt.weights)
70 | yaml2cfg(opt)
71 | print("convert {} to {} success".format(opt.yaml,opt.yaml.split(".")[0]+".cfg"))
72 | pt2weight(opt.weights)
73 | print("convert {} to {} success".format(opt.weights,opt.weights.split(".")[0]+".weights"))
74 | print("complete")
--------------------------------------------------------------------------------
/modules/yolov3.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | MIT License
3 |
4 | Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | *
24 | */
25 | #include "yolov3.h"
26 |
27 | YoloV3::YoloV3(const NetworkInfo& networkInfo,
28 | const InferParams& inferParams) :
29 | Yolo( networkInfo, inferParams){}
30 |
31 | std::vector YoloV3::decodeTensor(const int imageIdx,
32 | const int imageH,
33 | const int imageW,
34 | const TensorInfo& tensor)
35 | {
36 | float scale_h = 1.f;
37 | float scale_w = 1.f;
38 | int xOffset = 0;
39 | int yOffset = 0;
40 |
41 | const float* detections = &tensor.hostBuffer[imageIdx * tensor.volume];
42 |
43 | std::vector binfo;
44 | for (uint32_t y = 0; y < tensor.grid_h; ++y)
45 | {
46 | for (uint32_t x = 0; x < tensor.grid_w; ++x)
47 | {
48 | for (uint32_t b = 0; b < tensor.numBBoxes; ++b)
49 | {
50 | const float pw = tensor.anchors[tensor.masks[b] * 2];
51 | const float ph = tensor.anchors[tensor.masks[b] * 2 + 1];
52 |
53 | const int numGridCells = tensor.grid_h * tensor.grid_w;
54 | const int bbindex = y * tensor.grid_w+ x;
55 | const float bx
56 | = x + detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 0)];
57 |
58 | const float by
59 | = y + detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 1)];
60 | const float bw
61 | = pw * detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 2)];
62 | const float bh
63 | = ph * detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 3)];
64 |
65 | const float objectness
66 | = detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 4)];
67 |
68 | float maxProb = 0.0f;
69 | int maxIndex = -1;
70 |
71 | for (uint32_t i = 0; i < tensor.numClasses; ++i)
72 | {
73 | float prob
74 | = (detections[bbindex
75 | + numGridCells * (b * (5 + tensor.numClasses) + (5 + i))]);
76 |
77 | if (prob > maxProb)
78 | {
79 | maxProb = prob;
80 | maxIndex = i;
81 | }
82 | }
83 | maxProb = objectness * maxProb;
84 |
85 | if (maxProb > m_ProbThresh)
86 | {
87 | add_bbox_proposal(bx, by, bw, bh, tensor.stride_h, tensor.stride_w, scale_h, scale_w, xOffset, yOffset, maxIndex, maxProb, imageW, imageH, binfo);
88 | }
89 | }
90 | }
91 | }
92 | return binfo;
93 | }
94 |
--------------------------------------------------------------------------------
/modules/yolov2.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | MIT License
3 |
4 | Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | *
24 | */
25 |
26 | #include "yolov2.h"
27 | #include
28 |
29 | YoloV2::YoloV2(const NetworkInfo& networkInfo,
30 | const InferParams& inferParams) :
31 | Yolo(networkInfo, inferParams){}
32 |
33 | std::vector YoloV2::decodeTensor(const int imageIdx, const int imageH, const int imageW,
34 | const TensorInfo& tensor)
35 | {
36 | float scalingFactor
37 | = std::min(static_cast(m_InputW) / imageW, static_cast(m_InputH) / imageH);
38 | float xOffset = (m_InputW - scalingFactor * imageW) / 2;
39 | float yOffset = (m_InputH - scalingFactor * imageH) / 2;
40 |
41 | float* detections = &tensor.hostBuffer[imageIdx * tensor.volume];
42 |
43 | std::vector binfo;
44 | for (uint32_t y = 0; y < tensor.gridSize; y++)
45 | {
46 | for (uint32_t x = 0; x < tensor.gridSize; x++)
47 | {
48 | for (uint32_t b = 0; b < tensor.numBBoxes; b++)
49 | {
50 | const float pw = tensor.anchors[2 * b];
51 | const float ph = tensor.anchors[2 * b + 1];
52 | const int numGridCells = tensor.gridSize * tensor.gridSize;
53 | const int bbindex = y * tensor.gridSize + x;
54 | const float bx
55 | = x + detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 0)];
56 | const float by
57 | = y + detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 1)];
58 | const float bw = pw
59 | * exp(detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 2)]);
60 | const float bh = ph
61 | * exp(detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 3)]);
62 |
63 | const float objectness
64 | = detections[bbindex + numGridCells * (b * (5 + tensor.numClasses) + 4)];
65 | float maxProb = 0.0f;
66 | int maxIndex = -1;
67 |
68 | for (uint32_t i = 0; i < tensor.numClasses; i++)
69 | {
70 | float prob
71 | = detections[bbindex
72 | + numGridCells * (b * (5 + tensor.numClasses) + (5 + i))];
73 |
74 | if (prob > maxProb)
75 | {
76 | maxProb = prob;
77 | maxIndex = i;
78 | }
79 | }
80 |
81 | maxProb = objectness * maxProb;
82 |
83 | if (maxProb > m_ProbThresh)
84 | {
85 | addBBoxProposal(bx, by, bw, bh, tensor.stride, scalingFactor, xOffset, yOffset,
86 | maxIndex, maxProb,imageW,imageH, binfo);
87 | }
88 | }
89 | }
90 | }
91 | return binfo;
92 | }
93 |
--------------------------------------------------------------------------------
/modules/decodeTensorCUDA.cu:
--------------------------------------------------------------------------------
1 | #include "decodeTensorCUDA.h"
2 | __global__ void decodeTensorKernel(
3 | float* detections, uint32_t* masks, float* anchors, float* boxes, uint32_t grid_h, uint32_t grid_w, uint32_t numClasses, uint32_t numBBoxes)
4 | {
5 | // get idx
6 | uint32_t y = blockIdx.y * blockDim.y + threadIdx.y;
7 | uint32_t x = blockIdx.x * blockDim.x + threadIdx.x;
8 | if (y >= grid_h || x >= grid_w) return;
9 |
10 | const int numGridCells = grid_h * grid_w;
11 |
12 | for (uint32_t b = 0; b < numBBoxes; ++b)
13 | {
14 | const float pw = anchors[masks[b] * 2];
15 | const float ph = anchors[masks[b] * 2 + 1];
16 |
17 | // printf("pw %f, ph %f \n", pw, ph);
18 | const uint32_t bbindex = y * grid_w + x;
19 | boxes[18 * bbindex + 6 * b + 0] = x + detections[bbindex + numGridCells * (b * (5 + numClasses) + 0)];
20 |
21 | boxes[18 * bbindex + 6 * b + 1] = y + detections[bbindex + numGridCells * (b * (5 + numClasses) + 1)];
22 | boxes[18 * bbindex + 6 * b + 2] = pw * detections[bbindex + numGridCells * (b * (5 + numClasses) + 2)];
23 | boxes[18 * bbindex + 6 * b + 3] = ph * detections[bbindex + numGridCells * (b * (5 + numClasses) + 3)];
24 |
25 | // printf("x %f y %f w %f h %f\n", boxes[18 * bbindex + 6 * b + 0], boxes[18 * bbindex + 6 * b + 1], boxes[18 * bbindex + 6 * b + 2], boxes[18 * bbindex + 6 * b + 3]);
26 |
27 | const float objectness = detections[bbindex + numGridCells * (b * (5 + numClasses) + 4)];
28 | float maxProb = 0.0f;
29 | int maxIndex = -1;
30 |
31 | for (uint32_t i = 0; i < numClasses; ++i)
32 | {
33 | float prob = detections[bbindex + numGridCells * (b * (5 + numClasses) + (5 + i))];
34 |
35 | if (prob > maxProb)
36 | {
37 | maxProb = prob;
38 | maxIndex = i;
39 | }
40 | }
41 | // printf("objectness * maxProb %f , objectness %f , maxProb %f \n", objectness * maxProb, objectness, maxProb);
42 | boxes[18 * bbindex + 6 * b + 4] = objectness * maxProb;
43 | boxes[18 * bbindex + 6 * b + 5] = (float) maxIndex;
44 | }
45 | }
46 |
47 | float* decodeTensorCUDA(const int imageIdx, const TensorInfo& tensor)
48 | {
49 | // host
50 | int boxes_bytes = 6*sizeof(float)*tensor.grid_h*tensor.grid_w*tensor.numBBoxes; // x y w h maxProb maxIndex 6个元素
51 | const float* detections = &tensor.hostBuffer[imageIdx * tensor.volume];
52 | float* boxes = (float*) malloc(boxes_bytes);
53 |
54 | uint32_t grid_h = tensor.grid_h;
55 | uint32_t grid_w = tensor.grid_w;
56 | uint32_t numClasses = tensor.numClasses;
57 | uint32_t numBBoxes = tensor.numBBoxes;
58 |
59 | // device
60 | float* d_detections;
61 | int detections_bytes = sizeof(float) * grid_h * grid_w * (5 + numClasses) * numBBoxes;
62 | cudaMalloc((void**) &d_detections, detections_bytes);
63 | cudaMemcpy((void*) d_detections, (void*) detections, detections_bytes, cudaMemcpyHostToDevice);
64 |
65 | uint32_t* d_masks;
66 | cudaMalloc((void**) &d_masks, sizeof(uint32_t)*numBBoxes);
67 | cudaMemcpy((void*) d_masks, (void*) &tensor.masks[0], sizeof(uint32_t)*numBBoxes, cudaMemcpyHostToDevice);
68 |
69 | float* d_anchors;
70 | cudaMalloc((void**) &d_anchors, sizeof(float)*tensor.anchors.size());
71 | cudaMemcpy((void*) d_anchors, (void*) &tensor.anchors[0], sizeof(float)*tensor.anchors.size(), cudaMemcpyHostToDevice);
72 |
73 | float* d_boxes;
74 | cudaMalloc((void**) &d_boxes, boxes_bytes);
75 |
76 | // CUDA Grid and Block
77 | dim3 threads_per_block(20, 20);
78 | dim3 number_of_blocks((tensor.grid_w / threads_per_block.x) + 1, (tensor.grid_h / threads_per_block.y) + 1);
79 |
80 | // start kernel
81 | decodeTensorKernel<<>>(d_detections, d_masks, d_anchors, d_boxes, grid_h, grid_w, numClasses, numBBoxes);
82 |
83 | // asynchronous copy
84 | cudaMemcpyAsync((void*) boxes, (void*) d_boxes, boxes_bytes, cudaMemcpyDeviceToHost);
85 |
86 | // wait for kernel
87 | cudaDeviceSynchronize();
88 |
89 | // free memory
90 | cudaFree(d_detections);
91 | cudaFree(d_masks);
92 | cudaFree(d_anchors);
93 | cudaFree(d_boxes);
94 |
95 | // decode results
96 | return boxes;
97 | }
98 |
--------------------------------------------------------------------------------
/modules/hardswish.h:
--------------------------------------------------------------------------------
1 |
2 | #ifndef _HARDSWISH_H_
3 | #define _HARDSWISH_H_
4 |
5 | #include
6 | #include
7 | #include "NvInfer.h"
8 |
9 | namespace nvinfer1
10 | {
11 | template
12 | void w(char*& buffer, const T& val)
13 | {
14 | *reinterpret_cast(buffer) = val;
15 | buffer += sizeof(T);
16 | }
17 |
18 | template
19 | void r(const char*& buffer, T& val)
20 | {
21 | val = *reinterpret_cast(buffer);
22 | buffer += sizeof(T);
23 | }
24 |
25 | class Hardswish :public IPluginV2
26 | {
27 | public:
28 | Hardswish();
29 | Hardswish(const void* data, size_t length);
30 | ~Hardswish();
31 | int getNbOutputs()const noexcept override
32 | {
33 | return 1;
34 | }
35 | Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) noexcept override
36 | {
37 | return inputs[0];
38 | }
39 | int initialize() noexcept override
40 | {
41 | return 0;
42 | }
43 | void terminate() noexcept override
44 | {
45 | }
46 | size_t getWorkspaceSize(int maxBatchSize) const noexcept override
47 | {
48 | return 0;
49 | }
50 |
51 | bool supportsFormat(DataType type, PluginFormat format) const noexcept override;
52 | void configureWithFormat(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, DataType type, PluginFormat format, int maxBatchSize) noexcept override;
53 |
54 | int enqueue(int batchSize, const void* const* inputs, void* const* outputs, void* workspace,
55 | cudaStream_t stream) noexcept override;
56 |
57 | size_t getSerializationSize() const noexcept override;
58 | void serialize(void* buffer) const noexcept override;
59 | const char* getPluginType() const noexcept override
60 | {
61 | return "HARDSWISH_TRT";
62 | }
63 | const char* getPluginVersion() const noexcept override
64 | {
65 | return "1.0";
66 | }
67 | void destroy() noexcept override
68 | {
69 | delete this;
70 | }
71 | void setPluginNamespace(const char* pluginNamespace) noexcept override
72 | {
73 | _s_plugin_namespace = pluginNamespace;
74 | }
75 | const char* getPluginNamespace() const noexcept override
76 | {
77 | return _s_plugin_namespace.c_str();
78 | }
79 | DataType getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const noexcept
80 | {
81 | return DataType::kFLOAT;
82 | }
83 | bool isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const noexcept
84 | {
85 | return false;
86 | }
87 | bool canBroadcastInputAcrossBatch(int inputIndex) const noexcept
88 | {
89 | return false;
90 | }
91 | void attachToContext(
92 | cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator) noexcept
93 | {}
94 | void configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) noexcept;
95 | void detachFromContext() noexcept
96 | {}
97 | bool supportsFormatCombination(int pos, const PluginTensorDesc* inOut, int nbInputs, int nbOutputs) const noexcept
98 | {
99 | return inOut[pos].format == TensorFormat::kLINEAR && inOut[pos].type == DataType::kFLOAT;
100 | }
101 | IPluginV2* clone() const noexcept override;
102 | private:
103 |
104 | uint32_t _n_max_thread_pre_block;
105 | uint32_t _n_output_size;
106 | std::string _s_plugin_namespace;
107 | }; //end detect
108 |
109 | class HardswishPluginCreator : public IPluginCreator
110 | {
111 | public:
112 | HardswishPluginCreator();
113 | ~HardswishPluginCreator() override = default;
114 | const char* getPluginName()const noexcept override;
115 | const char* getPluginVersion() const noexcept override;
116 | const PluginFieldCollection* getFieldNames() noexcept override;
117 | IPluginV2* createPlugin(const char* name, const PluginFieldCollection* fc) noexcept override;
118 | IPluginV2* deserializePlugin(const char* name, const void* serialData, size_t serialLength) noexcept override;
119 | void setPluginNamespace(const char* libNamespace) noexcept override;
120 | const char* getPluginNamespace() const noexcept override;
121 | private:
122 | std::string _s_name_space;
123 | static PluginFieldCollection _fc;
124 | static std::vector _vec_plugin_attributes;
125 | };//end detect creator
126 |
127 | }//end namespace nvinfer1
128 |
129 |
130 |
131 | #endif
--------------------------------------------------------------------------------
/modules/mish.h:
--------------------------------------------------------------------------------
1 | #ifndef _MISH_PLUGIN_H
2 | #define _MISH_PLUGIN_H
3 |
4 | #include
5 | #include
6 | #include "NvInfer.h"
7 |
8 |
9 | //https://github.com/wang-xinyu/tensorrtx
10 | namespace nvinfer1
11 | {
12 | class MishPlugin: public IPluginV2
13 | {
14 | public:
15 | explicit MishPlugin();
16 | MishPlugin(const void* data, size_t length);
17 |
18 | ~MishPlugin();
19 |
20 | int getNbOutputs() const noexcept override
21 | {
22 | return 1;
23 | }
24 |
25 | Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) noexcept override;
26 |
27 | int initialize() noexcept override;
28 |
29 | virtual void terminate() noexcept override {}
30 |
31 | virtual size_t getWorkspaceSize(int maxBatchSize) const noexcept override { return 0;}
32 |
33 | // virtual int enqueue(int batchSize, const void*const * inputs, void** outputs, void* workspace, cudaStream_t stream);
34 | int enqueue(int batchSize, const void* const* inputs, void* const* outputs, void* workspace,
35 | cudaStream_t stream) noexcept override;
36 | bool supportsFormat(DataType type, PluginFormat format) const noexcept override;
37 | void configureWithFormat(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, DataType type, PluginFormat format, int maxBatchSize) noexcept override;
38 |
39 | virtual size_t getSerializationSize() const noexcept override;
40 |
41 | virtual void serialize(void* buffer) const noexcept override;
42 |
43 | bool supportsFormatCombination(int pos, const PluginTensorDesc* inOut, int nbInputs, int nbOutputs) const noexcept {
44 | return inOut[pos].format == TensorFormat::kLINEAR && inOut[pos].type == DataType::kFLOAT;
45 | }
46 |
47 | const char* getPluginType() const noexcept override;
48 |
49 | const char* getPluginVersion() const noexcept override;
50 |
51 | void destroy() noexcept override;
52 |
53 | IPluginV2* clone() const noexcept override;
54 |
55 | void setPluginNamespace(const char* pluginNamespace) noexcept override;
56 |
57 | const char* getPluginNamespace() const noexcept override;
58 |
59 | DataType getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const noexcept;
60 |
61 | bool isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const noexcept;
62 |
63 | bool canBroadcastInputAcrossBatch(int inputIndex) const noexcept;
64 |
65 | void attachToContext(
66 | cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator)noexcept;
67 |
68 | void configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput)noexcept;
69 |
70 | void detachFromContext()noexcept;
71 |
72 | int input_size_;
73 | private:
74 | void forwardGpu(const float *const * inputs, float* output, cudaStream_t stream, int batchSize = 1);
75 | int thread_count_ = 256;
76 | const char* mPluginNamespace;
77 | };
78 |
79 | class MishPluginCreator : public IPluginCreator
80 | {
81 | public:
82 | MishPluginCreator();
83 |
84 | ~MishPluginCreator() override = default;
85 |
86 | const char* getPluginName() const noexcept override;
87 |
88 | const char* getPluginVersion() const noexcept override;
89 |
90 | const PluginFieldCollection* getFieldNames() noexcept override;
91 |
92 | IPluginV2* createPlugin(const char* name, const PluginFieldCollection* fc) noexcept override;
93 |
94 | IPluginV2* deserializePlugin(const char* name, const void* serialData, size_t serialLength) noexcept override;
95 |
96 | void setPluginNamespace(const char* libNamespace) noexcept override;
97 |
98 | const char* getPluginNamespace() const noexcept override;
99 |
100 | private:
101 | std::string mNamespace;
102 | static PluginFieldCollection mFC;
103 | static std::vector mPluginAttributes;
104 | };
105 | }
106 | #endif
107 |
--------------------------------------------------------------------------------
/configs/yolov4-tiny.cfg:
--------------------------------------------------------------------------------
1 | [net]
2 | # Testing
3 | batch=2
4 | subdivisions=1
5 | # Training
6 | #batch=64
7 | #subdivisions=1
8 | width=416
9 | height=320
10 | channels=3
11 | momentum=0.9
12 | decay=0.0005
13 | angle=0
14 | saturation = 1.5
15 | exposure = 1.5
16 | hue=.1
17 |
18 | learning_rate=0.00261
19 | burn_in=1000
20 | max_batches = 500200
21 | policy=steps
22 | steps=400000,450000
23 | scales=.1,.1
24 |
25 | [convolutional]
26 | batch_normalize=1
27 | filters=32
28 | size=3
29 | stride=2
30 | pad=1
31 | activation=leaky
32 |
33 | [convolutional]
34 | batch_normalize=1
35 | filters=64
36 | size=3
37 | stride=2
38 | pad=1
39 | activation=leaky
40 |
41 | [convolutional]
42 | batch_normalize=1
43 | filters=64
44 | size=3
45 | stride=1
46 | pad=1
47 | activation=leaky
48 |
49 | [route]
50 | layers=-1
51 | groups=2
52 | group_id=1
53 |
54 | [convolutional]
55 | batch_normalize=1
56 | filters=32
57 | size=3
58 | stride=1
59 | pad=1
60 | activation=leaky
61 |
62 | [convolutional]
63 | batch_normalize=1
64 | filters=32
65 | size=3
66 | stride=1
67 | pad=1
68 | activation=leaky
69 |
70 | [route]
71 | layers = -1,-2
72 |
73 | [convolutional]
74 | batch_normalize=1
75 | filters=64
76 | size=1
77 | stride=1
78 | pad=1
79 | activation=leaky
80 |
81 | [route]
82 | layers = -6,-1
83 |
84 | [maxpool]
85 | size=2
86 | stride=2
87 |
88 | [convolutional]
89 | batch_normalize=1
90 | filters=128
91 | size=3
92 | stride=1
93 | pad=1
94 | activation=leaky
95 |
96 | [route]
97 | layers=-1
98 | groups=2
99 | group_id=1
100 |
101 | [convolutional]
102 | batch_normalize=1
103 | filters=64
104 | size=3
105 | stride=1
106 | pad=1
107 | activation=leaky
108 |
109 | [convolutional]
110 | batch_normalize=1
111 | filters=64
112 | size=3
113 | stride=1
114 | pad=1
115 | activation=leaky
116 |
117 | [route]
118 | layers = -1,-2
119 |
120 | [convolutional]
121 | batch_normalize=1
122 | filters=128
123 | size=1
124 | stride=1
125 | pad=1
126 | activation=leaky
127 |
128 | [route]
129 | layers = -6,-1
130 |
131 | [maxpool]
132 | size=2
133 | stride=2
134 |
135 | [convolutional]
136 | batch_normalize=1
137 | filters=256
138 | size=3
139 | stride=1
140 | pad=1
141 | activation=leaky
142 |
143 | [route]
144 | layers=-1
145 | groups=2
146 | group_id=1
147 |
148 | [convolutional]
149 | batch_normalize=1
150 | filters=128
151 | size=3
152 | stride=1
153 | pad=1
154 | activation=leaky
155 |
156 | [convolutional]
157 | batch_normalize=1
158 | filters=128
159 | size=3
160 | stride=1
161 | pad=1
162 | activation=leaky
163 |
164 | [route]
165 | layers = -1,-2
166 |
167 | [convolutional]
168 | batch_normalize=1
169 | filters=256
170 | size=1
171 | stride=1
172 | pad=1
173 | activation=leaky
174 |
175 | [route]
176 | layers = -6,-1
177 |
178 | [maxpool]
179 | size=2
180 | stride=2
181 |
182 | [convolutional]
183 | batch_normalize=1
184 | filters=512
185 | size=3
186 | stride=1
187 | pad=1
188 | activation=leaky
189 |
190 | ##################################
191 |
192 | [convolutional]
193 | batch_normalize=1
194 | filters=256
195 | size=1
196 | stride=1
197 | pad=1
198 | activation=leaky
199 |
200 | [convolutional]
201 | batch_normalize=1
202 | filters=512
203 | size=3
204 | stride=1
205 | pad=1
206 | activation=leaky
207 |
208 | [convolutional]
209 | size=1
210 | stride=1
211 | pad=1
212 | filters=255
213 | activation=linear
214 |
215 |
216 |
217 | [yolo]
218 | mask = 3,4,5
219 | anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
220 | classes=80
221 | num=6
222 | jitter=.3
223 | scale_x_y = 1.05
224 | cls_normalizer=1.0
225 | iou_normalizer=0.07
226 | iou_loss=ciou
227 | ignore_thresh = .7
228 | truth_thresh = 1
229 | random=0
230 | resize=1.5
231 | nms_kind=greedynms
232 | beta_nms=0.6
233 |
234 | [route]
235 | layers = -4
236 |
237 | [convolutional]
238 | batch_normalize=1
239 | filters=128
240 | size=1
241 | stride=1
242 | pad=1
243 | activation=leaky
244 |
245 | [upsample]
246 | stride=2
247 |
248 | [route]
249 | layers = -1, 23
250 |
251 | [convolutional]
252 | batch_normalize=1
253 | filters=256
254 | size=3
255 | stride=1
256 | pad=1
257 | activation=leaky
258 |
259 | [convolutional]
260 | size=1
261 | stride=1
262 | pad=1
263 | filters=255
264 | activation=linear
265 |
266 | [yolo]
267 | mask = 1,2,3
268 | anchors = 10,14, 23,27, 37,58, 81,82, 135,169, 344,319
269 | classes=80
270 | num=6
271 | jitter=.3
272 | scale_x_y = 1.05
273 | cls_normalizer=1.0
274 | iou_normalizer=0.07
275 | iou_loss=ciou
276 | ignore_thresh = .7
277 | truth_thresh = 1
278 | random=0
279 | resize=1.5
280 | nms_kind=greedynms
281 | beta_nms=0.6
282 |
--------------------------------------------------------------------------------
/modules/detect.h:
--------------------------------------------------------------------------------
1 | #ifndef _DETECT_H_
2 | #define _DETECT_H_
3 |
4 | #include
5 | #include
6 | #include "NvInfer.h"
7 |
8 | namespace nvinfer1
9 | {
10 | template
11 | void write(char*& buffer, const T& val)
12 | {
13 | *reinterpret_cast(buffer) = val;
14 | buffer += sizeof(T);
15 | }
16 |
17 | template
18 | void read(const char*& buffer, T& val)
19 | {
20 | val = *reinterpret_cast(buffer);
21 | buffer += sizeof(T);
22 | }
23 |
24 | class Detect :public IPluginV2
25 | {
26 | public:
27 | Detect();
28 | Detect(const void* data, size_t length);
29 | Detect(const uint32_t n_anchor_, const uint32_t _n_classes_,
30 | const uint32_t n_grid_h_, const uint32_t n_grid_w_/*,
31 | const uint32_t &n_stride_h_, const uint32_t &n_stride_w_*/);
32 | ~Detect();
33 | int getNbOutputs()const noexcept override
34 | {
35 | return 1;
36 | }
37 | Dims getOutputDimensions(int index, const Dims* inputs, int nbInputDims) noexcept override
38 | {
39 | return inputs[0];
40 | }
41 | int initialize() noexcept override
42 | {
43 | return 0;
44 | }
45 | void terminate() noexcept override
46 | {
47 | }
48 | size_t getWorkspaceSize(int maxBatchSize) const noexcept override
49 | {
50 | return 0;
51 | }
52 | int enqueue(int batchSize, const void* const* inputs, void* const* outputs, void* workspace,
53 | cudaStream_t stream) noexcept override;
54 |
55 | bool supportsFormat(DataType type, PluginFormat format) const noexcept override;
56 | void configureWithFormat(const Dims* inputDims, int nbInputs, const Dims* outputDims, int nbOutputs, DataType type, PluginFormat format, int maxBatchSize) noexcept override;
57 |
58 | size_t getSerializationSize() const noexcept override;
59 | void serialize(void* buffer) const noexcept override;
60 | const char* getPluginType() const noexcept override
61 | {
62 | return "DETECT_TRT";
63 | }
64 | const char* getPluginVersion() const noexcept override
65 | {
66 | return "1.0";
67 | }
68 | void destroy() noexcept override
69 | {
70 | delete this;
71 | }
72 | void setPluginNamespace(const char* pluginNamespace) noexcept override
73 | {
74 | _s_plugin_namespace = pluginNamespace;
75 | }
76 | const char* getPluginNamespace() const noexcept override
77 | {
78 | return _s_plugin_namespace.c_str();
79 | }
80 | DataType getOutputDataType(int index, const nvinfer1::DataType* inputTypes, int nbInputs) const noexcept
81 | {
82 | return DataType::kFLOAT;
83 | }
84 | bool isOutputBroadcastAcrossBatch(int outputIndex, const bool* inputIsBroadcasted, int nbInputs) const noexcept
85 | {
86 | return false;
87 | }
88 | bool canBroadcastInputAcrossBatch(int inputIndex) const noexcept
89 | {
90 | return false;
91 | }
92 | void attachToContext(
93 | cudnnContext* cudnnContext, cublasContext* cublasContext, IGpuAllocator* gpuAllocator)
94 | {}
95 | void configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) ;
96 | void detachFromContext()
97 | {}
98 | bool supportsFormatCombination(int pos, const PluginTensorDesc* inOut, int nbInputs, int nbOutputs) const noexcept
99 | {
100 | return inOut[pos].format == TensorFormat::kLINEAR && inOut[pos].type == DataType::kFLOAT;
101 | }
102 | IPluginV2* clone() const noexcept override;
103 | private:
104 |
105 | uint32_t _n_anchor;
106 | uint32_t _n_classes;
107 | uint32_t _n_grid_h;
108 | uint32_t _n_grid_w;
109 | //uint32_t _n_stride_h;
110 | // uint32_t _n_stride_w;
111 | uint64_t _n_output_size;
112 | std::string _s_plugin_namespace;
113 | }; //end detect
114 |
115 | class DetectPluginCreator : public IPluginCreator
116 | {
117 | public:
118 | DetectPluginCreator();
119 | ~DetectPluginCreator() override = default;
120 | const char* getPluginName()const noexcept override;
121 | const char* getPluginVersion() const noexcept override;
122 | const PluginFieldCollection* getFieldNames() noexcept override;
123 | IPluginV2* createPlugin(const char* name, const PluginFieldCollection* fc) noexcept override;
124 | IPluginV2* deserializePlugin(const char* name, const void* serialData, size_t serialLength) noexcept override;
125 | void setPluginNamespace(const char* libNamespace) noexcept override;
126 | const char* getPluginNamespace() const noexcept override;
127 | private:
128 | std::string _s_name_space;
129 | static PluginFieldCollection _fc;
130 | static std::vector _vec_plugin_attributes;
131 | };//end detect creator
132 |
133 | }//end namespace nvinfer1
134 |
135 |
136 |
137 | #endif
138 |
--------------------------------------------------------------------------------
/modules/class_yolo_detector.hpp:
--------------------------------------------------------------------------------
1 | #ifndef CLASS_YOLO_DETECTOR_HPP_
2 | #define CLASS_YOLO_DETECTOR_HPP_
3 |
4 | #include
5 | #include "ds_image.h"
6 | #include "trt_utils.h"
7 | #include "yolo.h"
8 | #include "yolov2.h"
9 | #include "yolov3.h"
10 | #include "yolov4.h"
11 | #include "yolov5.h"
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include /* defines FILENAME_MAX */
18 |
19 | #include "class_detector.h"
20 | #include "class_timer.hpp"
21 | class YoloDectector
22 | {
23 | public:
24 | YoloDectector()
25 | {
26 |
27 | }
28 | ~YoloDectector()
29 | {
30 |
31 | }
32 |
33 | void init(const Config &config)
34 | {
35 | _config = config;
36 |
37 | this->set_gpu_id(_config.gpu_id);
38 |
39 | this->parse_config();
40 |
41 | this->build_net();
42 | }
43 |
44 | void detect(const std::vector &vec_image,
45 | std::vector &vec_batch_result)
46 | {
47 | Timer timer;
48 | std::vector vec_ds_images;
49 | vec_batch_result.clear();
50 | vec_batch_result.resize(vec_image.size());
51 | for (const auto &img:vec_image)
52 | {
53 | vec_ds_images.emplace_back(img, _vec_net_type[_config.net_type], _p_net->getInputH(), _p_net->getInputW());
54 | }
55 | cv::Mat trtInput = blobFromDsImages(vec_ds_images, _p_net->getInputH(),_p_net->getInputW());
56 | timer.out("pre");
57 | _p_net->doInference(trtInput.data, vec_ds_images.size());
58 | timer.reset();
59 | for (uint32_t i = 0; i < vec_ds_images.size(); ++i)
60 | {
61 | auto curImage = vec_ds_images.at(i);
62 | auto binfo = _p_net->decodeDetections(i, curImage.getImageHeight(), curImage.getImageWidth());
63 | auto remaining = nmsAllClasses(_p_net->getNMSThresh(),
64 | binfo,
65 | _p_net->getNumClasses(),
66 | _vec_net_type[_config.net_type]);
67 | if (remaining.empty())
68 | {
69 | continue;
70 | }
71 | std::vector vec_result(0);
72 | for (const auto &b : remaining)
73 | {
74 | Result res;
75 | res.id = b.label;
76 | res.prob = b.prob;
77 | const int x = b.box.x1;
78 | const int y = b.box.y1;
79 | const int w = b.box.x2 - b.box.x1;
80 | const int h = b.box.y2 - b.box.y1;
81 | res.rect = cv::Rect(x, y, w, h);
82 | vec_result.push_back(res);
83 | }
84 | vec_batch_result[i] = vec_result;
85 | }
86 | timer.out("post");
87 | }
88 |
89 | private:
90 |
91 | void set_gpu_id(const int id = 0)
92 | {
93 | cudaError_t status = cudaSetDevice(id);
94 | if (status != cudaSuccess)
95 | {
96 | std::cout << "gpu id :" + std::to_string(id) + " not exist !" << std::endl;
97 | assert(0);
98 | }
99 | }
100 |
101 | void parse_config()
102 | {
103 | _yolo_info.networkType = _vec_net_type[_config.net_type];
104 | _yolo_info.configFilePath = _config.file_model_cfg;
105 | _yolo_info.wtsFilePath = _config.file_model_weights;
106 | _yolo_info.precision = _vec_precision[_config.inference_precison];
107 | _yolo_info.deviceType = "kGPU";
108 | auto npos = _yolo_info.wtsFilePath.find(".weights");
109 | assert(npos != std::string::npos
110 | && "wts file file not recognised. File needs to be of '.weights' format");
111 | _yolo_info.data_path = _yolo_info.wtsFilePath.substr(0, npos);
112 | _yolo_info.calibrationTablePath = _yolo_info.data_path + "-calibration.table";
113 | _yolo_info.inputBlobName = "data";
114 |
115 | _infer_param.printPerfInfo = false;
116 | _infer_param.printPredictionInfo = false;
117 | _infer_param.calibImages = _config.calibration_image_list_file_txt;
118 | _infer_param.calibImagesPath = "";
119 | _infer_param.probThresh = _config.detect_thresh;
120 | _infer_param.nmsThresh = 0.5;
121 | }
122 |
123 | void build_net()
124 | {
125 | if (_config.net_type == YOLOV3)
126 | {
127 | _p_net = std::unique_ptr{ new YoloV3(_yolo_info, _infer_param) };
128 | }
129 | else if( _config.net_type == YOLOV4)
130 | {
131 | _p_net = std::unique_ptr{ new YoloV4(_yolo_info,_infer_param) };
132 | }
133 | else if (_config.net_type == YOLOV5)
134 | {
135 | _p_net = std::unique_ptr{ new YoloV5(_yolo_info,_infer_param) };
136 | }
137 | else
138 | {
139 | assert(false && "Unrecognised network_type.");
140 | }
141 | }
142 |
143 | private:
144 | Config _config;
145 | NetworkInfo _yolo_info;
146 | InferParams _infer_param;
147 | std::vector _vec_net_type{ "yolov3","yolov4","yolov5" };
148 | std::vector _vec_precision{ "kINT8","kHALF","kFLOAT" };
149 | std::unique_ptr _p_net = nullptr;
150 | Timer _m_timer;
151 | };
152 |
153 |
154 | #endif
155 |
--------------------------------------------------------------------------------
/modules/calibrator.cpp:
--------------------------------------------------------------------------------
1 | /**
2 | MIT License
3 |
4 | Copyright (c) 2018 NVIDIA CORPORATION. All rights reserved.
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in all
14 | copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | SOFTWARE.
23 | *
24 | */
25 |
26 | #include "calibrator.h"
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | Int8EntropyCalibrator::Int8EntropyCalibrator(const uint32_t& batchSize, const std::string& calibImages,
33 | const std::string& calibImagesPath,
34 | const std::string& calibTableFilePath,
35 | const uint64_t& inputSize, const uint32_t& inputH,
36 | const uint32_t& inputW, const std::string& inputBlobName,
37 | const std::string &s_net_type_) :
38 | m_BatchSize(batchSize),
39 | m_InputH(inputH),
40 | m_InputW(inputW),
41 | m_InputSize(inputSize),
42 | m_InputCount(batchSize * inputSize),
43 | m_InputBlobName(inputBlobName),
44 | m_CalibTableFilePath(calibTableFilePath),
45 | m_ImageIndex(0),
46 | _s_net_type(s_net_type_)
47 | {
48 | if (!fileExists(m_CalibTableFilePath, false))
49 | {
50 | m_ImageList = loadImageList(calibImages, calibImagesPath);
51 | m_ImageList.resize(static_cast(m_ImageList.size() / m_BatchSize) * m_BatchSize);
52 | std::random_shuffle(m_ImageList.begin(), m_ImageList.end(),
53 | [](int i) { return rand() % i; });
54 | }
55 |
56 | NV_CUDA_CHECK(cudaMalloc(&m_DeviceInput, m_InputCount * sizeof(float)));
57 | }
58 |
59 | Int8EntropyCalibrator::~Int8EntropyCalibrator() { NV_CUDA_CHECK(cudaFree(m_DeviceInput)); }
60 |
61 | bool Int8EntropyCalibrator::getBatch(void* bindings[], const char* names[], int nbBindings)noexcept
62 | {
63 | if (m_ImageIndex + m_BatchSize >= m_ImageList.size()) return false;
64 |
65 | // Load next batch
66 | std::vector dsImages(m_BatchSize);
67 | for (uint32_t j = m_ImageIndex; j < m_ImageIndex + m_BatchSize; ++j)
68 | {
69 | dsImages.at(j - m_ImageIndex) = DsImage(m_ImageList.at(j), _s_net_type, m_InputH, m_InputW);
70 | }
71 | m_ImageIndex += m_BatchSize;
72 |
73 | cv::Mat trtInput = blobFromDsImages(dsImages, m_InputH, m_InputW);
74 |
75 | NV_CUDA_CHECK(cudaMemcpy(m_DeviceInput, trtInput.ptr(0), m_InputCount * sizeof(float),
76 | cudaMemcpyHostToDevice));
77 | assert(!strcmp(names[0], m_InputBlobName.c_str()));
78 | bindings[0] = m_DeviceInput;
79 | return true;
80 | }
81 |
82 | const void* Int8EntropyCalibrator::readCalibrationCache(size_t& length) noexcept
83 | {
84 | void* output;
85 | m_CalibrationCache.clear();
86 | assert(!m_CalibTableFilePath.empty());
87 | std::ifstream input(m_CalibTableFilePath, std::ios::binary | std::ios::in);
88 | input >> std::noskipws;
89 | if (m_ReadCache && input.good())
90 | std::copy(std::istream_iterator(input), std::istream_iterator(),
91 | std::back_inserter(m_CalibrationCache));
92 |
93 | length = m_CalibrationCache.size();
94 | if (length)
95 | {
96 | std::cout << "Using cached calibration table to build the engine" << std::endl;
97 | output = &m_CalibrationCache[0];
98 | }
99 |
100 | else
101 | {
102 | std::cout << "New calibration table will be created to build the engine" << std::endl;
103 | output = nullptr;
104 | }
105 |
106 | return output;
107 | }
108 |
109 | void Int8EntropyCalibrator::writeCalibrationCache(const void* cache, size_t length) noexcept
110 | {
111 | assert(!m_CalibTableFilePath.empty());
112 | std::ofstream output(m_CalibTableFilePath, std::ios::binary);
113 | output.write(reinterpret_cast(cache), length);
114 | output.close();
115 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Yolov5 Yolov4 Yolov3 TensorRT Implementation
2 |
3 |    [](https://gitter.im/yolo-tensorrt/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
4 |
5 | __news:__ 2021.10.31:yolov5-v6.0 support
6 |
7 | 
8 | ## INTRODUCTION
9 |
10 | The project is the encapsulation of nvidia official yolo-tensorrt [implementation](https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps). And you must have the trained yolo model(__.weights__) and __.cfg__ file from the darknet (yolov3 & yolov4). For the [yolov5](https://github.com/ultralytics/yolov5) ,you should prepare the model file (yolov5s.yaml) and the trained weight file (yolov5s.pt) from pytorch.
11 |
12 | 
13 |
14 | - [x] yolov5n ,yolov5s , yolov5m , yolov5l , yolov5x ,yolov5-p6 [tutorial](yolov5_tutorial.md)
15 | - [x] yolov4
16 | - [x] yolov3
17 |
18 | ## Features
19 |
20 | - [x] inequal net width and height
21 | - [x] batch inference
22 | - [x] support FP32,FP16,INT8
23 | - [ ] dynamic input size
24 |
25 |
26 | ## PLATFORM & BENCHMARK
27 |
28 | - [x] windows 10
29 | - [x] ubuntu 18.04
30 | - [x] L4T (Jetson platform)
31 |
32 | BENCHMARK
33 |
34 | #### x86 (inference time)
35 |
36 |
37 | | model | size | gpu | fp32 | fp16 | INT8 |
38 | | :-----: | :-----: | :----: | :--: | :--: | :--: |
39 | | yolov5s | 640x640 | 1080ti | 8ms | / | 7ms |
40 | | yolov5m | 640x640 | 1080ti | 13ms | / | 11ms |
41 | | yolov5l | 640x640 | 1080ti | 20ms | / | 15ms |
42 | | yolov5x | 640x640 | 1080ti | 30ms | / | 23ms |
43 | #### Jetson NX with Jetpack4.4.1 (inference / detect time)
44 |
45 | | model | size | gpu | fp32 | fp16 | INT8 |
46 | | :-------------: | :----: | :--: | :--: | :--: | :--: |
47 | | yolov3 | 416x416 | nx | 105ms/120ms | 30ms/48ms | 20ms/35ms |
48 | | yolov3-tiny | 416x416 | nx | 14ms/23ms | 8ms/15ms | 12ms/19ms |
49 | | yolov4-tiny | 416x416 | nx | 13ms/23ms | 7ms/16ms | 7ms/15ms |
50 | | yolov4 | 416x416 | nx | 111ms/125ms | 55ms/65ms | 47ms/57ms |
51 | | yolov5s | 416x416 | nx | 47ms/88ms | 33ms/74ms | 28ms/64ms |
52 | | yolov5m | 416x416 | nx | 110ms/145ms | 63ms/101ms | 49ms/91ms |
53 | | yolov5l | 416x416 | nx | 205ms/242ms | 95ms/123ms | 76ms/118ms |
54 | | yolov5x | 416x416 | nx | 351ms/405ms | 151ms/183ms | 114ms/149ms |
55 |
56 |
57 | ### ubuntu
58 | | model | size | gpu | fp32 | fp16 | INT8 |
59 | | :-------------: | :----: | :--: | :--: | :--: | :--: |
60 | | yolov4 | 416x416 | titanv | 11ms/17ms | 8ms/15ms | 7ms/14ms |
61 | | yolov5s | 416x416 | titanv | 7ms/22ms | 5ms/20ms | 5ms/18ms |
62 | | yolov5m | 416x416 | titanv | 9ms/23ms | 8ms/22ms | 7ms/21ms |
63 | | yolov5l | 416x416 | titanv | 17ms/28ms | 11ms/23ms | 11ms/24ms |
64 | | yolov5x | 416x416 | titanv | 25ms/40ms | 15ms/27ms | 15ms/27ms |
65 |
66 |
67 | ## WRAPPER
68 |
69 | Prepare the pretrained __.weights__ and __.cfg__ model.
70 |
71 | ```c++
72 | Detector detector;
73 | Config config;
74 |
75 | std::vector res;
76 | detector.detect(vec_image, res)
77 | ```
78 |
79 | ## Build and use yolo-trt as DLL or SO libraries
80 |
81 |
82 | ### windows10
83 |
84 | - dependency : TensorRT 7.1.3.4 , cuda 11.0 , cudnn 8.0 , opencv4 , vs2015
85 | - build:
86 |
87 | open MSVC _sln/sln.sln_ file
88 | - dll project : the trt yolo detector dll
89 | - demo project : test of the dll
90 |
91 | ### ubuntu & L4T (jetson)
92 |
93 | The project generate the __libdetector.so__ lib, and the sample code.
94 | **_If you want to use the libdetector.so lib in your own project,this [cmake file](https://github.com/enazoe/yolo-tensorrt/blob/master/scripts/CMakeLists.txt) perhaps could help you ._**
95 |
96 |
97 | ```bash
98 | git clone https://github.com/enazoe/yolo-tensorrt.git
99 | cd yolo-tensorrt/
100 | mkdir build
101 | cd build/
102 | cmake ..
103 | make
104 | ./yolo-trt
105 | ```
106 | ## API
107 |
108 | ```c++
109 | struct Config
110 | {
111 | std::string file_model_cfg = "configs/yolov4.cfg";
112 |
113 | std::string file_model_weights = "configs/yolov4.weights";
114 |
115 | float detect_thresh = 0.9;
116 |
117 | ModelType net_type = YOLOV4;
118 |
119 | Precision inference_precison = INT8;
120 |
121 | int gpu_id = 0;
122 |
123 | std::string calibration_image_list_file_txt = "configs/calibration_images.txt";
124 |
125 | };
126 |
127 | class API Detector
128 | {
129 | public:
130 | explicit Detector();
131 | ~Detector();
132 |
133 | void init(const Config &config);
134 |
135 | void detect(const std::vector &mat_image,std::vector &vec_batch_result);
136 |
137 | private:
138 | Detector(const Detector &);
139 | const Detector &operator =(const Detector &);
140 | class Impl;
141 | Impl *_impl;
142 | };
143 | ```
144 |
145 | ## REFERENCE
146 |
147 | - https://github.com/wang-xinyu/tensorrtx/tree/master/yolov4
148 | - https://github.com/mj8ac/trt-yolo-app_win64
149 | - https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps
150 |
151 | ## Contact
152 |
153 | 微信关注公众号EigenVison,回复yolo获取交流群号
154 |
155 |
156 |
157 | 
158 |
--------------------------------------------------------------------------------
/modules/hardswish.cu:
--------------------------------------------------------------------------------
1 | //sys
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | //my
11 | #include "hardswish.h"
12 |
13 | #define NV_CUDA_CHECK(status) \
14 | { \
15 | if (status != 0) \
16 | { \
17 | std::cout << "Cuda failure: " << cudaGetErrorString(status) << " in file " << __FILE__ \
18 | << " at line " << __LINE__ << std::endl; \
19 | abort(); \
20 | } \
21 | }
22 |
23 | namespace nvinfer1
24 | {
25 | Hardswish::Hardswish()
26 | {
27 | cudaDeviceProp prop;
28 | cudaGetDeviceProperties(&prop, 0);
29 | _n_max_thread_pre_block = prop.maxThreadsPerBlock;
30 | // printf("Hardswish():%d\n", _n_max_thread_pre_block);
31 | }
32 |
33 | Hardswish::Hardswish(const void* data, size_t length)
34 | {
35 | const char *d = reinterpret_cast(data), *a = d;
36 | r(d, _n_max_thread_pre_block);
37 | r(d, _n_output_size);
38 | // printf("r:threads:%d,size:%d\n", _n_max_thread_pre_block, _n_output_size);
39 | assert(d == a + length);
40 | }
41 |
42 | Hardswish::~Hardswish()
43 | {}
44 |
45 | __global__ void kernel_hardswish(const float *input_, float *output_, int n_data_size_)
46 | {
47 | int i = threadIdx.x + blockIdx.x * blockDim.x;
48 | if (i >= n_data_size_)return;
49 | if (input_[i] >= 3.0f)
50 | {
51 | output_[i] = input_[i];
52 | }
53 | else if (input_[i] <= -3.0f)
54 | {
55 | output_[i] = 0.0f;
56 | }
57 | else
58 | {
59 | output_[i] = input_[i] * (input_[i] + 3.0f) / 6.0f;
60 | }
61 | }
62 |
63 | cudaError_t cuda_hardswish_layer(const void* input_,
64 | void* output_,
65 | const int n_batch_size_,
66 | const int n_output_size_,
67 | const int threads_,
68 | cudaStream_t stream_)
69 | {
70 | int n_data_size = n_batch_size_ * n_output_size_;
71 | // printf("cuda_hardswish_layer:%d,size:%d\n", n_batch_size_, n_output_size_);
72 | kernel_hardswish << <(n_data_size + threads_ -1)/threads_, threads_, 0, stream_ >> >(
73 | reinterpret_cast(input_),
74 | reinterpret_cast(output_),
75 | n_data_size);
76 | return cudaGetLastError();
77 | }
78 |
79 | int Hardswish::enqueue(int batchSize,
80 | const void* const* inputs,
81 | void* const* outputs,
82 | void* workspace,
83 | cudaStream_t stream) noexcept
84 | {
85 | // printf("batch_size:%d,output_size:%d,threads:%d\n", batchSize, _n_output_size, _n_max_thread_pre_block);
86 | NV_CUDA_CHECK(cuda_hardswish_layer(inputs[0], outputs[0], batchSize, _n_output_size , _n_max_thread_pre_block, stream));
87 | return 0;
88 | }
89 |
90 | size_t Hardswish::getSerializationSize() const noexcept
91 | {
92 | return sizeof(_n_max_thread_pre_block) +sizeof(_n_output_size);
93 | }
94 |
95 | void Hardswish::serialize(void *buffer) const noexcept
96 | {
97 | char *d = static_cast(buffer), *a = d;
98 | w(d, _n_max_thread_pre_block);
99 | w(d, _n_output_size);
100 | // printf("serialize:%d,%d\n", _n_max_thread_pre_block, _n_output_size);
101 | assert(d == a + getSerializationSize());
102 | }
103 |
104 |
105 | bool Hardswish::supportsFormat(DataType type, PluginFormat format) const noexcept
106 | {
107 | return (type == DataType::kFLOAT && format == PluginFormat::kLINEAR);
108 | }
109 |
110 | void Hardswish::configureWithFormat(const Dims* inputDims, int nbInputs,
111 | const Dims* outputDims, int nbOutputs, DataType type, PluginFormat format, int maxBatchSize) noexcept
112 | {
113 |
114 | }
115 |
116 |
117 | void Hardswish::configurePlugin(const PluginTensorDesc* in, int nbInput, const PluginTensorDesc* out, int nbOutput) noexcept
118 | {
119 |
120 | _n_output_size = in->dims.d[0] * in->dims.d[1] * in->dims.d[2];
121 | // printf("configurePlugin:%d,%d,%d\n", in->dims.d[0], in->dims.d[1], in->dims.d[2]);
122 | }
123 | IPluginV2* Hardswish::clone() const noexcept
124 | {
125 | Hardswish *p = new Hardswish();
126 | p->setPluginNamespace(_s_plugin_namespace.c_str());
127 | p->_n_max_thread_pre_block = _n_max_thread_pre_block;
128 | p->_n_output_size = _n_output_size;
129 | // printf("clone:%d,%d\n", _n_max_thread_pre_block, _n_output_size);
130 | return p;
131 | }
132 |
133 |
134 | //
135 | PluginFieldCollection HardswishPluginCreator::_fc{};
136 | std::vector HardswishPluginCreator::_vec_plugin_attributes;
137 |
138 | HardswishPluginCreator::HardswishPluginCreator()
139 | {
140 | _vec_plugin_attributes.clear();
141 | _fc.nbFields = _vec_plugin_attributes.size();
142 | _fc.fields = _vec_plugin_attributes.data();
143 | }
144 |
145 | const char* HardswishPluginCreator::getPluginName() const noexcept
146 | {
147 | return "HARDSWISH_TRT";
148 | }
149 |
150 | const char* HardswishPluginCreator::getPluginVersion() const noexcept
151 | {
152 | return "1.0";
153 | }
154 |
155 | const PluginFieldCollection* HardswishPluginCreator::getFieldNames() noexcept
156 | {
157 | return &_fc;
158 | }
159 |
160 | IPluginV2* HardswishPluginCreator::createPlugin(const char* name, const PluginFieldCollection* fc) noexcept
161 | {
162 | Hardswish* obj = new Hardswish();
163 | obj->setPluginNamespace(_s_name_space.c_str());
164 | return obj;
165 | }
166 |
167 | IPluginV2* HardswishPluginCreator::deserializePlugin(const char* name, const void* serialData, size_t serialLength) noexcept
168 | {
169 | Hardswish* obj = new Hardswish(serialData, serialLength);
170 | obj->setPluginNamespace(_s_name_space.c_str());
171 | return obj;
172 | }
173 |
174 | void HardswishPluginCreator::setPluginNamespace(const char* libNamespace) noexcept
175 | {
176 | _s_name_space = libNamespace;
177 | }
178 |
179 | const char* HardswishPluginCreator::getPluginNamespace() const noexcept
180 | {
181 | return _s_name_space.c_str();
182 | }
183 | }//end namespace nvinfer1
184 |
--------------------------------------------------------------------------------
/sln/test_dll/test_dll.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Release
10 | Win32
11 |
12 |
13 | Debug
14 | x64
15 |
16 |
17 | Release
18 | x64
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 | {AE9921FC-C594-4C41-925A-5582896BD2A8}
29 | test_dll
30 | 10.0.17763.0
31 |
32 |
33 |
34 | Application
35 | true
36 | v141
37 | MultiByte
38 |
39 |
40 | Application
41 | false
42 | v141
43 | true
44 | MultiByte
45 |
46 |
47 | Application
48 | true
49 | v141
50 | MultiByte
51 |
52 |
53 | Application
54 | false
55 | v141
56 | true
57 | MultiByte
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 | Level3
84 | Disabled
85 | true
86 |
87 |
88 |
89 |
90 | Level3
91 | Disabled
92 | true
93 |
94 |
95 |
96 |
97 | Level3
98 | MaxSpeed
99 | true
100 | true
101 | true
102 |
103 |
104 | true
105 | true
106 |
107 |
108 |
109 |
110 | Level3
111 | MaxSpeed
112 | true
113 | true
114 | true
115 | ..\..\extra;%(AdditionalIncludeDirectories)
116 |
117 |
118 | true
119 | true
120 | detector.lib;%(AdditionalDependencies)
121 |
122 |
123 |
124 |
125 |
126 |
127 |
--------------------------------------------------------------------------------