Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

CMakeLists.txt 9.1 KB

You have to be logged in to leave a comment. Sign In
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
  1. project(OpenPose)
  2. cmake_minimum_required(VERSION 2.8.7 FATAL_ERROR) # min. cmake version recommended by Caffe
  3. ### VERSION INFO
  4. set(OpenPose_VERSION_MAJOR 1)
  5. set(OpenPose_VERSION_MINOR 1)
  6. set(OpenPose_VERSION_PATCH 0)
  7. set(OpenPose_VERSION ${OpenPose_VERSION_MAJOR}.${OpenPose_VERSION_MINOR}.${OpenPose_VERSION_PATCH})
  8. ### FIND THE OS
  9. if (WIN32) # OS is Windows
  10. message(FATAL_ERROR "Windows OS is not currently supported.")
  11. elseif (APPLE) # OS is Apple
  12. message(FATAL_ERROR "Apple OS is not currently supported.")
  13. elseif (UNIX AND NOT APPLE) # OS is a Linux distribution (it assumes Ubuntu)
  14. set(EXECUTE_COMMAND lsb_release -rs)
  15. execute_process(COMMAND ${EXECUTE_COMMAND} OUTPUT_VARIABLE UBUNTU_VERSION)
  16. string(SUBSTRING ${UBUNTU_VERSION} 0 2 UBUNTU_MAJOR_VERSION)
  17. if (${UBUNTU_MAJOR_VERSION} MATCHES "16") # if 16
  18. set(IS_UBUNTU_16 TRUE)
  19. set(IS_UBUNTU_14_OR_LESS FALSE)
  20. else (${UBUNTU_MAJOR_VERSION MATCHES "16") # if 14 or less
  21. set(IS_UBUNTU_16 FALSE)
  22. set(IS_UBUNTU_14_OR_LESS TRUE)
  23. endif (${UBUNTU_MAJOR_VERSION} MATCHES "16")
  24. endif ()
  25. ### FLAGS
  26. # Turn on C++11
  27. add_definitions(-std=c++11)
  28. # C++ additional flags
  29. set(OP_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp -Wpedantic -Wall -Wextra -Wfatal-errors")
  30. ### PROJECT OPTIONS
  31. # Select the DL Framework
  32. set(DL_FRAMEWORK CAFFE CACHE STRING "Select Deep Learning Framework.")
  33. set_property(CACHE DL_FRAMEWORK PROPERTY STRINGS CAFFE)
  34. # set_property(CACHE DL_FRAMEWORK PROPERTY STRINGS CAFFE CAFFE2 TENSORFLOW)
  35. # Suboptions for Caffe DL Framework
  36. include(CMakeDependentOption)
  37. if (${DL_FRAMEWORK} MATCHES "CAFFE")
  38. CMAKE_DEPENDENT_OPTION(BUILD_CAFFE "Build Caffe as part of OpenPose." ON
  39. "DL_FRAMEWORK" ON)
  40. # OpenPose flags
  41. add_definitions(-DUSE_CAFFE)
  42. endif (${DL_FRAMEWORK} MATCHES "CAFFE")
  43. # Set the acceleration library
  44. set(GPU_MODE CUDA CACHE STRING "Select the acceleration GPU library or CPU otherwise.")
  45. set_property(CACHE GPU_MODE PROPERTY STRINGS CUDA)
  46. # set_property(CACHE GPU_MODE PROPERTY STRINGS CUDA OPENCL CPU_ONLY)
  47. if (${GPU_MODE} MATCHES "CUDA")
  48. # OpenPose flags
  49. add_definitions(-DUSE_CUDA)
  50. elseif (${GPU_MODE} MATCHES "CPU_ONLY")
  51. # OpenPose flag for Caffe
  52. add_definitions(-DCPU_ONLY)
  53. endif ()
  54. # Suboptions for GPU architectures
  55. if (${GPU_MODE} MATCHES "CUDA")
  56. set(CUDA_ARCH Auto CACHE STRING "Select target NVIDIA GPU achitecture.")
  57. set_property(CACHE CUDA_ARCH PROPERTY STRINGS Auto All Manual)
  58. endif (${GPU_MODE} MATCHES "CUDA")
  59. # Suboptions for acceleration library
  60. if (${GPU_MODE} MATCHES "CUDA")
  61. option(USE_CUDNN "Build OpenPose with cuDNN library support." ON)
  62. endif (${GPU_MODE} MATCHES "CUDA")
  63. # Download the models
  64. option(DOWNLOAD_COCO_MODEL "Download COCO model." ON)
  65. option(DOWNLOAD_MPI_MODEL "Download MPI model." OFF)
  66. option(DOWNLOAD_HAND_MODEL "Download hand model." ON)
  67. option(DOWNLOAD_FACE_MODEL "Download face model." ON)
  68. # More options
  69. option(BUILD_EXAMPLES "Build OpenPose examples." ON)
  70. option(BUILD_DOCS "Build OpenPose documentation." OFF)
  71. # Build as shared library
  72. option(BUILD_SHARED_LIBS "Build as shared lib" ON)
  73. ### FIND REQUIRED PACKAGES
  74. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
  75. include(cmake/Cuda.cmake)
  76. # find_package(CUDA)
  77. find_package(Boost COMPONENTS system filesystem)
  78. find_package(CuDNN)
  79. find_package(GFlags)
  80. find_package(Glog)
  81. find_package(OpenCV)
  82. if (NOT Boost_FOUND)
  83. message(FATAL_ERROR "Boost not found. Install Boost from the command line using the command(s) --\
  84. sudo apt-get install libboost-all-dev")
  85. endif (NOT Boost_FOUND)
  86. if (NOT CUDA_FOUND)
  87. message(STATUS "CUDA not found.")
  88. execute_process(COMMAND cat install_cuda.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/ubuntu)
  89. message(FATAL_ERROR "Install CUDA using the above commands.")
  90. endif (NOT CUDA_FOUND)
  91. if (USE_CUDNN AND NOT CUDNN_FOUND)
  92. message(STATUS "cuDNN not found.")
  93. execute_process(COMMAND cat install_cudnn.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/ubuntu)
  94. message(FATAL_ERROR "Install cuDNN using the above commands. or turn off cuDNN by setting USE_CUDNN to OFF.")
  95. endif (USE_CUDNN AND NOT CUDNN_FOUND)
  96. if (NOT GLOG_FOUND)
  97. message(FATAL_ERROR "Glog not found. Install Glog from the command line using the command(s) -\
  98. sudo apt-get install libgoogle-glog-dev")
  99. endif (NOT GLOG_FOUND)
  100. if (NOT GFLAGS_FOUND)
  101. message(FATAL_ERROR "GFlags not found. Install GFlags from the command line using the command(s) --\
  102. sudo apt-get install libgflags-dev")
  103. endif (NOT GFLAGS_FOUND)
  104. if (NOT OpenCV_FOUND)
  105. message(FATAL_ERROR "OpenCV not found. Install OpenCV from the command line using the command(s) --\
  106. sudo apt-get install libopencv-dev")
  107. endif (NOT OpenCV_FOUND)
  108. # Set CUDA Flags
  109. set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++11")
  110. ### CAFFE
  111. if (${DL_FRAMEWORK} MATCHES "CAFFE")
  112. # Check if the user specified caffe paths
  113. if (Caffe_INCLUDE_DIRS AND Caffe_LIBS AND NOT BUILD_CAFFE)
  114. message(STATUS "\${Caffe_INCLUDE_DIRS} set by the user to " ${Caffe_INCLUDE_DIRS})
  115. message(STATUS "\${Caffe_LIBS} set by the user to " ${Caffe_LIBS})
  116. set(Caffe_FOUND 1)
  117. endif (Caffe_INCLUDE_DIRS AND Caffe_LIBS AND NOT BUILD_CAFFE)
  118. # Check if caffe is installed in known paths
  119. if (NOT Caffe_FOUND AND NOT BUILD_CAFFE)
  120. message(STATUS "Looking for caffe around in expected paths.")
  121. find_package(Caffe)
  122. endif (NOT Caffe_FOUND AND NOT BUILD_CAFFE)
  123. # Else build from scratch
  124. if (BUILD_CAFFE)
  125. message(STATUS "Caffe will be build from source now.")
  126. # Build Caffe
  127. include(ExternalProject)
  128. set(CAFFE_PREFIX caffe)
  129. set(CAFFE_URL ${CMAKE_SOURCE_DIR}/3rdparty/caffe)
  130. ExternalProject_Add(openpose_caffe
  131. SOURCE_DIR ${CAFFE_URL}
  132. PREFIX ${CAFFE_PREFIX}
  133. CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
  134. -DUSE_CUDNN=${USE_CUDNN}
  135. -DOpenCV_DIR=${OpenCV_DIR})
  136. ExternalProject_Get_Property(openpose_caffe install_dir)
  137. set(Caffe_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/caffe/include)
  138. # TODO -- Find a better soln.
  139. set(Caffe_LIBS ${CMAKE_BINARY_DIR}/caffe/lib/libcaffe.so)
  140. endif (BUILD_CAFFE)
  141. if (NOT Caffe_FOUND AND NOT BUILD_CAFFE)
  142. message(FATAL_ERROR "Caffe not found. Either turn on the BUILD_CAFFE option or specify the path of Caffe includes
  143. and libs using -DCaffe_INCLUDE_DIRS and -DCaffe_LIBS")
  144. endif (NOT Caffe_FOUND AND NOT BUILD_CAFFE)
  145. endif (${DL_FRAMEWORK} MATCHES "CAFFE")
  146. ### PROJECT INCLUDES
  147. # Specify the include directories
  148. include_directories(
  149. ${CMAKE_SOURCE_DIR}/include
  150. ${CUDA_INCLUDE_DIRS}
  151. ${GFLAGS_INCLUDE_DIR}
  152. ${GLOG_INCLUDE_DIR}
  153. ${Caffe_INCLUDE_DIRS}
  154. ${OpenCV_INCLUDE_DIRS})
  155. ### ADD SUBDIRECTORIES
  156. add_subdirectory(src)
  157. if (BUILD_EXAMPLES)
  158. add_subdirectory(examples)
  159. endif (BUILD_EXAMPLES)
  160. ### GENERATE DOCUMENTATION
  161. if (BUILD_DOCS)
  162. find_package(Doxygen)
  163. if (DOXYGEN_FOUND)
  164. # Set input and output files
  165. set(DOXYGEN_FILE ${CMAKE_SOURCE_DIR}/doc/doc_autogeneration.doxygen)
  166. # Custom target to build the documentation
  167. add_custom_target(doc_doxygen ALL
  168. COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_FILE}
  169. WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc
  170. COMMENT "Generating API documentation with Doxygen"
  171. VERBATIM )
  172. else (DOXYGEN_FOUND)
  173. message("Doxygen need to be installed to generate the doxygen documentation")
  174. endif (DOXYGEN_FOUND)
  175. endif (BUILD_DOCS)
  176. ### DOWNLOAD MODELS
  177. # Download the models if flag is set
  178. # TODO -- remove hardcoded ubuntu paths
  179. include(cmake/Utils.cmake)
  180. message(STATUS "Download the models.")
  181. # URL to the models
  182. set(OPENPOSE_URL "http://posefs1.perception.cs.cmu.edu/OpenPose/models/")
  183. # Body (COCO)
  184. if (DOWNLOAD_COCO_MODEL)
  185. download_model("body (COCO)" ${DOWNLOAD_COCO_MODEL} pose/coco/pose_iter_440000.caffemodel
  186. 5156d31f670511fce9b4e28b403f2939)
  187. endif (DOWNLOAD_COCO_MODEL)
  188. # Body (MPI)
  189. if (DOWNLOAD_MPI_MODEL)
  190. download_model("body (MPI)" ${DOWNLOAD_MPI_MODEL} pose/mpi/pose_iter_160000.caffemodel
  191. 2ca0990c7562bd7ae03f3f54afa96e00)
  192. endif (DOWNLOAD_MPI_MODEL)
  193. # Face
  194. if (DOWNLOAD_FACE_MODEL)
  195. download_model("face" ${DOWNLOAD_FACE_MODEL} face/pose_iter_116000.caffemodel
  196. e747180d728fa4e4418c465828384333)
  197. endif (DOWNLOAD_FACE_MODEL)
  198. # Hand
  199. if (DOWNLOAD_HAND_MODEL)
  200. download_model("hand" ${DOWNLOAD_HAND_MODEL} hand/pose_iter_102000.caffemodel
  201. a82cfc3fea7c62f159e11bd3674c1531)
  202. endif (DOWNLOAD_HAND_MODEL)
  203. message(STATUS "Models Downloaded.")
  204. ### INSTALL
  205. # Install the headers
  206. install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/openpose DESTINATION include)
  207. install(EXPORT OpenPose DESTINATION lib/OpenPose)
  208. if (BUILD_CAFFE)
  209. install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe/include/caffe DESTINATION include)
  210. install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe/lib/ DESTINATION lib)
  211. endif (BUILD_CAFFE)
  212. # Compute installation prefix relative to this file
  213. configure_file(
  214. ${CMAKE_SOURCE_DIR}/cmake/OpenPoseConfig.cmake.in
  215. ${CMAKE_BINARY_DIR}/cmake/OpenPoseConfig.cmake @ONLY)
  216. install(FILES ${CMAKE_BINARY_DIR}/cmake/OpenPoseConfig.cmake
  217. DESTINATION lib/OpenPose)
  218. # Uninstall target
  219. configure_file(
  220. "${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  221. "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake"
  222. IMMEDIATE @ONLY)
  223. add_custom_target(uninstall
  224. COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...