-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
252 lines (218 loc) · 7.98 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
cmake_minimum_required(VERSION 2.8.12)
project(darknet_ros)
# Set c++11 cmake flags
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
set(CMAKE_C_FLAGS "-Wall -Wno-unused-result -Wno-unknown-pragmas -Wno-unused-variable -Wfatal-errors -fPIC ${CMAKE_C_FLAGS}")
# Define path of darknet folder here.
find_path(DARKNET_PATH
NAMES "README.md"
HINTS "${CMAKE_CURRENT_SOURCE_DIR}/../darknet/")
message(STATUS "Darknet path dir = ${DARKNET_PATH}")
add_definitions(-DDARKNET_FILE_PATH="${DARKNET_PATH}")
# Find CUDA
find_package(CUDA QUIET)
if (CUDA_FOUND)
find_package(CUDA REQUIRED)
message(STATUS "CUDA Version: ${CUDA_VERSION_STRINGS}")
message(STATUS "CUDA Libararies: ${CUDA_LIBRARIES}")
set(
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-O3
-gencode arch=compute_30,code=sm_30
-gencode arch=compute_35,code=sm_35
-gencode arch=compute_50,code=[sm_50,compute_50]
-gencode arch=compute_52,code=[sm_52,compute_52]
-gencode arch=compute_61,code=sm_61
-gencode arch=compute_62,code=sm_62
)
add_definitions(-DGPU)
else()
list(APPEND LIBRARIES "m")
endif()
# Find X11
message ( STATUS "Searching for X11..." )
find_package ( X11 REQUIRED )
if ( X11_FOUND )
include_directories ( ${X11_INCLUDE_DIR} )
link_libraries ( ${X11_LIBRARIES} )
message ( STATUS " X11_INCLUDE_DIR: " ${X11_INCLUDE_DIR} )
message ( STATUS " X11_LIBRARIES: " ${X11_LIBRARIES} )
endif ( X11_FOUND )
# Find rquired packeges
find_package(Boost REQUIRED COMPONENTS thread)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
find_package(catkin REQUIRED
COMPONENTS
cv_bridge
roscpp
rospy
std_msgs
actionlib
darknet_ros_msgs
image_transport
)
# Enable OPENCV in darknet
add_definitions(-DOPENCV)
add_definitions(-O4 -g)
catkin_package(
INCLUDE_DIRS
include
LIBRARIES
${PROJECT_NAME}_lib
CATKIN_DEPENDS
cv_bridge
roscpp
actionlib
rospy
std_msgs
darknet_ros_msgs
image_transport
DEPENDS
Boost
)
include_directories(
${DARKNET_PATH}/src
${DARKNET_PATH}/include
include
${Boost_INCLUDE_DIRS}
${catkin_INCLUDE_DIRS}
)
set(PROJECT_LIB_FILES
src/YoloObjectDetector.cpp src/image_interface.c
)
set(DARKNET_CORE_FILES
${DARKNET_PATH}/src/activation_layer.c ${DARKNET_PATH}/src/im2col.c
${DARKNET_PATH}/src/activations.c ${DARKNET_PATH}/src/image.c
${DARKNET_PATH}/src/avgpool_layer.c ${DARKNET_PATH}/src/layer.c
${DARKNET_PATH}/src/batchnorm_layer.c ${DARKNET_PATH}/src/list.c
${DARKNET_PATH}/src/blas.c ${DARKNET_PATH}/src/local_layer.c
${DARKNET_PATH}/src/box.c ${DARKNET_PATH}/src/lstm_layer.c
${DARKNET_PATH}/src/col2im.c ${DARKNET_PATH}/src/matrix.c
${DARKNET_PATH}/src/connected_layer.c ${DARKNET_PATH}/src/maxpool_layer.c
${DARKNET_PATH}/src/convolutional_layer.c ${DARKNET_PATH}/src/network.c
${DARKNET_PATH}/src/cost_layer.c ${DARKNET_PATH}/src/normalization_layer.c
${DARKNET_PATH}/src/crnn_layer.c ${DARKNET_PATH}/src/option_list.c
${DARKNET_PATH}/src/crop_layer.c ${DARKNET_PATH}/src/parser.c
${DARKNET_PATH}/src/cuda.c ${DARKNET_PATH}/src/region_layer.c
${DARKNET_PATH}/src/data.c ${DARKNET_PATH}/src/reorg_layer.c
${DARKNET_PATH}/src/deconvolutional_layer.c ${DARKNET_PATH}/src/rnn_layer.c
${DARKNET_PATH}/src/demo.c ${DARKNET_PATH}/src/route_layer.c
${DARKNET_PATH}/src/detection_layer.c ${DARKNET_PATH}/src/shortcut_layer.c
${DARKNET_PATH}/src/dropout_layer.c ${DARKNET_PATH}/src/softmax_layer.c
${DARKNET_PATH}/src/gemm.c ${DARKNET_PATH}/src/tree.c
${DARKNET_PATH}/src/gru_layer.c ${DARKNET_PATH}/src/utils.c
${DARKNET_PATH}/src/upsample_layer.c ${DARKNET_PATH}/src/logistic_layer.c
${DARKNET_PATH}/src/l2norm_layer.c ${DARKNET_PATH}/src/yolo_layer.c
${DARKNET_PATH}/examples/art.c ${DARKNET_PATH}/examples/lsd.c
${DARKNET_PATH}/examples/attention.c ${DARKNET_PATH}/examples/nightmare.c
${DARKNET_PATH}/examples/captcha.c ${DARKNET_PATH}/examples/regressor.c
${DARKNET_PATH}/examples/cifar.c ${DARKNET_PATH}/examples/rnn.c
${DARKNET_PATH}/examples/classifier.c ${DARKNET_PATH}/examples/segmenter.c
${DARKNET_PATH}/examples/coco.c ${DARKNET_PATH}/examples/super.c
${DARKNET_PATH}/examples/darknet.c ${DARKNET_PATH}/examples/tag.c
${DARKNET_PATH}/examples/detector.c ${DARKNET_PATH}/examples/yolo.c
${DARKNET_PATH}/examples/go.c
)
set(DARKNET_CUDA_FILES
${DARKNET_PATH}/src/activation_kernels.cu ${DARKNET_PATH}/src/crop_layer_kernels.cu
${DARKNET_PATH}/src/avgpool_layer_kernels.cu ${DARKNET_PATH}/src/deconvolutional_kernels.cu
${DARKNET_PATH}/src/blas_kernels.cu ${DARKNET_PATH}/src/dropout_layer_kernels.cu
${DARKNET_PATH}/src/col2im_kernels.cu ${DARKNET_PATH}/src/im2col_kernels.cu
${DARKNET_PATH}/src/convolutional_kernels.cu ${DARKNET_PATH}/src/maxpool_layer_kernels.cu
)
if (CUDA_FOUND)
link_directories(
${CUDA_TOOLKIT_ROOT_DIR}/lib64
)
cuda_add_library(${PROJECT_NAME}_lib
${PROJECT_LIB_FILES} ${DARKNET_CORE_FILES}
${DARKNET_CUDA_FILES}
)
target_link_libraries(${PROJECT_NAME}_lib
cuda
cudart
cublas
curand
)
cuda_add_executable(${PROJECT_NAME}
src/yolo_object_detector_node.cpp
)
else()
add_library(${PROJECT_NAME}_lib
${PROJECT_LIB_FILES} ${DARKNET_CORE_FILES}
)
add_executable(${PROJECT_NAME}
src/yolo_object_detector_node.cpp
)
endif()
target_link_libraries(${PROJECT_NAME}_lib
m
pthread
stdc++
${Boost_LIBRARIES}
${OpenCV_LIBRARIES}
${catkin_LIBRARIES}
${OpenCV_LIBS}
)
target_link_libraries(${PROJECT_NAME}
${PROJECT_NAME}_lib
)
add_dependencies(${PROJECT_NAME}_lib
darknet_ros_msgs_generate_messages_cpp
)
install(TARGETS ${PROJECT_NAME}_lib
ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}
)
install(
DIRECTORY include/${PROJECT_NAME}/
DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}
FILES_MATCHING PATTERN "*.h"
)
install(DIRECTORY config launch yolo_network_config
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION}
)
# Download yolov2-tiny.weights
set(PATH "${CMAKE_CURRENT_SOURCE_DIR}/yolo_network_config/weights")
set(FILE "${PATH}/yolov2-tiny.weights")
message(STATUS "Checking and downloading yolov2-tiny.weights if needed ...")
if (NOT EXISTS "${FILE}")
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND wget http://pjreddie.com/media/files/yolov2-tiny.weights -P ${PATH})
endif()
# Download yolov3.weights
set(FILE "${PATH}/yolov3.weights")
message(STATUS "Checking and downloading yolov3.weights if needed ...")
if (NOT EXISTS "${FILE}")
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND wget http://pjreddie.com/media/files/yolov3.weights -P ${PATH})
endif()
#############
## Testing ##
#############
if(CATKIN_ENABLE_TESTING)
# Download yolov2.weights
set(PATH "${CMAKE_CURRENT_SOURCE_DIR}/yolo_network_config/weights")
set(FILE "${PATH}/yolov2.weights")
message(STATUS "Checking and downloading yolov2.weights if needed ...")
if (NOT EXISTS "${FILE}")
message(STATUS "... file does not exist. Downloading now ...")
execute_process(COMMAND wget http://pjreddie.com/media/files/yolov2.weights -P ${PATH})
endif()
find_package(rostest REQUIRED)
# Object detection in images.
add_rostest_gtest(${PROJECT_NAME}_object_detection-test
test/object_detection.test
test/test_main.cpp
test/ObjectDetection.cpp
)
target_link_libraries(${PROJECT_NAME}_object_detection-test
${catkin_LIBRARIES}
)
endif()