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.38k stars 355 forks source link

shape incompatible error #142

Closed ronin0304 closed 3 years ago

ronin0304 commented 3 years ago

Hi there, I think the packaage is terrific . I have CuDA 11 on my Windows 10 system and recently upgraded to tf 2.5.0 I needed to do this sinc I recently had some 'protobuf ' error message that i couldn't resolve, at least for now that is gone, however now another error pops up : ValueError: Cannot assign to variable fc_12/kernel:0 due to variable shape (256, 42) and value shape (256, 37) are incompatible

I have tf 2.5.0-dev20201126 and keras 2.3.4. Here is the complete error :


ValueError Traceback (most recent call last)

in 5 # keras-ocr will automatically download pretrained 6 # weights for the detector and recognizer. ----> 7 pipeline = keras_ocr.pipeline.Pipeline() 8 9 # Get a set of three example images ~\Anaconda3\envs\keras_ocr_conda\lib\site-packages\keras_ocr\pipeline.py in __init__(self, detector, recognizer, scale, max_size) 19 detector = detection.Detector() 20 if recognizer is None: ---> 21 recognizer = recognition.Recognizer() 22 self.scale = scale 23 self.detector = detector ~\Anaconda3\envs\keras_ocr_conda\lib\site-packages\keras_ocr\recognition.py in __init__(self, alphabet, weights, build_params) 330 tools.download_and_verify(url=weights_dict['weights']['top']['url'], 331 filename=weights_dict['weights']['top']['filename'], --> 332 sha256=weights_dict['weights']['top']['sha256'])) 333 else: 334 print('Provided alphabet does not match pretrained alphabet. ' ~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\engine\training.py in load_weights(self, filepath, by_name, skip_mismatch, options) 2278 f, self.layers, skip_mismatch=skip_mismatch) 2279 else: -> 2280 hdf5_format.load_weights_from_hdf5_group(f, self.layers) 2281 2282 def _updated_config(self): ~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\saving\hdf5_format.py in load_weights_from_hdf5_group(f, layers) 708 str(len(weight_values)) + ' elements.') 709 weight_value_tuples += zip(symbolic_weights, weight_values) --> 710 K.batch_set_value(weight_value_tuples) 711 712 ~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\util\dispatch.py in wrapper(*args, **kwargs) 204 """Call target, and fall back on dispatchers if there is a TypeError.""" 205 try: --> 206 return target(*args, **kwargs) 207 except (TypeError, ValueError): 208 # Note: convert_to_eager_tensor currently raises a ValueError, not a ~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\keras\backend.py in batch_set_value(tuples) 3811 if ops.executing_eagerly_outside_functions(): 3812 for x, value in tuples: -> 3813 x.assign(np.asarray(value, dtype=dtype(x))) 3814 else: 3815 with get_graph().as_default(): ~\AppData\Roaming\Python\Python37\site-packages\tensorflow\python\ops\resource_variable_ops.py in assign(self, value, use_locking, name, read_value) 889 ("Cannot assign to variable%s due to variable shape %s and value " 890 "shape %s are incompatible") % --> 891 (tensor_name, self._shape, value_tensor.shape)) 892 assign_op = gen_resource_variable_ops.assign_variable_op( 893 self.handle, value_tensor, name=name) ValueError: Cannot assign to variable fc_12/kernel:0 due to variable shape (256, 42) and value shape (256, 37) are incompatible --------------------------------------------------------------------------- this occurs on the same code from the Git website: --------------------------------------------------------------------------- import matplotlib.pyplot as plt import keras_ocr # keras-ocr will automatically download pretrained # weights for the detector and recognizer. pipeline = keras_ocr.pipeline.Pipeline() # Get a set of three example images images = [ keras_ocr.tools.read(url) for url in [ 'https://upload.wikimedia.org/wikipedia/commons/b/bd/Army_Reserves_Recruitment_Banner_MOD_45156284.jpg', 'https://upload.wikimedia.org/wikipedia/commons/e/e8/FseeG2QeLXo.jpg', 'https://upload.wikimedia.org/wikipedia/commons/b/b4/EUBanana-500x112.jpg' ] ] # 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) --------------------------------------------------------------------------- Thanks and happy holidays! Cheers,E
ronin0304 commented 3 years ago

Stupid mistake on my behalf, I created two environments and tried to change the alphabet in one , thought i switched but didn't , apologies