【发布时间】:2020-11-11 04:39:09
【问题描述】:
对此有很多问题,但我没有找到解决方案。我想从这个网站制作手写 OCR handwriting-ocr
导入库的时候发现这个错误
AttributeError Traceback (most recent call last)
<ipython-input-22-1c5011de3819> in <module>
8 sys.path.append('../src/')
9 from ocr.normalization import word_normalization, letter_normalization
---> 10 from ocr import page, words, characters
11 from ocr.helpers import implt, resize
12 from ocr.tfhelpers import Model
D:\Master\handwriting-ocr-master\handwriting-ocr-master\src\ocr\characters.py in <module>
14 location = os.path.dirname(os.path.abspath(__file__))
15 CNN_model = Model(
---> 16 os.path.join(location, '../../models/gap-clas/CNN-CG'))
17 CNN_slider = (60, 30)
18 RNN_model = Model(
D:\Master\handwriting-ocr-master\handwriting-ocr-master\src\ocr\tfhelpers.py in __init__(self, loc, operation, input_name)
18 self.input = input_name + ":0"
19 self.graph = tf.Graph()
---> 20 self.sess = tf.Session(graph=self.graph)
21 with self.graph.as_default():
22 saver = tf.train.import_meta_graph(loc + '.meta', clear_devices=True)
AttributeError: module 'tensorflow' has no attribute 'Session
因为我用tensorflow 2.1.0所以我尝试改成这个库
import tensorflow.compat.v1 as tf
试试这个
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()
print(sess.run(hello))
成功了。输出为b'Hello, TensorFlow!'。
如果使用 import tensorflow as tf 我将 tf.Session() 更改为 tf.compat.v1.Session() 成功但如果我在 ocr.py 中实现它仍然不起作用并返回相同的错误 no session
我也尝试重新安装tensorflow。
我使用 jupyter notebook、python 3.6 和 opencv 3.3.1
谢谢大家的帮助。
【问题讨论】:
标签: python-3.x tensorflow opencv ocr tensorflow2.0