关于这一点有很多问题,但我没有找到解决方案。我想从此网站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感谢大家的帮助。
发布于 2021-09-28 08:06:48
您需要禁用Tf2行为
import tensorflow.compat.v1 as tf
tf.compat.v1.disable_v2_behavior()
tf.compat.v1.Session()https://stackoverflow.com/questions/64780564
复制相似问题