├── CMakeLists.txt
├── CMakeLists.txt.user
├── Makefile
├── README.md
├── Utils.h
├── data
├── yolov3-tiny.cfg
├── yolov3.cfg
├── yolov4-tiny.cfg
└── yolov4.cfg
├── logging.h
├── main.cpp
├── mish.cu
├── mish.h
├── trt_utils.cpp
├── trt_utils.h
├── yolo.cpp
├── yolo.h
├── yololayer.cpp
├── yololayer.cu
└── yololayer.h
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.6)
2 |
3 | project(yolo)
4 |
5 | add_definitions(-std=c++11)
6 |
7 | option(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
8 | set(CMAKE_CXX_STANDARD 11)
9 | set(CMAKE_BUILD_TYPE Debug)
10 |
11 | find_package(CUDA REQUIRED)
12 |
13 | set(CUDA_NVCC_PLAGS ${CUDA_NVCC_PLAGS};-std=c++11;-g;-G;-gencode;arch=compute_61;code=sm_61)
14 |
15 | include_directories(${PROJECT_SOURCE_DIR}/)
16 |
17 | include_directories(/usr/local/cuda/include)
18 | link_directories(/usr/local/cuda/lib64)
19 |
20 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Ofast -Wfatal-errors -D_MWAITXINTRIN_H_INCLUDED")
21 |
22 | cuda_add_library(yololayer SHARED ${PROJECT_SOURCE_DIR}/yololayer.cu ${PROJECT_SOURCE_DIR}/mish.cu)
23 |
24 | include_directories(/home/wh/program/TensorRT-7.0.0.11/include)
25 | link_directories(/home/wh/program/TensorRT-7.0.0.11/lib )
26 |
27 | set(OpenCV_DIR /home/wh/program/opencv-4.2.0/build)
28 | find_package(OpenCV)
29 | include_directories(OpenCV_INCLUDE_DIRS)
30 |
31 |
32 | add_executable(yolo main.cpp trt_utils.cpp yolo.cpp)
33 | target_link_libraries(yolo nvinfer nvinfer_plugin nvparsers cudart cublas stdc++fs yololayer ${OpenCV_LIBS})
34 |
35 | add_definitions(-O2 -pthread)
36 |
37 |
--------------------------------------------------------------------------------
/CMakeLists.txt.user:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | EnvironmentId
7 | {fb0098ed-9136-48fb-a11b-4f3ef4b526e4}
8 |
9 |
10 | ProjectExplorer.Project.ActiveTarget
11 | 0
12 |
13 |
14 | ProjectExplorer.Project.EditorSettings
15 |
16 | true
17 | false
18 | true
19 |
20 | Cpp
21 |
22 | CppGlobal
23 |
24 |
25 |
26 | QmlJS
27 |
28 | QmlJSGlobal
29 |
30 |
31 | 2
32 | UTF-8
33 | false
34 | 4
35 | false
36 | 80
37 | true
38 | true
39 | 1
40 | true
41 | false
42 | 0
43 | true
44 | true
45 | 0
46 | 8
47 | true
48 | 1
49 | true
50 | true
51 | true
52 | false
53 |
54 |
55 |
56 | ProjectExplorer.Project.PluginSettings
57 |
58 |
59 | true
60 |
61 |
62 |
63 | ProjectExplorer.Project.Target.0
64 |
65 | Qt 5.14.2 (gcc_64)
66 | Qt 5.14.2 (gcc_64)
67 | {a69a9926-65a8-49d0-a70b-9fe5abf0939c}
68 | 0
69 | 0
70 | 0
71 |
72 |
73 | CMAKE_BUILD_TYPE:STRING=Debug
74 | CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
75 | CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}
76 | CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}
77 | QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}
78 |
79 | /home/wh/project/CUDA_learn/test_yololayer/deepstream_yolo/git_yolo/build-tensorrt-yolo-Qt_5_14_2_gcc_64-Debug
80 |
81 |
82 |
83 |
84 | all
85 |
86 | true
87 | CMakeProjectManager.MakeStep
88 |
89 | 1
90 | Build
91 | Build
92 | ProjectExplorer.BuildSteps.Build
93 |
94 |
95 |
96 |
97 |
98 | clean
99 |
100 | true
101 | CMakeProjectManager.MakeStep
102 |
103 | 1
104 | Clean
105 | Clean
106 | ProjectExplorer.BuildSteps.Clean
107 |
108 | 2
109 | false
110 |
111 | Debug
112 | CMakeProjectManager.CMakeBuildConfiguration
113 |
114 |
115 |
116 | CMAKE_BUILD_TYPE:STRING=Release
117 | CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
118 | CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}
119 | CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}
120 | QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}
121 |
122 | /home/wh/project/CUDA_learn/test_yololayer/deepstream_yolo/git_yolo/build-tensorrt-yolo-Qt_5_14_2_gcc_64-Release
123 |
124 |
125 |
126 |
127 | all
128 |
129 | true
130 | CMakeProjectManager.MakeStep
131 |
132 | 1
133 | Build
134 | Build
135 | ProjectExplorer.BuildSteps.Build
136 |
137 |
138 |
139 |
140 |
141 | clean
142 |
143 | true
144 | CMakeProjectManager.MakeStep
145 |
146 | 1
147 | Clean
148 | Clean
149 | ProjectExplorer.BuildSteps.Clean
150 |
151 | 2
152 | false
153 |
154 | Release
155 | CMakeProjectManager.CMakeBuildConfiguration
156 |
157 |
158 |
159 | CMAKE_BUILD_TYPE:STRING=RelWithDebInfo
160 | CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
161 | CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}
162 | CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}
163 | QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}
164 |
165 | /home/wh/project/CUDA_learn/test_yololayer/deepstream_yolo/git_yolo/build-tensorrt-yolo-Qt_5_14_2_gcc_64-RelWithDebInfo
166 |
167 |
168 |
169 |
170 | all
171 |
172 | true
173 | CMakeProjectManager.MakeStep
174 |
175 | 1
176 | Build
177 | Build
178 | ProjectExplorer.BuildSteps.Build
179 |
180 |
181 |
182 |
183 |
184 | clean
185 |
186 | true
187 | CMakeProjectManager.MakeStep
188 |
189 | 1
190 | Clean
191 | Clean
192 | ProjectExplorer.BuildSteps.Clean
193 |
194 | 2
195 | false
196 |
197 | Release with Debug Information
198 | CMakeProjectManager.CMakeBuildConfiguration
199 |
200 |
201 |
202 | CMAKE_BUILD_TYPE:STRING=MinSizeRel
203 | CMAKE_CXX_COMPILER:STRING=%{Compiler:Executable:Cxx}
204 | CMAKE_C_COMPILER:STRING=%{Compiler:Executable:C}
205 | CMAKE_PREFIX_PATH:STRING=%{Qt:QT_INSTALL_PREFIX}
206 | QT_QMAKE_EXECUTABLE:STRING=%{Qt:qmakeExecutable}
207 |
208 | /home/wh/project/CUDA_learn/test_yololayer/deepstream_yolo/git_yolo/build-tensorrt-yolo-Qt_5_14_2_gcc_64-MinSizeRel
209 |
210 |
211 |
212 |
213 | all
214 |
215 | true
216 | CMakeProjectManager.MakeStep
217 |
218 | 1
219 | Build
220 | Build
221 | ProjectExplorer.BuildSteps.Build
222 |
223 |
224 |
225 |
226 |
227 | clean
228 |
229 | true
230 | CMakeProjectManager.MakeStep
231 |
232 | 1
233 | Clean
234 | Clean
235 | ProjectExplorer.BuildSteps.Clean
236 |
237 | 2
238 | false
239 |
240 | Minimum Size Release
241 | CMakeProjectManager.CMakeBuildConfiguration
242 |
243 | 4
244 |
245 |
246 | 0
247 | Deploy
248 | Deploy
249 | ProjectExplorer.BuildSteps.Deploy
250 |
251 | 1
252 | ProjectExplorer.DefaultDeployConfiguration
253 |
254 | 1
255 |
256 |
257 | dwarf
258 |
259 | cpu-cycles
260 |
261 |
262 | 250
263 |
264 | -e
265 | cpu-cycles
266 | --call-graph
267 | dwarf,4096
268 | -F
269 | 250
270 |
271 | -F
272 | true
273 | 4096
274 | false
275 | false
276 | 1000
277 |
278 | true
279 |
280 | false
281 | false
282 | false
283 | false
284 | true
285 | 0.01
286 | 10
287 | true
288 | kcachegrind
289 | 1
290 | 25
291 |
292 | 1
293 | true
294 | false
295 | true
296 | valgrind
297 |
298 | 0
299 | 1
300 | 2
301 | 3
302 | 4
303 | 5
304 | 6
305 | 7
306 | 8
307 | 9
308 | 10
309 | 11
310 | 12
311 | 13
312 | 14
313 |
314 | 2
315 |
316 | yolo
317 | CMakeProjectManager.CMakeRunConfiguration.yolo
318 | yolo
319 |
320 | false
321 |
322 | false
323 | true
324 | true
325 | false
326 | false
327 | true
328 |
329 | /tmp/QtCreator-KeZdAz/qtc-cmake-GjVZhhZn
330 |
331 | 1
332 |
333 |
334 |
335 | ProjectExplorer.Project.TargetCount
336 | 1
337 |
338 |
339 | ProjectExplorer.Project.Updater.FileVersion
340 | 22
341 |
342 |
343 | Version
344 | 22
345 |
346 |
347 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 | #
4 | # Permission is hereby granted, free of charge, to any person obtaining a
5 | # copy of this software and associated documentation files (the "Software"),
6 | # to deal in the Software without restriction, including without limitation
7 | # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 | # and/or sell copies of the Software, and to permit persons to whom the
9 | # Software is furnished to do so, subject to the following conditions:
10 | #
11 | # The above copyright notice and this permission notice shall be included in
12 | # all copies or substantial portions of the Software.
13 | #
14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 | # DEALINGS IN THE SOFTWARE.
21 | ################################################################################
22 |
23 | CUDA_VER?=
24 | ifeq ($(CUDA_VER),)
25 | $(error "CUDA_VER is not set")
26 | endif
27 | CC:= g++
28 | NVCC:=/usr/local/cuda-$(CUDA_VER)/bin/nvcc
29 |
30 | CFLAGS:= -Wall -std=c++11 -shared -fPIC -Wno-error=deprecated-declarations
31 | CFLAGS+= -I../../includes -I/usr/local/cuda-$(CUDA_VER)/include
32 |
33 | LIBS:= -lnvinfer_plugin -lnvinfer -lnvparsers -L/usr/local/cuda-$(CUDA_VER)/lib64 -lcudart -lcublas -lstdc++fs
34 | LFLAGS:= -shared -Wl,--start-group $(LIBS) -Wl,--end-group
35 |
36 | INCS:= $(wildcard *.h)
37 | SRCFILES:= nvdsinfer_yolo_engine.cpp \
38 | nvdsparsebbox_Yolo.cpp \
39 | yoloPlugins.cpp \
40 | trt_utils.cpp \
41 | yolo.cpp \
42 | kernels.cu
43 | TARGET_LIB:= libnvdsinfer_custom_impl_Yolo.so
44 |
45 | TARGET_OBJS:= $(SRCFILES:.cpp=.o)
46 | TARGET_OBJS:= $(TARGET_OBJS:.cu=.o)
47 |
48 | all: $(TARGET_LIB)
49 |
50 | %.o: %.cpp $(INCS) Makefile
51 | $(CC) -c -o $@ $(CFLAGS) $<
52 |
53 | %.o: %.cu $(INCS) Makefile
54 | $(NVCC) -c -o $@ --compiler-options '-fPIC' $<
55 |
56 | $(TARGET_LIB) : $(TARGET_OBJS)
57 | $(CC) -o $@ $(TARGET_OBJS) $(LFLAGS)
58 |
59 | clean:
60 | rm -rf $(TARGET_LIB)
61 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # if this help to you,please star star star
2 | # tensorrt7-yolo
3 | Now, just support Ubuntu, windows will be soon.
4 |
5 | Support yolov3 yolov3-tiny yolov4 yolov4-tiny,even your custom cfg networ
6 |
7 | if you train from darknet(AB), it usually can support.
8 |
9 | Don't need onnx, directly transport .cfg and .weights to Tensorrt engine
10 |
11 | this project borrow from [Deepstream](https://github.com/NVIDIA-AI-IOT/deepstream_reference_apps/tree/restructure) and [wang-xinyu/tensorrtx](https://github.com/wang-xinyu/tensorrtx)
12 |
13 | ## Excute:
14 | ```
15 | 1. clone.
16 | 2.set CMakeList.txt tensorrt path, opencv path.
17 | 3.main.cpp, set diffenrt cfg and weights
18 | 4.set .cfg input_w and input_h,due to tensorrt upsample , input_w shuld equal input_h
19 | 5.copy .cfg and .weights file to folder
20 | 6.mkdir build.
21 | 7.cd build && cmake .. && make
22 | 7.run ./yolo -s to build yolo engine
23 | 7.run ./yolo -d to start detect
24 | ```
25 | ## set FP16 or FP32
26 | - FP16/FP32 can be selected by the macro `USE_FP16`
27 |
--------------------------------------------------------------------------------
/Utils.h:
--------------------------------------------------------------------------------
1 | #ifndef __TRT_UTILS_H_
2 | #define __TRT_UTILS_H_
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #ifndef CUDA_CHECK
10 |
11 | #define CUDA_CHECK(callstr) \
12 | { \
13 | cudaError_t error_code = callstr; \
14 | if (error_code != cudaSuccess) { \
15 | std::cerr << "CUDA error " << error_code << " at " << __FILE__ << ":" << __LINE__; \
16 | assert(0); \
17 | } \
18 | }
19 |
20 | #endif
21 |
22 | namespace Tn
23 | {
24 | class Profiler : public nvinfer1::IProfiler
25 | {
26 | public:
27 | void printLayerTimes(int itrationsTimes)
28 | {
29 | float totalTime = 0;
30 | for (size_t i = 0; i < mProfile.size(); i++)
31 | {
32 | printf("%-40.40s %4.3fms\n", mProfile[i].first.c_str(), mProfile[i].second / itrationsTimes);
33 | totalTime += mProfile[i].second;
34 | }
35 | printf("Time over all layers: %4.3f\n", totalTime / itrationsTimes);
36 | }
37 | private:
38 | typedef std::pair Record;
39 | std::vector mProfile;
40 |
41 | virtual void reportLayerTime(const char* layerName, float ms)
42 | {
43 | auto record = std::find_if(mProfile.begin(), mProfile.end(), [&](const Record& r){ return r.first == layerName; });
44 | if (record == mProfile.end())
45 | mProfile.push_back(std::make_pair(layerName, ms));
46 | else
47 | record->second += ms;
48 | }
49 | };
50 |
51 | //Logger for TensorRT info/warning/errors
52 | class Logger : public nvinfer1::ILogger
53 | {
54 | public:
55 |
56 | Logger(): Logger(Severity::kWARNING) {}
57 |
58 | Logger(Severity severity): reportableSeverity(severity) {}
59 |
60 | void log(Severity severity, const char* msg) override
61 | {
62 | // suppress messages with severity enum value greater than the reportable
63 | if (severity > reportableSeverity) return;
64 |
65 | switch (severity)
66 | {
67 | case Severity::kINTERNAL_ERROR: std::cerr << "INTERNAL_ERROR: "; break;
68 | case Severity::kERROR: std::cerr << "ERROR: "; break;
69 | case Severity::kWARNING: std::cerr << "WARNING: "; break;
70 | case Severity::kINFO: std::cerr << "INFO: "; break;
71 | default: std::cerr << "UNKNOWN: "; break;
72 | }
73 | std::cerr << msg << std::endl;
74 | }
75 |
76 | Severity reportableSeverity{Severity::kWARNING};
77 | };
78 |
79 | template
80 | void write(char*& buffer, const T& val)
81 | {
82 | *reinterpret_cast(buffer) = val;
83 | buffer += sizeof(T);
84 | }
85 |
86 | template
87 | void read(const char*& buffer, T& val)
88 | {
89 | val = *reinterpret_cast(buffer);
90 | buffer += sizeof(T);
91 | }
92 | }
93 |
94 | #endif
--------------------------------------------------------------------------------
/data/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 |
--------------------------------------------------------------------------------
/data/yolov3.cfg:
--------------------------------------------------------------------------------
1 | [net]
2 | # Testing
3 | batch=1
4 | subdivisions=1
5 | # Training
6 | # batch=64
7 | # subdivisions=16
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=32
28 | size=3
29 | stride=1
30 | pad=1
31 | activation=leaky
32 |
33 | # Downsample
34 |
35 | [convolutional]
36 | batch_normalize=1
37 | filters=64
38 | size=3
39 | stride=2
40 | pad=1
41 | activation=leaky
42 |
43 | [convolutional]
44 | batch_normalize=1
45 | filters=32
46 | size=1
47 | stride=1
48 | pad=1
49 | activation=leaky
50 |
51 | [convolutional]
52 | batch_normalize=1
53 | filters=64
54 | size=3
55 | stride=1
56 | pad=1
57 | activation=leaky
58 |
59 | [shortcut]
60 | from=-3
61 | activation=linear
62 |
63 | # Downsample
64 |
65 | [convolutional]
66 | batch_normalize=1
67 | filters=128
68 | size=3
69 | stride=2
70 | pad=1
71 | activation=leaky
72 |
73 | [convolutional]
74 | batch_normalize=1
75 | filters=64
76 | size=1
77 | stride=1
78 | pad=1
79 | activation=leaky
80 |
81 | [convolutional]
82 | batch_normalize=1
83 | filters=128
84 | size=3
85 | stride=1
86 | pad=1
87 | activation=leaky
88 |
89 | [shortcut]
90 | from=-3
91 | activation=linear
92 |
93 | [convolutional]
94 | batch_normalize=1
95 | filters=64
96 | size=1
97 | stride=1
98 | pad=1
99 | activation=leaky
100 |
101 | [convolutional]
102 | batch_normalize=1
103 | filters=128
104 | size=3
105 | stride=1
106 | pad=1
107 | activation=leaky
108 |
109 | [shortcut]
110 | from=-3
111 | activation=linear
112 |
113 | # Downsample
114 |
115 | [convolutional]
116 | batch_normalize=1
117 | filters=256
118 | size=3
119 | stride=2
120 | pad=1
121 | activation=leaky
122 |
123 | [convolutional]
124 | batch_normalize=1
125 | filters=128
126 | size=1
127 | stride=1
128 | pad=1
129 | activation=leaky
130 |
131 | [convolutional]
132 | batch_normalize=1
133 | filters=256
134 | size=3
135 | stride=1
136 | pad=1
137 | activation=leaky
138 |
139 | [shortcut]
140 | from=-3
141 | activation=linear
142 |
143 | [convolutional]
144 | batch_normalize=1
145 | filters=128
146 | size=1
147 | stride=1
148 | pad=1
149 | activation=leaky
150 |
151 | [convolutional]
152 | batch_normalize=1
153 | filters=256
154 | size=3
155 | stride=1
156 | pad=1
157 | activation=leaky
158 |
159 | [shortcut]
160 | from=-3
161 | activation=linear
162 |
163 | [convolutional]
164 | batch_normalize=1
165 | filters=128
166 | size=1
167 | stride=1
168 | pad=1
169 | activation=leaky
170 |
171 | [convolutional]
172 | batch_normalize=1
173 | filters=256
174 | size=3
175 | stride=1
176 | pad=1
177 | activation=leaky
178 |
179 | [shortcut]
180 | from=-3
181 | activation=linear
182 |
183 | [convolutional]
184 | batch_normalize=1
185 | filters=128
186 | size=1
187 | stride=1
188 | pad=1
189 | activation=leaky
190 |
191 | [convolutional]
192 | batch_normalize=1
193 | filters=256
194 | size=3
195 | stride=1
196 | pad=1
197 | activation=leaky
198 |
199 | [shortcut]
200 | from=-3
201 | activation=linear
202 |
203 |
204 | [convolutional]
205 | batch_normalize=1
206 | filters=128
207 | size=1
208 | stride=1
209 | pad=1
210 | activation=leaky
211 |
212 | [convolutional]
213 | batch_normalize=1
214 | filters=256
215 | size=3
216 | stride=1
217 | pad=1
218 | activation=leaky
219 |
220 | [shortcut]
221 | from=-3
222 | activation=linear
223 |
224 | [convolutional]
225 | batch_normalize=1
226 | filters=128
227 | size=1
228 | stride=1
229 | pad=1
230 | activation=leaky
231 |
232 | [convolutional]
233 | batch_normalize=1
234 | filters=256
235 | size=3
236 | stride=1
237 | pad=1
238 | activation=leaky
239 |
240 | [shortcut]
241 | from=-3
242 | activation=linear
243 |
244 | [convolutional]
245 | batch_normalize=1
246 | filters=128
247 | size=1
248 | stride=1
249 | pad=1
250 | activation=leaky
251 |
252 | [convolutional]
253 | batch_normalize=1
254 | filters=256
255 | size=3
256 | stride=1
257 | pad=1
258 | activation=leaky
259 |
260 | [shortcut]
261 | from=-3
262 | activation=linear
263 |
264 | [convolutional]
265 | batch_normalize=1
266 | filters=128
267 | size=1
268 | stride=1
269 | pad=1
270 | activation=leaky
271 |
272 | [convolutional]
273 | batch_normalize=1
274 | filters=256
275 | size=3
276 | stride=1
277 | pad=1
278 | activation=leaky
279 |
280 | [shortcut]
281 | from=-3
282 | activation=linear
283 |
284 | # Downsample
285 |
286 | [convolutional]
287 | batch_normalize=1
288 | filters=512
289 | size=3
290 | stride=2
291 | pad=1
292 | activation=leaky
293 |
294 | [convolutional]
295 | batch_normalize=1
296 | filters=256
297 | size=1
298 | stride=1
299 | pad=1
300 | activation=leaky
301 |
302 | [convolutional]
303 | batch_normalize=1
304 | filters=512
305 | size=3
306 | stride=1
307 | pad=1
308 | activation=leaky
309 |
310 | [shortcut]
311 | from=-3
312 | activation=linear
313 |
314 |
315 | [convolutional]
316 | batch_normalize=1
317 | filters=256
318 | size=1
319 | stride=1
320 | pad=1
321 | activation=leaky
322 |
323 | [convolutional]
324 | batch_normalize=1
325 | filters=512
326 | size=3
327 | stride=1
328 | pad=1
329 | activation=leaky
330 |
331 | [shortcut]
332 | from=-3
333 | activation=linear
334 |
335 |
336 | [convolutional]
337 | batch_normalize=1
338 | filters=256
339 | size=1
340 | stride=1
341 | pad=1
342 | activation=leaky
343 |
344 | [convolutional]
345 | batch_normalize=1
346 | filters=512
347 | size=3
348 | stride=1
349 | pad=1
350 | activation=leaky
351 |
352 | [shortcut]
353 | from=-3
354 | activation=linear
355 |
356 |
357 | [convolutional]
358 | batch_normalize=1
359 | filters=256
360 | size=1
361 | stride=1
362 | pad=1
363 | activation=leaky
364 |
365 | [convolutional]
366 | batch_normalize=1
367 | filters=512
368 | size=3
369 | stride=1
370 | pad=1
371 | activation=leaky
372 |
373 | [shortcut]
374 | from=-3
375 | activation=linear
376 |
377 | [convolutional]
378 | batch_normalize=1
379 | filters=256
380 | size=1
381 | stride=1
382 | pad=1
383 | activation=leaky
384 |
385 | [convolutional]
386 | batch_normalize=1
387 | filters=512
388 | size=3
389 | stride=1
390 | pad=1
391 | activation=leaky
392 |
393 | [shortcut]
394 | from=-3
395 | activation=linear
396 |
397 |
398 | [convolutional]
399 | batch_normalize=1
400 | filters=256
401 | size=1
402 | stride=1
403 | pad=1
404 | activation=leaky
405 |
406 | [convolutional]
407 | batch_normalize=1
408 | filters=512
409 | size=3
410 | stride=1
411 | pad=1
412 | activation=leaky
413 |
414 | [shortcut]
415 | from=-3
416 | activation=linear
417 |
418 |
419 | [convolutional]
420 | batch_normalize=1
421 | filters=256
422 | size=1
423 | stride=1
424 | pad=1
425 | activation=leaky
426 |
427 | [convolutional]
428 | batch_normalize=1
429 | filters=512
430 | size=3
431 | stride=1
432 | pad=1
433 | activation=leaky
434 |
435 | [shortcut]
436 | from=-3
437 | activation=linear
438 |
439 | [convolutional]
440 | batch_normalize=1
441 | filters=256
442 | size=1
443 | stride=1
444 | pad=1
445 | activation=leaky
446 |
447 | [convolutional]
448 | batch_normalize=1
449 | filters=512
450 | size=3
451 | stride=1
452 | pad=1
453 | activation=leaky
454 |
455 | [shortcut]
456 | from=-3
457 | activation=linear
458 |
459 | # Downsample
460 |
461 | [convolutional]
462 | batch_normalize=1
463 | filters=1024
464 | size=3
465 | stride=2
466 | pad=1
467 | activation=leaky
468 |
469 | [convolutional]
470 | batch_normalize=1
471 | filters=512
472 | size=1
473 | stride=1
474 | pad=1
475 | activation=leaky
476 |
477 | [convolutional]
478 | batch_normalize=1
479 | filters=1024
480 | size=3
481 | stride=1
482 | pad=1
483 | activation=leaky
484 |
485 | [shortcut]
486 | from=-3
487 | activation=linear
488 |
489 | [convolutional]
490 | batch_normalize=1
491 | filters=512
492 | size=1
493 | stride=1
494 | pad=1
495 | activation=leaky
496 |
497 | [convolutional]
498 | batch_normalize=1
499 | filters=1024
500 | size=3
501 | stride=1
502 | pad=1
503 | activation=leaky
504 |
505 | [shortcut]
506 | from=-3
507 | activation=linear
508 |
509 | [convolutional]
510 | batch_normalize=1
511 | filters=512
512 | size=1
513 | stride=1
514 | pad=1
515 | activation=leaky
516 |
517 | [convolutional]
518 | batch_normalize=1
519 | filters=1024
520 | size=3
521 | stride=1
522 | pad=1
523 | activation=leaky
524 |
525 | [shortcut]
526 | from=-3
527 | activation=linear
528 |
529 | [convolutional]
530 | batch_normalize=1
531 | filters=512
532 | size=1
533 | stride=1
534 | pad=1
535 | activation=leaky
536 |
537 | [convolutional]
538 | batch_normalize=1
539 | filters=1024
540 | size=3
541 | stride=1
542 | pad=1
543 | activation=leaky
544 |
545 | [shortcut]
546 | from=-3
547 | activation=linear
548 |
549 | ######################
550 |
551 | [convolutional]
552 | batch_normalize=1
553 | filters=512
554 | size=1
555 | stride=1
556 | pad=1
557 | activation=leaky
558 |
559 | [convolutional]
560 | batch_normalize=1
561 | size=3
562 | stride=1
563 | pad=1
564 | filters=1024
565 | activation=leaky
566 |
567 | [convolutional]
568 | batch_normalize=1
569 | filters=512
570 | size=1
571 | stride=1
572 | pad=1
573 | activation=leaky
574 |
575 | [convolutional]
576 | batch_normalize=1
577 | size=3
578 | stride=1
579 | pad=1
580 | filters=1024
581 | activation=leaky
582 |
583 | [convolutional]
584 | batch_normalize=1
585 | filters=512
586 | size=1
587 | stride=1
588 | pad=1
589 | activation=leaky
590 |
591 | [convolutional]
592 | batch_normalize=1
593 | size=3
594 | stride=1
595 | pad=1
596 | filters=1024
597 | activation=leaky
598 |
599 | [convolutional]
600 | size=1
601 | stride=1
602 | pad=1
603 | filters=255
604 | activation=linear
605 |
606 |
607 | [yolo]
608 | mask = 6,7,8
609 | anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
610 | classes=80
611 | num=9
612 | jitter=.3
613 | ignore_thresh = .7
614 | truth_thresh = 1
615 | random=1
616 |
617 |
618 | [route]
619 | layers = -4
620 |
621 | [convolutional]
622 | batch_normalize=1
623 | filters=256
624 | size=1
625 | stride=1
626 | pad=1
627 | activation=leaky
628 |
629 | [upsample]
630 | stride=2
631 |
632 | [route]
633 | layers = -1, 61
634 |
635 |
636 |
637 | [convolutional]
638 | batch_normalize=1
639 | filters=256
640 | size=1
641 | stride=1
642 | pad=1
643 | activation=leaky
644 |
645 | [convolutional]
646 | batch_normalize=1
647 | size=3
648 | stride=1
649 | pad=1
650 | filters=512
651 | activation=leaky
652 |
653 | [convolutional]
654 | batch_normalize=1
655 | filters=256
656 | size=1
657 | stride=1
658 | pad=1
659 | activation=leaky
660 |
661 | [convolutional]
662 | batch_normalize=1
663 | size=3
664 | stride=1
665 | pad=1
666 | filters=512
667 | activation=leaky
668 |
669 | [convolutional]
670 | batch_normalize=1
671 | filters=256
672 | size=1
673 | stride=1
674 | pad=1
675 | activation=leaky
676 |
677 | [convolutional]
678 | batch_normalize=1
679 | size=3
680 | stride=1
681 | pad=1
682 | filters=512
683 | activation=leaky
684 |
685 | [convolutional]
686 | size=1
687 | stride=1
688 | pad=1
689 | filters=255
690 | activation=linear
691 |
692 |
693 | [yolo]
694 | mask = 3,4,5
695 | anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
696 | classes=80
697 | num=9
698 | jitter=.3
699 | ignore_thresh = .7
700 | truth_thresh = 1
701 | random=1
702 |
703 |
704 |
705 | [route]
706 | layers = -4
707 |
708 | [convolutional]
709 | batch_normalize=1
710 | filters=128
711 | size=1
712 | stride=1
713 | pad=1
714 | activation=leaky
715 |
716 | [upsample]
717 | stride=2
718 |
719 | [route]
720 | layers = -1, 36
721 |
722 |
723 |
724 | [convolutional]
725 | batch_normalize=1
726 | filters=128
727 | size=1
728 | stride=1
729 | pad=1
730 | activation=leaky
731 |
732 | [convolutional]
733 | batch_normalize=1
734 | size=3
735 | stride=1
736 | pad=1
737 | filters=256
738 | activation=leaky
739 |
740 | [convolutional]
741 | batch_normalize=1
742 | filters=128
743 | size=1
744 | stride=1
745 | pad=1
746 | activation=leaky
747 |
748 | [convolutional]
749 | batch_normalize=1
750 | size=3
751 | stride=1
752 | pad=1
753 | filters=256
754 | activation=leaky
755 |
756 | [convolutional]
757 | batch_normalize=1
758 | filters=128
759 | size=1
760 | stride=1
761 | pad=1
762 | activation=leaky
763 |
764 | [convolutional]
765 | batch_normalize=1
766 | size=3
767 | stride=1
768 | pad=1
769 | filters=256
770 | activation=leaky
771 |
772 | [convolutional]
773 | size=1
774 | stride=1
775 | pad=1
776 | filters=255
777 | activation=linear
778 |
779 |
780 | [yolo]
781 | mask = 0,1,2
782 | anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
783 | classes=80
784 | num=9
785 | jitter=.3
786 | ignore_thresh = .7
787 | truth_thresh = 1
788 | random=1
789 |
790 |
--------------------------------------------------------------------------------
/data/yolov4-tiny.cfg:
--------------------------------------------------------------------------------
1 | [net]
2 | # Testing
3 | #batch=1
4 | #subdivisions=1
5 | # Training
6 | batch=64
7 | subdivisions=1
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.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 |
--------------------------------------------------------------------------------
/data/yolov4.cfg:
--------------------------------------------------------------------------------
1 | [net]
2 | # Testing
3 | #batch=1
4 | #subdivisions=1
5 | # Training
6 | batch=64
7 | subdivisions=8
8 | width=416
9 | height=416
10 | channels=3
11 | momentum=0.949
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 = 500500
21 | policy=steps
22 | steps=400000,450000
23 | scales=.1,.1
24 |
25 | #cutmix=1
26 | mosaic=1
27 |
28 | #:104x104 54:52x52 85:26x26 104:13x13 for 416
29 |
30 | [convolutional]
31 | batch_normalize=1
32 | filters=32
33 | size=3
34 | stride=1
35 | pad=1
36 | activation=mish
37 |
38 | # Downsample
39 |
40 | [convolutional]
41 | batch_normalize=1
42 | filters=64
43 | size=3
44 | stride=2
45 | pad=1
46 | activation=mish
47 |
48 | [convolutional]
49 | batch_normalize=1
50 | filters=64
51 | size=1
52 | stride=1
53 | pad=1
54 | activation=mish
55 |
56 | [route]
57 | layers = -2
58 |
59 | [convolutional]
60 | batch_normalize=1
61 | filters=64
62 | size=1
63 | stride=1
64 | pad=1
65 | activation=mish
66 |
67 | [convolutional]
68 | batch_normalize=1
69 | filters=32
70 | size=1
71 | stride=1
72 | pad=1
73 | activation=mish
74 |
75 | [convolutional]
76 | batch_normalize=1
77 | filters=64
78 | size=3
79 | stride=1
80 | pad=1
81 | activation=mish
82 |
83 | [shortcut]
84 | from=-3
85 | activation=linear
86 |
87 | [convolutional]
88 | batch_normalize=1
89 | filters=64
90 | size=1
91 | stride=1
92 | pad=1
93 | activation=mish
94 |
95 | [route]
96 | layers = -1,-7
97 |
98 | [convolutional]
99 | batch_normalize=1
100 | filters=64
101 | size=1
102 | stride=1
103 | pad=1
104 | activation=mish
105 |
106 | # Downsample
107 |
108 | [convolutional]
109 | batch_normalize=1
110 | filters=128
111 | size=3
112 | stride=2
113 | pad=1
114 | activation=mish
115 |
116 | [convolutional]
117 | batch_normalize=1
118 | filters=64
119 | size=1
120 | stride=1
121 | pad=1
122 | activation=mish
123 |
124 | [route]
125 | layers = -2
126 |
127 | [convolutional]
128 | batch_normalize=1
129 | filters=64
130 | size=1
131 | stride=1
132 | pad=1
133 | activation=mish
134 |
135 | [convolutional]
136 | batch_normalize=1
137 | filters=64
138 | size=1
139 | stride=1
140 | pad=1
141 | activation=mish
142 |
143 | [convolutional]
144 | batch_normalize=1
145 | filters=64
146 | size=3
147 | stride=1
148 | pad=1
149 | activation=mish
150 |
151 | [shortcut]
152 | from=-3
153 | activation=linear
154 |
155 | [convolutional]
156 | batch_normalize=1
157 | filters=64
158 | size=1
159 | stride=1
160 | pad=1
161 | activation=mish
162 |
163 | [convolutional]
164 | batch_normalize=1
165 | filters=64
166 | size=3
167 | stride=1
168 | pad=1
169 | activation=mish
170 |
171 | [shortcut]
172 | from=-3
173 | activation=linear
174 |
175 | [convolutional]
176 | batch_normalize=1
177 | filters=64
178 | size=1
179 | stride=1
180 | pad=1
181 | activation=mish
182 |
183 | [route]
184 | layers = -1,-10
185 |
186 | [convolutional]
187 | batch_normalize=1
188 | filters=128
189 | size=1
190 | stride=1
191 | pad=1
192 | activation=mish
193 |
194 | # Downsample
195 |
196 | [convolutional]
197 | batch_normalize=1
198 | filters=256
199 | size=3
200 | stride=2
201 | pad=1
202 | activation=mish
203 |
204 | [convolutional]
205 | batch_normalize=1
206 | filters=128
207 | size=1
208 | stride=1
209 | pad=1
210 | activation=mish
211 |
212 | [route]
213 | layers = -2
214 |
215 | [convolutional]
216 | batch_normalize=1
217 | filters=128
218 | size=1
219 | stride=1
220 | pad=1
221 | activation=mish
222 |
223 | [convolutional]
224 | batch_normalize=1
225 | filters=128
226 | size=1
227 | stride=1
228 | pad=1
229 | activation=mish
230 |
231 | [convolutional]
232 | batch_normalize=1
233 | filters=128
234 | size=3
235 | stride=1
236 | pad=1
237 | activation=mish
238 |
239 | [shortcut]
240 | from=-3
241 | activation=linear
242 |
243 | [convolutional]
244 | batch_normalize=1
245 | filters=128
246 | size=1
247 | stride=1
248 | pad=1
249 | activation=mish
250 |
251 | [convolutional]
252 | batch_normalize=1
253 | filters=128
254 | size=3
255 | stride=1
256 | pad=1
257 | activation=mish
258 |
259 | [shortcut]
260 | from=-3
261 | activation=linear
262 |
263 | [convolutional]
264 | batch_normalize=1
265 | filters=128
266 | size=1
267 | stride=1
268 | pad=1
269 | activation=mish
270 |
271 | [convolutional]
272 | batch_normalize=1
273 | filters=128
274 | size=3
275 | stride=1
276 | pad=1
277 | activation=mish
278 |
279 | [shortcut]
280 | from=-3
281 | activation=linear
282 |
283 | [convolutional]
284 | batch_normalize=1
285 | filters=128
286 | size=1
287 | stride=1
288 | pad=1
289 | activation=mish
290 |
291 | [convolutional]
292 | batch_normalize=1
293 | filters=128
294 | size=3
295 | stride=1
296 | pad=1
297 | activation=mish
298 |
299 | [shortcut]
300 | from=-3
301 | activation=linear
302 |
303 |
304 | [convolutional]
305 | batch_normalize=1
306 | filters=128
307 | size=1
308 | stride=1
309 | pad=1
310 | activation=mish
311 |
312 | [convolutional]
313 | batch_normalize=1
314 | filters=128
315 | size=3
316 | stride=1
317 | pad=1
318 | activation=mish
319 |
320 | [shortcut]
321 | from=-3
322 | activation=linear
323 |
324 | [convolutional]
325 | batch_normalize=1
326 | filters=128
327 | size=1
328 | stride=1
329 | pad=1
330 | activation=mish
331 |
332 | [convolutional]
333 | batch_normalize=1
334 | filters=128
335 | size=3
336 | stride=1
337 | pad=1
338 | activation=mish
339 |
340 | [shortcut]
341 | from=-3
342 | activation=linear
343 |
344 | [convolutional]
345 | batch_normalize=1
346 | filters=128
347 | size=1
348 | stride=1
349 | pad=1
350 | activation=mish
351 |
352 | [convolutional]
353 | batch_normalize=1
354 | filters=128
355 | size=3
356 | stride=1
357 | pad=1
358 | activation=mish
359 |
360 | [shortcut]
361 | from=-3
362 | activation=linear
363 |
364 | [convolutional]
365 | batch_normalize=1
366 | filters=128
367 | size=1
368 | stride=1
369 | pad=1
370 | activation=mish
371 |
372 | [convolutional]
373 | batch_normalize=1
374 | filters=128
375 | size=3
376 | stride=1
377 | pad=1
378 | activation=mish
379 |
380 | [shortcut]
381 | from=-3
382 | activation=linear
383 |
384 | [convolutional]
385 | batch_normalize=1
386 | filters=128
387 | size=1
388 | stride=1
389 | pad=1
390 | activation=mish
391 |
392 | [route]
393 | layers = -1,-28
394 |
395 | [convolutional]
396 | batch_normalize=1
397 | filters=256
398 | size=1
399 | stride=1
400 | pad=1
401 | activation=mish
402 |
403 | # Downsample
404 |
405 | [convolutional]
406 | batch_normalize=1
407 | filters=512
408 | size=3
409 | stride=2
410 | pad=1
411 | activation=mish
412 |
413 | [convolutional]
414 | batch_normalize=1
415 | filters=256
416 | size=1
417 | stride=1
418 | pad=1
419 | activation=mish
420 |
421 | [route]
422 | layers = -2
423 |
424 | [convolutional]
425 | batch_normalize=1
426 | filters=256
427 | size=1
428 | stride=1
429 | pad=1
430 | activation=mish
431 |
432 | [convolutional]
433 | batch_normalize=1
434 | filters=256
435 | size=1
436 | stride=1
437 | pad=1
438 | activation=mish
439 |
440 | [convolutional]
441 | batch_normalize=1
442 | filters=256
443 | size=3
444 | stride=1
445 | pad=1
446 | activation=mish
447 |
448 | [shortcut]
449 | from=-3
450 | activation=linear
451 |
452 |
453 | [convolutional]
454 | batch_normalize=1
455 | filters=256
456 | size=1
457 | stride=1
458 | pad=1
459 | activation=mish
460 |
461 | [convolutional]
462 | batch_normalize=1
463 | filters=256
464 | size=3
465 | stride=1
466 | pad=1
467 | activation=mish
468 |
469 | [shortcut]
470 | from=-3
471 | activation=linear
472 |
473 |
474 | [convolutional]
475 | batch_normalize=1
476 | filters=256
477 | size=1
478 | stride=1
479 | pad=1
480 | activation=mish
481 |
482 | [convolutional]
483 | batch_normalize=1
484 | filters=256
485 | size=3
486 | stride=1
487 | pad=1
488 | activation=mish
489 |
490 | [shortcut]
491 | from=-3
492 | activation=linear
493 |
494 |
495 | [convolutional]
496 | batch_normalize=1
497 | filters=256
498 | size=1
499 | stride=1
500 | pad=1
501 | activation=mish
502 |
503 | [convolutional]
504 | batch_normalize=1
505 | filters=256
506 | size=3
507 | stride=1
508 | pad=1
509 | activation=mish
510 |
511 | [shortcut]
512 | from=-3
513 | activation=linear
514 |
515 |
516 | [convolutional]
517 | batch_normalize=1
518 | filters=256
519 | size=1
520 | stride=1
521 | pad=1
522 | activation=mish
523 |
524 | [convolutional]
525 | batch_normalize=1
526 | filters=256
527 | size=3
528 | stride=1
529 | pad=1
530 | activation=mish
531 |
532 | [shortcut]
533 | from=-3
534 | activation=linear
535 |
536 |
537 | [convolutional]
538 | batch_normalize=1
539 | filters=256
540 | size=1
541 | stride=1
542 | pad=1
543 | activation=mish
544 |
545 | [convolutional]
546 | batch_normalize=1
547 | filters=256
548 | size=3
549 | stride=1
550 | pad=1
551 | activation=mish
552 |
553 | [shortcut]
554 | from=-3
555 | activation=linear
556 |
557 |
558 | [convolutional]
559 | batch_normalize=1
560 | filters=256
561 | size=1
562 | stride=1
563 | pad=1
564 | activation=mish
565 |
566 | [convolutional]
567 | batch_normalize=1
568 | filters=256
569 | size=3
570 | stride=1
571 | pad=1
572 | activation=mish
573 |
574 | [shortcut]
575 | from=-3
576 | activation=linear
577 |
578 | [convolutional]
579 | batch_normalize=1
580 | filters=256
581 | size=1
582 | stride=1
583 | pad=1
584 | activation=mish
585 |
586 | [convolutional]
587 | batch_normalize=1
588 | filters=256
589 | size=3
590 | stride=1
591 | pad=1
592 | activation=mish
593 |
594 | [shortcut]
595 | from=-3
596 | activation=linear
597 |
598 | [convolutional]
599 | batch_normalize=1
600 | filters=256
601 | size=1
602 | stride=1
603 | pad=1
604 | activation=mish
605 |
606 | [route]
607 | layers = -1,-28
608 |
609 | [convolutional]
610 | batch_normalize=1
611 | filters=512
612 | size=1
613 | stride=1
614 | pad=1
615 | activation=mish
616 |
617 | # Downsample
618 |
619 | [convolutional]
620 | batch_normalize=1
621 | filters=1024
622 | size=3
623 | stride=2
624 | pad=1
625 | activation=mish
626 |
627 | [convolutional]
628 | batch_normalize=1
629 | filters=512
630 | size=1
631 | stride=1
632 | pad=1
633 | activation=mish
634 |
635 | [route]
636 | layers = -2
637 |
638 | [convolutional]
639 | batch_normalize=1
640 | filters=512
641 | size=1
642 | stride=1
643 | pad=1
644 | activation=mish
645 |
646 | [convolutional]
647 | batch_normalize=1
648 | filters=512
649 | size=1
650 | stride=1
651 | pad=1
652 | activation=mish
653 |
654 | [convolutional]
655 | batch_normalize=1
656 | filters=512
657 | size=3
658 | stride=1
659 | pad=1
660 | activation=mish
661 |
662 | [shortcut]
663 | from=-3
664 | activation=linear
665 |
666 | [convolutional]
667 | batch_normalize=1
668 | filters=512
669 | size=1
670 | stride=1
671 | pad=1
672 | activation=mish
673 |
674 | [convolutional]
675 | batch_normalize=1
676 | filters=512
677 | size=3
678 | stride=1
679 | pad=1
680 | activation=mish
681 |
682 | [shortcut]
683 | from=-3
684 | activation=linear
685 |
686 | [convolutional]
687 | batch_normalize=1
688 | filters=512
689 | size=1
690 | stride=1
691 | pad=1
692 | activation=mish
693 |
694 | [convolutional]
695 | batch_normalize=1
696 | filters=512
697 | size=3
698 | stride=1
699 | pad=1
700 | activation=mish
701 |
702 | [shortcut]
703 | from=-3
704 | activation=linear
705 |
706 | [convolutional]
707 | batch_normalize=1
708 | filters=512
709 | size=1
710 | stride=1
711 | pad=1
712 | activation=mish
713 |
714 | [convolutional]
715 | batch_normalize=1
716 | filters=512
717 | size=3
718 | stride=1
719 | pad=1
720 | activation=mish
721 |
722 | [shortcut]
723 | from=-3
724 | activation=linear
725 |
726 | [convolutional]
727 | batch_normalize=1
728 | filters=512
729 | size=1
730 | stride=1
731 | pad=1
732 | activation=mish
733 |
734 | [route]
735 | layers = -1,-16
736 |
737 | [convolutional]
738 | batch_normalize=1
739 | filters=1024
740 | size=1
741 | stride=1
742 | pad=1
743 | activation=mish
744 |
745 | ##########################
746 |
747 | [convolutional]
748 | batch_normalize=1
749 | filters=512
750 | size=1
751 | stride=1
752 | pad=1
753 | activation=leaky
754 |
755 | [convolutional]
756 | batch_normalize=1
757 | size=3
758 | stride=1
759 | pad=1
760 | filters=1024
761 | activation=leaky
762 |
763 | [convolutional]
764 | batch_normalize=1
765 | filters=512
766 | size=1
767 | stride=1
768 | pad=1
769 | activation=leaky
770 |
771 | ### SPP ###
772 | [maxpool]
773 | stride=1
774 | size=5
775 |
776 | [route]
777 | layers=-2
778 |
779 | [maxpool]
780 | stride=1
781 | size=9
782 |
783 | [route]
784 | layers=-4
785 |
786 | [maxpool]
787 | stride=1
788 | size=13
789 |
790 | [route]
791 | layers=-1,-3,-5,-6
792 | ### End SPP ###
793 |
794 | [convolutional]
795 | batch_normalize=1
796 | filters=512
797 | size=1
798 | stride=1
799 | pad=1
800 | activation=leaky
801 |
802 | [convolutional]
803 | batch_normalize=1
804 | size=3
805 | stride=1
806 | pad=1
807 | filters=1024
808 | activation=leaky
809 |
810 | [convolutional]
811 | batch_normalize=1
812 | filters=512
813 | size=1
814 | stride=1
815 | pad=1
816 | activation=leaky
817 |
818 | [convolutional]
819 | batch_normalize=1
820 | filters=256
821 | size=1
822 | stride=1
823 | pad=1
824 | activation=leaky
825 |
826 | [upsample]
827 | stride=2
828 |
829 | [route]
830 | layers = 85
831 |
832 | [convolutional]
833 | batch_normalize=1
834 | filters=256
835 | size=1
836 | stride=1
837 | pad=1
838 | activation=leaky
839 |
840 | [route]
841 | layers = -1, -3
842 |
843 | [convolutional]
844 | batch_normalize=1
845 | filters=256
846 | size=1
847 | stride=1
848 | pad=1
849 | activation=leaky
850 |
851 | [convolutional]
852 | batch_normalize=1
853 | size=3
854 | stride=1
855 | pad=1
856 | filters=512
857 | activation=leaky
858 |
859 | [convolutional]
860 | batch_normalize=1
861 | filters=256
862 | size=1
863 | stride=1
864 | pad=1
865 | activation=leaky
866 |
867 | [convolutional]
868 | batch_normalize=1
869 | size=3
870 | stride=1
871 | pad=1
872 | filters=512
873 | activation=leaky
874 |
875 | [convolutional]
876 | batch_normalize=1
877 | filters=256
878 | size=1
879 | stride=1
880 | pad=1
881 | activation=leaky
882 |
883 | [convolutional]
884 | batch_normalize=1
885 | filters=128
886 | size=1
887 | stride=1
888 | pad=1
889 | activation=leaky
890 |
891 | [upsample]
892 | stride=2
893 |
894 | [route]
895 | layers = 54
896 |
897 | [convolutional]
898 | batch_normalize=1
899 | filters=128
900 | size=1
901 | stride=1
902 | pad=1
903 | activation=leaky
904 |
905 | [route]
906 | layers = -1, -3
907 |
908 | [convolutional]
909 | batch_normalize=1
910 | filters=128
911 | size=1
912 | stride=1
913 | pad=1
914 | activation=leaky
915 |
916 | [convolutional]
917 | batch_normalize=1
918 | size=3
919 | stride=1
920 | pad=1
921 | filters=256
922 | activation=leaky
923 |
924 | [convolutional]
925 | batch_normalize=1
926 | filters=128
927 | size=1
928 | stride=1
929 | pad=1
930 | activation=leaky
931 |
932 | [convolutional]
933 | batch_normalize=1
934 | size=3
935 | stride=1
936 | pad=1
937 | filters=256
938 | activation=leaky
939 |
940 | [convolutional]
941 | batch_normalize=1
942 | filters=128
943 | size=1
944 | stride=1
945 | pad=1
946 | activation=leaky
947 |
948 | ##########################
949 |
950 | [convolutional]
951 | batch_normalize=1
952 | size=3
953 | stride=1
954 | pad=1
955 | filters=256
956 | activation=leaky
957 |
958 | [convolutional]
959 | size=1
960 | stride=1
961 | pad=1
962 | filters=255
963 | activation=linear
964 |
965 |
966 | [yolo]
967 | mask = 0,1,2
968 | anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401
969 | classes=80
970 | num=9
971 | jitter=.3
972 | ignore_thresh = .7
973 | truth_thresh = 1
974 | scale_x_y = 1.2
975 | iou_thresh=0.213
976 | cls_normalizer=1.0
977 | iou_normalizer=0.07
978 | iou_loss=ciou
979 | nms_kind=greedynms
980 | beta_nms=0.6
981 |
982 |
983 | [route]
984 | layers = -4
985 |
986 | [convolutional]
987 | batch_normalize=1
988 | size=3
989 | stride=2
990 | pad=1
991 | filters=256
992 | activation=leaky
993 |
994 | [route]
995 | layers = -1, -16
996 |
997 | [convolutional]
998 | batch_normalize=1
999 | filters=256
1000 | size=1
1001 | stride=1
1002 | pad=1
1003 | activation=leaky
1004 |
1005 | [convolutional]
1006 | batch_normalize=1
1007 | size=3
1008 | stride=1
1009 | pad=1
1010 | filters=512
1011 | activation=leaky
1012 |
1013 | [convolutional]
1014 | batch_normalize=1
1015 | filters=256
1016 | size=1
1017 | stride=1
1018 | pad=1
1019 | activation=leaky
1020 |
1021 | [convolutional]
1022 | batch_normalize=1
1023 | size=3
1024 | stride=1
1025 | pad=1
1026 | filters=512
1027 | activation=leaky
1028 |
1029 | [convolutional]
1030 | batch_normalize=1
1031 | filters=256
1032 | size=1
1033 | stride=1
1034 | pad=1
1035 | activation=leaky
1036 |
1037 | [convolutional]
1038 | batch_normalize=1
1039 | size=3
1040 | stride=1
1041 | pad=1
1042 | filters=512
1043 | activation=leaky
1044 |
1045 | [convolutional]
1046 | size=1
1047 | stride=1
1048 | pad=1
1049 | filters=255
1050 | activation=linear
1051 |
1052 |
1053 | [yolo]
1054 | mask = 3,4,5
1055 | anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401
1056 | classes=80
1057 | num=9
1058 | jitter=.3
1059 | ignore_thresh = .7
1060 | truth_thresh = 1
1061 | scale_x_y = 1.1
1062 | iou_thresh=0.213
1063 | cls_normalizer=1.0
1064 | iou_normalizer=0.07
1065 | iou_loss=ciou
1066 | nms_kind=greedynms
1067 | beta_nms=0.6
1068 |
1069 |
1070 | [route]
1071 | layers = -4
1072 |
1073 | [convolutional]
1074 | batch_normalize=1
1075 | size=3
1076 | stride=2
1077 | pad=1
1078 | filters=512
1079 | activation=leaky
1080 |
1081 | [route]
1082 | layers = -1, -37
1083 |
1084 | [convolutional]
1085 | batch_normalize=1
1086 | filters=512
1087 | size=1
1088 | stride=1
1089 | pad=1
1090 | activation=leaky
1091 |
1092 | [convolutional]
1093 | batch_normalize=1
1094 | size=3
1095 | stride=1
1096 | pad=1
1097 | filters=1024
1098 | activation=leaky
1099 |
1100 | [convolutional]
1101 | batch_normalize=1
1102 | filters=512
1103 | size=1
1104 | stride=1
1105 | pad=1
1106 | activation=leaky
1107 |
1108 | [convolutional]
1109 | batch_normalize=1
1110 | size=3
1111 | stride=1
1112 | pad=1
1113 | filters=1024
1114 | activation=leaky
1115 |
1116 | [convolutional]
1117 | batch_normalize=1
1118 | filters=512
1119 | size=1
1120 | stride=1
1121 | pad=1
1122 | activation=leaky
1123 |
1124 | [convolutional]
1125 | batch_normalize=1
1126 | size=3
1127 | stride=1
1128 | pad=1
1129 | filters=1024
1130 | activation=leaky
1131 |
1132 | [convolutional]
1133 | size=1
1134 | stride=1
1135 | pad=1
1136 | filters=255
1137 | activation=linear
1138 |
1139 |
1140 | [yolo]
1141 | mask = 6,7,8
1142 | anchors = 12, 16, 19, 36, 40, 28, 36, 75, 76, 55, 72, 146, 142, 110, 192, 243, 459, 401
1143 | classes=80
1144 | num=9
1145 | jitter=.3
1146 | ignore_thresh = .7
1147 | truth_thresh = 1
1148 | random=1
1149 | scale_x_y = 1.05
1150 | iou_thresh=0.213
1151 | cls_normalizer=1.0
1152 | iou_normalizer=0.07
1153 | iou_loss=ciou
1154 | nms_kind=greedynms
1155 | beta_nms=0.6
1156 |
1157 |
--------------------------------------------------------------------------------
/logging.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | #ifndef TENSORRT_LOGGING_H
18 | #define TENSORRT_LOGGING_H
19 |
20 | #include "NvInferRuntimeCommon.h"
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | using Severity = nvinfer1::ILogger::Severity;
30 |
31 | class LogStreamConsumerBuffer : public std::stringbuf
32 | {
33 | public:
34 | LogStreamConsumerBuffer(std::ostream& stream, const std::string& prefix, bool shouldLog)
35 | : mOutput(stream)
36 | , mPrefix(prefix)
37 | , mShouldLog(shouldLog)
38 | {
39 | }
40 |
41 | LogStreamConsumerBuffer(LogStreamConsumerBuffer&& other)
42 | : mOutput(other.mOutput)
43 | {
44 | }
45 |
46 | ~LogStreamConsumerBuffer()
47 | {
48 | // std::streambuf::pbase() gives a pointer to the beginning of the buffered part of the output sequence
49 | // std::streambuf::pptr() gives a pointer to the current position of the output sequence
50 | // if the pointer to the beginning is not equal to the pointer to the current position,
51 | // call putOutput() to log the output to the stream
52 | if (pbase() != pptr())
53 | {
54 | putOutput();
55 | }
56 | }
57 |
58 | // synchronizes the stream buffer and returns 0 on success
59 | // synchronizing the stream buffer consists of inserting the buffer contents into the stream,
60 | // resetting the buffer and flushing the stream
61 | virtual int sync()
62 | {
63 | putOutput();
64 | return 0;
65 | }
66 |
67 | void putOutput()
68 | {
69 | if (mShouldLog)
70 | {
71 | // prepend timestamp
72 | std::time_t timestamp = std::time(nullptr);
73 | tm* tm_local = std::localtime(×tamp);
74 | std::cout << "[";
75 | std::cout << std::setw(2) << std::setfill('0') << 1 + tm_local->tm_mon << "/";
76 | std::cout << std::setw(2) << std::setfill('0') << tm_local->tm_mday << "/";
77 | std::cout << std::setw(4) << std::setfill('0') << 1900 + tm_local->tm_year << "-";
78 | std::cout << std::setw(2) << std::setfill('0') << tm_local->tm_hour << ":";
79 | std::cout << std::setw(2) << std::setfill('0') << tm_local->tm_min << ":";
80 | std::cout << std::setw(2) << std::setfill('0') << tm_local->tm_sec << "] ";
81 | // std::stringbuf::str() gets the string contents of the buffer
82 | // insert the buffer contents pre-appended by the appropriate prefix into the stream
83 | mOutput << mPrefix << str();
84 | // set the buffer to empty
85 | str("");
86 | // flush the stream
87 | mOutput.flush();
88 | }
89 | }
90 |
91 | void setShouldLog(bool shouldLog)
92 | {
93 | mShouldLog = shouldLog;
94 | }
95 |
96 | private:
97 | std::ostream& mOutput;
98 | std::string mPrefix;
99 | bool mShouldLog;
100 | };
101 |
102 | //!
103 | //! \class LogStreamConsumerBase
104 | //! \brief Convenience object used to initialize LogStreamConsumerBuffer before std::ostream in LogStreamConsumer
105 | //!
106 | class LogStreamConsumerBase
107 | {
108 | public:
109 | LogStreamConsumerBase(std::ostream& stream, const std::string& prefix, bool shouldLog)
110 | : mBuffer(stream, prefix, shouldLog)
111 | {
112 | }
113 |
114 | protected:
115 | LogStreamConsumerBuffer mBuffer;
116 | };
117 |
118 | //!
119 | //! \class LogStreamConsumer
120 | //! \brief Convenience object used to facilitate use of C++ stream syntax when logging messages.
121 | //! Order of base classes is LogStreamConsumerBase and then std::ostream.
122 | //! This is because the LogStreamConsumerBase class is used to initialize the LogStreamConsumerBuffer member field
123 | //! in LogStreamConsumer and then the address of the buffer is passed to std::ostream.
124 | //! This is necessary to prevent the address of an uninitialized buffer from being passed to std::ostream.
125 | //! Please do not change the order of the parent classes.
126 | //!
127 | class LogStreamConsumer : protected LogStreamConsumerBase, public std::ostream
128 | {
129 | public:
130 | //! \brief Creates a LogStreamConsumer which logs messages with level severity.
131 | //! Reportable severity determines if the messages are severe enough to be logged.
132 | LogStreamConsumer(Severity reportableSeverity, Severity severity)
133 | : LogStreamConsumerBase(severityOstream(severity), severityPrefix(severity), severity <= reportableSeverity)
134 | , std::ostream(&mBuffer) // links the stream buffer with the stream
135 | , mShouldLog(severity <= reportableSeverity)
136 | , mSeverity(severity)
137 | {
138 | }
139 |
140 | LogStreamConsumer(LogStreamConsumer&& other)
141 | : LogStreamConsumerBase(severityOstream(other.mSeverity), severityPrefix(other.mSeverity), other.mShouldLog)
142 | , std::ostream(&mBuffer) // links the stream buffer with the stream
143 | , mShouldLog(other.mShouldLog)
144 | , mSeverity(other.mSeverity)
145 | {
146 | }
147 |
148 | void setReportableSeverity(Severity reportableSeverity)
149 | {
150 | mShouldLog = mSeverity <= reportableSeverity;
151 | mBuffer.setShouldLog(mShouldLog);
152 | }
153 |
154 | private:
155 | static std::ostream& severityOstream(Severity severity)
156 | {
157 | return severity >= Severity::kINFO ? std::cout : std::cerr;
158 | }
159 |
160 | static std::string severityPrefix(Severity severity)
161 | {
162 | switch (severity)
163 | {
164 | case Severity::kINTERNAL_ERROR: return "[F] ";
165 | case Severity::kERROR: return "[E] ";
166 | case Severity::kWARNING: return "[W] ";
167 | case Severity::kINFO: return "[I] ";
168 | case Severity::kVERBOSE: return "[V] ";
169 | default: assert(0); return "";
170 | }
171 | }
172 |
173 | bool mShouldLog;
174 | Severity mSeverity;
175 | };
176 |
177 | //! \class Logger
178 | //!
179 | //! \brief Class which manages logging of TensorRT tools and samples
180 | //!
181 | //! \details This class provides a common interface for TensorRT tools and samples to log information to the console,
182 | //! and supports logging two types of messages:
183 | //!
184 | //! - Debugging messages with an associated severity (info, warning, error, or internal error/fatal)
185 | //! - Test pass/fail messages
186 | //!
187 | //! The advantage of having all samples use this class for logging as opposed to emitting directly to stdout/stderr is
188 | //! that the logic for controlling the verbosity and formatting of sample output is centralized in one location.
189 | //!
190 | //! In the future, this class could be extended to support dumping test results to a file in some standard format
191 | //! (for example, JUnit XML), and providing additional metadata (e.g. timing the duration of a test run).
192 | //!
193 | //! TODO: For backwards compatibility with existing samples, this class inherits directly from the nvinfer1::ILogger
194 | //! interface, which is problematic since there isn't a clean separation between messages coming from the TensorRT
195 | //! library and messages coming from the sample.
196 | //!
197 | //! In the future (once all samples are updated to use Logger::getTRTLogger() to access the ILogger) we can refactor the
198 | //! class to eliminate the inheritance and instead make the nvinfer1::ILogger implementation a member of the Logger
199 | //! object.
200 |
201 | class Logger : public nvinfer1::ILogger
202 | {
203 | public:
204 | Logger(Severity severity = Severity::kWARNING)
205 | : mReportableSeverity(severity)
206 | {
207 | }
208 |
209 | //!
210 | //! \enum TestResult
211 | //! \brief Represents the state of a given test
212 | //!
213 | enum class TestResult
214 | {
215 | kRUNNING, //!< The test is running
216 | kPASSED, //!< The test passed
217 | kFAILED, //!< The test failed
218 | kWAIVED //!< The test was waived
219 | };
220 |
221 | //!
222 | //! \brief Forward-compatible method for retrieving the nvinfer::ILogger associated with this Logger
223 | //! \return The nvinfer1::ILogger associated with this Logger
224 | //!
225 | //! TODO Once all samples are updated to use this method to register the logger with TensorRT,
226 | //! we can eliminate the inheritance of Logger from ILogger
227 | //!
228 | nvinfer1::ILogger& getTRTLogger()
229 | {
230 | return *this;
231 | }
232 |
233 | //!
234 | //! \brief Implementation of the nvinfer1::ILogger::log() virtual method
235 | //!
236 | //! Note samples should not be calling this function directly; it will eventually go away once we eliminate the
237 | //! inheritance from nvinfer1::ILogger
238 | //!
239 | void log(Severity severity, const char* msg) override
240 | {
241 | LogStreamConsumer(mReportableSeverity, severity) << "[TRT] " << std::string(msg) << std::endl;
242 | }
243 |
244 | //!
245 | //! \brief Method for controlling the verbosity of logging output
246 | //!
247 | //! \param severity The logger will only emit messages that have severity of this level or higher.
248 | //!
249 | void setReportableSeverity(Severity severity)
250 | {
251 | mReportableSeverity = severity;
252 | }
253 |
254 | //!
255 | //! \brief Opaque handle that holds logging information for a particular test
256 | //!
257 | //! This object is an opaque handle to information used by the Logger to print test results.
258 | //! The sample must call Logger::defineTest() in order to obtain a TestAtom that can be used
259 | //! with Logger::reportTest{Start,End}().
260 | //!
261 | class TestAtom
262 | {
263 | public:
264 | TestAtom(TestAtom&&) = default;
265 |
266 | private:
267 | friend class Logger;
268 |
269 | TestAtom(bool started, const std::string& name, const std::string& cmdline)
270 | : mStarted(started)
271 | , mName(name)
272 | , mCmdline(cmdline)
273 | {
274 | }
275 |
276 | bool mStarted;
277 | std::string mName;
278 | std::string mCmdline;
279 | };
280 |
281 | //!
282 | //! \brief Define a test for logging
283 | //!
284 | //! \param[in] name The name of the test. This should be a string starting with
285 | //! "TensorRT" and containing dot-separated strings containing
286 | //! the characters [A-Za-z0-9_].
287 | //! For example, "TensorRT.sample_googlenet"
288 | //! \param[in] cmdline The command line used to reproduce the test
289 | //
290 | //! \return a TestAtom that can be used in Logger::reportTest{Start,End}().
291 | //!
292 | static TestAtom defineTest(const std::string& name, const std::string& cmdline)
293 | {
294 | return TestAtom(false, name, cmdline);
295 | }
296 |
297 | //!
298 | //! \brief A convenience overloaded version of defineTest() that accepts an array of command-line arguments
299 | //! as input
300 | //!
301 | //! \param[in] name The name of the test
302 | //! \param[in] argc The number of command-line arguments
303 | //! \param[in] argv The array of command-line arguments (given as C strings)
304 | //!
305 | //! \return a TestAtom that can be used in Logger::reportTest{Start,End}().
306 | static TestAtom defineTest(const std::string& name, int argc, char const* const* argv)
307 | {
308 | auto cmdline = genCmdlineString(argc, argv);
309 | return defineTest(name, cmdline);
310 | }
311 |
312 | //!
313 | //! \brief Report that a test has started.
314 | //!
315 | //! \pre reportTestStart() has not been called yet for the given testAtom
316 | //!
317 | //! \param[in] testAtom The handle to the test that has started
318 | //!
319 | static void reportTestStart(TestAtom& testAtom)
320 | {
321 | reportTestResult(testAtom, TestResult::kRUNNING);
322 | assert(!testAtom.mStarted);
323 | testAtom.mStarted = true;
324 | }
325 |
326 | //!
327 | //! \brief Report that a test has ended.
328 | //!
329 | //! \pre reportTestStart() has been called for the given testAtom
330 | //!
331 | //! \param[in] testAtom The handle to the test that has ended
332 | //! \param[in] result The result of the test. Should be one of TestResult::kPASSED,
333 | //! TestResult::kFAILED, TestResult::kWAIVED
334 | //!
335 | static void reportTestEnd(const TestAtom& testAtom, TestResult result)
336 | {
337 | assert(result != TestResult::kRUNNING);
338 | assert(testAtom.mStarted);
339 | reportTestResult(testAtom, result);
340 | }
341 |
342 | static int reportPass(const TestAtom& testAtom)
343 | {
344 | reportTestEnd(testAtom, TestResult::kPASSED);
345 | return EXIT_SUCCESS;
346 | }
347 |
348 | static int reportFail(const TestAtom& testAtom)
349 | {
350 | reportTestEnd(testAtom, TestResult::kFAILED);
351 | return EXIT_FAILURE;
352 | }
353 |
354 | static int reportWaive(const TestAtom& testAtom)
355 | {
356 | reportTestEnd(testAtom, TestResult::kWAIVED);
357 | return EXIT_SUCCESS;
358 | }
359 |
360 | static int reportTest(const TestAtom& testAtom, bool pass)
361 | {
362 | return pass ? reportPass(testAtom) : reportFail(testAtom);
363 | }
364 |
365 | Severity getReportableSeverity() const
366 | {
367 | return mReportableSeverity;
368 | }
369 |
370 | private:
371 | //!
372 | //! \brief returns an appropriate string for prefixing a log message with the given severity
373 | //!
374 | static const char* severityPrefix(Severity severity)
375 | {
376 | switch (severity)
377 | {
378 | case Severity::kINTERNAL_ERROR: return "[F] ";
379 | case Severity::kERROR: return "[E] ";
380 | case Severity::kWARNING: return "[W] ";
381 | case Severity::kINFO: return "[I] ";
382 | case Severity::kVERBOSE: return "[V] ";
383 | default: assert(0); return "";
384 | }
385 | }
386 |
387 | //!
388 | //! \brief returns an appropriate string for prefixing a test result message with the given result
389 | //!
390 | static const char* testResultString(TestResult result)
391 | {
392 | switch (result)
393 | {
394 | case TestResult::kRUNNING: return "RUNNING";
395 | case TestResult::kPASSED: return "PASSED";
396 | case TestResult::kFAILED: return "FAILED";
397 | case TestResult::kWAIVED: return "WAIVED";
398 | default: assert(0); return "";
399 | }
400 | }
401 |
402 | //!
403 | //! \brief returns an appropriate output stream (cout or cerr) to use with the given severity
404 | //!
405 | static std::ostream& severityOstream(Severity severity)
406 | {
407 | return severity >= Severity::kINFO ? std::cout : std::cerr;
408 | }
409 |
410 | //!
411 | //! \brief method that implements logging test results
412 | //!
413 | static void reportTestResult(const TestAtom& testAtom, TestResult result)
414 | {
415 | severityOstream(Severity::kINFO) << "&&&& " << testResultString(result) << " " << testAtom.mName << " # "
416 | << testAtom.mCmdline << std::endl;
417 | }
418 |
419 | //!
420 | //! \brief generate a command line string from the given (argc, argv) values
421 | //!
422 | static std::string genCmdlineString(int argc, char const* const* argv)
423 | {
424 | std::stringstream ss;
425 | for (int i = 0; i < argc; i++)
426 | {
427 | if (i > 0)
428 | ss << " ";
429 | ss << argv[i];
430 | }
431 | return ss.str();
432 | }
433 |
434 | Severity mReportableSeverity;
435 | };
436 |
437 | namespace
438 | {
439 |
440 | //!
441 | //! \brief produces a LogStreamConsumer object that can be used to log messages of severity kVERBOSE
442 | //!
443 | //! Example usage:
444 | //!
445 | //! LOG_VERBOSE(logger) << "hello world" << std::endl;
446 | //!
447 | inline LogStreamConsumer LOG_VERBOSE(const Logger& logger)
448 | {
449 | return LogStreamConsumer(logger.getReportableSeverity(), Severity::kVERBOSE);
450 | }
451 |
452 | //!
453 | //! \brief produces a LogStreamConsumer object that can be used to log messages of severity kINFO
454 | //!
455 | //! Example usage:
456 | //!
457 | //! LOG_INFO(logger) << "hello world" << std::endl;
458 | //!
459 | inline LogStreamConsumer LOG_INFO(const Logger& logger)
460 | {
461 | return LogStreamConsumer(logger.getReportableSeverity(), Severity::kINFO);
462 | }
463 |
464 | //!
465 | //! \brief produces a LogStreamConsumer object that can be used to log messages of severity kWARNING
466 | //!
467 | //! Example usage:
468 | //!
469 | //! LOG_WARN(logger) << "hello world" << std::endl;
470 | //!
471 | inline LogStreamConsumer LOG_WARN(const Logger& logger)
472 | {
473 | return LogStreamConsumer(logger.getReportableSeverity(), Severity::kWARNING);
474 | }
475 |
476 | //!
477 | //! \brief produces a LogStreamConsumer object that can be used to log messages of severity kERROR
478 | //!
479 | //! Example usage:
480 | //!
481 | //! LOG_ERROR(logger) << "hello world" << std::endl;
482 | //!
483 | inline LogStreamConsumer LOG_ERROR(const Logger& logger)
484 | {
485 | return LogStreamConsumer(logger.getReportableSeverity(), Severity::kERROR);
486 | }
487 |
488 | //!
489 | //! \brief produces a LogStreamConsumer object that can be used to log messages of severity kINTERNAL_ERROR
490 | // ("fatal" severity)
491 | //!
492 | //! Example usage:
493 | //!
494 | //! LOG_FATAL(logger) << "hello world" << std::endl;
495 | //!
496 | inline LogStreamConsumer LOG_FATAL(const Logger& logger)
497 | {
498 | return LogStreamConsumer(logger.getReportableSeverity(), Severity::kINTERNAL_ERROR);
499 | }
500 |
501 | } // anonymous namespace
502 |
503 | #endif // TENSORRT_LOGGING_H
504 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include