jalused / Deconvnet-keras

Deconvnet example based on Keras
MIT License
65 stars 17 forks source link

Error regarding weight dimensions #2

Closed jyuan1322 closed 7 years ago

jyuan1322 commented 7 years ago

Hi! I am getting the following error when running the code:

ValueError: Layer weight shape (3, 64, 3, 3) not compatible with provided weight shape (3, 3, 3, 64)

I wonder if this has to do with compatibility between different versions of Keras? I am using 1.2.2, although I tried switching to 1.1.0 as well, and it didn't appear to resolve it.

jalused commented 7 years ago

It shows the shape of pre-trained weight provided is not the same as the shape of weight the layer needs, I'm not sure where the problem occurs, but I guess it could be the backend you use(tensorflow or theano) and the configuration of image_dim_ordering(th or tf).
Try this:

  1. Check whether file ~/.keras/keras.json exists, if ~/.keras/keras.json does not exist, just create it.
  2. Insert following content into ~/.keras/keras.json { "epsilon": 1e-07, "floatx": "float32", "backend": "theano", "image_dim_ordering" : "th" }
  3. Run the code again

If this does not work, please show us the complete error message, including in which line the error occurs. It will help us find out where the problem occurs.

jyuan1322 commented 7 years ago

Ah, it works now - I was using tensorflow as my backend. If theano is a requirement, it would be great if that can be added to the dependencies in the readme file, in case anyone else has the same issue. Thanks for your help!

jalused commented 7 years ago

Great, hope this repo can give you some help. I will update the dependencies, thanks for your advice.

ariaaay commented 7 years ago

Hi, I am having the exact same error. And the keras.json file already exists, and has the exact same line as you described above. My keras version is 2.0.3.

Do you know what would be the problem? Thanks!

ariaaay commented 7 years ago
Traceback (most recent call last):
  File "Deconvnet-keras.py", line 526, in <module>
    main()
  File "Deconvnet-keras.py", line 514, in main
    layer_name, feature_to_visualize, visualize_mode)
  File "Deconvnet-keras.py", line 418, in visualize
    deconv_layers.append(DConvolution2D(model.layers[i]))
  File "Deconvnet-keras.py", line 59, in __init__
    )(input)
  File "/Users/AriaW/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 558, in __call__
    self.set_weights(self._initial_weights)
  File "/Users/AriaW/anaconda2/lib/python2.7/site-packages/keras/engine/topology.py", line 1158, in set_weights
    'provided weight shape ' + str(w.shape))
ValueError: Layer weight shape (3, 64, 3, 3) not compatible with provided weight shape (3, 3, 3, 64)
jalused commented 7 years ago

Hi, This is a backend problem, because the weight shapes of tensorflow and theano are different. Make sure you are using theano backend. I will test the code with keras 2.0.3 and then give you a reply

ariaaay commented 7 years ago

I am sure I am using the theano backend.

ariaaay commented 7 years ago

Downgrading keras to 1.1 did solve this. Thanks!