openpose icon indicating copy to clipboard operation
openpose copied to clipboard

The models are not downloading correctly when building from source on macos

Open ipflowss opened this issue 4 months ago • 1 comments

I cloned the current openpose repository on an M3 running macos 15.5 I do not think the body, face, and hand models were downloaded. For instance the body file took over 15 minutes until I hit control-C and canceled the cmake command. The next time I ran the cmake command the line following "Downloading BODY_25" line says "Model already exists." Is there a way to verify the models were downloaded completely?

Then rm -rf build and started over and there were errors and timeouts. See the second output snippet. Help please.

I used the following command to build

cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5  ..
❯ cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5  ..
CMake Warning (dev) at CMakeLists.txt:19 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at CMakeLists.txt:34 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- GCC detected, adding compile flags
-- Building CPU Only.
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found GFlags: /opt/homebrew/include
-- Found gflags  (include: /opt/homebrew/include, library: /opt/homebrew/lib/libgflags.dylib)
-- Found Glog: /opt/homebrew/include
-- Found glog    (include: /opt/homebrew/include, library: /opt/homebrew/lib/libglog.dylib)
CMake Warning at /opt/homebrew/share/cmake/Modules/FindProtobuf.cmake:685 (message):
  Protobuf compiler version 25.3 doesn't match library version 5.29.3
Call Stack (most recent call first):
  CMakeLists.txt:429 (find_package)


-- Found Protobuf: /opt/homebrew/lib/libprotobuf.dylib (found version "5.29.3")
-- Found OpenCV: /usr/local (found version "4.13.0")
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
-- Caffe will be downloaded from source now. NOTE: This process might take several minutes depending
        on your internet connection.
-- Caffe has already been downloaded.
HEAD is now at 1807aada Added Ampere arch's (CUDA11)
-- Caffe will be built from source now.
-- Download the models.
-- Downloading BODY_25 model...
-- Model already exists.
-- Not downloading body (COCO) model
-- Not downloading body (MPI) model
-- Downloading face model...
-- NOTE: This process might take several minutes depending on your internet connection.
^C
❯ cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5  ..
CMake Warning (dev) at CMakeLists.txt:19 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at CMakeLists.txt:34 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- GCC detected, adding compile flags
-- Building CPU Only.
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found GFlags: /opt/homebrew/include
-- Found gflags  (include: /opt/homebrew/include, library: /opt/homebrew/lib/libgflags.dylib)
-- Found Glog: /opt/homebrew/include
-- Found glog    (include: /opt/homebrew/include, library: /opt/homebrew/lib/libglog.dylib)
CMake Warning at /opt/homebrew/share/cmake/Modules/FindProtobuf.cmake:685 (message):
  Protobuf compiler version 25.3 doesn't match library version 5.29.3
Call Stack (most recent call first):
  CMakeLists.txt:429 (find_package)


-- Found Protobuf: /opt/homebrew/lib/libprotobuf.dylib (found version "5.29.3")
-- Found OpenCV: /usr/local (found version "4.13.0")
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
-- Caffe will be downloaded from source now. NOTE: This process might take several minutes depending
        on your internet connection.
-- Caffe has already been downloaded.
HEAD is now at 1807aada Added Ampere arch's (CUDA11)
-- Caffe will be built from source now.
-- Download the models.
-- Downloading BODY_25 model...
-- Model already exists.
-- Not downloading body (COCO) model
-- Not downloading body (MPI) model
-- Downloading face model...
-- Model already exists.
-- Downloading hand model...
-- NOTE: This process might take several minutes depending on your internet connection.
^C
❯ cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5  ..
CMake Warning (dev) at CMakeLists.txt:19 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at CMakeLists.txt:34 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- GCC detected, adding compile flags
-- Building CPU Only.
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found GFlags: /opt/homebrew/include
-- Found gflags  (include: /opt/homebrew/include, library: /opt/homebrew/lib/libgflags.dylib)
-- Found Glog: /opt/homebrew/include
-- Found glog    (include: /opt/homebrew/include, library: /opt/homebrew/lib/libglog.dylib)
CMake Warning at /opt/homebrew/share/cmake/Modules/FindProtobuf.cmake:685 (message):
  Protobuf compiler version 25.3 doesn't match library version 5.29.3
Call Stack (most recent call first):
  CMakeLists.txt:429 (find_package)


-- Found Protobuf: /opt/homebrew/lib/libprotobuf.dylib (found version "5.29.3")
-- Found OpenCV: /usr/local (found version "4.13.0")
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
-- Caffe will be downloaded from source now. NOTE: This process might take several minutes depending
        on your internet connection.
-- Caffe has already been downloaded.
HEAD is now at 1807aada Added Ampere arch's (CUDA11)
-- Caffe will be built from source now.
-- Download the models.
-- Downloading BODY_25 model...
-- Model already exists.
-- Not downloading body (COCO) model
-- Not downloading body (MPI) model
-- Downloading face model...
-- Model already exists.
-- Downloading hand model...
-- Model already exists.
-- Models Downloaded.
-- Configuring done (0.5s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/noah/3d-project/openpose/build
❯ cmake ..
CMake Warning (dev) at CMakeLists.txt:24 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error at CMakeLists.txt:39 (cmake_minimum_required):
  Compatibility with CMake < 3.5 has been removed from CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.

  Or, add -DCMAKE_POLICY_VERSION_MINIMUM=3.5 to try configuring anyway.


-- Configuring incomplete, errors occurred!
❯ cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 ..
CMake Warning (dev) at CMakeLists.txt:24 (project):
  cmake_minimum_required() should be called prior to this top-level project()
  call.  Please see the cmake-commands(7) manual for usage documentation of
  both commands.
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Deprecation Warning at CMakeLists.txt:39 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- GCC detected, adding compile flags
-- Building CPU Only.
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Found GFlags: /opt/homebrew/include
-- Found gflags  (include: /opt/homebrew/include, library: /opt/homebrew/lib/libgflags.dylib)
-- Found Glog: /opt/homebrew/include
-- Found glog    (include: /opt/homebrew/include, library: /opt/homebrew/lib/libglog.dylib)
CMake Warning at /Applications/CMake.app/Contents/share/cmake-4.0/Modules/FindProtobuf.cmake:685 (message):
  Protobuf compiler version 25.3 doesn't match library version 5.29.3
Call Stack (most recent call first):
  CMakeLists.txt:434 (find_package)


-- Found Protobuf: /opt/homebrew/lib/libprotobuf.dylib (found version "5.29.3")
-- Found OpenCV: /usr/local (found version "4.13.0")
-- Could NOT find OpenMP_C (missing: OpenMP_C_FLAGS OpenMP_C_LIB_NAMES)
-- Could NOT find OpenMP_CXX (missing: OpenMP_CXX_FLAGS OpenMP_CXX_LIB_NAMES)
-- Could NOT find OpenMP (missing: OpenMP_C_FOUND OpenMP_CXX_FOUND)
-- Caffe will be downloaded from source now. NOTE: This process might take several minutes depending
        on your internet connection.
-- Caffe has already been downloaded.
error: pathspec '1807aad' did not match any file(s) known to git
-- Caffe will be built from source now.
-- Download the models.
-- Downloading BODY_25 model...
-- NOTE: This process might take several minutes depending on your internet connection.
CMake Error at cmake/Utils.cmake:8 (file):
  file DOWNLOAD cannot compute hash on failed download

    status: [28;"Timeout was reached"]
Call Stack (most recent call first):
  CMakeLists.txt:991 (download_model)


-- Not downloading body (COCO) model
-- Not downloading body (MPI) model
-- Downloading face model...
-- NOTE: This process might take several minutes depending on your internet connection.
CMake Error at cmake/Utils.cmake:8 (file):
  file DOWNLOAD cannot compute hash on failed download

    status: [28;"Timeout was reached"]
Call Stack (most recent call first):
  CMakeLists.txt:997 (download_model)


-- Downloading hand model...
-- NOTE: This process might take several minutes depending on your internet connection.
CMake Error at cmake/Utils.cmake:8 (file):
  file DOWNLOAD cannot compute hash on failed download

    status: [28;"Timeout was reached"]
Call Stack (most recent call first):
  CMakeLists.txt:999 (download_model)


-- Models Downloaded.
-- Configuring incomplete, errors occurred!

ipflowss avatar Jul 17 '25 07:07 ipflowss

Update CMakeLists.txt

### VERSION INFO
set(OpenPose_VERSION_MAJOR 1)
set(OpenPose_VERSION_MINOR 7)
set(OpenPose_VERSION_PATCH 0)
set(OpenPose_VERSION ${OpenPose_VERSION_MAJOR}.${OpenPose_VERSION_MINOR}.${OpenPose_VERSION_PATCH})

### CMAKE VERSION & POLICIES
cmake_minimum_required(VERSION 3.6 FATAL_ERROR)
# CMake 3.30+: keep legacy FindBoost behavior
if (POLICY CMP0167)
  cmake_policy(SET CMP0167 OLD)
endif()

### OS-DEPENDENT FLAGS
set(CMAKE_MACOSX_RPATH 1)

### CMAKE HEADERS & PROJECT
if (${CMAKE_VERSION} VERSION_GREATER 3.9.0)
  cmake_policy(SET CMP0048 NEW)
  project(OpenPose VERSION ${OpenPose_VERSION})
elseif (${CMAKE_VERSION} VERSION_GREATER 3.0.0)
  cmake_policy(SET CMP0048 NEW)
  project(OpenPose VERSION ${OpenPose_VERSION})
else ()
  project(OpenPose)
endif ()

# IMPORTANT: always use FindBoost, not BoostConfig.cmake
set(Boost_NO_BOOST_CMAKE ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

# Path hints for Boost installed via b2
set(BOOST_ROOT "/usr/local" CACHE PATH "Boost root prefix")
set(Boost_INCLUDE_DIR "/usr/local/include" CACHE PATH "Boost include dir")
set(Boost_LIBRARY_DIR "/usr/local/lib" CACHE PATH "Boost library dir")

### Extra functionality
include(cmake/Utils.cmake)
if (NOT WIN32 AND NOT UNIX AND NOT APPLE)
  message(FATAL_ERROR "Unsupported operating system. Only Windows, Mac and Unix systems supported.")
endif ()

### CMAKE_BUILD_TYPE - FIXED VERSION
if (NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
endif ()
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Release" "Debug" "MinSizeRel" "RelWithDebInfo")

### FLAGS
if (WIN32)
  set(CMAKE_SUPPRESS_REGENERATION ON)
  string (REPLACE "/D_WINDOWS" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  string (REPLACE "/DWIN32" ""   CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  message(STATUS "CMAKE_VERSION = ${CMAKE_VERSION}")
  if (${CMAKE_VERSION} VERSION_LESS "3.14.0")
    set(CMAKE_CONFIGURATION_TYPES Release Debug CACHE TYPE INTERNAL FORCE)
  else ()
    set(CMAKE_CONFIGURATION_TYPES Release Debug CACHE STRING "" FORCE)
  endif ()
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
  string(REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  string(REPLACE "/GR" ""   CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  string(REPLACE "/O2" "/Ox" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
  string(REPLACE "/Ob2" ""   CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
  set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Ot /Oi /Gy /Z7")
  set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /LTCG:incremental /OPT:REF /OPT:ICF")
elseif (UNIX)
  add_definitions(-std=c++11)
  set(CMAKE_CXX_FLAGS_RELEASE "-O3")
elseif (APPLE)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
  set(CMAKE_CXX_FLAGS_RELEASE "-O3")
endif ()

# C++ additional flags
if (CMAKE_COMPILER_IS_GNUCXX)
  message(STATUS "GCC detected, adding compile flags")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
  set(OP_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wpedantic -Wall -Wextra -Wfatal-errors")
endif ()

# Select the Enhanced Instruction Set
set(INSTRUCTION_SET NONE CACHE STRING "Enable Enhanced Instruction Set")
set_property(CACHE INSTRUCTION_SET PROPERTY STRINGS NONE AVX2)
if (${INSTRUCTION_SET} MATCHES "AVX2")
  add_definitions("-DWITH_AVX")
endif ()

if (WIN32)
  if (${INSTRUCTION_SET} MATCHES "AVX2")
    add_definitions("/arch:AVX2")
  endif ()
else ()
  if (${INSTRUCTION_SET} MATCHES "AVX2")
    set(SIMD_FLAGS "${SIMD_FLAGS} -mavx -march=native")
  endif ()
  message(STATUS "GCC detected, adding compile flags")
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SIMD_FLAGS}")
endif ()

### PROJECT OPTIONS
set(DL_FRAMEWORK CAFFE CACHE STRING "Select Deep Learning Framework.")
if (WIN32)
  set_property(CACHE DL_FRAMEWORK PROPERTY STRINGS CAFFE)
else ()
  set_property(CACHE DL_FRAMEWORK PROPERTY STRINGS CAFFE NV_CAFFE)
endif ()

include(CMakeDependentOption)
if (${DL_FRAMEWORK} MATCHES "CAFFE" OR ${DL_FRAMEWORK} MATCHES "NV_CAFFE")
  cmake_dependent_option(BUILD_CAFFE "Build Caffe as part of OpenPose." ON "DL_FRAMEWORK" ON)
  add_definitions(-DUSE_CAFFE)
  if (${DL_FRAMEWORK} MATCHES "NV_CAFFE")
    message(STATUS "Using NVIDIA NVCaffe")
    add_definitions(-DNV_CAFFE)
  endif ()
endif ()

if (APPLE)
  set(GPU_MODE CPU_ONLY CACHE STRING "Select the acceleration GPU library or CPU otherwise.")
else ()
  set(GPU_MODE CUDA CACHE STRING "Select the acceleration GPU library or CPU otherwise.")
endif ()
set_property(CACHE GPU_MODE PROPERTY STRINGS CUDA OPENCL CPU_ONLY)

# Look for CUDA/OpenCL
set(CUDA_FOUND FALSE)
if (${GPU_MODE} MATCHES "CUDA")
  find_package(CUDA)
endif ()
set(OpenCL_FOUND FALSE)
set(CUDA_VERSION_MAJOR 0)
if (${GPU_MODE} MATCHES "OPENCL")
  find_package(OpenCL)
endif ()
if (NOT OpenCL_FOUND)
  set(OpenCl_LIBRARIES "")
endif ()
if (CUDA_FOUND AND OpenCL_FOUND AND ${CUDA_VERSION_MAJOR} LESS 9)
  add_definitions(-DLOWER_CL_VERSION)
endif ()
if (${GPU_MODE} MATCHES "CUDA")
  add_definitions(-DUSE_CUDA)
  message(STATUS "Building with CUDA.")
elseif (${GPU_MODE} MATCHES "CPU_ONLY")
  add_definitions(-DUSE_CPU_ONLY -DCPU_ONLY)
  message(STATUS "Building CPU Only.")
elseif (${GPU_MODE} MATCHES "OPENCL")
  add_definitions(-DUSE_OPENCL -DUSE_GREENTEA)
  message(STATUS "Building with OpenCL.")
endif ()

# Intel MKL option (Linux only)
if (${GPU_MODE} MATCHES "CPU_ONLY")
  if (UNIX AND NOT APPLE)
    option(USE_MKL "Use MKL Intel Branch." OFF)
  endif ()
endif ()
if (USE_MKL)
  add_definitions(-DUSE_MKL)
  message(STATUS "Building with MKL support.")
endif ()
if (PROFILER_ENABLED)
  add_definitions(-DPROFILER_ENABLED)
endif ()

# CUDA suboptions
if (${GPU_MODE} MATCHES "CUDA")
  set(CUDA_ARCH Auto CACHE STRING "Select target NVIDIA GPU architecture.")
  set_property(CACHE CUDA_ARCH PROPERTY STRINGS Auto All Manual)
  option(USE_CUDNN "Build OpenPose with cuDNN library support." ON)
endif ()

# 3D/extra options
option(WITH_3D_RENDERER "Add OpenPose 3D renderer module (it requires FreeGLUT library)." OFF)
if (UNIX AND NOT APPLE)
  option(WITH_CERES "Add Ceres support for advanced 3-D reconstruction." OFF)
endif ()
option(WITH_FLIR_CAMERA "Add FLIR camera code (requires Spinnaker SDK)." OFF)
option(WITH_OPENCV_WITH_OPENGL "Faster GUI display (requires OpenCV WITH_OPENGL=ON)." OFF)

if (WIN32 OR APPLE)
  set(WITH_EIGEN NONE CACHE STRING "Eigen mode: NONE/AUTOBUILD/FIND")
elseif (UNIX AND NOT APPLE)
  set(WITH_EIGEN NONE CACHE STRING "Eigen mode: NONE/AUTOBUILD/FIND")
endif ()
set_property(CACHE WITH_EIGEN PROPERTY STRINGS NONE AUTOBUILD FIND)

option(BUILD_EXAMPLES "Build OpenPose examples." ON)
option(BUILD_DOCS "Build OpenPose documentation." OFF)
option(BUILD_PYTHON "Build OpenPose python." OFF)
if (WIN32)
  option(BUILD_BIN_FOLDER "Copy required 3rd-party DLL files into {build}/bin." ON)
endif ()
option(BUILD_UNITY_SUPPORT "Build OpenPose as a Unity plugin." OFF)
option(BUILD_SHARED_LIBS "Build as shared lib." ON)
option(PROFILER_ENABLED "Print runtime speed info." OFF)

# Threads
if (${GPU_MODE} MATCHES "OPENCL" OR (UNIX OR APPLE))
  unset(CMAKE_THREAD_LIBS_INIT CACHE)
  find_package(Threads)
endif ()

if (APPLE)
  # Debug: list Boost libraries found in Homebrew [email protected]
  message(STATUS "Checking for Boost libraries in /usr/local/opt/[email protected]/lib")
  file(GLOB BOOST_LIBS "/usr/local/opt/[email protected]/lib/libboost_*")
  if (BOOST_LIBS)
    message(STATUS "Found Boost libraries: ${BOOST_LIBS}")
  endif()

  if (${GPU_MODE} MATCHES "OPENCL" OR BUILD_PYTHON)
    find_package(Boost 1.58 REQUIRED COMPONENTS system filesystem)
    if (TARGET Boost::system)
      set(Boost_SYSTEM_LIBRARY Boost::system)
    else()
      unset(Boost_SYSTEM_LIBRARY)
    endif()
    if (TARGET Boost::filesystem)
      set(Boost_FILESYSTEM_LIBRARY Boost::filesystem)
    else()
      unset(Boost_FILESYSTEM_LIBRARY)
    endif()
  else ()
    set(Boost_SYSTEM_LIBRARY "")
  endif ()
endif ()

set(DOWNLOAD_SERVER "http://vcl.snu.ac.kr/OpenPose/" CACHE STRING "Server used to download models/3rdparty.")
mark_as_advanced(DOWNLOAD_SERVER)

### FIND REQUIRED PACKAGES
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
if (${GPU_MODE} MATCHES "CUDA")
  find_package(CUDA)
endif ()

if (WITH_OPENCV_WITH_OPENGL)
  add_definitions(-DUSE_OPENCV_WITH_OPENGL)
endif ()
if (WITH_3D_RENDERER)
  add_definitions(-DUSE_3D_RENDERER)
endif ()
if (WITH_CERES)
  add_definitions(-DUSE_CERES)
endif ()
if (WITH_FLIR_CAMERA)
  add_definitions(-DUSE_FLIR_CAMERA)
endif ()
if (WITH_3D_ADAM_MODEL)
  add_definitions(-DUSE_3D_ADAM_MODEL)
endif ()
if (WITH_TRACKING)
  add_definitions(-DUSE_TRACKING)
endif ()
if (BUILD_UNITY_SUPPORT)
  add_definitions(-DUSE_UNITY_SUPPORT)
endif ()

# Eigen
if (${WITH_EIGEN} MATCHES "NONE")
  if (WITH_CERES)
    message(FATAL_ERROR "Eigen is required (enable WITH_EIGEN) if CERES is enabled.")
  endif ()
else ()
  add_definitions(-DUSE_EIGEN)
  if (${WITH_EIGEN} MATCHES "AUTOBUILD")
    set(OP_URL "${DOWNLOAD_SERVER}3rdparty/")
    set(FIND_LIB_PREFIX ${CMAKE_SOURCE_DIR}/3rdparty/)
    download_zip("eigen_2020_11_18.zip" ${OP_URL} ${FIND_LIB_PREFIX} 57672715C62C1A795300FE1AE4D2687E)
    set(EIGEN3_INCLUDE_DIRS "3rdparty/eigen/include/")
  elseif (${WITH_EIGEN} MATCHES "FIND")
    if (CUDA_VERSION_STRING STRGREATER "9.0")
      find_package(Eigen3 3.3.5 REQUIRED NO_MODULE)
    else ()
      find_package(Eigen3 3 REQUIRED NO_MODULE)
    endif ()
  endif ()
endif ()

if (UNIX OR APPLE)
  if (${GPU_MODE} MATCHES "CUDA")
    include(cmake/Cuda.cmake)
    find_package(CuDNN)
  endif ()
  find_package(GFlags)
  find_package(Glog)
  find_package(Protobuf REQUIRED)

  if (OpenCV_CONFIG_FILE)
    include (${OpenCV_CONFIG_FILE})
  elseif (OpenCV_INCLUDE_DIRS AND OpenCV_LIBS)
    set(OpenCV_FOUND 1)
  elseif (OpenCV_INCLUDE_DIRS AND OpenCV_LIBS_DIR)
    file(GLOB_RECURSE OpenCV_LIBS "${OpenCV_LIBS_DIR}*.so")
    set(OpenCV_FOUND 1)
  else ()
    find_package(OpenCV)
  endif ()

  if (WITH_3D_RENDERER)
    find_package(OpenGL REQUIRED)
    find_package(GLUT REQUIRED)
    find_package(OpenGL REQUIRED)
  endif ()
  if (WITH_CERES)
    find_package(Ceres REQUIRED COMPONENTS SuiteSparse)
  endif ()
  if (WITH_FLIR_CAMERA)
    find_package(Spinnaker)
    if (NOT SPINNAKER_FOUND)
      message(FATAL_ERROR "Spinnaker not found. Disable WITH_FLIR_CAMERA or provide include/lib paths.")
    endif ()
  endif ()
  if (WITH_3D_ADAM_MODEL)
    if (NOT WITH_3D_RENDERER)
      message(FATAL_ERROR "WITH_3D_RENDERER is required if WITH_3D_ADAM_MODEL is enabled.")
    endif ()
    if (CUDA_VERSION_STRING STRGREATER "9.0")
      find_package(Eigen3 3.3.5 REQUIRED NO_MODULE)
    else ()
      find_package(Eigen3 3 REQUIRED NO_MODULE)
    endif ()
    find_package(Ceres REQUIRED COMPONENTS SuiteSparse)
    find_package(GLEW REQUIRED)
    find_package(LIBIGL REQUIRED)
    find_package(OpenMP REQUIRED)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
  endif ()

  if (${GPU_MODE} MATCHES "CPU_ONLY")
    find_package(OpenMP)
    if (OPENMP_FOUND)
      set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
      set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
      set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
    endif ()
  endif ()

  if (${GPU_MODE} MATCHES "CUDA")
    set(CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS} -std=c++14")
    set(CUDA_NVCC_FLAGS_DEBUG "${CUDA_NVCC_FLAGS_DEBUG} -D_DEBUG -g")
    if (NOT CUDA_FOUND)
      message(STATUS "CUDA not found.")
      execute_process(COMMAND cat install_cuda.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/scripts/ubuntu)
      message(FATAL_ERROR "Install CUDA using the above commands.")
    endif ()
    if (USE_CUDNN AND NOT CUDNN_FOUND)
      message(STATUS "cuDNN not found.")
      execute_process(COMMAND cat install_cudnn_up_to_Ubuntu16.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/scripts/ubuntu)
      message(FATAL_ERROR "Install cuDNN or set USE_CUDNN=OFF.")
    endif ()
  endif ()

  if (NOT GLOG_FOUND)
    message(FATAL_ERROR "Glog not found. Install libgoogle-glog-dev (or brew install glog).")
  endif ()
  if (NOT GFLAGS_FOUND)
    message(FATAL_ERROR "GFlags not found. Install libgflags-dev (or brew install gflags).")
  endif ()
  if (NOT OpenCV_FOUND)
    message(FATAL_ERROR "OpenCV not found. Install libopencv-dev (or brew install opencv).")
  endif ()
endif ()

if (WIN32)
  # Windows-specific configuration placeholder
endif ()

### CAFFE/NVCAFFE in Ubuntu/macOS
if (UNIX OR APPLE)
  if (${DL_FRAMEWORK} MATCHES "CAFFE" OR ${DL_FRAMEWORK} MATCHES "NV_CAFFE")
    if (Caffe_INCLUDE_DIRS AND Caffe_LIBS AND NOT BUILD_CAFFE)
      message(STATUS "\${Caffe_INCLUDE_DIRS} set by the user to " ${Caffe_INCLUDE_DIRS})
      message(STATUS "\${Caffe_LIBS} set by the user to " ${Caffe_LIBS})
      set(Caffe_FOUND 1)
    endif ()

    if (BUILD_CAFFE)
      message(STATUS "Caffe will be downloaded from source now. NOTE: This might take several minutes.")
      file(GLOB CAFFE_DIR_VALID ${CMAKE_SOURCE_DIR}/3rdparty/caffe/*)
      list(LENGTH CAFFE_DIR_VALID CAFFE_DIR_VALID_LENGTH)
      if (CAFFE_DIR_VALID_LENGTH EQUAL 0)
        execute_process(COMMAND git submodule update --init ${CMAKE_SOURCE_DIR}/3rdparty/caffe)
      else ()
        message(STATUS "Caffe has already been downloaded.")
      endif ()

      set(CAFFE_CPU_ONLY OFF)
      if (${GPU_MODE} MATCHES "CUDA")
        execute_process(COMMAND git checkout 1807aad WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/caffe)
      elseif (${GPU_MODE} MATCHES "CPU_ONLY")
        if (USE_MKL)
          execute_process(COMMAND git checkout b6712ce WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/caffe)
          execute_process(COMMAND sh prepare_mkl.sh WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/caffe/external/mkl OUTPUT_VARIABLE rv)
          set( MLIST ${rv} )
          separate_arguments(MLIST)
          list(GET MLIST 0 MKL_PATH)
          message(STATUS ${MKL_PATH})
          file(GLOB MKL_SO "${MKL_PATH}lib/*")
          file(COPY ${MKL_SO} DESTINATION ${CMAKE_BINARY_DIR}/caffe)
          set(MKL_LIBS
            "${CMAKE_BINARY_DIR}/caffe/libiomp5.so"
            "${CMAKE_BINARY_DIR}/caffe/libmklml_intel.so"
            "${CMAKE_BINARY_DIR}/caffe/lib/libmkldnn.so")
        else ()
          execute_process(COMMAND git checkout 1807aad WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/caffe)
        endif ()
        set(CAFFE_CPU_ONLY ON)
        set(USE_CUDNN OFF)
      elseif (${GPU_MODE} MATCHES "OPENCL")
        execute_process(COMMAND git checkout fe2a1102 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/3rdparty/caffe)
        set(USE_CUDNN OFF)
      endif ()

      message(STATUS "Caffe will be built from source now.")
      find_package(Caffe)
      include(ExternalProject)
      set(CAFFE_PREFIX caffe)
      set(CAFFE_URL ${CMAKE_SOURCE_DIR}/3rdparty/caffe)

      # Pass critical flags to ensure Caffe uses FindBoost
      set(_COMMON_CAFFE_ARGS
        -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
        -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
        -DUSE_CUDNN=${USE_CUDNN}
        -DCUDA_ARCH_NAME=${CUDA_ARCH}
        -DCUDA_ARCH_BIN=${CUDA_ARCH_BIN}
        -DCUDA_ARCH_PTX=${CUDA_ARCH_PTX}
        -DCPU_ONLY=${CAFFE_CPU_ONLY}
        -DCMAKE_BUILD_TYPE=Release
        -DCMAKE_CXX_STANDARD=17
        -DCMAKE_CXX_STANDARD_REQUIRED=ON
        -DCMAKE_CXX_FLAGS=-DABSL_USES_STD_STRING_VIEW=0
        -DBUILD_docs=OFF
        -DBUILD_python=OFF
        -DBUILD_python_layer=OFF
        -DUSE_LEVELDB=OFF
        -DUSE_LMDB=OFF
        -DUSE_OPENCV=OFF
        -DBoost_NO_BOOST_CMAKE=ON
        -DBOOST_ROOT=/usr/local/opt/[email protected]
        -DBoost_INCLUDE_DIR=/usr/local/opt/[email protected]/include
        -DBoost_LIBRARY_DIR=/usr/local/opt/[email protected]/lib
        -DBoost_USE_MULTITHREADED=ON
        -DBoost_USE_STATIC_RUNTIME=OFF
        -DCMAKE_POLICY_DEFAULT_CMP0167=OLD
      )

      ExternalProject_Add(openpose_lib
        SOURCE_DIR ${CAFFE_URL}
        PREFIX ${CAFFE_PREFIX}
        CMAKE_ARGS ${_COMMON_CAFFE_ARGS}
      )

      ExternalProject_Get_Property(openpose_lib install_dir)

      if (NOT Caffe_FOUND)
        add_custom_command(TARGET openpose_lib
            POST_BUILD
            COMMAND ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR}
            COMMAND $(MAKE)
            WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
            COMMENT "Rerunning cmake after building Caffe submodule")
      endif ()
    endif ()

    if (NOT Caffe_FOUND AND NOT BUILD_CAFFE)
      message(FATAL_ERROR "Caffe not found. Turn ON BUILD_CAFFE or set -DCaffe_INCLUDE_DIRS and -DCaffe_LIBS.")
    endif ()
  endif ()
endif ()

### PROJECT INCLUDES
include_directories(
  include
  ${Protobuf_INCLUDE_DIRS}
  ${GFLAGS_INCLUDE_DIR}
  ${GLOG_INCLUDE_DIR}
  ${OpenCV_INCLUDE_DIRS})

if (USE_ASIO)
  include_directories(${CMAKE_SOURCE_DIR}/3rdparty/asio/include/)
  add_definitions(-DUSE_ASIO -DASIO_STANDALONE)
endif ()

if (NOT ${WITH_EIGEN} MATCHES "NONE")
  include_directories(${EIGEN3_INCLUDE_DIRS})
  if (${WITH_EIGEN} MATCHES "FIND")
    list(APPEND OpenPose_3rdparty_libraries Eigen3::Eigen)
  endif ()
endif ()

if (APPLE)
  include_directories("/usr/local/opt/openblas/include")
endif ()
if (USE_MKL)
  include_directories("${MKL_PATH}/include/")
endif ()
if (Caffe_FOUND)
  include_directories(${Caffe_INCLUDE_DIRS})
endif ()
if (${GPU_MODE} MATCHES "CUDA")
  include_directories(${CUDA_INCLUDE_DIRS})
elseif (${GPU_MODE} MATCHES "OPENCL")
  include_directories(${OpenCL_INCLUDE_DIRS})
endif ()
if (WITH_3D_RENDERER)
  include_directories(${GLUT_INCLUDE_DIRS})
endif ()
if (WITH_CERES)
  include_directories(${CERES_INCLUDE_DIRS})
endif ()
if (WITH_FLIR_CAMERA)
  include_directories(SYSTEM ${SPINNAKER_INCLUDE_DIRS})
endif ()
if (WITH_3D_ADAM_MODEL)
  include_directories(include/adam)
  include_directories(${CERES_INCLUDE_DIRS} ${EIGEN3_INCLUDE_DIRS} ${IGL_INCLUDE_DIRS} ${LIBIGL_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR} ${GLUT_INCLUDE_DIRS} ${GLEW_INCLUDE_DIRS})
  list(APPEND OpenPose_3rdparty_libraries Eigen3::Eigen)
endif ()
if (WIN32)
  include_directories(${WINDOWS_INCLUDE_DIRS})
endif ()

### COLLECT ALL 3RD-PARTY LIBRARIES
if (UNIX OR APPLE)
  set(OpenPose_3rdparty_libraries ${OpenPose_3rdparty_libraries} ${OpenCV_LIBS} ${GLOG_LIBRARY})
  if (TARGET Boost::system)
    list(APPEND OpenPose_3rdparty_libraries Boost::system)
  endif ()
  if (TARGET Boost::filesystem)
    list(APPEND OpenPose_3rdparty_libraries Boost::filesystem)
  endif ()
elseif (WIN32)
  set(OpenPose_3rdparty_libraries ${OpenPose_3rdparty_libraries}
      debug ${OpenCV_LIBS_DEBUG} optimized ${OpenCV_LIBS_RELEASE}
      debug ${GFLAGS_LIBRARY_DEBUG} optimized ${GFLAGS_LIBRARY_RELEASE}
      debug ${GLOG_LIBRARY_DEBUG}   optimized ${GLOG_LIBRARY_RELEASE})
endif ()
if (UNIX OR APPLE)
  set(examples_3rdparty_libraries ${OpenPose_3rdparty_libraries} ${GFLAGS_LIBRARY})
endif ()
if (${DL_FRAMEWORK} MATCHES "CAFFE" OR ${DL_FRAMEWORK} MATCHES "NV_CAFFE")
  if (UNIX OR APPLE)
    set(OpenPose_3rdparty_libraries ${OpenPose_3rdparty_libraries} ${Caffe_LIBS})
  else ()
    set(OpenPose_3rdparty_libraries ${OpenPose_3rdparty_libraries}
      debug ${Caffe_LIBS_DEBUG} optimized ${Caffe_LIBS_RELEASE})
  endif ()
endif ()
if (USE_MKL)
  list(APPEND OpenPose_3rdparty_libraries ${MKL_LIBS})
endif ()
if (${GPU_MODE} MATCHES "OPENCL")
  list(APPEND OpenPose_3rdparty_libraries ${CMAKE_THREAD_LIBS_INIT} ${OpenCL_LIBRARIES})
endif ()
if (WITH_3D_ADAM_MODEL)
  list(APPEND OpenPose_3rdparty_libraries ${OPENGL_LIBRARIES} ${GLUT_LIBRARY} ${GLEW_LIBRARY} ${FREE_IMAGE_LIBRARY})
endif ()
if (WITH_3D_RENDERER)
  list(APPEND OpenPose_3rdparty_libraries ${GLUT_LIBRARY} ${OPENGL_LIBRARIES})
endif ()
if (WITH_CERES)
  list(APPEND OpenPose_3rdparty_libraries ${CERES_LIBRARIES})
endif ()
if (WITH_FLIR_CAMERA)
  list(APPEND OpenPose_3rdparty_libraries ${SPINNAKER_LIB})
endif ()
if (UNIX OR APPLE)
  list(APPEND OpenPose_3rdparty_libraries pthread)
endif ()

### ADD SUBDIRECTORIES
if (Caffe_FOUND)
  add_subdirectory(src)
  if (BUILD_EXAMPLES)
    add_subdirectory(examples)
  endif ()
endif ()

### DOWNLOAD MODELS
message(STATUS "Download the models.")
set(OPENPOSE_URL "${DOWNLOAD_SERVER}models/")

option(DOWNLOAD_BODY_25_MODEL "Download BODY_25 model." ON)
option(DOWNLOAD_BODY_COCO_MODEL "Download body (COCO) model." ON)
option(DOWNLOAD_BODY_MPI_MODEL "Download body (MPI) model." ON)
option(DOWNLOAD_FACE_MODEL "Download face model." ON)
option(DOWNLOAD_HAND_MODEL "Download hand model." ON)

download_model("BODY_25" ${DOWNLOAD_BODY_25_MODEL} pose/body_25/pose_iter_584000.caffemodel 78287B57CF85FA89C03F1393D368E5B7)
download_model("body (COCO)" ${DOWNLOAD_BODY_COCO_MODEL} pose/coco/pose_iter_440000.caffemodel 5156d31f670511fce9b4e28b403f2939)
download_model("body (MPI)" ${DOWNLOAD_BODY_MPI_MODEL} pose/mpi/pose_iter_160000.caffemodel 2ca0990c7562bd7ae03f3f54afa96e00)
download_model("face" ${DOWNLOAD_FACE_MODEL} face/pose_iter_116000.caffemodel e747180d728fa4e4418c465828384333)
download_model("hand" ${DOWNLOAD_HAND_MODEL} hand/pose_iter_102000.caffemodel a82cfc3fea7c62f159e11bd3674c1531)
message(STATUS "Models Downloaded.")

### PYTHON
if (BUILD_PYTHON)
  if (WIN32)
    execute_process(COMMAND cmd /c cd ${CMAKE_SOURCE_DIR} & git submodule update --init 3rdparty/pybind11/)
    add_subdirectory(3rdparty/pybind11)
    add_subdirectory(python)
  elseif (UNIX OR APPLE)
    if (Caffe_FOUND)
      execute_process(COMMAND git submodule update --init ${CMAKE_SOURCE_DIR}/3rdparty/pybind11/)
      add_subdirectory(3rdparty/pybind11)
      add_subdirectory(python)
    endif ()
  else ()
    message(FATAL_ERROR "Unknown OS.")
  endif ()
endif ()

### GENERATE DOCUMENTATION
if (UNIX OR APPLE)
  if (BUILD_DOCS)
    find_package(Doxygen)
    if (DOXYGEN_FOUND)
      set(DOXYGEN_FILE ${CMAKE_SOURCE_DIR}/.doc_autogeneration.doxygen)
      add_custom_target(doc_doxygen ALL
        COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_FILE}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/doc
        COMMENT "Generating API documentation with Doxygen"
        VERBATIM)
    else ()
      message(FATAL_ERROR "Doxygen needs to be installed to generate the doxygen documentation.")
    endif ()
  endif ()
endif ()

### INSTALL
if (UNIX OR APPLE)
  if (Caffe_FOUND)
    install(DIRECTORY ${CMAKE_SOURCE_DIR}/include/openpose DESTINATION include)
    install(EXPORT OpenPose DESTINATION lib/OpenPose)
    if (BUILD_CAFFE)
      install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe/include/caffe DESTINATION include)
      install(DIRECTORY ${CMAKE_BINARY_DIR}/caffe/lib/ DESTINATION lib)
    endif ()
    configure_file(${CMAKE_SOURCE_DIR}/cmake/OpenPoseConfig.cmake.in
                   ${CMAKE_BINARY_DIR}/cmake/OpenPoseConfig.cmake @ONLY)
    install(FILES ${CMAKE_BINARY_DIR}/cmake/OpenPoseConfig.cmake DESTINATION lib/OpenPose)
    configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
                   "${CMAKE_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
    add_custom_target(uninstall
        COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
  endif ()
endif ()

Install Protobuf 3.15.8

wget https://github.com/protocolbuffers/protobuf/releases/download/v3.15.8/protobuf-all-3.15.8.tar.gz
tar -xzf protobuf-all-3.15.8.tar.gz
cd protobuf-3.15.8

# Build and install
./configure --prefix=/usr/local CXXFLAGS="-std=c++11"
make -j"$(nproc || sysctl -n hw.ncpu || echo 8)"
sudo make install

Fix in Caffe (openpose/3rdparty/caffe/src/caffe/layers/hdf5_data_layer.cpp)

Add the include and replace std::random_shuffle with std::shuffle using a static engine:

#include <random>  // add this

// ...
static std::random_device rd;
static std::mt19937 g(rd());

// Replace all occurrences of:
std::random_shuffle(data_permutation_.begin(), data_permutation_.end());

// With:
std::shuffle(data_permutation_.begin(), data_permutation_.end(), g);

Download Models

bash models/getModels.sh

GermanZvezdin avatar Sep 17 '25 20:09 GermanZvezdin