天天看点

Win10+CTPN训练过程(填坑)

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

真的是难啊。。。下面解决示意图

Win10+CTPN训练过程(填坑)

终于可以运行了,风扇开始轰鸣...

Win10+CTPN训练过程(填坑)

继续阅读