mathDR / reading-text-in-the-wild

A Keras/Theano implementation of "Reading Text in the Wild with Convolutional Neural Networks" by M Jaderberg et.al.
GNU General Public License v3.0
116 stars 30 forks source link

ValueError: Layer weight shape (24576, 4096) not compatible with provided weight shape (26624, 4096) #17

Closed lorenzob closed 7 years ago

lorenzob commented 7 years ago

Update: using the correct version of keras and theano works perfectly.

Hi, I'm getting the above error running make_keras_dictnet_model.py.

This is what I've done:

I've added the class and the function to theano (with a debug print line at the beginning of each).

Downloaded the second model, from the "Click here for NIPS DLW 2014 models" link:

http://www.robots.ox.ac.uk/~vgg/research/text/model_release.tar.gz

Extracted and run:

$ python extract_dictnet_weights.py

pointing at the dictnet.mat file.

I got this file as a result:

matlab_dictnet_weights.npz (1.823.321.714 bytes)

Then I run:

$ python make_keras_dictnet_model.py Using Theano backend. WARNING (theano.sandbox.cuda): The cuda backend is deprecated and will be removed in the next release (v0.10). Please switch to the gpuarray backend. You can get more information about how to switch at this URL: https://github.com/Theano/Theano/wiki/Converting-to-the-new-gpu-back-end%28gpuarray%29

Using gpu device 0: Quadro K1100M (CNMeM is disabled, cuDNN 5110) ** DEBUG: CustomZeroPadding2D Traceback (most recent call last): File "/home/trz/progetti/machineLearning/reading-text-in-the-wild/DICT2/make_keras_dictnet_model.py", line 74, in model.add(Dense(4096,activation='relu',weights=weights)) File "/home/trz/.local/lib/python2.7/site-packages/keras/models.py", line 332, in add output_tensor = layer(self.outputs[0]) File "/home/trz/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 546, in call self.build(input_shapes[0]) File "/home/trz/.local/lib/python2.7/site-packages/keras/layers/core.py", line 809, in build self.set_weights(self.initial_weights) File "/home/trz/.local/lib/python2.7/site-packages/keras/engine/topology.py", line 985, in set_weights 'provided weight shape ' + str(w.shape)) ValueError: Layer weight shape (24576, 4096) not compatible with provided weight shape (26624, 4096)

you can see the debug line from the CustomZeroPadding2D class. The one from the custom_spatial_2d_padding function does not appear but I think it's just because the code exits before it gets called.

This is a fragment from make_keras_dictnet_model.py

# First Dense layer
model.add(Flatten())
weights = [all_weights['dense1W'],all_weights['dense1b']]
model.add(Dense(4096,activation='relu',weights=weights))   # Line 74
model.add(Dropout(0.5))

I also tried the model from the first link ("Click here for ECCV 2014 models") and I get an identical error.

This is my environment:

Python 2.7.12 Theano 0.9.0 Keras 1.2.2 Cuda compilation tools, release 8.0, V8.0.61 Linux Mint 4.4.0-89-generic x86_64

Am I doing something wrong? May be a known version problem (I've seen the notes on the Keras and Theano versions but I tried anyway)? Any help is appreciated.

Thanks for sharing this project.

lorenzob commented 7 years ago

Just a couple of extra notes for future users arriving here:

THEANO_FLAGS='device=cpu' python use_dictnet.py

because it requires more free GPU memory than I have (a little more than 2GB I think)