deeplab运行指南
以下僅僅為一個總結,參考了網上的眾多資料,僅備忘記。
主要鏈接
- deeplab主頁:http://liangchiehchen.com/projects/DeepLab.html
- 官方代碼:https://bitbucket.org/aquariusjay/deeplab-public-ver2
- python 版caffe實現:https://github.com/TheLegendAli/DeepLab-Context2
- model下載:http://liangchiehchen.com/projects/DeepLab_Models.html
- DeepLabv2_VGG16 預訓練模型
- DeepLabv2_ResNet101預訓練模型
- pytorch實現的deeplab:https://github.com/isht7/pytorch-deeplab-resnet
- 網上開源代碼:martinkersner/train-DeepLab
主要運行步驟
如下我們主要以網上開源的一個版本講解:https://github.com/xmojiao/deeplab_v2 .
主要的步驟可以參考:
1. 圖像語義分割:從頭開始訓練deeplab v2系列之一【源碼解析】
2. 圖像語義分割:從頭開始訓練deeplab v2系列之二【VOC2012數據集】
3. Deeplab v2 調試全過程(Ubuntu 16.04+cuda8.0)
下面說一些這上面沒有的我遇到的一些問題。
1. 安裝 matio:
上面資料中都使用 matio-1.5.2.tar.gz ,但是我裝不上,可能與我的庫不兼容,于是我下載了最新的 matio-1.5.11 ,并且按照如下命令運行安裝:
參考:http://blog.csdn.net/houqiqi/article/details/46469981
2. 使用的Caffe版本比較陳舊,導致會出現很多和最新環境不兼容的情況,我使用的是cuDNN6.0,cuda8.0
出現:
這是由于所使用的cuDNN版本不一致的導致的,作者配置環境是cuDNN 4.0,但是5.0版本后的cuDNN接口有所變化。
解決方法 :將以下幾個文件用最新BVLC版本的caffe對應文件替換并重新編譯
./include/caffe/util/cudnn.hpp ./include/caffe/layers/cudnn_conv_layer.hpp ./include/caffe/layers/cudnn_relu_layer.hpp ./include/caffe/layers/cudnn_sigmoid_layer.hpp ./include/caffe/layers/cudnn_tanh_layer.hpp./src/caffe/layers/cudnn_conv_layer.cpp ./src/caffe/layers/cudnn_conv_layer.cu ./src/caffe/layers/cudnn_relu_layer.cpp ./src/caffe/layers/cudnn_relu_layer.cu ./src/caffe/layers/cudnn_sigmoid_layer.cpp ./src/caffe/layers/cudnn_sigmoid_layer.cu ./src/caffe/layers/cudnn_tanh_layer.cpp ./src/caffe/layers/cudnn_tanh_layer.cu參考:http://blog.csdn.net/tianrolin/article/details/71246472
3. 如何解決deeplab v2識別結果為全黑圖像的問題?
正如作者而言:http://liangchiehchen.com/projects/DeepLab_FAQ.html
主要是作者預訓練的模型與你實際測試的模型出現了偏差。主要是fc8 的問題。
以https://github.com/xmojiao/deeplab_v2 為例,如果直接使用此代碼,則run_pascal.sh出現在voc12目錄下,而run_pascal.sh上EXP2=. ,這與官方的預設不同。官方代碼,假定run_pascal.sh應該出現在voc12上一級目錄下。 這樣最后測試時會出現fc8_voc12_1,fc8_voc12_2,fc8_voc12_3,fc8_voc12_4被忽略的情況。
另外由于測試時需要將test.prototxt復制為test_val.prototxt,所以應該主要修改test.prototxt。
test.prototxt改動如下
run_pascal.sh改變如下
#!/bin/sh ## MODIFY PATH for YOUR SETTING ROOT_DIR=/data1/caiyong.wang/data/deeplab_dataCAFFE_DIR=../deeplab-public-ver2 CAFFE_BIN=${CAFFE_DIR}/.build_release/tools/caffe.binEXP=voc12 #適應原始訓練好的模型目錄 (改變) EXP2=. #當前目錄下 (改變)if [ "${EXP2}" = "." ]; thenNUM_LABELS=21DATA_ROOT=${ROOT_DIR}/VOC_aug/dataset/ elseNUM_LABELS=0echo "Wrong EXP name" fi## Specify which model to train ########### voc12 ################ NET_ID=deeplab_largeFOV## Variables used for weakly or semi-supervisedly training #TRAIN_SET_SUFFIX= TRAIN_SET_SUFFIX=_aug#TRAIN_SET_STRONG=train #TRAIN_SET_STRONG=train200 #TRAIN_SET_STRONG=train500 #TRAIN_SET_STRONG=train1000 #TRAIN_SET_STRONG=train750#TRAIN_SET_WEAK_LEN=5000DEV_ID=0####### Create dirsCONFIG_DIR=${EXP2}/config/${NET_ID} MODEL_DIR=${EXP2}/model/${NET_ID} mkdir -p ${MODEL_DIR} LOG_DIR=${EXP2}/log/${NET_ID} mkdir -p ${LOG_DIR} export GLOG_log_dir=${LOG_DIR}## RunRUN_TRAIN=0 RUN_TEST=1 RUN_TRAIN2=0 RUN_TEST2=0## Training #1 (on train_aug)if [ ${RUN_TRAIN} -eq 1 ]; then#LIST_DIR=${EXP2}/listTRAIN_SET=train${TRAIN_SET_SUFFIX}if [ -z ${TRAIN_SET_WEAK_LEN} ]; thenTRAIN_SET_WEAK=${TRAIN_SET}_diff_${TRAIN_SET_STRONG}comm -3 ${LIST_DIR}/${TRAIN_SET}.txt ${LIST_DIR}/${TRAIN_SET_STRONG}.txt > ${LIST_DIR}/${TRAIN_SET_WEAK}.txtelseTRAIN_SET_WEAK=${TRAIN_SET}_diff_${TRAIN_SET_STRONG}_head${TRAIN_SET_WEAK_LEN}comm -3 ${LIST_DIR}/${TRAIN_SET}.txt ${LIST_DIR}/${TRAIN_SET_STRONG}.txt | head -n ${TRAIN_SET_WEAK_LEN} > ${LIST_DIR}/${TRAIN_SET_WEAK}.txtfi#MODEL=${EXP2}/model/${NET_ID}/init.caffemodel#echo Training net ${EXP2}/${NET_ID}for pname in train solver; dosed "$(eval echo $(cat sub.sed))" \${CONFIG_DIR}/${pname}.prototxt > ${CONFIG_DIR}/${pname}_${TRAIN_SET}.prototxtdoneCMD="${CAFFE_BIN} train \--solver=${CONFIG_DIR}/solver_${TRAIN_SET}.prototxt \--gpu=${DEV_ID}"if [ -f ${MODEL} ]; thenCMD="${CMD} --weights=${MODEL}"fiecho Running ${CMD} && ${CMD} fi## Test #1 specification (on val or test)if [ ${RUN_TEST} -eq 1 ]; then#for TEST_SET in val; doTEST_ITER=`cat ${EXP2}/list/${TEST_SET}.txt | wc -l`MODEL=${EXP2}/model/${NET_ID}/test.caffemodelif [ ! -f ${MODEL} ]; thenMODEL=`ls -t ${EXP2}/model/${NET_ID}/train_iter_*.caffemodel | head -n 1`fi#echo Testing net ${EXP2}/${NET_ID}FEATURE_DIR=${EXP2}/features/${NET_ID}mkdir -p ${FEATURE_DIR}/${TEST_SET}/fc8mkdir -p ${FEATURE_DIR}/${TEST_SET}/fc9mkdir -p ${FEATURE_DIR}/${TEST_SET}/seg_scoresed "$(eval echo $(cat sub.sed))" \${CONFIG_DIR}/test.prototxt > ${CONFIG_DIR}/test_${TEST_SET}.prototxtCMD="${CAFFE_BIN} test \--model=${CONFIG_DIR}/test_${TEST_SET}.prototxt \--weights=${MODEL} \--gpu=${DEV_ID} \--iterations=${TEST_ITER}"echo Running ${CMD} && ${CMD}done fi## Training #2 (finetune on trainval_aug)if [ ${RUN_TRAIN2} -eq 1 ]; then#LIST_DIR=${EXP2}/listTRAIN_SET=trainval${TRAIN_SET_SUFFIX}if [ -z ${TRAIN_SET_WEAK_LEN} ]; thenTRAIN_SET_WEAK=${TRAIN_SET}_diff_${TRAIN_SET_STRONG}comm -3 ${LIST_DIR}/${TRAIN_SET}.txt ${LIST_DIR}/${TRAIN_SET_STRONG}.txt > ${LIST_DIR}/${TRAIN_SET_WEAK}.txtelseTRAIN_SET_WEAK=${TRAIN_SET}_diff_${TRAIN_SET_STRONG}_head${TRAIN_SET_WEAK_LEN}comm -3 ${LIST_DIR}/${TRAIN_SET}.txt ${LIST_DIR}/${TRAIN_SET_STRONG}.txt | head -n ${TRAIN_SET_WEAK_LEN} > ${LIST_DIR}/${TRAIN_SET_WEAK}.txtfi#MODEL=${EXP2}/model/${NET_ID}/init2.caffemodelif [ ! -f ${MODEL} ]; thenMODEL=`ls -t ${EXP2}/model/${NET_ID}/train_iter_*.caffemodel | head -n 1`fi#echo Training2 net ${EXP2}/${NET_ID}for pname in train solver2; dosed "$(eval echo $(cat sub.sed))" \${CONFIG_DIR}/${pname}.prototxt > ${CONFIG_DIR}/${pname}_${TRAIN_SET}.prototxtdoneCMD="${CAFFE_BIN} train \--solver=${CONFIG_DIR}/solver2_${TRAIN_SET}.prototxt \--weights=${MODEL} \--gpu=${DEV_ID}"echo Running ${CMD} && ${CMD} fi## Test #2 on official test setif [ ${RUN_TEST2} -eq 1 ]; then#for TEST_SET in val test; doTEST_ITER=`cat ${EXP2}/list/${TEST_SET}.txt | wc -l`MODEL=${EXP2}/model/${NET_ID}/test2.caffemodelif [ ! -f ${MODEL} ]; thenMODEL=`ls -t ${EXP2}/model/${NET_ID}/train2_iter_*.caffemodel | head -n 1`fi#echo Testing2 net ${EXP2}/${NET_ID}FEATURE_DIR=${EXP2}/features2/${NET_ID}mkdir -p ${FEATURE_DIR}/${TEST_SET}/fc8mkdir -p ${FEATURE_DIR}/${TEST_SET}/crfsed "$(eval echo $(cat sub.sed))" \${CONFIG_DIR}/test.prototxt > ${CONFIG_DIR}/test_${TEST_SET}.prototxtCMD="${CAFFE_BIN} test \--model=${CONFIG_DIR}/test_${TEST_SET}.prototxt \--weights=${MODEL} \--gpu=${DEV_ID} \--iterations=${TEST_ITER}"echo Running ${CMD} && ${CMD}done fi總結
以上是生活随笔為你收集整理的deeplab运行指南的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于FCN的数据集着色说明
- 下一篇: JAVA API中文在线帮助文档