xiaofengShi / CHINESE-OCR

[python3.6] 运用tf实现自然场景文字检测,keras/pytorch实现ctpn+crnn+ctc实现不定长场景文字OCR识别
2.9k stars 958 forks source link

你好,请问你跑通了吗 #1

Open qingfenghcy opened 6 years ago

xiaofengShi commented 6 years ago

是的

qingfenghcy commented 6 years ago

CHINESE-OCR/ctpn/目录下是不是少了个lib文件夹,这边导入模型失败。

ModuleNotFoundError Traceback (most recent call last)

in () ----> 1 import model ~/code/hcy/chinese_ocr/chinese-ocr-test/chinese-ocr-xaiofengshi/model.py in () 13 from crnn.crnn import crnnOcr 14 ---> 15 from ctpn.text_detect import text_detect 16 from ocr.model import predict as ocr 17 ~/code/hcy/chinese_ocr/chinese-ocr-test/chinese-ocr-xaiofengshi/ctpn/text_detect.py in () 1 import numpy as np 2 # import tensorflow as tf ----> 3 from .ctpn.detectors import TextDetector 4 from .ctpn.model import ctpn 5 from .ctpn.other import draw_boxes ~/code/hcy/chinese_ocr/chinese-ocr-test/chinese-ocr-xaiofengshi/ctpn/ctpn/detectors.py in () 8 9 sys.path.append('..') ---> 10 from ..lib.fast_rcnn.nms_wrapper import nms 11 # from lib.fast_rcnn.test import test_ctpn 12 ModuleNotFoundError: No module named 'ctpn.lib'
xiaofengShi commented 6 years ago

@qingfenghcy 对比了一下本地和远程仓库,发现远程的确是少一个lib文件夹,经过查看gitignore文件,发现lib文件被禁了,应该是lib文件夹的命名会跟系统的默认文件发生冲突,以后再进行文件夹命名时要注意这一点了,实在是抱歉,这次应该代码是没有问题的,我这边本地都是可以跑通的

qingfenghcy commented 6 years ago

@xiaofengShi 谢谢指教,麻烦了

qingfenghcy commented 6 years ago

@xiaofengShi ctpn和crnn模型参数可以分享下吗,谢谢~

xiaofengShi commented 6 years ago

模型参数在readme里面已经把连接挂上去了呢

On May 18, 2018, at 10:09, Chunyu Hao notifications@github.com wrote:

@xiaofengShi https://github.com/xiaofengShi ctpn和crnn模型参数可以分享下吗,谢谢~

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xiaofengShi/CHINESE-OCR/issues/1#issuecomment-390072905, or mute the thread https://github.com/notifications/unsubscribe-auth/Ac_1AcyAV-9GEqHv6t-bQyyOzHdhu4wTks5tzi1rgaJpZM4TXkd2.

qingfenghcy commented 6 years ago

@xiaofengShi 只看到了vgg的还有crnn的keras和pytorch预训练参数。。。不好意思。。。 ~/code/hcy/chinese_ocr/chinese-ocr-test/chinese-ocr-xiaofengshi/ctpn/ctpn/model.py in load_tf_model() 34 ckpt = tf.train.get_checkpoint_state( 35 '/Users/xiaofeng/Code/Github/dataset/CHINESE_OCR/ctpn/checkpoints/') ---> 36 reader = tf.train.NewCheckpointReader(ckpt.model_checkpoint_path) 37 var_to_shape_map = reader.get_variable_to_shape_map() 38 for key in var_to_shape_map: AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path'

xiaofengShi commented 6 years ago

对于ctpn,实际上就是进行场景内文字区域的确定,这个模型使用的是vgg的网络进行图像特征提取,之后是rpn和rnn,实现思路实际上跟传统的faster-rcnn类似,只是加入了rnn层,readme中的vgg的权重就是ctpn的网络权重(权重文件https://pan.baidu.com/s/1JO_ZojA5bkmJZsnxsShgkg https://pan.baidu.com/s/1JO_ZojA5bkmJZsnxsShgkg);对于crnn,是整个网络结构中连接在ctpn之后的,目前提供keras版本(https://pan.baidu.com/s/1vTG6-i_bFMWxQ_7xF06usg https://pan.baidu.com/s/1vTG6-i_bFMWxQ_7xF06usg)和pytorch版本(https://pan.baidu.com/s/1LEDNHEr3luloB7eZK6GOeA https://pan.baidu.com/s/1LEDNHEr3luloB7eZK6GOeA);此外,还有一个进行图像文字旋转方向的检测网络,使用的就是一个简单的 分类网络(权重文件连接https://pan.baidu.com/s/1zquQNdO0MUsLMsuwxbgPYg https://pan.baidu.com/s/1zquQNdO0MUsLMsuwxbgPYg)设置的位置在angel/predict.py 中的load函数中的model.loadweight(‘权重文件位置')。以上,这三个网络的所有权重均在readme中进行了提供。

On May 18, 2018, at 11:11, Chunyu Hao notifications@github.com wrote:

@xiaofengShi https://github.com/xiaofengShi 只看到了vgg的还有crnn的keras和pytorch预训练参数。。。不好意思。。。 ~/code/hcy/chinese_ocr/chinese-ocr-test/chinese-ocr-xiaofengshi/ctpn/ctpn/model.py in load_tf_model() 34 ckpt = tf.train.get_checkpoint_state( 35 '/Users/xiaofeng/Code/Github/dataset/CHINESE_OCR/ctpn/checkpoints/') ---> 36 reader = tf.train.NewCheckpointReader(ckpt.model_checkpoint_path) 37 var_to_shape_map = reader.get_variable_to_shape_map() 38 for key in var_to_shape_map: AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path'

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/xiaofengShi/CHINESE-OCR/issues/1#issuecomment-390081489, or mute the thread https://github.com/notifications/unsubscribe-auth/Ac_1ATYIaq1cVpvL4akwNVPmElmVvbn7ks5tzjvUgaJpZM4TXkd2.

qingfenghcy commented 6 years ago

@xiaofengShi 谢谢耐心指导。。。

qingfenghcy commented 6 years ago

@xiaofengShi ctpn/ctpn/model.py中代码 ckpt=tf.train.get_checkpoint_state('/Users/xiaofeng/Code/Github/dataset/CHINESE_OCR/ctpn/checkpoints/') reader = tf.train.NewCheckpointReader(ckpt.model_checkpoint_path) 这个checkpoints文件夹一直没有找到。

xiaofengShi commented 6 years ago

https://pan.baidu.com/s/19nx07mHVhye95YWPt-zjgA https://pan.baidu.com/s/19nx07mHVhye95YWPt-zjgA 关于ocr的所有权重都在这里啦,你找一下吧,前两天开会的时候整理的readme,有可能ckp遗漏掉了,抱歉

On May 18, 2018, at 15:55, Chunyu Hao notifications@github.com wrote:

tf.train.NewCheckpointReader

qingfenghcy commented 6 years ago

@xiaofengShi 谢谢啦,耽误你这么长时间

xxllp commented 6 years ago

@qingfenghcy ,我在windows 下一直跑不通,你是否可以哈

xxllp commented 6 years ago

@xiaofengShi ,我怎么用你的文件一直由报缺失一些算子,你训练用的是啥版本的tf

xiaofengShi commented 6 years ago

@xxllp 使用环境:python3.6+tensorflow1.7+cpu 这个仓库是初始版的,都能跑通的,只不过在crnn的pytorch我目前是mac没有安装warpctc所以现在没有跑,至于在此基础上进一步增强的版本,受限于实验室规定,目前无法上传

xxllp commented 6 years ago

Tensor("Placeholder_38:0", shape=(?, ?, ?, 3), dtype=float32) Tensor("conv5_3/conv5_3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_conv/3x3/rpn_conv/3x3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_cls_score/Reshape_1:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_cls_prob:0", shape=(?, ?, ?, ?), dtype=float32) Tensor("Reshape_2:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_bbox_pred/Reshape_1:0", shape=(?, ?, ?, 40), dtype=float32) Tensor("Placeholder_39:0", shape=(?, 3), dtype=float32) Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/kernel Tensor_name is : conv1_1/biases Tensor_name is : conv3_1/biases Tensor_name is : conv1_1/weights Tensor_name is : conv1_2/biases Tensor_name is : conv1_2/weights Tensor_name is : conv2_1/weights Tensor_name is : conv4_3/weights Tensor_name is : conv2_1/biases Tensor_name is : conv2_2/biases Tensor_name is : conv2_2/weights Tensor_name is : conv3_1/weights Tensor_name is : conv3_2/biases Tensor_name is : conv3_2/weights Tensor_name is : conv3_3/biases Tensor_name is : conv3_3/weights Tensor_name is : conv4_1/biases Tensor_name is : rpn_conv/3x3/biases Tensor_name is : conv4_1/weights Tensor_name is : conv4_2/biases Tensor_name is : conv4_2/weights Tensor_name is : conv4_3/biases Tensor_name is : conv5_1/biases Tensor_name is : conv5_1/weights Tensor_name is : conv5_2/biases Tensor_name is : conv5_2/weights Tensor_name is : conv5_3/biases Tensor_name is : conv5_3/weights Tensor_name is : lstm_o/biases Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/bias Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/bias Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/kernel Tensor_name is : lstm_o/weights Tensor_name is : rpn_bbox_pred/weights Tensor_name is : rpn_bbox_pred/biases Tensor_name is : rpn_cls_score/biases Tensor_name is : rpn_cls_score/weights Tensor_name is : rpn_conv/3x3/weights E://BaiduNetdiskDownload/OCR checkpoints\VGGnet_fast_rcnn_iter_50000.ckpt 2018-06-05 14:47:44.523806: W T:\src\github\tensorflow\tensorflow\core\framework\op_kernel.cc:1273] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Not found: Key SGD/decay not found in checkpoint Traceback (most recent call last): File "C:\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1327, in _do_call return fn(*args) File "C:\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1312, in _run_fn options, feed_dict, fetch_list, target_list, run_metadata) File "C:\Anaconda3\lib\site-packages\tensorflow\python\client\session.py", line 1420, in _call_tf_sessionrun status, run_metadata) File "C:\Anaconda3\lib\site-packages\tensorflow\python\framework\errors_impl.py", line 516, in exit c_api.TF_GetCode(self.status.status)) tensorflow.python.framework.errors_impl.NotFoundError: Key SGD/decay not found in checkpoint [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT, DT_INT64, DT_FLOAT, DT_FLOAT, DT_FLOAT, ..., DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]

xxllp commented 6 years ago

我分布测试了crnn 和 ctpn 的功能,基本都是可以的,但是我直接跑demo ,却会报错

xxllp commented 6 years ago

ctpn 里面的demo 为啥 图片识别出的box 为空

xiaofengShi commented 6 years ago

@xxllp Using TensorFlow backend. Tensor("Placeholder:0", shape=(?, ?, ?, 3), dtype=float32) Tensor("conv5_3/conv5_3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_conv/3x3/rpn_conv/3x3:0", shape=(?, ?, ?, 512), dtype=float32) WARNING:tensorflow:From /anaconda3/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/datasets/base.py:198: retry (from tensorflow.contrib.learn.python.learn.datasets.base) is deprecated and will be removed in a future version. Instructions for updating: Use the retry module or similar alternatives. Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_cls_score/Reshape_1:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_cls_prob:0", shape=(?, ?, ?, ?), dtype=float32) Tensor("Reshape_2:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_bbox_pred/Reshape_1:0", shape=(?, ?, ?, 40), dtype=float32) Tensor("Placeholder_1:0", shape=(?, 3), dtype=float32) 2018-06-05 15:09:29.871016: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA ckpt model_checkpoint_path: "/Users/xiaofeng/Code/Github/dataset/CHINESE_OCR/ctpn/ctpn_checkpoints/VGGnet_fast_rcnn_iter_50000.ckpt" all_model_checkpoint_paths: "/Users/xiaofeng/Code/Github/dataset/CHINESE_OCR/ctpn/ctpn_checkpoints/VGGnet_fast_rcnn_iter_50000.ckpt"

Tensor_name is : rpn_cls_score/weights Tensor_name is : rpn_cls_score/biases Tensor_name is : rpn_bbox_pred/weights Tensor_name is : lstm_o/weights Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/kernel Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/bias Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/kernel Tensor_name is : rpn_conv/3x3/weights Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/bias Tensor_name is : lstm_o/biases Tensor_name is : conv5_3/biases Tensor_name is : conv5_3/weights Tensor_name is : conv5_2/weights Tensor_name is : conv5_2/biases Tensor_name is : conv5_1/biases Tensor_name is : conv2_2/weights Tensor_name is : conv1_2/biases Tensor_name is : conv4_3/weights Tensor_name is : conv4_2/biases Tensor_name is : conv4_1/weights Tensor_name is : conv4_1/biases Tensor_name is : conv3_3/weights Tensor_name is : rpn_bbox_pred/biases Tensor_name is : conv1_1/weights Tensor_name is : conv3_2/weights Tensor_name is : conv3_3/biases Tensor_name is : conv1_2/weights Tensor_name is : conv3_1/weights Tensor_name is : conv3_1/biases Tensor_name is : conv2_2/biases Tensor_name is : conv5_1/weights Tensor_name is : conv4_3/biases Tensor_name is : conv4_2/weights Tensor_name is : conv1_1/biases Tensor_name is : conv3_2/biases Tensor_name is : rpn_conv/3x3/biases Tensor_name is : conv2_1/biases Tensor_name is : conv2_1/weights load vggnet done The angel of this character is: 0 Rotate the array of this img! It takes time:20.755679845809937s

产品名称:个体营养分析仪型号:Ni+-mlcs 输入功率:957 输入电源: 220Y频率:50Hz 安全类别:I类BF型 产品注册编号:晋械注准20152210006 出厂编号:NA021602001B 生产日期:2016年02月25日 生产地址:山西省太原市小店区刘家餐乡西里解村北 住所:太原高新区产业路48号新总科技局C座208室 联系方式:0351-7037508 住所/生产地址:北京市大兴医中关村科技邑医大兴生制 生产许可证编号:京食药监械生产许可20140021号 企 贷毡丙零详迅说明书 :

刚运行了一下,是ok的

xxllp commented 6 years ago

那很奇怪哈,我试了好几个版本的tf 都是不行。看来真不行只能自己训练了

xiaofengShi commented 6 years ago

@xxllp 你的错误是‘Key SGD/decay not found in checkpoin’,我也不知道为何,你可以在加尝试载权重的时候,将这一项忽略掉

xxllp commented 6 years ago

怎么忽略呢。。

xxllp commented 6 years ago

终于搞好了,但是在测试一些图片后发现文字识别错误还是有点啊。

xiaofengShi commented 6 years ago

@xxllp 主要是跑了没多久,而且crnn训练集较小,这个模型主要为一个不定长场景文字识别提供一个框架,把这个路走通了,肯定还有很多要优化的地方,比如数据集,网络结构,加载tf,keras,pytorch的预训练权重,进行迁移学习,将RNN加深加宽,或者加入词向量对文字识别的处理等等,想要做相关方面的研究或工作,就要你对这个模型自己不断修改啦

xxllp commented 6 years ago

@xiaofengShi 嗯,这块太小白了,能加个联系方式嘛

xuewengeophysics commented 6 years ago

@xiaofengShi 大神,您好!我在跑demo的是否遇到了下面的错误,能否麻烦您知道一下呢?谢谢您! Using TensorFlow backend. Tensor("Placeholder:0", shape=(?, ?, ?, 3), dtype=float32) Tensor("conv5_3/conv5_3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_conv/3x3/rpn_conv/3x3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_cls_score/Reshape_1:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_cls_prob:0", shape=(?, ?, ?, ?), dtype=float32) Tensor("Reshape_2:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_bbox_pred/Reshape_1:0", shape=(?, ?, ?, 40), dtype=float32) Tensor("Placeholder_1:0", shape=(?, 3), dtype=float32) 2018-06-16 10:03:22.612203: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2018-06-16 10:03:22.729420: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2018-06-16 10:03:22.729817: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties: name: GeForce GTX 1070 major: 6 minor: 1 memoryClockRate(GHz): 1.645 pciBusID: 0000:01:00.0 totalMemory: 7.92GiB freeMemory: 7.51GiB 2018-06-16 10:03:22.729831: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0 2018-06-16 10:03:22.919152: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-06-16 10:03:22.919186: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 2018-06-16 10:03:22.919192: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N 2018-06-16 10:03:22.919376: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7256 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1) Tensor_name is : rpn_conv/3x3/biases Tensor_name is : rpn_cls_score/weights Tensor_name is : rpn_bbox_pred/biases Tensor_name is : lstm_o/weights Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/bias Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/kernel Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/bias Tensor_name is : conv5_3/weights Tensor_name is : conv5_3/biases Tensor_name is : lstm_o/biases Tensor_name is : conv5_2/weights Tensor_name is : conv2_2/weights Tensor_name is : conv1_1/weights Tensor_name is : conv4_2/weights Tensor_name is : conv2_2/biases Tensor_name is : conv2_1/biases Tensor_name is : conv1_2/weights Tensor_name is : conv4_1/biases Tensor_name is : conv2_1/weights Tensor_name is : rpn_cls_score/biases Tensor_name is : conv1_2/biases Tensor_name is : rpn_conv/3x3/weights Tensor_name is : conv3_1/weights Tensor_name is : conv4_3/weights Tensor_name is : conv3_2/biases Tensor_name is : rpn_bbox_pred/weights Tensor_name is : conv3_2/weights Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/kernel Tensor_name is : conv3_3/biases Tensor_name is : conv5_2/biases Tensor_name is : conv5_1/weights Tensor_name is : conv3_3/weights Tensor_name is : conv4_1/weights Tensor_name is : conv1_1/biases Tensor_name is : conv4_2/biases Tensor_name is : conv3_1/biases Tensor_name is : conv4_3/biases Tensor_name is : conv5_1/biases load vggnet done 2018-06-16 10:03:23.100380: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0 2018-06-16 10:03:23.100431: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-06-16 10:03:23.100440: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 2018-06-16 10:03:23.100446: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N 2018-06-16 10:03:23.100581: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7256 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1) Traceback (most recent call last): File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1567, in _create_c_op c_op = c_api.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 1 but is rank 4 for 'batch_normalization_1/cond/FusedBatchNorm' (op: 'FusedBatchNorm') with input shapes: [?,4,?,512], [1,4,1,1], [1,4,1,1], [1,4,1,1], [1,4,1,1].

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "demo.py", line 8, in import model File "/media/wenxue/DATA/AIGithubProject/ChineseRecog/CHINESE-OCR-Shixiaofeng/model.py", line 16, in from ocr.model import predict as ocr File "/media/wenxue/DATA/AIGithubProject/ChineseRecog/CHINESE-OCR-Shixiaofeng/ocr/model.py", line 79, in model, basemodel = get_model(height, nclass) File "/media/wenxue/DATA/AIGithubProject/ChineseRecog/CHINESE-OCR-Shixiaofeng/ocr/model.py", line 42, in get_model m = BatchNormalization(axis=1)(m) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/engine/base_layer.py", line 460, in call output = self.call(inputs, *kwargs) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/layers/normalization.py", line 204, in call training=training) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3069, in in_train_phase x = switch(training, x, alt) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3004, in switch else_expression_fn) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 432, in new_func return func(args, **kwargs) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2072, in cond orig_res_f, res_f = context_f.BuildCondBranch(false_fn) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1913, in BuildCondBranch original_result = fn() File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/layers/normalization.py", line 165, in normalize_inference epsilon=self.epsilon) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 1894, in batch_normalization is_training=False File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/ops/nn_impl.py", line 904, in fused_batch_norm name=name) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 3429, in _fused_batch_norm is_training=is_training, name=name) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op op_def=op_def) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1734, in init control_input_ops) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1570, in _create_c_op raise ValueError(str(e)) ValueError: Shape must be rank 1 but is rank 4 for 'batch_normalization_1/cond/FusedBatchNorm' (op: 'FusedBatchNorm') with input shapes: [?,4,?,512], [1,4,1,1], [1,4,1,1], [1,4,1,1], [1,4,1,1].

snowwindy commented 6 years ago

Hello, when I run this code, I always remind me "No module named 'utils'", and I can't find the reason. Import util Import dataset Import models.crnn as crnn Import keys_crnn These few words suggest that the util,dataset,models.crnn and key_crnn modules could not be found. How should I solve this?

qingfenghcy commented 6 years ago

具体错误日志粘一下吧,你ctpn/utils有这个文件夹吗 @snowwindy

snowwindy commented 6 years ago

qq 20180718152210 qq 20180718152247 qq 20180718152058

@qingfenghcy 错误就是这样子,明明那几个文件都有,但就是import不进来,您有遇到这个问题吗?怎么解决的?

doufu89 commented 6 years ago

@xxllp 请教一下你这个问题怎么解决的呢“Key SGD/decay not found in checkpoin”

xxllp commented 6 years ago

忘了,过了好久了感觉,应该是版本哪里的问题

Cony07f5 commented 6 years ago

@qingfenghcy 还在吗?你遇到的AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path'这个问题解决了吗?能加微信讨论一下吗?

xiaoxiao-chen commented 6 years ago

遇到了同样的问题:AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path',请问怎么解决的呢?

xiaofengShi commented 6 years ago

@Cony07f5 @xiaoxiao-chen 请问遇到了什么问题,这个项目已经多日没看了,当初完全跑通了才挂上来的呢

xiaoxiao-chen commented 6 years ago

(1)运行demo.py时,报错: Using TensorFlow backend. Tensor("Placeholder:0", shape=(?, ?, ?, 3), dtype=float32) Tensor("conv5_3/conv5_3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_conv/3x3/rpn_conv/3x3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_cls_score/Reshape_1:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_cls_prob:0", shape=(?, ?, ?, ?), dtype=float32) Tensor("Reshape_2:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_bbox_pred/Reshape_1:0", shape=(?, ?, ?, 40), dtype=float32) Tensor("Placeholder_1:0", shape=(?, 3), dtype=float32) 2018-07-25 14:20:30.617083: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA Traceback (most recent call last): File "demo.py", line 8, in import model File "/root/CHINESE-OCR/model.py", line 15, in from ctpn.text_detect import text_detect File "/root/CHINESE-OCR/ctpn/text_detect.py", line 4, in from .ctpn.model import ctpn File "/root/CHINESE-OCR/ctpn/ctpn/model.py", line 47, in sess, saver, net = load_tf_model() File "/root/CHINESE-OCR/ctpn/ctpn/model.py", line 36, in load_tf_model reader = tf.train.NewCheckpointReader(ckpt.model_checkpoint_path) AttributeError: 'NoneType' object has no attribute 'model_checkpoint_path' (2)从错误来看,请问只运行demo.py时,需要下载checkpoints文件吗?我安装了各种python所需的包之后,直接定位到CHINESE-OCR ,运行python demo.py是不对吗?需要别的操作吗?谢谢

xiaofengShi commented 6 years ago

@xiaoxiao-chen 从报错问题来看,ckpt这个参数现在为None,也就是说没有加载预训练的权重或者权重的路径给的错误,你需要从readme的连接中找到权重并将ckpt指向该路径

xiaoxiao-chen commented 6 years ago

就是说需要下载checkpoints这个文件夹,然后将ckpt指向该路径吗?

Cony07f5 commented 6 years ago

@xiaofengShi 问题已经解决了,不过我还有一些问题需要请教你,方便加个微信或者QQ吗? 我留下联系方式:微信:pop0fa, QQ506049021.

gydlcc commented 6 years ago

2018-08-11 16-20-01 请问大家这个怎么解决的?!

07freedom commented 6 years ago

@gydlcc 你没有下载crnn预训练模型或者你的模型加载路径不对

gydlcc commented 6 years ago

@07freedom 哦哦 是这样啊,我把路径改改看 谢谢你

ZJU-PLP commented 6 years ago

@xiaofengShi 您好,想问一下直接跑demo.py这个文件应该不需要自己训练吧,但是为什么会出现这个错误啊? screenshot from 2018-09-06 20-09-58 screenshot from 2018-09-06 20-10-15

ghost commented 6 years ago

@xiaofengShi ,你好,我目前正在运行你的代码,但是出了错,想请你帮我看看 Using TensorFlow backend. Tensor("Placeholder:0", shape=(?, ?, ?, 3), dtype=float32) Tensor("conv5_3/conv5_3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_conv/3x3/rpn_conv/3x3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_cls_score/Reshape_1:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_cls_prob:0", shape=(?, ?, ?, ?), dtype=float32) Tensor("Reshape_2:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_bbox_pred/Reshape_1:0", shape=(?, ?, ?, 40), dtype=float32) Tensor("Placeholder_1:0", shape=(?, 3), dtype=float32) 2018-09-15 19:02:45.896676: I C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\35\tensorflow\core\platform\cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2 Tensor_name is : conv3_1/weights Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/bias Tensor_name is : conv3_3/biases Tensor_name is : conv4_2/biases Tensor_name is : conv3_2/biases Tensor_name is : conv2_1/biases Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/bias Tensor_name is : conv1_1/biases Tensor_name is : conv2_2/biases Tensor_name is : conv4_3/weights Tensor_name is : conv1_2/biases Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/kernel Tensor_name is : conv5_2/biases Tensor_name is : rpn_cls_score/biases Tensor_name is : conv2_2/weights Tensor_name is : conv4_2/weights Tensor_name is : conv2_1/weights Tensor_name is : rpn_conv/3x3/biases Tensor_name is : conv4_3/biases Tensor_name is : conv5_1/biases Tensor_name is : rpn_conv/3x3/weights Tensor_name is : conv5_1/weights Tensor_name is : conv5_3/biases Tensor_name is : conv5_2/weights Tensor_name is : conv1_2/weights Tensor_name is : conv4_1/biases Tensor_name is : conv1_1/weights Tensor_name is : rpn_cls_score/weights Tensor_name is : conv3_3/weights Tensor_name is : conv5_3/weights Tensor_name is : rpn_bbox_pred/weights Tensor_name is : lstm_o/biases Tensor_name is : conv3_2/weights Tensor_name is : conv3_1/biases Tensor_name is : lstm_o/weights Tensor_name is : rpn_bbox_pred/biases Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/kernel Tensor_name is : conv4_1/weights load vggnet done The angel of this character is: 180 Rotate the array of this img! 2018-09-15 19:03:49.378000: W C:\tf_jenkins\home\workspace\rel-win\M\windows\PY\35\tensorflow\core\framework\op_kernel.cc:1192] Invalid argument: ValueError: Buffer dtype mismatch, expected 'int_t' but got 'long long'

QQ2737499951 commented 6 years ago

我的环境是win10 +cuda9.2+vs2017 有谁在win 环境跑通了吗? 我的warp-ctc 这个编译安装总是不成功,有谁能指导一下吗?谢谢 QQ2737499951

harlanhong commented 5 years ago

image 请问这个有遇到吗

siriusi commented 5 years ago

qq 20180718152210 qq 20180718152247 qq 20180718152058

@qingfenghcy 错误就是这样子,明明那几个文件都有,但就是import不进来,您有遇到这个问题吗?怎么解决的?

我也遇到这种问题了,这个问题主要是路径不对,我是把#sys.path.insert(1, "./crnn")改为sys.path.insert(1, "./crnn/models")成功的,你看一下你那边的路径。

aslily1234 commented 5 years ago

@xiaofengShi 大神,您好!我在跑demo的是否遇到了下面的错误,能否麻烦您知道一下呢?谢谢您! Using TensorFlow backend. Tensor("Placeholder:0", shape=(?, ?, ?, 3), dtype=float32) Tensor("conv5_3/conv5_3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_conv/3x3/rpn_conv/3x3:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("lstm_o/Reshape_2:0", shape=(?, ?, ?, 512), dtype=float32) Tensor("rpn_cls_score/Reshape_1:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_cls_prob:0", shape=(?, ?, ?, ?), dtype=float32) Tensor("Reshape_2:0", shape=(?, ?, ?, 20), dtype=float32) Tensor("rpn_bbox_pred/Reshape_1:0", shape=(?, ?, ?, 40), dtype=float32) Tensor("Placeholder_1:0", shape=(?, 3), dtype=float32) 2018-06-16 10:03:22.612203: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA 2018-06-16 10:03:22.729420: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2018-06-16 10:03:22.729817: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1356] Found device 0 with properties: name: GeForce GTX 1070 major: 6 minor: 1 memoryClockRate(GHz): 1.645 pciBusID: 0000:01:00.0 totalMemory: 7.92GiB freeMemory: 7.51GiB 2018-06-16 10:03:22.729831: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0 2018-06-16 10:03:22.919152: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-06-16 10:03:22.919186: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 2018-06-16 10:03:22.919192: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N 2018-06-16 10:03:22.919376: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7256 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1) Tensor_name is : rpn_conv/3x3/biases Tensor_name is : rpn_cls_score/weights Tensor_name is : rpn_bbox_pred/biases Tensor_name is : lstm_o/weights Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/bias Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/kernel Tensor_name is : lstm_o/bidirectional_rnn/bw/lstm_cell/bias Tensor_name is : conv5_3/weights Tensor_name is : conv5_3/biases Tensor_name is : lstm_o/biases Tensor_name is : conv5_2/weights Tensor_name is : conv2_2/weights Tensor_name is : conv1_1/weights Tensor_name is : conv4_2/weights Tensor_name is : conv2_2/biases Tensor_name is : conv2_1/biases Tensor_name is : conv1_2/weights Tensor_name is : conv4_1/biases Tensor_name is : conv2_1/weights Tensor_name is : rpn_cls_score/biases Tensor_name is : conv1_2/biases Tensor_name is : rpn_conv/3x3/weights Tensor_name is : conv3_1/weights Tensor_name is : conv4_3/weights Tensor_name is : conv3_2/biases Tensor_name is : rpn_bbox_pred/weights Tensor_name is : conv3_2/weights Tensor_name is : lstm_o/bidirectional_rnn/fw/lstm_cell/kernel Tensor_name is : conv3_3/biases Tensor_name is : conv5_2/biases Tensor_name is : conv5_1/weights Tensor_name is : conv3_3/weights Tensor_name is : conv4_1/weights Tensor_name is : conv1_1/biases Tensor_name is : conv4_2/biases Tensor_name is : conv3_1/biases Tensor_name is : conv4_3/biases Tensor_name is : conv5_1/biases load vggnet done 2018-06-16 10:03:23.100380: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1435] Adding visible gpu devices: 0 2018-06-16 10:03:23.100431: I tensorflow/core/common_runtime/gpu/gpu_device.cc:923] Device interconnect StreamExecutor with strength 1 edge matrix: 2018-06-16 10:03:23.100440: I tensorflow/core/common_runtime/gpu/gpu_device.cc:929] 0 2018-06-16 10:03:23.100446: I tensorflow/core/common_runtime/gpu/gpu_device.cc:942] 0: N 2018-06-16 10:03:23.100581: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1053] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 7256 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070, pci bus id: 0000:01:00.0, compute capability: 6.1) Traceback (most recent call last): File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1567, in _create_c_op c_op = c_api.TF_FinishOperation(op_desc) tensorflow.python.framework.errors_impl.InvalidArgumentError: Shape must be rank 1 but is rank 4 for 'batch_normalization_1/cond/FusedBatchNorm' (op: 'FusedBatchNorm') with input shapes: [?,4,?,512], [1,4,1,1], [1,4,1,1], [1,4,1,1], [1,4,1,1].

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "demo.py", line 8, in import model File "/media/wenxue/DATA/AIGithubProject/ChineseRecog/CHINESE-OCR-Shixiaofeng/model.py", line 16, in from ocr.model import predict as ocr File "/media/wenxue/DATA/AIGithubProject/ChineseRecog/CHINESE-OCR-Shixiaofeng/ocr/model.py", line 79, in model, basemodel = get_model(height, nclass) File "/media/wenxue/DATA/AIGithubProject/ChineseRecog/CHINESE-OCR-Shixiaofeng/ocr/model.py", line 42, in get_model m = BatchNormalization(axis=1)(m) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/engine/base_layer.py", line 460, in call output = self.call(inputs, *kwargs) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/layers/normalization.py", line 204, in call training=training) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3069, in in_train_phase x = switch(training, x, alt) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 3004, in switch else_expression_fn) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/util/deprecation.py", line 432, in new_func return func(args, kwargs) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 2072, in cond orig_res_f, res_f = context_f.BuildCondBranch(false_fn) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py", line 1913, in BuildCondBranch original_result = fn() File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/layers/normalization.py", line 165, in normalize_inference epsilon=self.epsilon) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py", line 1894, in batch_normalization is_training=False File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/ops/nn_impl.py", line 904, in fused_batch_norm name=name) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/ops/gen_nn_ops.py", line 3429, in _fused_batch_norm is_training=is_training, name=name) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/op_def_library.py", line 787, in _apply_op_helper op_def=op_def) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 3392, in create_op op_def=op_def) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1734, in init** control_input_ops) File "/opt/anaconda3/envs/tf-gpu/lib/python3.6/site-packages/tensorflow/python/framework/ops.py", line 1570, in _create_c_op raise ValueError(str(e)) ValueError: Shape must be rank 1 but is rank 4 for 'batch_normalization_1/cond/FusedBatchNorm' (op: 'FusedBatchNorm') with input shapes: [?,4,?,512], [1,4,1,1], [1,4,1,1], [1,4,1,1], [1,4,1,1].

针对“Shape must be rank 1 but is rank 4 for 'batch_normalization_1/cond/FusedBatchNorm' ” 这类报错,可以更新keras到最新版本(具体参考---> https://github.com/keras-team/keras/issues/10648) : pip uninstall keras git clone https://github.com/keras-team/keras.git cd keras sudo python3 setup.py install

Lanme commented 5 years ago

@xuewengeophysics 请问你解决了么?

C188 commented 5 years ago

@07freedom 哦哦 是这样啊,我把路径改改看 谢谢你

你解决了那个问题了么,我把两个model路径都改了之后还是不对,依旧是这个错误

C188 commented 5 years ago

@07freedom 哦哦 是这样啊,我把路径改改看 谢谢你

你解决了那个问题了么,我把两个model路径都改了之后还是不对,依旧是这个错误

刚发现有个老哥已经总结完了https://github.com/xiaofengShi/CHINESE-OCR/issues/83#issue-447506385