2017-03-26 4 views
1

나는 최근에 caffe_rtpose을 발견하고 예제를 컴파일하고 실행하려고 시도했다. 불행히도 저는 C++에 익숙한 경험이 많아서 컴파일하고 링크하는 데 많은 어려움을 겪었습니다.OSX에서 caffe_rtpose를 컴파일하는 방법은 무엇입니까?

나는 (existing Ubuntu config에서 수정 된) Makefile 설정을 조정 해 보았습니다. (I는 엔비디아 지포스 750M와 OSX 10.11.5를 실행하는 시스템을 사용하고 있는데 나는 CUDA 7.5 libcudnn를 설치 한) :

## Refer to http://caffe.berkeleyvision.org/installation.html 
# Contributions simplifying and improving our build system are welcome! 

# cuDNN acceleration switch (uncomment to build with cuDNN). 
USE_CUDNN := 1 

# CPU-only switch (uncomment to build without GPU support). 
# CPU_ONLY := 1 

# uncomment to disable IO dependencies and corresponding data layers 
# USE_OPENCV := 0 
# USE_LEVELDB := 0 
# USE_LMDB := 0 

# uncomment to allow MDB_NOLOCK when reading LMDB files (only if necessary) 
# You should not set this flag if you will be reading LMDBs with any 
# possibility of simultaneous read and write 
# ALLOW_LMDB_NOLOCK := 1 

# Uncomment if you're using OpenCV 3 
# OPENCV_VERSION := 3 

# To customize your choice of compiler, uncomment and set the following. 
# N.B. the default for Linux is g++ and the default for OSX is clang++ 
# CUSTOM_CXX := g++ 

# CUDA directory contains bin/ and lib/ directories that we need. 
CUDA_DIR := /usr/local/cuda 
# On Ubuntu 14.04, if cuda tools are installed via 
# "sudo apt-get install nvidia-cuda-toolkit" then use this instead: 
# CUDA_DIR := /usr 

# CUDA architecture setting: going with all of them. 
# For CUDA < 6.0, comment the *_50 lines for compatibility. 
CUDA_ARCH := -gencode arch=compute_30,code=sm_30 \ 
     -gencode arch=compute_35,code=sm_35 \ 
     -gencode arch=compute_50,code=sm_50 \ 
     -gencode arch=compute_50,code=compute_50 \ 
     -gencode arch=compute_52,code=sm_52 \ 
     # -gencode arch=compute_60,code=sm_60 \ 
     # -gencode arch=compute_61,code=sm_61 
# Deprecated 
#CUDA_ARCH := -gencode arch=compute_20,code=sm_20 \ 
#  -gencode arch=compute_20,code=sm_21 \ 
#  -gencode arch=compute_30,code=sm_30 \ 
#  -gencode arch=compute_35,code=sm_35 \ 
#  -gencode arch=compute_50,code=sm_50 \ 
#  -gencode arch=compute_50,code=compute_50 

# BLAS choice: 
# atlas for ATLAS (default) 
# mkl for MKL 
# open for OpenBlas 
BLAS := atlas 
# Custom (MKL/ATLAS/OpenBLAS) include and lib directories. 
# Leave commented to accept the defaults for your choice of BLAS 
# (which should work)! 
# BLAS_INCLUDE := /path/to/your/blas 
# BLAS_LIB := /path/to/your/blas 

# Homebrew puts openblas in a directory that is not on the standard search path 
# BLAS_INCLUDE := $(shell brew --prefix openblas)/include 
# BLAS_LIB := $(shell brew --prefix openblas)/lib 
BLAS_INCLUDE := /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/Headers/ 
BLAS_LIB := /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A 

# This is required only if you will compile the matlab interface. 
# MATLAB directory should contain the mex binary in /bin. 
# MATLAB_DIR := /usr/local 
# MATLAB_DIR := /Applications/MATLAB_R2012b.app 

# NOTE: this is required only if you will compile the python interface. 
# We need to be able to find Python.h and numpy/arrayobject.h. 
PYTHON_INCLUDE := /usr/include/python2.7 \ 
     /usr/lib/python2.7/dist-packages/numpy/core/include 
# Anaconda Python distribution is quite popular. Include path: 
# Verify anaconda location, sometimes it's in root. 
# ANACONDA_HOME := $(HOME)/anaconda 
# PYTHON_INCLUDE := $(ANACONDA_HOME)/include \ 
     # $(ANACONDA_HOME)/include/python2.7 \ 
     # $(ANACONDA_HOME)/lib/python2.7/site-packages/numpy/core/include \ 

# We need to be able to find libpythonX.X.so or .dylib. 
PYTHON_LIB := /usr/lib 
# PYTHON_LIB := $(ANACONDA_HOME)/lib 

# Homebrew installs numpy in a non standard path (keg only) 
# PYTHON_INCLUDE += $(dir $(shell python -c 'import numpy.core; print(numpy.core.__file__)'))/include 
# PYTHON_LIB += $(shell brew --prefix numpy)/lib 

# Uncomment to support layers written in Python (will link against Python libs) 
# WITH_PYTHON_LAYER := 1 

# Whatever else you find you need goes here. 
# INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include /usr/include/hdf5/serial 
# LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib /usr/lib/x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/hdf5/serial 

INCLUDE_DIRS := $(PYTHON_INCLUDE) /usr/local/include 
LIBRARY_DIRS := $(PYTHON_LIB) /usr/local/lib /usr/lib 

# If Homebrew is installed at a non standard location (for example your home directory) and you use it for general dependencies 
# INCLUDE_DIRS += $(shell brew --prefix)/include 
# LIBRARY_DIRS += $(shell brew --prefix)/lib 

# Uncomment to use `pkg-config` to specify OpenCV library paths. 
# (Usually not necessary -- OpenCV libraries are normally installed in one of the above $LIBRARY_DIRS.) 
# USE_PKG_CONFIG := 1 

BUILD_DIR := build 
DISTRIBUTE_DIR := distribute 

# Uncomment for debugging. Does not work on OSX due to https://github.com/BVLC/caffe/issues/171 
# DEBUG := 1 

# The ID of the GPU that 'make runtest' will use to run unit tests. 
TEST_GPUID := 0 

# enable pretty build (comment to see full commands) 
# Q ?= @ 

을 그리고 이것은 install_caffe_and_cpm_osx.sh 스크립트의 수정 된 버전입니다 :

#!/bin/bash 



echo "------------------------- INSTALLING CAFFE AND CPM -------------------------" 
echo "NOTE: This script assumes that CUDA and cuDNN are already installed on your machine. Otherwise, it might fail." 



function exitIfError { 
    if [[ $? -ne 0 ]] ; then 
     echo "" 
     echo "------------------------- -------------------------" 
     echo "Errors detected. Exiting script. The software might have not been successfully installed." 
     echo "------------------------- -------------------------" 
     exit 1 
    fi 
} 



# echo "------------------------- Checking Ubuntu Version -------------------------" 
# ubuntu_version="$(lsb_release -r)" 
# echo "Ubuntu $ubuntu_version" 
# if [[ $ubuntu_version == *"14."* ]]; then 
#  ubuntu_le_14=true 
# elif [[ $ubuntu_version == *"16."* || $ubuntu_version == *"15."* || $ubuntu_version == *"17."* || $ubuntu_version == *"18."* ]]; then 
#  ubuntu_le_14=false 
# else 
#  echo "Ubuntu release older than version 14. This installation script might fail." 
#  ubuntu_le_14=true 
# fi 
# exitIfError 
# echo "------------------------- Ubuntu Version Checked -------------------------" 
# echo "" 



echo "------------------------- Checking Number of Processors -------------------------" 
NUM_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) 
echo "$NUM_CORES cores" 
exitIfError 
echo "------------------------- Number of Processors Checked -------------------------" 
echo "" 



echo "------------------------- Installing some Caffe Dependencies -------------------------" 
# Basic 
# sudo apt-get --assume-yes update 
# sudo apt-get --assume-yes install build-essential 
#General dependencies 
brew install protobuf leveldb snappy hdf5 
# with Python pycaffe needs dependencies built from source - from http://caffe.berkeleyvision.org/install_osx.html 
# brew install --build-from-source --with-python -vd protobuf 
# brew install --build-from-source -vd boost boost-python 
# without Python the usual installation suffices 
brew install boost 
# sudo apt-get --assume-yes install libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler 
# sudo apt-get --assume-yes install --no-install-recommends libboost-all-dev 
# Remaining dependencies, 14.04 
brew install gflags glog lmdb 
# if [[ $ubuntu_le_14 == true ]]; then 
#  sudo apt-get --assume-yes install libgflags-dev libgoogle-glog-dev liblmdb-dev 
# fi 
# OpenCV 2.4 
# sudo apt-get --assume-yes install libopencv-dev 
exitIfError 
echo "------------------------- Some Caffe Dependencies Installed -------------------------" 
echo "" 



echo "------------------------- Compiling Caffe & CPM -------------------------" 
cp Makefile.config.OSX.10.11.5.example Makefile.config 
make all -j$NUM_CORES 
# make test -j$NUM_CORES 
# make runtest -j$NUM_CORES 
exitIfError 
echo "------------------------- Caffe & CPM Compiled -------------------------" 
echo "" 


# echo "------------------------- Installing CPM -------------------------" 
# echo "Compiled" 
# exitIfError 
# echo "------------------------- CPM Installed -------------------------" 
# echo "" 



echo "------------------------- Downloading CPM Models -------------------------" 
models_folder="./model/" 
# COCO 
coco_folder="$models_folder"coco/"" 
coco_model="$coco_folder"pose_iter_440000.caffemodel"" 
if [ ! -f $coco_model ]; then 
    wget http://posefs1.perception.cs.cmu.edu/Users/tsimon/Projects/coco/data/models/coco/pose_iter_440000.caffemodel -P $coco_folder 
fi 
exitIfError 
# MPI 
mpi_folder="$models_folder"mpi/"" 
mpi_model="$mpi_folder"pose_iter_160000.caffemodel"" 
if [ ! -f $mpi_model ]; then 
    wget http://posefs1.perception.cs.cmu.edu/Users/tsimon/Projects/coco/data/models/mpi/pose_iter_160000.caffemodel -P $mpi_folder 
fi 
exitIfError 
echo "Models downloaded" 
echo "------------------------- CPM Models Downloaded -------------------------" 
echo "" 



echo "------------------------- CAFFE AND CPM INSTALLED -------------------------" 
echo "" 

: 나는 벡터의 배열을 교환하려고했습니다

examples/rtpose/rtpose.cpp:1088:22: error: variable length array of non-POD element type 'Frame' 
    Frame frame_batch[BATCH_SIZE]; 

:

는하지만이 오류가

컴파일 오류가 발생했는데 이제는 링커 오류가 발생합니다. ld : -lgomp에 라이브러리가 없습니다. clang : 오류 : 링커 명령이 종료 코드 1과 함께 실패했습니다 (호출을 보려면 -v를 사용하십시오).)

lib lib gomp를 검색했으며 OSX 및 OpenMP에서 clang 관련 문제를 언급하는 caffe 및 OpenMP에 대한 관련 게시물을 발견했습니다. 내가 시도하는 것 :

  1. 은 (너무 높을 수 있습니다있는 GCC (5)의 사제 수식으로 5.9 설치합니다?) 나는 사제와 GCC 4.9을 설치 한 this post에 따라 내가 Andrey Bokhanko's answer에 따라 -fopenmp=libomp를 설정 한
  2. : 나를 ++-4.9: error: unrecognized command line option '-fopenmp=libomp'

을 다운로드하고 별도로 official instructions를 사용하여 CAFFE을 만들 수이 작동하지 않았다, 그러나 나는이 멋진 찾고 데모를 컴파일하는 방법을 알아낼 수 없습니다. 불행히도 저는 C++과 OpenMP에 익숙하지 않았기 때문에 여기서 여러분의 제안을 사용할 수 있습니다. 고맙습니다.

업데이트 : Mark Setchell이 ​​clang을 통해 llvm을 설치하는 데 도움이되는 제안을 시도했습니다. 나는

CUSTOM_CXX := /usr/local/opt/llvm/bin/clang++ 

를 사용하도록 메이크 파일 설정을 업데이트했지만 CUDA는 그것을 좋아하지 않습니다

nvcc fatal : The version ('30801') of the host compiler ('clang') is not supported 

을 내가 CPU_ONLY 컴파일 해봤지만 여전히 CUDA 오류를 얻을 :

examples/rtpose/rtpose.cpp:235:5: error: use of undeclared identifier 'cudaMalloc' 
    cudaMalloc(&net_copies[device_id].canvas, DISPLAY_RESOLUTION_WIDTH * DISPLAY_RESOLUTION_HEIGHT * 3 * sizeof(float)); 
    ^
examples/rtpose/rtpose.cpp:236:5: error: use of undeclared identifier 'cudaMalloc' 
    cudaMalloc(&net_copies[device_id].joints, MAX_NUM_PARTS*3*MAX_PEOPLE * sizeof(float)); 
    ^
examples/rtpose/rtpose.cpp:1130:146: error: use of undeclared identifier 'cudaMemcpyHostToDevice' 
       cudaMemcpy(net_copies[tid].canvas, frame.data_for_mat, DISPLAY_RESOLUTION_WIDTH * DISPLAY_RESOLUTION_HEIGHT * 3 * sizeof(float), cudaMemcpyHostToDevice); 
                                       ^
examples/rtpose/rtpose.cpp:1136:108: error: use of undeclared identifier 'cudaMemcpyHostToDevice' 
       cudaMemcpy(pointer + 0 * offset, frame_batch[0].data, BATCH_SIZE * offset * sizeof(float), cudaMemcpyHostToDevice); 
                             ^
examples/rtpose/rtpose.cpp:1178:13: error: use of undeclared identifier 'cudaMemcpyHostToDevice' 
      cudaMemcpyHostToDevice); 
      ^
examples/rtpose/rtpose.cpp:1192:155: error: use of undeclared identifier 'cudaMemcpyDeviceToHost' 
       cudaMemcpy(frame_batch[n].data_for_mat, net_copies[tid].canvas, DISPLAY_RESOLUTION_HEIGHT * DISPLAY_RESOLUTION_WIDTH * 3 * sizeof(float), cudaMemcpyDeviceToHost); 
                                         ^
examples/rtpose/rtpose.cpp:1202:155: error: use of undeclared identifier 'cudaMemcpyDeviceToHost' 
       cudaMemcpy(frame_batch[n].data_for_mat, net_copies[tid].canvas, DISPLAY_RESOLUTION_HEIGHT * DISPLAY_RESOLUTION_WIDTH * 3 * sizeof(float), cudaMemcpyDeviceToHost); 

나는 전문가는 아니지만 코드를 빠르게 검사 할 때 CPU_ONLY 버전이 cuda 호출과 함께 작동하는 방법을 알지 못합니다. caffe OSX Installation guide 또 다른 모습을 갖는

, 안 드디어 rtpose 예를 컴파일 관리 한 마음

+1

답변이 아니기 때문에이 글에서는 100 % 확신 할 수는 없지만, macOS에서 OpenMP를 gcc/g ++과 함께 사용하려면 multilib없이 설치해야합니다. bcc install gcc --without-multilib'을 실행하십시오. 더 자세한 정보는 여기에 ... http://stackoverflow.com/a/41980786/2836621 –

+0

@MarkSetchell 나는 [이 질문에 따라] homebrew/versions/gcc49 --without-multilib을 설치했다. (http : // stackoverflow .com/questions/29057437/compile-openmp-programs-gcc-compiler-on-os-x-yosemite). gcc49를 컴파일러로 지정했지만 여전히 무시되는'-fopenmp'에 대한 컴파일러 경고가 있습니다. 또한'-opopenmp = libomp'를 사용하여 시도했지만 컴파일러 오류가 발생했습니다 (위에서 지정). 또한 makefile에서 명시 적으로'''CPU_ONLY''를 지정했지만 gcc49를 사용하여 CUDA 관련 오류를 얻습니다. 나는 비록 llvm을 아직 시도하지 않았다! 그 점을 지적 해 주셔서 감사합니다. 나는 이걸 줄거야! 감사합니다 –

+0

당신의 초기 오류는'BATCH_SIZE'가 해당 번역 단위에 대해 정의되지 않았 음을 알려줍니다. 설정 헤더와 컴파일 플래그를 다시 확인하십시오. –

답변

0

의 약한> 경로를 시도 할 수 있습니다.여기

내가 무슨 짓을했는지 :

기본 clang++ 컴파일러를 사용
std::vector<Frame> frame_batch; 
    std::cout << "allocating " << BATCH_SIZE << " frames" << std::endl; 
    frame_batch.reserve(BATCH_SIZE); 

후 실패한 시도에서 : 위에서 언급 한 바와 같이

는, 예/rtpose/rtpose.cpp에서 벡터의 프레임 배열을 스왑 gcc++-4.9 사용 브루은 this answer

,536,913에 따라 -fopenmp 플래그와 -pthread 링커 플래그 아닌 컴파일러 플래그를 LLVM의 clang++를 설치하지만, 제거 컴파일이 완료되면 63,210

, 나는 그것을 실행하려고하지만 libjpeg 관련 오류 가지고 : 해결 방법은 mdemirst's answer했다

dyld: Symbol not found: __cg_jpeg_resync_to_restart 
    Referenced from: /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO 
    Expected in: /usr/local/lib/libJPEG.dylib 
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO 
Trace/BPT trap: 5 

합니다. 그래도 이전의 상징적 인 링크를 백업했습니다. ImageIO.framework에서 libjpeg/libpng/libtiff/libgif를 심볼릭 링크로 사용했습니다.

github에 위의 config/setup 스크립트를 위탁했습니다. 이제 예를 컴파일 할 것을

, 난 여전히 가능성으로 인해 충분하지 GPU 메모리에, 그것을 실행할 수 없습니다 :

./build/examples/rtpose/rtpose.bin -caffemodel ./model/coco/pose_iter_440000.caffemodel -caffeproto ./model/coco/pose_deploy_linevec.prototxt -camera_resolution "40x30" -camera 0 -resolution "40x30" -start_scale 0.1 -num_scales=0 -no_display true -net_resolution "16x16" 
: 나는 가능한 한 아래로 많은 설정을 디밍 시도

F0331 02:02:16.231935 528384 syncedmem.cpp:56] Check failed: error == cudaSuccess (2 vs. 0) out of memory 
*** Check failure stack trace: *** 
    @  0x10c7a89da google::LogMessage::Fail() 
    @  0x10c7a80d5 google::LogMessage::SendToLog() 
    @  0x10c7a863b google::LogMessage::Flush() 
    @  0x10c7aba17 google::LogMessageFatal::~LogMessageFatal() 
    @  0x10c7a8cc7 google::LogMessageFatal::~LogMessageFatal() 
    @  0x1079481db caffe::SyncedMemory::to_gpu() 
    @  0x107947c9e caffe::SyncedMemory::mutable_gpu_data() 
    @  0x1079affba caffe::CuDNNConvolutionLayer<>::Forward_gpu() 
    @  0x107861331 caffe::Layer<>::Forward() 
    @  0x107918016 caffe::Net<>::ForwardFromTo() 
    @  0x1077a86f1 warmup() 
    @  0x1077b211d processFrame() 
    @  0x7fff8b11899d _pthread_body 
    @  0x7fff8b11891a _pthread_start 
    @  0x7fff8b116351 thread_start 
Abort trap: 6 

하지만 아무 소용이 없습니다. 실제로 예제를 실행하는 것은 그 자체로 또 하나의 질문 일 수 있습니다.