Fast RCNN筆記1:TFFRCNN demo 調試 (這個版本比較久沒更新換endernewton繼續)

實現TFFRCNN demo過程當中遇到的問題記錄(github地址:https://github.com/CharlesShang/TFFRCNN):python

參考:1.https://blog.csdn.net/ssmixi/article/details/75147532c++

   2.https://blog.csdn.net/zichen7055/article/details/82316553git

   3.https://blog.csdn.net/m_z_g_y/article/details/81203943github

1.因爲TFFRCNN這份代碼是python2.7 版本,因此要麼全用Python2解釋器,要麼用Python自帶工具2to3.py所有轉換爲Python3版本bash

python 2to3.py -w 路徑(最好所有英文)

2.將fastrcnn目錄下demo copy到TFFRCNN目錄下,並在根目錄下創建model文件夾,將下載的VGGnet_fast_rcnn_iter_150000.ckpt複製到裏面,架構

基本目錄架構以下python2.7

 

3.關於yaml moduleimport error,pip安裝pyyaml便可:工具

sudo pip3 install pyyaml -i http://pypi.mirrors.ustc.edu.cn/simple --trusted-host pypi.mirrors.ustc.edu.cn

4.cd lib路徑根據本身tensorflow版本和gcc修改make.sh文件,make 一下,若是後續出錯能夠用測試

find lib -name "*.so" -delete

 

刪除編譯後的文件。(修改後文件以下:)ui

#!/usr/bin/env bash
TF_LIB=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_lib())')
TF_INC=$(python -c 'import tensorflow as tf; print(tf.sysconfig.get_include())')
echo $TF_INC

CUDA_PATH=/usr/local/cuda/

cd roi_pooling_layer

nvcc -std=c++11 -c -o roi_pooling_op.cu.o roi_pooling_op_gpu.cu.cc \
    -I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -arch=sm_52

## if you install tf using already-built binary, or gcc version 4.x, uncomment the two lines below
#g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=0 -o roi_pooling.so roi_pooling_op.cc \
#    roi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64

# for gcc5-built tf
g++ -std=c++11 -shared -o roi_pooling.so roi_pooling_op.cc -D_GLIBCXX_USE_CXX11_ABI=0 \
    roi_pooling_op.cu.o -I $TF_INC -L $TF_LIB -ltensorflow_framework -D GOOGLE_CUDA=1 \
    -fPIC $CXXFLAGS -lcudart -L $CUDA_PATH/lib64

cd ..

# add building psroi_pooling layer
cd psroi_pooling_layer
nvcc -std=c++11 -c -o psroi_pooling_op.cu.o psroi_pooling_op_gpu.cu.cc \
    -I $TF_INC -D GOOGLE_CUDA=1 -x cu -Xcompiler -fPIC -arch=sm_52

g++ -std=c++11 -shared -o psroi_pooling.so psroi_pooling_op.cc -D_GLIBCXX_USE_CXX11_ABI=0\
    psroi_pooling_op.cu.o -I $TF_INC -L $TF_LIB -ltensorflow_framework -D GOOGLE_CUDA=1 \
    -fPIC $CXXFLAGS -lcudart -L $CUDA_PATH/lib64

## if you install tf using already-built binary, or gcc version 4.x, uncomment the two lines below
#g++ -std=c++11 -shared -D_GLIBCXX_USE_CXX11_ABI=0 -o psroi_pooling.so psroi_pooling_op.cc \
#    psroi_pooling_op.cu.o -I $TF_INC -fPIC -lcudart -L $CUDA_PATH/lib64

cd ..

4.在根目錄下執行:

python demo.py --model model/VGGnet_fast_rcnn_iter_150000.ckpt

若是出現keyerror:b'Test',解決連接:https://github.com/CharlesShang/TFFRCNN/issues/14

須要修改rpn_msr下proposal_layer_tf.py 第70行,加上

cfg_key = cfg_key.decode("utf-8")

修改後以下:

5.運行後發現無結果,須要保存結果,修改demo.py

# for im_name in im_names:
    #     print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
    #     print('Demo for {:s}'.format(im_name))
    #     demo(sess, net, im_name)
    for im_name in im_names:
        print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')
        print('Demo for {:s}'.format(im_name))
        demo(sess, net, im_name)
        plt.savefig(im_name)

    plt.show()

6.demo測試運行結果以下:

相關文章
相關標籤/搜索