Faster-RCNN用於場景文字檢測訓練測試過程記錄(轉)


[訓練測試過程記錄]Faster-RCNN用於場景文字檢測

原創 2017年11月06日 20:09:00
        <ul class="article_tags clearfix csdn-tracking-statistics tracking-click" data-mod="popu_377" style="display: none;">
            <li class="tit">標簽:</li>
            <!--          [endarticletags]-->
        </ul>
        <ul class="right_bar">
            <li><button class="btn-noborder"><i class="icon iconfont icon-read"></i><span class="txt">609</span></button></li>
            <li class="edit" style="display: none;">
                <a class="btn-noborder" href="https://mp.csdn.net/postedit/78457624">
                    <i class="icon iconfont icon-bianji"></i><span class="txt">編輯</span>
                </a>
            </li>
            <li class="del" style="display: none;">
                <a class="btn-noborder" onclick="javascript:deleteArticle(fileName);return false;">
                    <i class="icon iconfont icon-shanchu"></i><span class="txt">刪除</span>
                </a>
            </li>
        </ul>
    </div>
    <div id="article_content" class="article_content csdn-tracking-statistics tracking-click" data-mod="popu_519" data-dsm="post" style="overflow: hidden;">
                        <div class="htmledit_views">

寫在前面:github上面的Text-Detection-with-FRCN項目是基於py-faster-rcnn項目在場景文字識別領域的擴展。

和py-faster-rcnn相比,該項目的主要改動為:將檢測類別換成了背景和文字,並且更改了數據集。

對於初學者而言,要實現一個自己的baseline,第一步可以嘗試訓練別人已經實現了的網絡,看看整個的運行流程是怎么樣的。那么,接下來,我就記錄一下我自己在訓練和測試過程中遇到的問題。大家在參考的時候可以參照Text-Detection-with-FRCN項目中的README.md文件。

一.編譯部分

在編譯caffe的時候,可能會遇到一些問題,這里,我來介紹一下我遇到的問題。

1.Makefile.config.example文件修改問題

切換到caffe目錄:cd $Text-Detection-with-FRCN/py-faster-rcnn/caffe-fast-rcnn

修改Makefile.config.example文件:

(1)去掉USE_CUDNN := 1的注釋

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

(2)去掉WITH_PYTHON_LAYER := 1的注釋

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


2.CUDNN版本問題

在上一步中,修改了Makefile.config.example問題,再執行如下指令:

cp Makefile.config.example Makefile.config

make -16 && make pycaffe

在make的過程中,可能出現由於CUDNN版本問題導致的錯誤:

  1. In file included from ./include/caffe/util/device_alternate.hpp:40:0,    
  2.                      from ./include/caffe/common.hpp:19,    
  3.                      from src/caffe/common.cpp:7:    
  4.     ./include/caffe/util/cudnn.hpp: In function ‘void caffe::cudnn::createPoolingDesc(cudnnPoolingStruct**, caffe::PoolingParameter_PoolMethod, cudnnPoolingMode_t*, int, int, int, int, int, int)’:    
  5.     ./include/caffe/util/cudnn.hpp:127:41: error: too few arguments to function ‘cudnnStatus_t cudnnSetPooling2dDescriptor(cudnnPoolingDescriptor_t, cudnnPoolingMode_t, cudnnNanPropagation_t, int, int, int, int, int, int)’    
  6.              pad_h, pad_w, stride_h, stride_w));    
  7.                                              ^    
  8.     ./include/caffe/util/cudnn.hpp:15:28: note: in definition of macro ‘CUDNN_CHECK’    
  9.          cudnnStatus_t status = condition; \    
  10.                                 ^    
  11.     In file included from ./include/caffe/util/cudnn.hpp:5:0,    
  12.                      from ./include/caffe/util/device_alternate.hpp:40,    
  13.                      from ./include/caffe/common.hpp:19,    
  14.                      from src/caffe/common.cpp:7:    
  15.     /usr/local/cuda-7.5//include/cudnn.h:803:27: note: declared here    
  16.      cudnnStatus_t CUDNNWINAPI cudnnSetPooling2dDescriptor(    
  17.                                ^    
  18.     make: *** [.build_release/src/caffe/common.o] Error 1    

這是由於當前版本的caffe的cudnn實現與系統所安裝的cudnn的版本不一致引起的。

解決辦法:

下載最新版的caffe

1)將./include/caffe/util/cudnn.hpp換成最新版的caffe里的cudnn.hpp;

2)將./include/caffe/layers里面,所有以cudnn開頭的文件,都換成最新版的caffe里面相應的同名文件;

3)將./src/caffe/layers里面,所有以cudnn開頭的文件,都換成最新版的caffe里面相應的同名文件。

tips:其他部分的以cudnn開頭的文件,就不要動了。


二.准備數據集

在Text-Detection-with-FRCN項目的readme中,給出了coco-text數據集的制作方式。下面,就來具體說明。

1.下載數據集

切換目錄:cd $Text-Detection-with-FRCN/datasets/script

原指令為:./fetch_dataset.sh coco-text,可能會出現-bash: ./fetch_dataset.sh: Permission denied的錯誤。

可先運行:chmod +x ./fetch_dataset.sh

再運行: ./fetch_dataset.sh coco-text


下載到的數據集包括:train2014.zip文件和COCO_Text.json,下面,需要將數據進行格式化,與原py-faster-rcnn中的pascal_voc的數據格式進行統一。


2.數據格式化

(1)pascal_voc數據集的格式為:

--Annotations

--*.xml

--JPEGImages

--*.jpg

--ImageSets

--Main

......

圖像文件夾(JPEGImages):例如2008_000200.jpg

標記文件夾(Annotations):例如2008_000200.xml

<annotation>

<folder>VOC2012</folder>

<filename>2008_000200.jpg</filename>

<source>

<database>TheVOC2008 Database</database>

<annotation>PASCALVOC2008</annotation>

<image>flickr</image>

</source>

<size>

<width>500</width>

<height>375</height>

<depth>3</depth>

</size>

<segmented>0</segmented>

<object>

<name>person</name>

<bndbox>

<xmin>119</xmin>

<ymin>76</ymin>

<xmax>184</xmax>

<ymax>311</ymax>

</bndbox>

</object>

......


區分訓練樣本與測試樣本(ImageSets):

test.txt為例:

2008_000001

2008_000004

2008_000005

2008_000006


(2)coco-text的格式為:

圖片集:Train2014.zip:COCO_train2014_000000378466.jpg

文件標記:

COCO_Text.json

{"imgs":

{"378466":{"width": 612, "file_name":"COCO_train2014_000000378466.jpg", "set":"train", "id": 378466, "height": 612},

"370250":{"width": 427, "file_name":"COCO_train2014_000000370250.jpg", "set": "test","id": 370250, "height": 640},

"36606":{"width": 640, "file_name":"COCO_train2014_000000036606.jpg", "set": "val","id": 36606, "height": 480}


(3)將coco-text的數據集格式轉換為pascal_voc的格式


切換目錄:cd $Text-Detection-with-FRCN/datasets/script

運行指令:./format_annotation.py --dataset coco-text


format_annotation.py中:

1.format_coco_text函數,是利用coco-text.json中的信息,生成類似於pascal_voc的ImageSets文件夾中的信息。

2.os.system('./ann2voc2007.sh ' + args.dataset),是調用相同文件夾下面的ann2voc2007.m文件,來生成類似於pascal_voc的Annotations文件夾中的信息。


如果不想花時間安裝matlib,可以將ann2voc2007.m改寫為python文件,效果是一樣的。


改寫后的代碼如下:(具體原理可參考:利用python生成xml文件

[python] view plain copy
print ?
  1. #coding:utf-8  
  2. from PIL import Image  
  3. from xml.dom.minidom import Document  
  4. import os  
  5.   
  6. def main():  
  7.     imgpath = 'JPEGImages/'  
  8.     txtpath = 'images.annotations'  
  9.     xmlpath_new = 'Annotations/'  
  10.     coco = {}  
  11.       
  12.     # 得到圖像的標注信息  
  13.     file_object = open(txtpath,'rU')  
  14.     try:   
  15.         for line in file_object:  
  16.             line = line.rstrip('\n')  
  17.             strs = line.split(' ')  
  18.             print strs[0]  
  19.             foldername = 'VOC2007'  
  20.               
  21.             # 用xml替換jpg,得到同名文件  
  22.             xmlname = strs[0].replace('.jpg','.xml')  
  23.             info = Image.open(imgpath + strs[0])  
  24.             # read image size  
  25.             (width,height) = info.size  
  26.             strs[2] = max(int(strs[2]), 1)  
  27.             strs[3] = max(int(strs[3]), 1)  
  28.             strs[4] = min(int(strs[4]), width);  
  29.             strs[5] = min(int(strs[5]), height);  
  30.   
  31.             # 過濾異常  
  32.             if strs[2] >= strs[4or strs[3] >= strs[5or strs[2] <=0 or strs[3] <= 0 or strs[4] > width or strs[5] > height:  
  33.                 continue  
  34.               
  35.             if os.path.exists(imgpath + strs[0]):  
  36.                 if xmlname in coco:  
  37.                     Createnode = coco[xmlname]  
  38.                     object_node = Createnode.createElement('object')  
  39.                       
  40.                     Root = Createnode.getElementsByTagName('annotation')[0]  
  41.                     Root.appendChild(object_node)  
  42.                       
  43.                     node=Createnode.createElement('name')  
  44.                     node.appendChild(Createnode.createTextNode(strs[1]))  
  45.                     object_node.appendChild(node)  
  46.                       
  47.                     node=Createnode.createElement('pose')  
  48.                     node.appendChild(Createnode.createTextNode('Unspecified'))  
  49.                     object_node.appendChild(node)  
  50.                       
  51.                     node=Createnode.createElement('truncated')  
  52.                     node.appendChild(Createnode.createTextNode('0'))  
  53.                     object_node.appendChild(node)  
  54.                       
  55.                     node=Createnode.createElement('difficult')  
  56.                     node.appendChild(Createnode.createTextNode('0'))  
  57.                     object_node.appendChild(node)  
  58.                       
  59.                     bndbox_node=Createnode.createElement('bndbox')  
  60.                     object_node.appendChild(bndbox_node)  
  61.                       
  62.                     node=Createnode.createElement('xmin')  
  63.                     node.appendChild(Createnode.createTextNode(str(strs[2])))  
  64.                     bndbox_node.appendChild(node)  
  65.                       
  66.                     node=Createnode.createElement('ymin')  
  67.                     node.appendChild(Createnode.createTextNode(str(strs[3])))  
  68.                     bndbox_node.appendChild(node)  
  69.                       
  70.                     node=Createnode.createElement('xmax')  
  71.                     node.appendChild(Createnode.createTextNode(str(strs[4])))  
  72.                     bndbox_node.appendChild(node)  
  73.                       
  74.                     node=Createnode.createElement('ymax')  
  75.                     node.appendChild(Createnode.createTextNode(str(strs[5])))  
  76.                     bndbox_node.appendChild(node)  
  77.                 else:  
  78.                     Createnode=Document()  #創建DOM文檔對象  
  79.                       
  80.                     Root=Createnode.createElement('annotation'#創建根元素  
  81.                     Createnode.appendChild(Root)  
  82.                       
  83.                     # folder  
  84.                     folder=Createnode.createElement('folder')  
  85.                     folder.appendChild(Createnode.createTextNode(foldername))  
  86.                     Root.appendChild(folder)  
  87.                       
  88.                     # filename  
  89.                     filename = Createnode.createElement('filename')  
  90.                     filename.appendChild(Createnode.createTextNode(strs[0]))  
  91.                     Root.appendChild(filename)  
  92.                       
  93.                     # source  
  94.                     source_node = Createnode.createElement('source')  
  95.                     Root.appendChild(source_node)  
  96.                       
  97.                     node = Createnode.createElement('database')  
  98.                     node.appendChild(Createnode.createTextNode('MS COCO-Text'))  
  99.                     source_node.appendChild(node)  
  100.                       
  101.                     node = Createnode.createElement('annotation')  
  102.                     node.appendChild(Createnode.createTextNode('MS COCO-Text 2014'))  
  103.                     source_node.appendChild(node)  
  104.               
  105.                     node=Createnode.createElement('image')  
  106.                     node.appendChild(Createnode.createTextNode('NULL'))  
  107.                     source_node.appendChild(node)  
  108.               
  109.                     node=Createnode.createElement('flickrid');  
  110.                     node.appendChild(Createnode.createTextNode('NULL'));  
  111.                     source_node.appendChild(node);  
  112.                       
  113.                     # owner  
  114.                     owner_node=Createnode.createElement('owner')  
  115.                     Root.appendChild(owner_node)  
  116.                       
  117.                     node=Createnode.createElement('flickrid')  
  118.                     node.appendChild(Createnode.createTextNode('NULL'))  
  119.                     owner_node.appendChild(node)  
  120.                       
  121.                     node=Createnode.createElement('name')  
  122.                     node.appendChild(Createnode.createTextNode('ligen'))  
  123.                     owner_node.appendChild(node)  
  124.                       
  125.                     # size  
  126.                     size_node=Createnode.createElement('size')  
  127.                     Root.appendChild(size_node)  
  128.                       
  129.                     node=Createnode.createElement('width')  
  130.                     node.appendChild(Createnode.createTextNode(str(width)))  
  131.                     size_node.appendChild(node)  
  132.                       
  133.                     node=Createnode.createElement('height');  
  134.                     node.appendChild(Createnode.createTextNode(str(height)))  
  135.                     size_node.appendChild(node)  
  136.                       
  137.                     node=Createnode.createElement('depth')  
  138.                     node.appendChild(Createnode.createTextNode('3'))  
  139.                     size_node.appendChild(node)  
  140.                       
  141.                     # segmented  
  142.                     node=Createnode.createElement('segmented')  
  143.                     node.appendChild(Createnode.createTextNode('0'))  
  144.                     Root.appendChild(node)  
  145.                       
  146.                     # object  
  147.                     object_node=Createnode.createElement('object')  
  148.                     Root.appendChild(object_node)  
  149.                       
  150.                     node=Createnode.createElement('name')  
  151.                     node.appendChild(Createnode.createTextNode(strs[1]))  
  152.                     object_node.appendChild(node)  
  153.                       
  154.                     node=Createnode.createElement('pose')  
  155.                     node.appendChild(Createnode.createTextNode('Unspecified'))  
  156.                     object_node.appendChild(node)  
  157.                       
  158.                     node=Createnode.createElement('truncated')  
  159.                     node.appendChild(Createnode.createTextNode('0'))  
  160.                     object_node.appendChild(node)  
  161.                       
  162.                     node=Createnode.createElement('difficult')  
  163.                     node.appendChild(Createnode.createTextNode('0'))  
  164.                     object_node.appendChild(node)  
  165.                       
  166.                     bndbox_node=Createnode.createElement('bndbox')  
  167.                     object_node.appendChild(bndbox_node)  
  168.                       
  169.                     node=Createnode.createElement('xmin')  
  170.                     node.appendChild(Createnode.createTextNode(str(strs[2])))  
  171.                     bndbox_node.appendChild(node)  
  172.                       
  173.                     node=Createnode.createElement('ymin')  
  174.                     node.appendChild(Createnode.createTextNode(str(strs[3])))  
  175.                     bndbox_node.appendChild(node)  
  176.                       
  177.                     node=Createnode.createElement('xmax')  
  178.                     node.appendChild(Createnode.createTextNode(str(strs[4])))  
  179.                     bndbox_node.appendChild(node)  
  180.                       
  181.                     node=Createnode.createElement('ymax')  
  182.                     node.appendChild(Createnode.createTextNode(str(strs[5])))  
  183.                     bndbox_node.appendChild(node)  
  184.                       
  185.                     coco[xmlname] = Createnode  
  186.               
  187.     finally:  
  188.          file_object.close()  
  189.     print 'begin load xml...'  
  190.     for key in coco:  
  191.         print key  
  192.         f = open(xmlpath_new + key,'w')  
  193.         f.write(coco[key].toprettyxml(indent = '\t'))  
  194.         f.close()  
  195.   
  196. if __name__ == "__main__":  
  197.     main()  


最后,再運行rm_headline.sh。就得到我們所需要的數據集。

我得到的文件目錄如下:


在Annotations的目錄下,


在JPEGImages的目錄下,


在ImageSets的目錄下,


以train.txt為例,包含的內容為:

COCO_train2014_000000351622
COCO_train2014_000000058397
COCO_train2014_000000282380
COCO_train2014_000000223830
......

均為文件名


3.創建軟鏈接

軟鏈接就是:ln -s  源文件 目標文件

在代碼中給出的數據集的目錄為:train_data

因此,需要將上面得到的coco-text的目錄鏈接到train_data上。

在github的readme中,給出的軟鏈接操作為:

# link your data folder to train_data
cd $Text-Detection-with-FRCN/datasets/
ln -s train_data coco-text    # $YOUR_DATA
但是在我實際操作的時候,是需要:

ln -s coco-text train_data 的。


三.下載預訓練模型

首先,下載在imagenet上面預先訓練好的模型。

# finetune on this model, you can also use one model you train before
cd $Text-Detection-with-FRCN/py-faster-rcnn
./data/scripts/fetch_imagenet_models.sh
# download it takes long!
可能由於這個項目clone “py-faster-rcnn” 的時間比較早,這里面/data/scripts文件夾下面,fetch_imagenet_models.sh中的下載url已經不能用了。該文件夾下面的其他.sh文件中的url應該也都失效了。

新的py-faster-rcnn中已經對此做了更正。fetch_imagenet_models.sh中的url可改為:

[python] view plain copy
print ?
  1. ......  
  2. 6 FILE=imagenet_models.tgz  
  3. 7 URL=https://dl.dropbox.com/s/gstw7122padlf0l/imagenet_models.tgz?dl=0  
  4. 8 CHECKSUM=ed34ca912d6782edfb673a8c3a0bda6d  
  5. .....  

具體更改位置為第8行。

注意:下載需要翻牆。


三.開始訓練

切換目錄:

cd $Text-Detection-with-FRCN/py-faster-rcnn/

運行指令:

./experiments/scripts/faster_rcnn_end2end.sh 0 VGG16 pascal_voc

需要注意的是:在運行指令的時候,需要切換到指定的目錄。

運行的時候,可能會保錯:

1)TypeError: 'numpy.float64' object cannot be interpreted as an index


2)TypeError: slice indices must be integers or None or have an index method

這兩個問題的出現,都是由於Numpy的版本問題。在numpy 1.12.0中,不支持float index。類似於x[1.0, 3.0],會被看作無效。

解決這個問題,有如下可能的解決辦法:

1.對numpy進行降級

sudo pip install -U numpy==1.11.0

但是這種做法,可能會引入新的錯誤:

ImportError: numpy.core.multiarray failed to import 

解決這個問題是要升級numpy ,於是又升回去:pip install -U numpy 

所以,只能逐個將float類型轉換為int類型

2.目前發現的幾處需要進行修改的地方:

1.添加astype(np.int)

lib/roi_data_layer/minibatch.py line 26:將fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)

改為:fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image).astype(np.int)

同理,其他需要在末尾添加.astype(np.int) 的地方:

lib/datasets/ds_utils.py line 12 : hashes = np.round(boxes * scale).dot(v)

lib/fast_rcnn/test.py line 129 : hashes = np.round(blobs['rois'] * cfg.DEDUP_BOXES).dot(v)

lib/rpn/proposal_target_layer.py line 60 : fg_rois_per_image = np.round(cfg.TRAIN.FG_FRACTION * rois_per_image)

2.強制轉化為int類型

lib/roi_data_layer/minibatch.py line173:將cls = clss[ind] 改為:cls = int(clss[ind])

lib/rpn/proposal_target_layer.py line 124:將cls = clss[ind] 改為:cls = int(clss[ind])

四.訓練模型

當解決了上面所有的問題,我們就可以開始訓練了。

具體訓練過程:

1.創建輸入層

layer_factory.hpp:77 Creatinglayer input-data

net.cpp:106 CreatingLayer input-data

net.cpp:411 input-data-> data

net.cpp:411 input-data-> im_info

net.cpp:411 input-data-> gt_boxes

net.cpp:150 Settingup input-data

net.cpp:157 Topshape: 1 3 600 1000 (1800000)

net.cpp:157 Topshape: 1 3 (3)

net.cpp:157 Topshape: 1 4 (4)

net.cpp:165 Memoryrequired for data: 7200028

............


2.創建卷積層

layer_factory.hpp:77 Creatinglayer conv1_1

net.cpp:106 CreatingLayer conv1_1

net.cpp:454 conv1_1<- data_input-data_0_split_0

net.cpp:411 conv1_1-> conv1_1

net.cpp:150 Settingup conv1_1

net.cpp:157 Topshape: 1 64 600 1000 (38400000)

net.cpp:165 Memoryrequired for data: 175200084

............


3.創建激活層

layer_factory.hpp:77 Creatinglayer relu1_1

net.cpp:106 CreatingLayer relu1_1

net.cpp:454 relu1_1<- conv1_1

net.cpp:397 relu1_1-> conv1_1 (in-place)

net.cpp:150 Settingup relu1_1

net.cpp:157 Topshape: 1 64 600 1000 (38400000)

net.cpp:165 Memoryrequired for data: 328800084

............


判斷是否需要反向計算(back forward)

部分需要反向計算:

net.cpp:226 loss_bboxneeds backward computation.

loss_clsneeds backward computation.

bbox_predneeds backward computation.

cls_scoreneeds backward computation.

fc7_drop7_0_splitneeds backward computation.

............


部分不需要反向計算:

net.cpp:228pool2does not need backward computation.

relu2_2does not need backward computation.

conv2_2does not need backward computation.

relu2_1does not need backward computation.

conv2_1does not need backward computation.

input-datadoes not need backward computation.

............


整個網絡初始化完畢:

net.cpp:270 Thisnetwork produces output loss_bbox

Thisnetwork produces output loss_cls

Thisnetwork produces output rpn_cls_loss

Thisnetwork produces output rpn_loss_bbox

Networkinitialization done.

solver.cpp:60 Solverscaffolding done.


開始迭代,輸出結果:

solver.cpp:229 Iteration0, loss = 1.98441

solver.cpp:245

Trainnet output #0: loss_bbox = 0.00188451 (* 1 = 0.00188451 loss)

Trainnet output #1: loss_cls = 0.484446 (* 1 = 0.484446 loss)

Trainnet output #2: rpn_cls_loss = 0.766564 (* 1 = 0.766564 loss)

Trainnet output #3: rpn_loss_bbox = 0.484638 (* 1 = 0.484638 loss)

sgd_solver.cpp:106Iteration0, lr = 0.001


solver.cpp:229 Iteration20, loss = 1.58353

solver.cpp:245

Trainnet output #0: loss_bbox = 0.00184912 (* 1 = 0.00184912 loss)

Trainnet output #1: loss_cls = 0.213403 (* 1 = 0.213403 loss)

Trainnet output #2: rpn_cls_loss = 0.444577 (* 1 = 0.444577 loss)

Trainnet output #3: rpn_loss_bbox = 0.818097 (* 1 = 0.818097 loss)

sgd_solver.cpp:106:Iteration20, lr = 0.001


.......


solver.cpp:229 Iteration69980, loss =0.374131

solver.cpp:245

Trainnet output #0: loss_bbox =0.00462239 (* 1 =0.00462239 loss)

Trainnet output #1: loss_cls =0.00527413 (* 1 =0.00527413 loss)

Trainnet output #2: rpn_cls_loss =0.0607663 (* 1 =0.0607663 loss)

Trainnet output #3: rpn_loss_bbox =0.139714 (* 1 =0.139714 loss)

sgd_solver.cpp:106:Iteration69980, lr = 0.001



real 681m44.284s
user 565m0.152s
sys 115m29.578s


生成的模型

保存在:

/Text-Detection-with-FRCN/py-faster-rcnn/output/faster_rcnn_end2end/voc_2007_trainval文件夾中。

vgg16_faster_rcnn_iter_*.caffemodel中,其中*為迭代次數

每迭代10000次,生成一個模型。迭代了70000次,共生成了7個模型。


五.測試模型

實際上,在./experiments/scripts/faster_rcnn_end2end.sh 中,訓練完畢后會對模型進行測試。

那么,怎樣單獨執行測試呢?

切換目錄:

cd $Text-Detection-with-FRCN/py-faster-rcnn/

運行指令:

tools/test_net.py --gpu 0

 --def models/coco_text/VGG16/faster_rcnn_end2end/test.prototxt \

--netoutput/faster_rcnn_end2end/voc_2007_trainval/vgg16_faster_rcnn_iter_70000.caffemodel\

--imdb voc_2007_test\

--cfg experiments/cfgs/faster_rcnn_end2end.yml \


1.運行可能出現的錯誤:

File "/Text-Detection-with-FRCN/py-faster-rcnn/tools/../lib/datasets/voc_eval.py", line 23, in parse_rec
    obj_struct['bbox'] = [int(bbox.find('xmin').text),
ValueError: invalid literal for int() with base 10: '391.0'

解決方案:改為:

obj_struct['bbox'] = [int(float(bbox.find('xmin').text)),
                              int(float(bbox.find('ymin').text)),
                              int(float(bbox.find('xmax').text)),
                              int(float(bbox.find('ymax').text))]


2.測試運行結果:

對於vgg16_faster_rcnn_iter_70000.caffemodel:

AP for text = 0.3422
Mean AP = 0.3422
~~~~~~~~
Results:
0.342
0.342
~~~~~~~~


對於github中已經訓練好的vgg16_faster_rcnn_fine_tune_on_coco.caffemodel

AP for text = 0.1013
Mean AP = 0.1013
~~~~~~~~
Results:
0.101
0.101
~~~~~~~~

3.運行demo

在/Text-Detection-with-FRCN/script目錄下,有text_detect_demo.sh文件:

./py-faster-rcnn/tools/text_detect_demo.py \
--gpu 0 \
--net models/deploy.prototxt \
--model models/vgg16_faster_rcnn_fine_tune_on_coco.caffemodel \
--dataset datasets/test


通過修改其中的model,來指定模型。

運行demo得到的結果:

左邊:vgg16_faster_rcnn_iter_70000.caffemodel的測試結果,右邊:github中已經訓練好的vgg16_faster_rcnn_fine_tune_on_coco.caffemodel的測試結果。






免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM