Walleclipse/ChineseAddress_OCR

对不起我问你一个问题。

eye289475 opened this issue · 9 comments

可以针对任何地址获悉吗?
你是怎么做到的?
例如,从其他国家学习并推断地址。
很抱歉,如果联系地点错误。

你好,
这个项目可以针对任何**国内的地址。
因为我们的训练数据就包含了**国内的地址数据。
如果添加其他国家的数据到训练集中,应该也可以,但是我们暂时没有那么做。
具体的项目介绍可以查看 ChineseAddress_OCR_Report.pdf

多谢您的回覆
如果您可以为每个日本汉字准备图像,还需要什么其他数据? 您能告诉我文件夹结构和学习命令吗?

  1. 数据准备: 需要准备日本汉字图像,文字位置的 bounding box(用于文本检测),text label(用于文本识别)。
  2. 训练OCR:首先训练 CTPN用于文本检测, 再训练densenet用于文字识别.
  3. 进行地址的判断与修正:查看 demo_final.py

谢谢啦

该github文件夹中有3400张图像,并且相应字符边界的坐标也位于txt文件中。

这些图像有很多英文和数字。

但是,我认为您现在正在使用此边界框中的训练数据来标识中文地址。

换句话说,如果您可以准备每个汉字的每个图像,
我认为仅使用汉字图像即可获得与中文地址相同的结果。

我错了吗

为了学习,将汉字名称设为文件夹名称,将其分为多个文件夹并准备。
谢谢啦

首先,我想使用现有的训练数据。

cd drive/ChineseAddress_OCR-master/ctpn/lib/utils/
chmod +x make.sh
./make.sh

cd /content/drive/ChineseAddress_OCR-master/
python demo_final.py

但是,出现以下错误:

Loading network VGGnet_test... 
WARNING:tensorflow:From /content/drive/ChineseAddress_OCR-master/ctpn/text_detect.py:35: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.

Restoring from /data/share/chinese_ocr/ctpn/checkpoints/VGGnet_fast_rcnn_iter_86000.ckpt...
Traceback (most recent call last):
  File "/content/drive/ChineseAddress_OCR-master/ctpn/text_detect.py", line 39, in load_tf_model
    saver.restore(sess, ckpt.model_checkpoint_path)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/training/saver.py", line 1280, in restore
    if not checkpoint_management.checkpoint_exists_internal(checkpoint_prefix):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/training/checkpoint_management.py", line 366, in checkpoint_exists_internal
    if file_io.get_matching_files(pathname):
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/lib/io/file_io.py", line 363, in get_matching_files
    return get_matching_files_v2(filename)
  File "/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/lib/io/file_io.py", line 384, in get_matching_files_v2
    compat.as_bytes(pattern))
tensorflow.python.framework.errors_impl.NotFoundError: /data/share/chinese_ocr/ctpn/checkpoints; No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "demo_final.py", line 3, in <module>
    import ocr_whole
  File "/content/drive/ChineseAddress_OCR-master/ocr_whole.py", line 12, in <module>
    from ctpn.text_detect import text_detect
  File "/content/drive/ChineseAddress_OCR-master/ctpn/text_detect.py", line 46, in <module>
    sess, net = load_tf_model()
  File "/content/drive/ChineseAddress_OCR-master/ctpn/text_detect.py", line 42, in load_tf_model
    raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path)
TypeError: exceptions must derive from BaseException

检查点路径是否错误?

这是与以下准备工作相同的错误。
text_detect.py


Loading network VGGnet_test... 
WARNING:tensorflow:From text_detect.py:35: The name tf.train.Saver is deprecated. Please use tf.compat.v1.train.Saver instead.

Traceback (most recent call last):
  File "text_detect.py", line 38, in load_tf_model
    print('Restoring from {}...'.format(ckpt.model_checkpoint_path))
AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "text_detect.py", line 46, in <module>
    sess, net = load_tf_model()
  File "text_detect.py", line 42, in load_tf_model
    raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path)
AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path'

我查了一下
checkpoints


    ckpt = tf.train.(cfget_checkpoint_stateg.TEST.checkpoints_path)
                    ^
SyntaxError: invalid syntax

这里描述的语法有问题吗?

与中文

  1. 我现在的项目只能识别中文和数字,没有英文。我用的数据不是 ctpn/lib/utils/里面的数据。我是单独收集了地址数据,这个数据不方便公开,所以我没放在github上。
  2. CTPN不需要为每个汉字准备各自单独的图片。就像身份证上的地址一样,我们准备一个带地址的图片,随后我们只需要在text label里写下总的地址就好。不需要单独给每个汉字准备图片。
  1. 你可以检查一下路径 ctpn/checkpoints/。该repo的checkpoint就是放在了 ctpn/checkpoints/下。

  2. 语法错了,应该是
    ckpt = tf.train.get_checkpoint_state(cfg.TEST.checkpoints_path)

  3. 有关CTPN,你可以查看官方代码 这里这里

Traceback (most recent call last):
  File "text_detect.py", line 46, in <module>
    sess, net = load_tf_model()
  File "text_detect.py", line 42, in load_tf_model
    raise 'Check your pretrained {:s}'.format(ckpt.model_checkpoint_path)
AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path'

仍然出现相同的错误。

我的源代码如下。

Google Colab(GPU)
Google Drive

# mount
!export CUDA_HOME=/usr/local/cuda-10.0
!export LD_LIBRARY_PATH=${CUDA_HOME}/lib64
!PATH=${CUDA_HOME}/bin:${PATH}
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse

from google.colab import auth
auth.authenticate_user()
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
!mkdir -p drive
!google-drive-ocamlfuse drive
!ls drive

# execute
cd drive/ChineseAddress_OCR-master/ctpn/lib/utils/
!chmod +x make.sh
!./make.sh

cd /content/drive/ChineseAddress_OCR-master/densenet/
!python densenet.py

cd /content/drive/ChineseAddress_OCR-master/ctpn
!python text_detect.py

你好,
我也不太懂,可能是 Google Colab 的问题。你需要把 pretrained model 上传到 Colab上。
然后可能需要 修改 cfg.TEST.checkpoints_path
你可以 print(cfg.TEST.checkpoints_pat) 看一下,然后用 cd 进入查看一下是否路径正确。