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

Cannot Download Pipeline: Unrecognized keyword arguments passed to Dense #252

Closed Ge0rg3 closed 3 weeks ago

Ge0rg3 commented 3 weeks ago

Hi, when running only:

import keras_ocr
pipeline = keras_ocr.pipeline.Pipeline()

I get this error:

ValueError: Unrecognized keyword arguments passed to Dense: {'weights': [array([[0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0., 0.],

Running python3.9, cuda 12.3 and tensorflow 2.16.1

For reference, here is where the error is spawning from:

<ipython-input-2-6b85d751285a> in <module>
----> 1 pipeline = keras_ocr.pipeline.Pipeline()

~/.local/lib/python3.10/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

~/.local/lib/python3.10/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]

~/.local/lib/python3.10/site-packages/keras_ocr/recognition.py in build_model(alphabet, height, width, color, filters, rnn_units, dropout, rnn_steps_to_discard, pool_size, stn)
    275         locnet_y = keras.layers.Flatten()(locnet_y)
    276         locnet_y = keras.layers.Dense(64, activation="relu")(locnet_y)
--> 277         locnet_y = keras.layers.Dense(
    278             6,
    279             weights=[

~/.local/lib/python3.10/site-packages/keras/src/layers/core/dense.py in __init__(self, units, activation, use_bias, kernel_initializer, bias_initializer, kernel_regularizer, bias_regularizer, activity_regularizer, kernel_constraint, bias_constraint, lora_rank, **kwargs)
     85         **kwargs,
     86     ):
---> 87         super().__init__(activity_regularizer=activity_regularizer, **kwargs)
     88         self.units = units
     89         self.activation = activations.get(activation)

~/.local/lib/python3.10/site-packages/keras/src/layers/layer.py in __init__(self, activity_regularizer, trainable, dtype, autocast, name, **kwargs)
    262             self._input_shape_arg = input_shape_arg
    263         if kwargs:
--> 264             raise ValueError(
    265                 "Unrecognized keyword arguments "
    266                 f"passed to {self.__class__.__name__}: {kwargs}"

ValueError: Unrecognized keyword arguments passed to Dense: {'weights': [array([[0., 0., 0., 0., 0., 0.],
Ge0rg3 commented 3 weeks ago

Downgraded to tensorflow 2.13.0 as others have suggested but the same issue persists.

Ge0rg3 commented 3 weeks ago

Edit for people seeing in future: I was testing in ipython3 which was outside of my conda env, when running in just python3 it worked as expected.