Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Layer weight shape not compatible with provided weight shape #38

Closed
AdrienLemaire opened this issue Mar 30, 2017 · 11 comments
Closed

Comments

@AdrienLemaire
Copy link

after installing Tensorflow Python 3 / CPU only on anaconda, I tried to run the script without success:

$ make_image_analogy.py images/a.jpg images/a.jpg images/b.jpg out/b                                       
Using TensorFlow backend.
Tensorflow detected. Forcing --a-scale-mode=match (A images are scaled to same size as B images)
Using PatchMatch model
Scale factor 0.25 "A" shape (1, 3, 48, 64) "B" shape (1, 3, 48, 64)
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE3 instructions, but these areavailable on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX2 instructions, but these areavailable on your machine and could speed up CPU computations.
W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use FMA instructions, but these are available on your machine and could speed up CPU computations.
Traceback (most recent call last):
  File "/home/dori/.conda/envs/py36/bin/make_image_analogy.py", line 27, in <module>
    image_analogy.main.main(args, model_class)
  File "/home/dori/.conda/envs/py36/lib/python3.6/site-packages/image_analogy/main.py", line 69, in main
    net = vgg16.get_model(img_width, img_height, weights_path=args.vgg_weights, pool_mode=args.pool_mode)
  File "/home/dori/.conda/envs/py36/lib/python3.6/site-packages/image_analogy/vgg16.py", line 89, in get_model
    layer.set_weights(weights)
  File "/home/dori/.conda/envs/py36/lib/python3.6/site-packages/keras/engine/topology.py", line 1154, in set_weights
    'provided weight shape ' + str(w.shape))
ValueError: Layer weight shape (3, 3, 3, 64) not compatible with provided weight shape (64, 3, 3, 3)

Any idea how to solve this issue ?

PS: Note that I renamed all calls Convolution2D(XXX, 3, 3, activation=... into Conv2D(XXX, (3, 3), activation=... to fix the many UserWarnings

/home/dori/.conda/envs/py36/lib/python3.6/site-packages/image_analogy/vgg16.py:71: 
UserWarning: Update your `Conv2D` call to theKeras 2 API: `Conv2D(512, (3, 3), activation="relu", name="conv5_3")`
model.add(Convolution2D(512, 3, 3, activation='relu', name='conv5_3'))
@AdrienLemaire
Copy link
Author

Update. After adding the following line:

weights[0] = weights[0].reshape(list(reversed(weights[0].shape))) 

after line 88, I got the error Intel MKL FATAL ERROR: Cannot load libmkl_avx2.so or libmkl_def.so. just after start of iteration 0x0.

Might be something wrong with my conda env. Reinstalled a tensorflow + image-analogies env with virtualenv py3.6 and it seems to work now (now iteration 1x4)

@AdrienLemaire
Copy link
Author

Well, the resulting images look like nothing, so there must be something wrong with my installation and the code :( Support appreciated.

Input
A:
osaka_rivers_small
A':
osaka_small
B:
blue_contour_small

Output:
osaka_dori_at_iteration_2_4

@awentzonline
Copy link
Owner

Which version of Keras are you using? Sounds like you're using Keras v2 whereas this currently supports v1.

@AdrienLemaire
Copy link
Author

I see, maybe this could be updated in the readme. Will try again, thx!

@AdrienLemaire
Copy link
Author

@awentzonline there's also something wrong with the pip package. While I can see versions hardcoded with == in the requirements.txt file, the pip package metadata shows >= instead, hence keras 2 gets installed instead of 1:

Requires-Dist: Keras (>=1.0.0)
Requires-Dist: Pillow (>=3.1.1)
Requires-Dist: PyYAML (>=3.11)
Requires-Dist: Theano (>=0.8.2)
Requires-Dist: h5py (>=2.5.0)
Requires-Dist: numpy (>=1.10.4)
Requires-Dist: scikit-learn (>=0.17.0)
Requires-Dist: scipy (>=0.17.0)
Requires-Dist: six (>=1.10.0)

@AdrienLemaire
Copy link
Author

AdrienLemaire commented Mar 31, 2017

@awentzonline after force installing the requirements.txt package versions, I'm now getting the following error:

Using TensorFlow backend.
ValueError: Not property objects (Not property objects)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dori/Projects/personal/image-analogies/venv/bin/make_image_analogy.py", line 13, in <module>
    import image_analogy.main
  File "/home/dori/Projects/personal/image-analogies/venv/lib/python3.6/site-packages/image_analogy/main.py", line 9, in <module>
    from image_analogy import img_utils, vgg16
  File "/home/dori/Projects/personal/image-analogies/venv/lib/python3.6/site-packages/image_analogy/img_utils.py", line 4, in <module>
    from . import vgg16
  File "/home/dori/Projects/personal/image-analogies/venv/lib/python3.6/site-packages/image_analogy/vgg16.py", line 3, in <module>
    import h5py
  File "/home/dori/Projects/personal/image-analogies/venv/lib/python3.6/site-packages/h5py/__init__.py", line 31, in <module>
    from .highlevel import *
  File "/home/dori/Projects/personal/image-analogies/venv/lib/python3.6/site-packages/h5py/highlevel.py", line 13, in <module>
    from ._hl.base import is_hdf5, HLObject
  File "/home/dori/Projects/personal/image-analogies/venv/lib/python3.6/site-packages/h5py/_hl/base.py", line 78, in <module>
    dlapl = default_lapl()
  File "/home/dori/Projects/personal/image-analogies/venv/lib/python3.6/site-packages/h5py/_hl/base.py", line 65, in default_lapl
    lapl = h5p.create(h5p.LINK_ACCESS)
  File "h5py/_objects.pyx", line 54, in h5py._objects.with_phil.wrapper (/tmp/pip-build-a61i3wcx/h5py/h5py/_objects.c:2847)
  File "h5py/_objects.pyx", line 55, in h5py._objects.with_phil.wrapper (/tmp/pip-build-a61i3wcx/h5py/h5py/_objects.c:2805)
  File "h5py/h5p.pyx", line 131, in h5py.h5p.create (/tmp/pip-build-a61i3wcx/h5py/h5py/h5p.c:2886)
  File "h5py/h5p.pyx", line 72, in h5py.h5p.propwrap (/tmp/pip-build-a61i3wcx/h5py/h5py/h5p.c:2693)
ValueError: Not a property list class (Not a property list class)

What version of h5py are you using ? The one I have installed is v2.5.0 :/

@AdrienLemaire
Copy link
Author

looking at the h5py repo, seems like the v2.5 branch was quite buggy. Installed the latest version 2.7, and it force installed numpy 1.12.1. Restarting a make_image_analogy.py run and crossing fingers...

@AdrienLemaire
Copy link
Author

Unfortunately, it still doesn't look anything like a city. I wasn't expecting something of high quality (purposedly ran on images scaled down to 512px to test it out with cpu on my laptop), and the plan was then to re-run the script on AWS with GPU using the HD images. But clearly, if I tried AWS now, it'd still result in some garbled image.

osaka_dori_at_iteration_2_4

I didn't use any option (simply make_image_analogy.py images/a.jpg images/ap.jpg images/bp.jpg out/b). Does that explain the result? Are options mandatory for this use-case maybe?

@awentzonline
Copy link
Owner

@Fandekasp I must've accidentally closed this without commenting.

Two things: quality settings are documented in the readme, and the mask you're using for the city should probably be more detailed if you want interesting results.

This is some random thing I made available for free a year ago and is otherwise a time sink for me. Passive-aggressive comments like yours make me less enthusiastic about supporting this at all.

@AdrienLemaire
Copy link
Author

@awentzonline at the time, it felt like coming to your door, explaining you an issue I had and asking for help, then... getting the door slammed to my face ^^ Sorry for the reaction, and thank you for coming back to give more details.

I'm currently finishing the fast.ai course, and will then study Keras in more detail. Since I'm very interested by this kind of project, I might even be able to upgrade your repo to the latest packages versions. Keep in touch

@awentzonline
Copy link
Owner

Hey, no big deal--I hope you end up with some nice results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants