前言:
論文及源代碼網址:
https://github.com/ZheC/Realtime_Multi-Person_Pose_Estimation
地址2:
https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/installation.md
1. 一個失敗的嘗試
首先是跑一個例子試試,使用
https://github.com/CMU-Perceptual-Computing-Lab/openpose/
按照作者的指導,如下:
Training Steps
- Run
cd training; bash getData.sh
to obtain the COCO images indataset/COCO/images/
, keypoints annotations indataset/COCO/annotations/
and COCO official toolbox indataset/COCO/coco/
.- 這里建議開screen,因為要下載超級久
- Run
getANNO.m
in matlab to convert the annotation format from json to mat indataset/COCO/mat/
. - Run
genCOCOMask.m
in matlab to obatin the mask images for unlabeled person. You can use 'parfor' in matlab to speed up the code.- 注意修改Matlab程序中的路徑,在 im = imread(['dataset/COCO/', img_paths]);的COCO后面加上images/,原程序有點問題
- 這里嘗試開啟了一下並行運算,速度特別快,將代碼中第二個for循環改為parfor i = 1:L,然后使用Matlab的時候,先輸入matlabpool open,然后再運行程序。關閉的方法為matlabpool close
- 然后遇到了Subscripted assignment between dissimilar structures.問題,看代碼也沒有找到問題,參考 [1]
- Run
genJSON('COCO')
to generate a json file indataset/COCO/json/
folder. The json files contain raw informations needed for training. - Run
python genLMDB.py
to generate your LMDB. (You can also download our LMDB for the COCO dataset (189GB file) by:bash get_lmdb.sh
) - Download our modified caffe: caffe_train. Compile pycaffe. It will be merged with caffe_rtpose (for testing) soon.
- Run
python setLayers.py --exp 1
to generate the prototxt and shell file for training. - Download VGG-19 model, we use it to initialize the first 10 layers for training.
- Run
bash train_pose.sh 0,1
(generated by setLayers.py) to start the training with two gpus.
2. 安裝Caffe
這種跑一個例子失敗之后,
轉而使用最根本的方法從頭按照步驟編譯,不走捷徑:參考下面的網址
因為電腦里已經安裝過caffe的依賴環境了,所以把caffe編譯一下就可以用了,參考下面的話 [3]
### Install Caffe ### cd 3rdparty/caffe/ # Select your desired Makefile file (run only one of the next 4 commands) cp Makefile.config.Ubuntu14_cuda7.example Makefile.config # Ubuntu 14, cuda 7 cp Makefile.config.Ubuntu14_cuda8.example Makefile.config # Ubuntu 14, cuda 8 cp Makefile.config.Ubuntu16_cuda7.example Makefile.config # Ubuntu 16, cuda 7 cp Makefile.config.Ubuntu16_cuda8.example Makefile.config # Ubuntu 16, cuda 8 # Change any custom flag from the resulting Makefile.config (e.g. OpenCV 3, Atlas/OpenBLAS/MKL, etc.) # Compile Caffe
make all -j${number_of_cpus} && make distribute -j${number_of_cpus}
比如make all -j16(使用16個CPU同時運行)
3. 安裝 OpenPose cd ../../models/ bash ./getModels.sh # It just downloads the Caffe trained models cd .. # Same file cp command as the one used for Caffe cp ubuntu/Makefile.config.Ubuntu14_cuda7.example Makefile.config # Change any custom flag from the resulting Makefile.config (e.g. OpenCV 3, Atlas/OpenBLAS/MKL, etc.) make all -j${number_of_cpus}
一定要嚴格按照順序(實驗室服務器用的是zsh,所以注意替換bash為zsh)
如果使用OpenCV 3版本的話,可以通過所有make,但是不能運行實際的例子
按照作者在某個Issue下的回答,應該使用OpenCV2.4,然后折騰很久,見另一篇博客 [7]
然后出現無法make,錯誤中關鍵行為這個
../lib/libcaffe.so: undefined reference to cv::imread(cv::String const&, int)'
搜索之后得到解答:[4]
open your Makefile with some text editor, locate line 164 (in my case), add opencv_imgcodecs behind.
LIBRARIES += glog gflags protobuf leveldb snappy \ lmdb boost_system hdf5_hl hdf5 m \ opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
在vim里使用
:se nu
然后回車,可以顯示行號;使用
/opencv
可以快速定位到第一個出現的opencv字符串的位置
添加后可以make了,然后不出意料的還是不能運行實際的例子:
4. 運行一個例子
實際例子運行方法:[3]
1. Running on Video
# Ubuntu ./build/examples/openpose/openpose.bin --video examples/media/video.avi # With face and hands ./build/examples/openpose/openpose.bin --video examples/media/video.avi --face --hand
會出現
zsh: abort (core dumped) ./build/examples/openpose/openpose.bin --video examples/media/video.avi
再試試別的運行方法:
3. Running on Images
# Ubuntu ./build/examples/openpose/openpose.bin --image_dir examples/media/ # With face and hands ./build/examples/openpose/openpose.bin --image_dir examples/media/ --face --hand
會出現
Starting pose estimation demo.
Error:
boost::filesystem::directory_iterator::construct: No such file or directory
Coming from:
- src/openpose/utilities/fileSystem.cpp:getFilesOnDirectory():186
- src/openpose/producer/imageDirectoryReader.cpp:getImagePathsOnDirectory():25
- src/openpose/utilities/flagsToOpenPose.cpp:flagsToProducer():133
terminate called after throwing an instance of 'std::runtime_error'
what():
Error:
boost::filesystem::directory_iterator::construct: No such file or directory
Coming from:
- src/openpose/utilities/fileSystem.cpp:getFilesOnDirectory():186
- src/openpose/producer/imageDirectoryReader.cpp:getImagePathsOnDirectory():25
- src/openpose/utilities/flagsToOpenPose.cpp:flagsToProducer():133
zsh: abort (core dumped) ./build/examples/openpose/openpose.bin --image_dir examples/media/
然后搜索后,根據 [5] DuinoDu的回答,去 [6] 里找答案,“install boost from src.”
根據user3715812的回答,輸入以下命令行來安裝BOOST:
wget -O boost_1_55_0.tar.gz http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download tar xzvf boost_1_55_0.tar.gz cd boost_1_55_0/ ./bootstrap.sh --prefix=/usr/local // 這里改成自己想要安裝到的目錄 ./b2 ./b2 install // 沒有SUDO權限但是也可以
然后再去運行
./build/examples/openpose/openpose.bin --image_dir examples/media/
這次的報錯和上次不一樣了,是
Starting pose estimation demo. Auto-detecting GPUs... Detected 16 GPU(s), using them all. Starting thread(s) : cannot connect to X server E0819 00:20:53.031266 20765 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20766 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20771 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20773 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20767 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20775 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20776 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20777 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20778 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20765 common.cpp:121] Cannot create Curand generator. Curand won't be available. E0819 00:20:53.031266 20769 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20768 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20774 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20770 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20779 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20772 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20779 common.cpp:121] Cannot create Curand generator. Curand won't be available. E0819 00:20:53.031266 20771 common.cpp:121] Cannot create Curand generator. Curand won't be available. E0819 00:20:53.031266 20773 common.cpp:121] Cannot create Curand generator. Curand won't be available. F0819 00:20:53.031266 20779 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting downF0819 00:20:53.031266 20771 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting downF0819 00:20:53.035267 20773 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting down *** Check failure stack trace: *** E0819 00:20:53.031266 20780 common.cpp:114] Cannot create Cublas handle. Cublas won't be available. E0819 00:20:53.031266 20778 common.cpp:121] Cannot create Curand generator. Curand won't be available. E0819 00:20:53.031266 20775 common.cpp:121] Cannot create Curand generator. Curand won't be available. E0819 00:20:53.031266 20767 common.cpp:121] Cannot create Curand generator. Curand won't be available. F0819 00:20:53.031266 20779 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting downF0819 00:20:53.031266 20771 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting downF0819 00:20:53.035267 20773 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting downF0819 00:20:53.035267 20778 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting downF0819 00:20:53.035267 20775 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting downF0819 00:20:53.035267 20767 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting down *** Check failure stack trace: *** F0819 00:20:53.031266 20765 common.cpp:152] Check failed: error == cudaSuccess (29 vs. 0) driver shutting down zsh: abort (core dumped) ./build/examples/openpose/openpose.bin --image_dir examples/media/
然后在GITHUB 的ISSUE區准備提問的時候,根據提示
Note: add
--logging_level 0
to get higher debug information.
在運行的命令行后加上了這個,即:
./build/examples/openpose/openpose.bin --image_dir examples/media/ --logging_level 0
於是得到了較為准確的信息:
可以理解為又一個圖形界面要展示但是出不來 [8](X server相關),
查閱資料后根據 [9] 的xiaoyan的回答:
Add "export DISPLAY=your ip:0.0" in ~/.bashrc, source ~/.bashrc (ip is your host IP, where you wanna display plots or things like that. If you are using Windows, cmd-ipconfig, find your IP).
於是不再出現X server問題了,出現了下圖的問題
找了好久沒找到問題,最后求助了組里的史博士,這里表示非常感謝!!!
原因是這個Demo默認使用所有探測到的CUDA 設備,而實驗室的CUDA設備還有很多人在用,這會造成問題(可能是沖突或者資源不夠,或者不被允許個人使用這么多個?)
所以在運行的命令行前面要加上一定的限制:
CUDA_VISIBLE_DEVICES=2 ./build/examples/openpose/openpose.bin --net_resolution "160x80" --video examples/media/video.avi
使得被探測到的設備數量只有兩個。
然后發現還是運行不了,為什么呢?
因為OS X上的SHELL並不具備顯示遠程窗口的功能,
所以在史博士的推薦下使用了MobaXterm(在WIN10下),然后就成功了,因為這個軟件直接內置了X server的接口
更新:如果想在Mac上運行,可以參考
[10] http://blog.csdn.net/dobell/article/details/55047811
安裝XQuartz, https://www.xquartz.org 按說明安裝好 打開 mac terminal ssh -X {用戶名}@{遠程端ip}; (注意大寫的X) 這次就可以了
實際運行截圖如下:
你也可以讀一下我在GITHUB上的提問:
https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/184
可能會有幫助
另外:
因為實驗室的服務器出於安全考慮不允許使用
sudo pip install
, 所以使用
pip install --user
來替代。[2]
參考文獻:
[1] http://www.cnblogs.com/emituofo/archive/2011/11/13/2247523.html
[2] https://stackoverflow.com/questions/31512422/pip-install-r-oserror-errno-13-permission-denied
[3] https://github.com/CMU-Perceptual-Computing-Lab/openpose/blob/master/doc/installation.md
[4] https://github.com/BVLC/caffe/issues/1276
[5] https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/17
[6] https://stackoverflow.com/questions/12578499/how-to-install-boost-on-ubuntu
[7] http://www.cnblogs.com/QingHuan/p/7278357.html
[8] http://www.cnblogs.com/super119/archive/2010/12/18/1910065.html
[9] https://askubuntu.com/questions/571116/cannot-connect-to-x-server-error