awslabs / handwritten-text-recognition-for-apache-mxnet

This repository lets you train neural networks models for performing end-to-end full-page handwriting recognition using the Apache MXNet deep learning frameworks on the IAM Dataset.
Apache License 2.0
481 stars 189 forks source link

AssertionError: Shape of params are incompatible #42

Closed jbuehler1337 closed 4 years ago

jbuehler1337 commented 4 years ago

Hi again,

I am a bit confused about this error, happening in the 4_text_denoising notebook. I just did every step from before but something does not fit with the dimensions. Can you explain why this is happening?


AssertionErrorTraceback (most recent call last)
<ipython-input-31-2a0e848a57c4> in <module>
      1 model_path = 'models/denoiser2.params'
      2 if (os.path.isfile(model_path)):
----> 3     net.load_parameters(model_path, ctx=ctx)
      4     print("Loaded parameters")
      5     best_test_loss = evaluate(net, val_data_ft)

/usr/local/lib/python3.6/dist-packages/mxnet/gluon/block.py in load_parameters(self, filename, ctx, allow_missing, ignore_extra, cast_dtype, dtype_source)
    553                         name, filename, _brief_print_list(self._params.keys())))
    554             if name in params:
--> 555                 params[name]._load_init(loaded[name], ctx, cast_dtype=cast_dtype, dtype_source=dtype_source)
    556 
    557     def load_params(self, filename, ctx=None, allow_missing=False,

/usr/local/lib/python3.6/dist-packages/mxnet/gluon/parameter.py in _load_init(self, data, ctx, cast_dtype, dtype_source)
    280                     "Failed loading Parameter '%s' from saved params: " \
    281                     "shape incompatible expected %s vs saved %s"%(
--> 282                         self.name, str(self.shape), str(data.shape))
    283             self.shape = tuple(i if i != unknown_dim_size else j
    284                                for i, j in zip(self.shape, data.shape))

AssertionError: Failed loading Parameter 'transformer_enc_const' from saved params: shape incompatible expected (150, 512) vs saved (150, 256)
jonomon commented 4 years ago

Are you using the IAM images?

jbuehler1337 commented 4 years ago

Yes I am using the IAM data from the official page and your code just like you described it in the read me. I did not change the data set. Just lowered the number of workers or the batch size (32 to 16) to prevent my GPU memory to be overloaded... How can I solve this? Can I see the dimensions somehow? Do you need any further information?

jonomon commented 4 years ago

Were you able to run through 0_handwriting_ocr.ipynb without any issues?

jbuehler1337 commented 4 years ago

Yes I run through 0_handwriting_ocr.ipynb , 1_a_paragraph_segmentation_msers.ipynb , 1_b_paragraph_segmentation_dcnn.ipynb, 2_line_word_segmentation.ipynb , 3_handwriting_recognition.ipynb notebooks without an error.

jbuehler1337 commented 4 years ago

Hey, are there any news? Can I support you with additional information?

jonomon commented 4 years ago

There was a typo in the code.

Please change

num_heads = 16
embed_size = 512
num_layers = 2

epochs = 5
key = 'language_denoising'
best_test_loss = 10e20

learning_rate = 0.00004
send_every_n = 50

to

num_heads = 16
embed_size = 256
num_layers = 2

epochs = 5
key = 'language_denoising'
best_test_loss = 10e20

learning_rate = 0.00004
send_every_n = 50
jbuehler1337 commented 4 years ago

Thank you @jonomon so much, it is working fine now.