导入keras-ocr触发ValueError报错,求解决方案
Keras-OCR初始化触发ValueError问题求助
按照keras_ocr相关教程操作,从初始步骤就遇到问题,代码如下:
import pandas as pd import numpy as np from glob import glob from tqdm.notebook import tqdm import matplotlib.pyplot as plt from PIL import Image plt.style.use('ggplot')
import keras_ocr pipeline = keras_ocr.pipeline.Pipeline() # 运行时提示:Looking for C:\Users\{myusername}\.keras-ocr\craft_mlt_25k.h5
运行后触发如下ValueError报错:
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) Cell In[65], line 3 1 import keras_ocr ----> 3 pipeline = keras_ocr.pipeline.Pipeline() File c:\Python312\Lib\site-packages\keras_ocr\pipeline.py:22, in Pipeline.__init__(self, detector, recognizer, scale, max_size) 20 detector = detection.Detector() 21 if recognizer is None: ---> 22 recognizer = recognition.Recognizer() 23 self.scale = scale 24 self.detector = detector File c:\Python312\Lib\site-packages\keras_ocr\recognition.py:388, in Recognizer.__init__(self, alphabet, weights, build_params) 381 self.alphabet = alphabet 382 self.blank_label_idx = len(alphabet) 383 ( 384 self.backbone, 385 self.model, 386 self.training_model, 387 self.prediction_model, ---> 388 ) = build_model(alphabet=alphabet, **build_params) 389 if weights is not None: 390 weights_dict = PRETRAINED_WEIGHTS[weights] ... [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.], [0., 0., 0., 0., 0., 0.]], dtype=float32), array([1., 0., 0., 0., 1., 0.], dtype=float32)]} Output is truncated. View as a scrollable element or open in a text editor. Adjust cell output settings...
已尝试的解决手段:
- 通过Anaconda Navigator环境重装keras
- 在项目虚拟环境及全局环境中用pip重装keras-ocr
- 更换Python、tensorflow、keras版本
- 移除tensorflow单独使用keras-ocr
上述操作均未解决问题。
内容的提问来源于stack exchange,提问作者Yanislav Yanakiev
相关产品推荐
相关产品推荐

