mask rcnn模型踩坑指南 tusimple mx-maskrcnn

既然如此發表於2017-12-13
mask rcnn模型踩坑指南(MxNet框架):
1. 環境:anaconda2+tensorflow-gpu+python2.7.14
pip freeze: certifi==2017.11.5 / Cython==0.27.3 / easydict==1.7 / frcnn-cython==0.0.0 / numpy==1.13.3 / olefile==0.44 / opencv-python==3.3.0.10 / Pillow==4.3.0 / pycocotools==0.0.0
2. 步驟 :

a.原始資料集+原始程式碼。模型執行原始碼網址:https://github.com/TuSimple/mx-maskrcnn,

資料集網址:https://www.cityscapes-dataset.com/ . 

先下載資料集gtFine_trainvaltest.zip, leftImg8bit_trainvaltest.zip(需先註冊,有些麻煩)和程式碼git clone https://github.com/TuSimple/mx-maskrcnn.git. 

資料集解壓到 ./data/cityscape/目錄下


b.***@ubuntu: mx-maskrcnn-master $ bash scripts/download_res50.sh  #Download Resnet-50 pretrained model 


c.安裝mxnet, tutorial: https://mxnet.incubator.apache.org/get_started/build_from_source.html


***@ubuntu:mx-maskrcnn-master$ git clone --recursive https://github.com/apache/incubator-mxnet.git 

[mxnet]# mxnet官網GitHub下載地址,download incubator-mxnet,即mxnet模組,--recursive必不可少,否則可能make失敗,導致後面缺少libmxnet.so庫。


d.  ***@ubuntu: mx-maskrcnn-master $ cp rcnn/CXX_OP/* incubator-mxnet/src/operator/  # Build MXNet with ROIAlign operator.
cd incubator-mxnet

make -j8 USE_BLAS=openblas USE_CUDA=1 USE_CUDA_PATH=/usr/local/cuda USE_CUDNN=1 USE_CPP_PACKAGE=1

# c++編譯選項USE_CPP_PACKAGE=1


e. ***@ubuntu: mx-maskrcnn-master $ make #build related cython code , maybe need install cython package, 
f. ***@ubuntu: mx-maskrcnn-master $ sh scripts/train_alternate.sh  #Kick off training, 需修改train_alternate.sh最後一行為單GPU,原本為4GPU


模型正常訓練結果:先載入影像,再迭代
========================1285 ============================
data/cityscape/gtFine/train/bochum/bochum_000000_006746_gtFine_instanceIds.png
(2048, 1024)
========================1286 ============================
data/cityscape/gtFine/train/weimar/weimar_000022_000019_gtFine_instanceIds.png
(2048, 1024)
 
模型訓練2h顯示:
 
模型訓練20h顯示:
 


3. 踩的2個大坑:
a.
(1) 報如下錯誤:

執行最後一步bash scripts/train_alternate.sh報錯,File "_mask.pyx", line 56, in init rcnn.pycocotools._mask AttributeError: type object 'rcnn.pycocotools._mask.RLEs' has no attribute '__reduce_cython__' 


(2) 解決方案:將anaconda中的python3.6更換為python2.7(python3.6中還會報其他格式錯誤)
(3) 可能原因:見https://groups.google.com/forum/#!topic/cython-users/tQlwfcpdf0k,可能是Cython 0.26與python3不相容(谷歌搜__reduce_cython__)
b.
(1) 報如下錯誤:
src/storage/storage.cc:63: Check failed: e == cudaSuccess || e == cudaErrorCudartUnloading CUDA: invalid device ordinal
 
(2) 解決方案:將./scripts/train_alternate.sh指令碼最後一行作如下修改:
--gpu 0,1,2,3 |& tee -a ${TRAIN_DIR}/train.log  ->  --gpu 0 |& tee -a ${TRAIN_DIR}/train.log
(3) 可能原因:見http://blog.csdn.net/zpp13hao1/article/details/78581767?locationNum=7&fps=1中間部分“使用一個GPU,原始碼是使用了4個GPU,需要在train_alternate.sh中的最後一句話改為”
4. 備註
訓練模型時,如出現如下libmxnet.so檔案缺失,說明mxnet安裝不成功,需從步驟c開始重新安裝mxnet。
列印如下:RuntimeError: Cannot find the files. List of candidates:./incubator-mxnet/python/mxnet/libmxnet.so
./incubator-mxnet/python/mxnet/../../lib/libmxnet.so

./incubator-mxnet/python/mxnet/../../build/libmxnet.so

5. openblas 可能找不到  cblas.h,環境變數可能需要新增:

C_INCLUDE_PATH=/*/OpenBLAS/include:/MyLib
export C_INCLUDE_PATH
CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/*/OpenBLAS/include:/MyLib
export CPLUS_INCLUDE_PATH


6. 出現/usr/bin/ld: cannot find -lxxx 的解決辦法

export LIBRARY_PATH=/opt/biosoft/hdf5-1.8.15-patch1/lib/:$LIBRARY_PATH
若修改變數 LD_LIBRARY_PATH 不奏效,則修改變數 LIBRARY_PATH 。

7 出現

/usr/lib/libopencv_highgui.so.2.4: undefined reference to TIFFRGBAImageOK@LIBTIFF_4.0' 1> 
/usr/lib/libopencv_highgui.so.2.4: undefined reference toTIFFReadRGBAStrip@LIBTIFF_4.0'

解決方法是在cmake時加入下面引數

-D BUILD_TIFF=ON

相關文章