YCG09 / chinese_ocr

CTPN + DenseNet + CTC based end-to-end Chinese OCR implemented using tensorflow and keras
Apache License 2.0
2.76k stars 1.08k forks source link

demo.py 加载densenet模型预测时报错,Attempting to use uninitialized value #198

Open bing1zhi2 opened 5 years ago

bing1zhi2 commented 5 years ago

安装环境后,运行测试时报错: Loading network VGGnet_test... Restoring from ./ctpn/checkpoints/VGGnet_fast_rcnn_iter_50000.ckpt... done Using TensorFlow backend. modelPath /home/kunqian/nvidia_dev/chinese_ocr-master/densenet/models/weights_densenet.h5 load_weights <keras.engine.training.Model object at 0x7fb9474597b8>


Detection took 3.500s for 24 object proposals Traceback (most recent call last): File "/root/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1327, in _do_call return fn(*args) File "/root/anaconda3/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1306, in _run_fn status, run_metadata) File "/root/anaconda3/lib/python3.5/contextlib.py", line 66, in exit next(self.gen) File "/root/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value batch_normalization_55/beta [[Node: batch_normalization_55/beta/read = IdentityT=DT_FLOAT, _class=["loc:@batch_normalization_55/beta"], _device="/job:localhost/replica:0/task:0/cpu:0"]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "demo.py", line 34, in result, image_framed = ocr.model(image) File "/home/kunqian/nvidia_dev/chinese_ocr-master/ocr.py", line 85, in model result = charRec(img, text_recs, adjust) File "/home/kunqian/nvidia_dev/chinese_ocr-master/ocr.py", line 69, in charRec text = keras_densenet(image) File "/home/kunqian/nvidia_dev/chinese_ocr-master/densenet/model.py", line 56, in predict y_pred = basemodel.predict(X)

tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value batch_normalization_55/beta [[Node: batch_normalization_55/beta/read = IdentityT=DT_FLOAT, _class=["loc:@batch_normalization_55/beta"], _device="/job:localhost/replica:0/task:0/cpu:0"]]

我按setup 进行安装的环境

bing1zhi2 commented 5 years ago

Detection took 6.520s for 24 object proposals Traceback (most recent call last): File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1327, in _do_call return fn(*args) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1306, in _run_fn status, run_metadata) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/contextlib.py", line 66, in exit next(self.gen) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/framework/errors_impl.py", line 466, in raise_exception_on_not_ok_status pywrap_tensorflow.TF_GetCode(status)) tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value conv2d_55/kernel [[Node: conv2d_55/kernel/read = IdentityT=DT_FLOAT, _class=["loc:@conv2d_55/kernel"], _device="/job:localhost/replica:0/task:0/cpu:0"]]

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/media/chenhao/study/code/other/chinese_ocr-master/demo.py", line 34, in result, image_framed = ocr.model(image) File "/media/chenhao/study/code/other/chinese_ocr-master/ocr.py", line 85, in model result = charRec(img, text_recs, adjust) File "/media/chenhao/study/code/other/chinese_ocr-master/ocr.py", line 69, in charRec text = keras_densenet(image) File "/media/chenhao/study/code/other/chinese_ocr-master/densenet/model.py", line 64, in predict y_pred = basemodel.predict(X) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/keras/engine/training.py", line 1790, in predict verbose=verbose, steps=steps) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/keras/engine/training.py", line 1299, in _predict_loop batch_outs = f(ins_batch) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 2357, in call **self.session_kwargs) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 895, in run run_metadata_ptr) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1124, in _run feed_dict_tensor, options, run_metadata) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1321, in _do_run options, run_metadata) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 1340, in _do_call raise type(e)(node_def, op, message) tensorflow.python.framework.errors_impl.FailedPreconditionError: Attempting to use uninitialized value conv2d_55/kernel [[Node: conv2d_55/kernel/read = IdentityT=DT_FLOAT, _class=["loc:@conv2d_55/kernel"], _device="/job:localhost/replica:0/task:0/cpu:0"]]

Caused by op 'conv2d_55/kernel/read', defined at: File "/media/chenhao/study/code/other/chinese_ocr-master/demo.py", line 3, in import ocr File "", line 968, in _find_and_load File "", line 957, in _find_and_load_unlocked File "", line 673, in _load_unlocked File "", line 697, in exec_module File "", line 222, in _call_with_frames_removed File "/media/chenhao/study/code/other/chinese_ocr-master/ocr.py", line 12, in from densenet.model import predict as keras_densenet File "", line 968, in _find_and_load File "", line 957, in _find_and_load_unlocked File "", line 673, in _load_unlocked File "", line 697, in exec_module File "", line 222, in _call_with_frames_removed File "/media/chenhao/study/code/other/chinese_ocr-master/densenet/model.py", line 23, in y_pred= densenet.dense_cnn(input, nclass) File "/media/chenhao/study/code/other/chinese_ocr-master/densenet/densenet.py", line 53, in dense_cnn use_bias=False, kernel_regularizer=l2(_weight_decay))(input) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/keras/engine/topology.py", line 576, in call self.build(input_shapes[0]) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/keras/layers/convolutional.py", line 134, in build constraint=self.kernel_constraint) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/keras/legacy/interfaces.py", line 87, in wrapper return func(*args, **kwargs) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/keras/engine/topology.py", line 400, in add_weight constraint=constraint) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/keras/backend/tensorflow_backend.py", line 385, in variable v = tf.Variable(value, dtype=tf.as_dtype(dtype), name=name) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/ops/variables.py", line 199, in init expected_shape=expected_shape) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/ops/variables.py", line 330, in _init_from_args self._snapshot = array_ops.identity(self._variable, name="read") File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/ops/gen_array_ops.py", line 1400, in identity result = _op_def_lib.apply_op("Identity", input=input, name=name) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/framework/op_def_library.py", line 767, in apply_op op_def=op_def) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 2630, in create_op original_op=self._default_original_op, op_def=op_def) File "/home/chenhao/anaconda2/envs/dl35/lib/python3.5/site-packages/tensorflow/python/framework/ops.py", line 1204, in init self._traceback = self._graph._extract_stack() # pylint: disable=protected-access

FailedPreconditionError (see above for traceback): Attempting to use uninitialized value conv2d_55/kernel [[Node: conv2d_55/kernel/read = IdentityT=DT_FLOAT, _class=["loc:@conv2d_55/kernel"], _device="/job:localhost/replica:0/task:0/cpu:0"]]

bing1zhi2 commented 5 years ago

目前我把模型转化成tensorflow 模型,重写了demo.py 可以运行demo.py了,但上面的问题暂时还没解决。

bing1zhi2 commented 5 years ago

现在看这个问题,估计是tensorflow 版本的问题,我用的 tf 1.6.

simplify23 commented 5 years ago

你好,我也遇到这个问题了,tf版本是1.8, 可以吧你重写的demo,py发给我吗,跑了三天,还是没通,十分感谢

bing1zhi2 commented 5 years ago

@simplify23 先下载这个模型: 链接:https://pan.baidu.com/s/1gm0Uq_sLe00En-IbUPiQUg 提取码:qcco 复制这段内容后打开百度网盘手机App,操作更方便哦

然后可以参考这个代码使用: https://github.com/bing1zhi2/chinese_ocr/blob/master/chinese_ocr/predict_tf_tool.py 这个项目我还在更新,刚刚提交了一版

simplify23 commented 5 years ago

@simplify23 先下载这个模型: 链接:https://pan.baidu.com/s/1gm0Uq_sLe00En-IbUPiQUg 提取码:qcco 复制这段内容后打开百度网盘手机App,操作更方便哦

然后可以参考这个代码使用: https://github.com/bing1zhi2/chinese_ocr/blob/master/chinese_ocr/predict_tf_tool.py 这个项目我还在更新,刚刚提交了一版

感谢您的项目,看到您的项目参考了两个中文OCR项目。想问一下您具体是做什么的,您觉得yolo3+crnn和ctpn+densenet+ctc各有什么优势和缺点吗,非常感谢

bing1zhi2 commented 5 years ago

@simplify23 我弄的那个项目是打算整合两个中文ocr项目的,看能不能更快更好。之前各自单独测试了下,现在在开发打算整合下。上面给你发的那个文件,它是使用cptn+densenet里的预训练模型用代码转化后的模型的,应该可以支持高版本tf, 单独测试过可以用的

666888985 commented 4 years ago

@bing1zhi2 你好,这个项目里的demo.py只对给了检测代码,先检测再识别的代码没有,想问下大佬有吗?还有评估准确率,召回率的代码大佬有吗,是否可以发我一份,1971103492@qq.com,谢谢