faustomorales / keras-ocr

A packaged and flexible version of the CRAFT text detector and Keras CRNN recognition model.
https://keras-ocr.readthedocs.io/
MIT License
1.37k stars 349 forks source link

keras_ocr.pipeline.Pipeline() NotImplementedError: Cannot convert a symbolic Tensor (lambda_1/meshgrid/Size_1:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported #202

Open ffffffffffffhhhhhhhhhhhh opened 2 years ago

ffffffffffffhhhhhhhhhhhh commented 2 years ago

Fails to run the example code with this error


Traceback (most recent call last):
  File "C:\Users\tyler\PycharmProjects\HSBOT\main.py", line 7, in <module>
    pipeline = keras_ocr.pipeline.Pipeline()
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\keras_ocr\pipeline.py", line 22, in __init__
    recognizer = recognition.Recognizer()
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\keras_ocr\recognition.py", line 388, in __init__
    ) = build_model(alphabet=alphabet, **build_params)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\keras_ocr\recognition.py", line 285, in build_model
    x = keras.layers.Lambda(_transform, output_shape=stn_input_output_shape)(
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 969, in __call__
    return self._functional_construction_call(inputs, args, kwargs,
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 1107, in _functional_construction_call
    outputs = self._keras_tensor_symbolic_call(
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 840, in _keras_tensor_symbolic_call
    return self._infer_output_signature(inputs, args, kwargs, input_masks)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\keras\engine\base_layer.py", line 880, in _infer_output_signature
    outputs = call_fn(inputs, *args, **kwargs)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\keras\layers\core.py", line 919, in call
    result = self.function(inputs, **kwargs)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\keras_ocr\recognition.py", line 88, in _transform
    indices_grid = _meshgrid(output_height, output_width)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\keras_ocr\recognition.py", line 64, in _meshgrid
    x_coordinates, y_coordinates = tf.meshgrid(x_linspace, y_linspace)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\util\dispatch.py", line 206, in wrapper
    return target(*args, **kwargs)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\ops\array_ops.py", line 3644, in meshgrid
    mult_fact = ones(shapes, output_dtype)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\util\dispatch.py", line 206, in wrapper
    return target(*args, **kwargs)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\ops\array_ops.py", line 3212, in ones
    output = _constant_if_small(one, shape, dtype, name)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\ops\array_ops.py", line 2896, in _constant_if_small
    if np.prod(shape) < 1000:
  File "<__array_function__ internals>", line 180, in prod
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\fromnumeric.py", line 3088, in prod
    return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\numpy\core\fromnumeric.py", line 86, in _wrapreduction
    return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
  File "C:\Users\tyler\AppData\Local\Programs\Python\Python39\lib\site-packages\tensorflow\python\framework\ops.py", line 867, in __array__
    raise NotImplementedError(
NotImplementedError: Cannot convert a symbolic Tensor (lambda_1/meshgrid/Size_1:0) to a numpy array. This error may indicate that you're trying to pass a Tensor to a NumPy call, which is not supported

Process finished with exit code 1
```_
MahmoudKanbar commented 2 years ago

Same issue I've got

shamine5 commented 2 years ago

I am facing the same issue. Were you able to solve the error @MahmoudKanbar @ffffffffffffhhhhhhhhhhhh

RafaelOO commented 1 year ago

It seems to be a problem of compatibility between tf and np.

GrigoriiTarasov commented 1 year ago

Just reinstall to

numpy='1.19.5'