Keras_ocr遇到的问题

OS

 win10
 anaconda 4.8.3
 CUDA 10.1 Cudnn7.6.5
 Nvidia  driver 445.87

OSError: [WinError 126] 找不到指定的模块 。解决办法:将shapely版本从1.7降为1.6

C:\ProgramData\Anaconda3\python.exe C:/PycharmProjects/keras_cor_build/main.py
2020-05-22 10:05:24.226186: W tensorflow/stream_executor/platform/default/dso_loader.cc:55] Could not load dynamic library 'cudart64_101.dll'; dlerror: cudart64_101.dll not found
2020-05-22 10:05:24.226387: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
Traceback (most recent call last):
  File "C:/PycharmProjects/keras_cor_build/main.py", line 3, in <module>
    import keras_ocr
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras_ocr\__init__.py", line 1, in <module>
    from . import (detection, recognition, tools, data_generation, pipeline, evaluation, datasets)
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras_ocr\detection.py", line 31, in <module>
    from . import tools
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras_ocr\tools.py", line 14, in <module>
    from shapely import geometry
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\geometry\__init__.py", line 4, in <module>
    from .base import CAP_STYLE, JOIN_STYLE
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\geometry\base.py", line 18, in <module>
    from shapely.coords import CoordinateSequence
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\coords.py", line 8, in <module>
    from shapely.geos import lgeos
  File "C:\ProgramData\Anaconda3\lib\site-packages\shapely\geos.py", line 145, in <module>
    _lgeos = CDLL(os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll'))
  File "C:\ProgramData\Anaconda3\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] 找不到指定的模块。

1 显示内存不够 解决办法 :使用GPU版TensorFlow

Looking for C:\Users\有对象真好\.keras-ocr\crnn_kurapan.h5
2020-05-21 14:00:01.016118: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 3019898880 exceeds 10% of free system memory.
2020-05-21 14:00:03.402349: W tensorflow/core/framework/cpu_allocator_impl.cc:81] Allocation of 3019898880 exceeds 10% of free system memory.

2 URL失效,改为本地连接,将图片下载到本地磁盘,输入图形可使用opencv 读取,读取后改为RBG,再输入网络

urllib.error.URLError: <urlopen error [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。>
images = [
    keras_ocr.tools.read(url) for url in [
        'D:\\Bosun\\out\\140_zifuhor.bmp',
        'D:\\Bosun\\binary_img\\wordROI173.bmp',
        'D:\\Bosun\\binary_img\\wordROI193.bmp'
    ]
]

3 矩阵相乘维度对不上

File "C:\ProgramData\Anaconda3\lib\site-packages\keras_ocr\detection.py", line 40, in compute_input
    image -= mean * 255
ValueError: operands could not be broadcast together with shapes (2048,2) (3,) (2048,2)

源代码为

def compute_input(image):
    # should be RGB order
    image = image.astype('float32')
    mean = np.array([0.485, 0.456, 0.406])
    variance = np.array([0.229, 0.224, 0.225])

    image -= mean * 255
    image /= variance * 255
    return image

4 Loaded runtime CuDNN library: 7.5.0 but source was compiled with: 7.6.5. cudnn版本对不上

2020-05-23 22:23:09.758126: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
Looking for C:\Users\有对象真好\.keras-ocr\craft_mlt_25k.h5
2020-05-23 22:23:14.446656: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-05-23 22:23:14.470724: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:09:00.0 name: GeForce GTX 1070 Ti computeCapability: 6.1
coreClock: 1.683GHz coreCount: 19 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 238.66GiB/s
2020-05-23 22:23:14.475854: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-05-23 22:23:14.501773: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-05-23 22:23:14.515525: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-05-23 22:23:14.527552: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-05-23 22:23:14.539852: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-05-23 22:23:14.555317: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-05-23 22:23:14.584781: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-05-23 22:23:14.588281: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-05-23 22:23:14.591930: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-05-23 22:23:14.607133: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x24171b62870 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-23 22:23:14.610707: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-05-23 22:23:14.619303: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:09:00.0 name: GeForce GTX 1070 Ti computeCapability: 6.1
coreClock: 1.683GHz coreCount: 19 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 238.66GiB/s
2020-05-23 22:23:14.632733: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-05-23 22:23:14.637275: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-05-23 22:23:14.643415: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-05-23 22:23:14.648087: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-05-23 22:23:14.654401: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-05-23 22:23:14.658880: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-05-23 22:23:14.665943: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-05-23 22:23:14.671485: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-05-23 22:23:15.173514: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-05-23 22:23:15.176237: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0
2020-05-23 22:23:15.180192: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N
2020-05-23 22:23:15.186064: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6285 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070 Ti, pci bus id: 0000:09:00.0, compute capability: 6.1)
2020-05-23 22:23:15.200484: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2411a2f3d10 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-05-23 22:23:15.206422: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1070 Ti, Compute Capability 6.1
2020-05-23 22:23:17.259729: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-05-23 22:23:18.011912: E tensorflow/stream_executor/cuda/cuda_dnn.cc:319] Loaded runtime CuDNN library: 7.5.0 but source was compiled with: 7.6.5.  CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.
2020-05-23 22:23:18.032912: E tensorflow/stream_executor/cuda/cuda_dnn.cc:319] Loaded runtime CuDNN library: 7.5.0 but source was compiled with: 7.6.5.  CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.
Traceback (most recent call last):
  File "lal.python", line 8, in <module>
    boxes = detector.detect(images=[image])[0]
  File "C:\ProgramData\Anaconda3\lib\site-packages\keras_ocr\detection.py", line 679, in detect
    boxes = getBoxes(self.model.predict(np.array(images), **kwargs),
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 88, in _method_wrapper
    return method(self, *args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\keras\engine\training.py", line 1268, in predict
    tmp_batch_outputs = predict_function(iterator)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py", line 580, in __call__
    result = self._call(*args, **kwds)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\def_function.py", line 650, in _call
    return self._concrete_stateful_fn._filtered_call(canon_args, canon_kwds)  # pylint: disable=protected-access
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 1665, in _filtered_call
    self.captured_inputs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 1746, in _call_flat
    ctx, args, cancellation_manager=cancellation_manager))
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\function.py", line 598, in call
    ctx=ctx)
  File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\eager\execute.py", line 60, in quick_execute
    inputs, attrs, num_outputs)
tensorflow.python.framework.errors_impl.UnknownError:  Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
         [[node model_1/basenet.slice1.0/Conv2D (defined at C:\ProgramData\Anaconda3\lib\site-packages\keras_ocr\detection.py:679) ]] [Op:__inference_predict_function_3683]

Function call stack:
predict_function

但是问题出在了cudnn的版本上。

Loaded runtime CuDNN library: 7.5.0 but source was compiled with: 7.6.5.  CuDNN library major and minor version needs to match or have higher minor version in case of CuDNN 7.0 or later version. If using a binary install, upgrade your CuDNN library.  If building from sources, make sure the library loaded at runtime is compatible with the version specified during compile configuration.

4的解决办法:通过everything这个软件找到所有的cudnn.dll,发现C:\Windows\System路径下有一个,这是以前的9.1.4版本的cudnn.dll,所有无论在CUDA10.1的环境下怎么更新cudnn都不起作用,因为先读取的系统盘路径C:\Windows\System下的dll,所有项目反复提醒报错cudnn.dll的版本不够。

在这里插入图片描述

运行没问题,但是没有输出,即matplot不起作用

完整日志如下

2020-05-28 16:02:14.778674: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
{'Name': 'Zara'}
Looking for C:\Users\有对象真好\.keras-ocr\craft_mlt_25k.h5
2020-05-28 16:02:18.069896: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-05-28 16:02:18.112526: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:09:00.0 name: GeForce GTX 1070 Ti computeCapability: 6.1
coreClock: 1.683GHz coreCount: 19 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 238.66GiB/s
2020-05-28 16:02:18.112828: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-05-28 16:02:18.150937: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-05-28 16:02:18.173217: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-05-28 16:02:18.183328: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-05-28 16:02:18.218229: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-05-28 16:02:18.242067: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-05-28 16:02:18.305875: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-05-28 16:02:18.306559: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-05-28 16:02:18.306996: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-05-28 16:02:18.316371: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2003e378d00 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-05-28 16:02:18.316749: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-05-28 16:02:18.317672: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:09:00.0 name: GeForce GTX 1070 Ti computeCapability: 6.1
coreClock: 1.683GHz coreCount: 19 deviceMemorySize: 8.00GiB deviceMemoryBandwidth: 238.66GiB/s
2020-05-28 16:02:18.318039: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
2020-05-28 16:02:18.318206: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll
2020-05-28 16:02:18.318389: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_10.dll
2020-05-28 16:02:18.318638: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_10.dll
2020-05-28 16:02:18.318841: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_10.dll
2020-05-28 16:02:18.319062: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_10.dll
2020-05-28 16:02:18.319260: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-05-28 16:02:18.320180: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-05-28 16:02:18.987038: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-05-28 16:02:18.987219: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-05-28 16:02:18.987316: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-05-28 16:02:18.988039: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 6285 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1070 Ti, pci bus id: 0000:09:00.0, compute capability: 6.1)
2020-05-28 16:02:18.991259: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2005db21c60 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-05-28 16:02:18.991655: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce GTX 1070 Ti, Compute Capability 6.1
WARNING:tensorflow:From C:\ProgramData\Anaconda3\envs\tensorflow2.1\lib\site-packages\tensorflow\python\keras\backend.py:5871: sparse_to_dense (from tensorflow.python.ops.sparse_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Create a `tf.sparse.SparseTensor` and use `tf.sparse.to_dense` instead.
Looking for C:\Users\有对象真好\.keras-ocr\crnn_kurapan.h5
2020-05-28 16:02:22.147557: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-05-28 16:02:23.248637: W tensorflow/stream_executor/gpu/redzone_allocator.cc:314] Internal: Invoking GPU asm compilation is supported on Cuda non-Windows platforms only
Relying on driver to perform ptx compilation. 
Modify $PATH to customize ptxas location.
This message will be only logged once.
2020-05-28 16:02:23.358222: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_10.dll

Process finished with exit code -1

解决办法:在代码最后的一行加上plt.show()
完整代码如下:

import matplotlib.pyplot as plt
import keras_ocr
import cv2

from imgmath import binaryimgpath

print(binaryimgpath)
# Get a set of three example images
images = [
    keras_ocr.tools.read(url) for url in [
        'D:\\Bosun\\out\\140_zifuhor.bmp',
        'D:\\Bosun\\binary_img\\wordROI173.bmp',
        'D:\\Bosun\\binary_img\\wordROI193.bmp'
    ]
]

# for image in images:
#     cv2.imshow("sds",image)
#     cv2.waitKey(1000)

# keras-ocr will automatically download pretrained
# weights for the detector and recognizer.
pipeline = keras_ocr.pipeline.Pipeline()
# Each list of predictions in prediction_groups is a list of
# (word, box) tuples.
prediction_groups = pipeline.recognize(images)

# Plot the predictions
fig, axs = plt.subplots(nrows=len(images), figsize=(20, 20))

for ax, image, predictions in zip(axs, images, prediction_groups):
    keras_ocr.tools.drawAnnotations(image=image, predictions=predictions, ax=ax)
plt.show()
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值