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.36k stars 347 forks source link

keras_ocr throwing errors when importing on Jupyter Notebook #211

Open shamine5 opened 2 years ago

shamine5 commented 2 years ago
import keras_ocr
pipeline = keras_ocr.pipeline.Pipeline()

Error

Looking for C:\Users\keras-ocr\craft_mlt_25k.h5
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-34-6e067efdc308> in <module>
      1 import keras_ocr
      2 
----> 3 pipeline = keras_ocr.pipeline.Pipeline()

~\anaconda3\envs\Tensorflow_1\lib\site-packages\keras_ocr\pipeline.py in __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

~\anaconda3\envs\Tensorflow_1\lib\site-packages\keras_ocr\recognition.py in __init__(self, alphabet, weights, build_params)
    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]

~\anaconda3\envs\Tensorflow_1\lib\site-packages\keras_ocr\recognition.py in build_model(alphabet, height, width, color, filters, rnn_units, dropout, rnn_steps_to_discard, pool_size, stn)
    283         )(locnet_y)
    284         localization_net = keras.models.Model(inputs=stn_input_layer, outputs=locnet_y)
--> 285         x = keras.layers.Lambda(_transform, output_shape=stn_input_output_shape)(
    286             [x, localization_net(x)]
    287         )

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in __call__(self, *args, **kwargs)
    923     # >> model = tf.keras.Model(inputs, outputs)
    924     if _in_functional_construction_mode(self, inputs, args, kwargs, input_list):
--> 925       return self._functional_construction_call(inputs, args, kwargs,
    926                                                 input_list)
    927 

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\keras\engine\base_layer.py in _functional_construction_call(self, inputs, args, kwargs, input_list)
   1115           try:
   1116             with ops.enable_auto_cast_variables(self._compute_dtype_object):
-> 1117               outputs = call_fn(cast_inputs, *args, **kwargs)
   1118 
   1119           except errors.OperatorNotAllowedInGraphError as e:

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\keras\layers\core.py in call(self, inputs, mask, training)
    901     with backprop.GradientTape(watch_accessed_variables=True) as tape,\
    902         variable_scope.variable_creator_scope(_variable_creator):
--> 903       result = self.function(inputs, **kwargs)
    904     self._check_variables(created_variables, tape.watched_variables())
    905     return result

~\anaconda3\envs\Tensorflow_1\lib\site-packages\keras_ocr\recognition.py in _transform(inputs)
     86     output_height = output_size[0]
     87     output_width = output_size[1]
---> 88     indices_grid = _meshgrid(output_height, output_width)
     89     indices_grid = tf.expand_dims(indices_grid, 0)
     90     indices_grid = tf.reshape(indices_grid, [-1])  # flatten?

~\anaconda3\envs\Tensorflow_1\lib\site-packages\keras_ocr\recognition.py in _meshgrid(height, width)
     62     x_linspace = tf.linspace(-1.0, 1.0, width)
     63     y_linspace = tf.linspace(-1.0, 1.0, height)
---> 64     x_coordinates, y_coordinates = tf.meshgrid(x_linspace, y_linspace)
     65     x_coordinates = tf.reshape(x_coordinates, shape=(1, -1))
     66     y_coordinates = tf.reshape(y_coordinates, shape=(1, -1))

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\util\dispatch.py in wrapper(*args, **kwargs)
    199     """Call target, and fall back on dispatchers if there is a TypeError."""
    200     try:
--> 201       return target(*args, **kwargs)
    202     except (TypeError, ValueError):
    203       # Note: convert_to_eager_tensor currently raises a ValueError, not a

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\ops\array_ops.py in meshgrid(*args, **kwargs)
   3471 
   3472     # TODO(nolivia): improve performance with a broadcast
-> 3473     mult_fact = ones(shapes, output_dtype)
   3474     return [x * mult_fact for x in output]
   3475 

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\util\dispatch.py in wrapper(*args, **kwargs)
    199     """Call target, and fall back on dispatchers if there is a TypeError."""
    200     try:
--> 201       return target(*args, **kwargs)
    202     except (TypeError, ValueError):
    203       # Note: convert_to_eager_tensor currently raises a ValueError, not a

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\ops\array_ops.py in ones(shape, dtype, name)
   3039           # Create a constant if it won't be very big. Otherwise create a fill
   3040           # op to prevent serialized GraphDefs from becoming too large.
-> 3041           output = _constant_if_small(one, shape, dtype, name)
   3042           if output is not None:
   3043             return output

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\ops\array_ops.py in _constant_if_small(value, shape, dtype, name)
   2730 def _constant_if_small(value, shape, dtype, name):
   2731   try:
-> 2732     if np.prod(shape) < 1000:
   2733       return constant(value, shape=shape, dtype=dtype, name=name)
   2734   except TypeError:

<__array_function__ internals> in prod(*args, **kwargs)

~\anaconda3\envs\Tensorflow_1\lib\site-packages\numpy\core\fromnumeric.py in prod(a, axis, dtype, out, keepdims, initial, where)
   3028     10
   3029     """
-> 3030     return _wrapreduction(a, np.multiply, 'prod', axis, dtype, out,
   3031                           keepdims=keepdims, initial=initial, where=where)
   3032 

~\anaconda3\envs\Tensorflow_1\lib\site-packages\numpy\core\fromnumeric.py in _wrapreduction(obj, ufunc, method, axis, dtype, out, **kwargs)
     85                 return reduction(axis=axis, out=out, **passkwargs)
     86 
---> 87     return ufunc.reduce(obj, axis, dtype, out, **passkwargs)
     88 
     89 

~\anaconda3\envs\Tensorflow_1\lib\site-packages\tensorflow\python\framework\ops.py in __array__(self)
    843 
    844   def __array__(self):
--> 845     raise NotImplementedError(
    846         "Cannot convert a symbolic Tensor ({}) to a numpy array."
    847         " This error may indicate that you're trying to pass a Tensor to"

NotImplementedError: Cannot convert a symbolic Tensor (lambda_7/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

I tried the same commands on Collab its working but on Jupyter Notebook it throws error. May I Know how to fix this.