1、下載下傳代碼:https://github.com/eragonruan/text-detection-ctpn
2、在utils/bbox檔案夾,python setup.py instll, 生成build檔案夾,将.pyd檔案複制到utils/bbox
3、運作demo,從https://pan.baidu.com/s/1BNHt_9fiqRPGmEXPaxaFXw 下載下傳checkpoints_mlt,并複制到項目的main目錄;
運作報錯:ValueError: Buffer dtype mismatch, expected 'int_t' but got 'long long':
解決:https://www.jianshu.com/p/027e9399e699?tdsourcetag=s_pctim_aiomsg(舊版tf是cython_nms.pyx,新版是nms.pyx)
step 1:make some change
change "np.int_t " to "np.intp_t" in line 25 of the file lib\utils\cython_nms.pyx
otherwise appear " ValueError: Buffer dtype mismatch, expected 'int_t' but got 'long long' " in step 6.
## cython_nms.py/nms.py
step 2:updata c file
execute:cd your_dir\text-detection-ctpn-master\lib\utils
execute:cython bbox.pyx
execute:cython cython_nms.pyx
step 3:builf setup file as setup_new.py
import numpy as np
from distutils.core import setup
from Cython.Build import cythonize
from distutils.extension import Extension
numpy_include = np.get_include()
setup(ext_modules=cythonize("bbox.pyx"),include_dirs=[numpy_include])
setup(ext_modules=cythonize("cython_nms.pyx"),include_dirs=[numpy_include])
step 4:build .pyd file
execute:python setup_new.py install
copy bbox.cp36-win_amd64.pyd and cython_nms.cp36-win_amd64.pyd to your_dir\text-detection-ctpn-master\lib\utils
step 5:make some change
(1) Set "USE_GPU_NMS " in the file \ctpn\text.yml as "False"
(2) Set the "_*C.USE_GPU_NMS" in the file \lib\fast_rcnn\config.py as "False";
(3) Comment out the line "from lib.utils.gpu_nms import gpu_nms" in the file \lib\fast_rcnn\nms_wrapper.py;
(4) Comment out the line "from . import gpu_nms" in the file \lib\utils_*init**.py;
(5) change "base_name = image_name.split('/')[-1]" to "base_name = image_name.split('\')[-1]" in line 24 of the file ctpn\demo.py
step 6:run demo
execute:cd your_dir\text-detection-ctpn-master
execute:python ./ctpn/demo.py
3、下載下傳預訓練模型
https://github.com/tensorflow/models/tree/1af55e018eebce03fb61bba9959a04672536107d/research/slim
放在在main/data/imagenet_weights(路徑根據檔案來,注意命名)
4、下載下傳資料集(自己的資料集)https://pan.baidu.com/s/1nbbCZwlHdgAI20_P9uw9LQ,
另外,您可以根據以下步驟準備自己的數 據集。 根據您的資料集,在utils / prepare / split_label.py中修改DATA_FOLDER和OUTPUT。 然後在根目錄下運作split_label.py
python ./utils/prepare/split_label.py
它将在data / dataset /中生成準備好的資料;
split_label.py的輸入檔案格式示範可在gt_img_859.txt中找到。 并且split_label.py的輸出檔案是img_859.txt。 準備的資料的示範圖像如下所示。
5、train.py
absl.flags._exceptions.IllegalFlagValueError: flag --decay_rate=0.1: Expect argument to be a string or int, found <class 'float'>
解決:将運作的該檔案内的 ,指定參數中的flags.DEFINE_integer 改為flags.DEFINE_float(http://www.matools.com/blog/190357814)
又遇到程序啟動問題:AttributeError: Can't pickle local object 'GeneratorEnqueuer.start.<locals>.data_generator_task'
解決:将data_provider.py中第81行的use_multiprocessing改為False,又遇到ValueError: generator already executing
真的是難啊。。。下面解決示意圖
終于可以運作了,風扇開始轟鳴...