image-analogies icon indicating copy to clipboard operation
image-analogies copied to clipboard

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

Open chikiuso opened this issue 7 years ago • 13 comments

Hi, I got the following message running the command, it seems to be the weight shape problem , any idea on solving it? thanks :

Traceback (most recent call last): File "/usr/local/bin/make_image_analogy.py", line 27, in image_analogy.main.main(args, model_class) File "/usr/local/lib/python2.7/dist-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 "/usr/local/lib/python2.7/dist-packages/image_analogy/vgg16.py", line 89, in get_model layer.set_weights(weights) File "/usr/local/lib/python2.7/dist-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)

chikiuso avatar Apr 06 '17 10:04 chikiuso

I suspect you have keras 2 installed, but this only runs on v1. I need to update the versions in setup.py. To confirm, run pip show keras.

awentzonline avatar Apr 06 '17 16:04 awentzonline

Hi creator of project, yes, my keras version is 2.02

chikiuso avatar Apr 07 '17 02:04 chikiuso

Hi @awentzonline, are you planning on supporting Keras 2 anytime soon? Is there a workaround for the time being?

AhmadBaracat avatar Apr 18 '17 21:04 AhmadBaracat

Hi, I had the same question as above. I don't have a way to access anything below Keras 2 as I'm using a shared computing cluster. Any suggestions? Thanks!

pmlantos avatar Apr 29 '17 02:04 pmlantos

@pmlantos What I have done is to use virtualenv and instal Keras==1.1.1 on it. Not sure if that is feasible in your case.

AhmadBaracat avatar Apr 29 '17 07:04 AhmadBaracat

Thanks, it may be ... I've set up a virtual environment with 1.2.1. Do I need to reinstall image-analogies in the virtual environment too?

On Apr 29, 2017 3:26 AM, "Ahmed Baracat" [email protected] wrote:

@pmlantos https://github.com/pmlantos What I have done is to use virtualenv and instal Keras==1.1.1 on it. Not sure if that is feasible in your case.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/awentzonline/image-analogies/issues/39#issuecomment-298152957, or mute the thread https://github.com/notifications/unsubscribe-auth/AajKY8OQ9Stizg_xb3WcUmOhiv7mjwOrks5r0uY-gaJpZM4M1bVy .

pmlantos avatar Apr 29 '17 14:04 pmlantos

Unfortunately I can't get this package to run within a virtual environment, though setting the environment up seems straightforward. Wonder if I can find a way to cheaply do it on AWS.

pmlantos avatar Apr 30 '17 01:04 pmlantos

That's what worked for me. Hope it helps.

  1. Activate the virtualenv
  2. Check the version of keras installed using pip show keras
  3. If it is Keras version 2 then pip uninstall keras followed by pip install keras==1.1.1.
  4. Uninstall image-analogies
  5. Reinstall image-analogies

AhmadBaracat avatar Apr 30 '17 09:04 AhmadBaracat

Thanks, unfortunately doesn't work for me. Some of the installation has to go into shared parts of the computing cluster that I don't have access to. Appreciate the help though.

On Sun, Apr 30, 2017 at 5:37 AM, Ahmed Baracat [email protected] wrote:

That's what worked for me. Hope it helps.

  1. Activate the virtualenv
  2. Check the version of keras installed using pip show keras
  3. If it is Keras version 2 then pip uninstall keras followed by pip install keras==1.1.1.
  4. Uninstall image-analogies
  5. Reinstall image-analogies

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/awentzonline/image-analogies/issues/39#issuecomment-298222050, or mute the thread https://github.com/notifications/unsubscribe-auth/AajKY7SbYca6ke1ZGs0AHy1Wbm_dkBhfks5r1FZegaJpZM4M1bVy .

pmlantos avatar Apr 30 '17 13:04 pmlantos

No worries, but I think that if you are using virtualenv then you don't need to depend on shared parts because you get to create an isolated environment.

AhmadBaracat avatar Apr 30 '17 19:04 AhmadBaracat

I have same problem as first

make sure that

requirements.txt

Cython==0.23.4 h5py==2.5.0 Keras==1.1.1 numpy==1.10.4 Pillow==3.1.1 PyYAML==3.11 scipy==0.17.0 scikit-learn==0.17.0 six==1.10.0 -e git://github.com/Theano/Theano.git@954c3816a40de172c28124017a25387f3bf551b2#egg=Theano

and I use sudo pip install theano==0.9.0b1

than it works~

oceanjack avatar Jul 17 '17 12:07 oceanjack

and make sure that you have edit ~/.keras/keras.json like this { "image_dim_ordering": "th", "epsilon": 1e-07, "floatx": "float32", "backend": "theano" }

oceanjack avatar Jul 17 '17 12:07 oceanjack

I have replaced the 94th line in image_analogy/vgg16.py with weights[0] = np.transpose(np.array(weights[0])[:, :, ::-1, ::-1], (2, 3, 1, 0)) and it works like charm now.

HeadstrongCatgirl avatar Oct 12 '17 16:10 HeadstrongCatgirl