尝试导入 keras-ocr 时出现错误

问题描述 投票:0回答:1

我尝试遵循有关 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                                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-orc,但仍然没有运气。

python tensorflow keras jupyter-notebook ocr
1个回答
0
投票

有完全相同的问题,请尝试使用较低版本的Python。 Python 3.8.10 似乎可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.