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

about the pre-train weight #6

Open
Fahim-F opened this issue Jul 6, 2017 · 15 comments
Open

about the pre-train weight #6

Fahim-F opened this issue Jul 6, 2017 · 15 comments

Comments

@Fahim-F
Copy link

Fahim-F commented Jul 6, 2017

Hi,
Did you test the pre-train model on tensorflow backend?
I got an error when use it while the theano backend works.
I need a tensorflow pre-train model.

Thanks

@flyyufelix
Copy link
Owner

flyyufelix commented Jul 10, 2017

Oh yes, I forgot to erase a line in custom_layers.py which resulted in an error. It should work now!

@Fahim-F
Copy link
Author

Fahim-F commented Jul 11, 2017

Hi
Thanks for your attention!
But again it does not work!!
I think it is not related to custom_layers.py, the *.h5 weights file of tensorflow has a problem and I think you save it with the old version of tensorflow.
Thanks

@flyyufelix
Copy link
Owner

@fahim7 , I think the *.h5 weights file is backward compatible. Which model did you try to run? What was the corresponding error message?

@Fahim-F
Copy link
Author

Fahim-F commented Jul 12, 2017

I tested it with all three models in a tensorflow backend and I got a dimension error.
for example if I only load the weights of the pre-trained model (DenseNet 121 (k=32)) as follow:

model.load_weights('/weights/densenet121_weights_tf.h5',by_name = True)

I get the following error:
ValueError: Dimension 0 in both shapes must be equal, but are 192 and 256 for 'Assign_41' (op: 'Assign') with input shapes: [192], [256].

while if I change the backend as theano and load a model in the theano backend, every things done well.
But I want to use a tensoflow backend.

@flyyufelix
Copy link
Owner

I am using Keras 2.0.5 and Tensorflow 1.2.1 and all models work fine with Tensorflow backend. What version of Keras and Tensorflow are you using?

@Fahim-F
Copy link
Author

Fahim-F commented Jul 12, 2017

My keras 2.0.5 and tensorflow 1.2.0

@datlife
Copy link

datlife commented Jul 23, 2017

Same error with DenseNet169 TF weights.

Here is my system info:

>>> print(keras.__version__)
2.0.5
>>> print(tensorflow.__version__)
1.2.0

...
ValueError: Dimension 0 in both shapes must be equal, but are 1 and 128 for 'Assign_97' (op: 'Assign') with input shapes: [1,1,256,256], [128,256,1,1].

@Tangzy7
Copy link

Tangzy7 commented Aug 27, 2017

same problems with tensorflow 1.2.1 and keras 2.0.6

@taoddiao
Copy link

taoddiao commented Dec 9, 2017

set reduction=0.5 to fix the ValueError issue when loading weights

@Rabia-Metis
Copy link

It's also not working with reduction=0.5. Before it was giving error in 'Assign_97' and now by changing reduction=0.5 it is giving error in 'Assign_1126'

@taoddiao
Copy link

@Rabia-Metis which densenet did you run. I am doing fine with densenet121 on tensorflow 1.3 and keras 2.0.9

@Rabia-Metis
Copy link

Rabia-Metis commented Dec 21, 2017

@taoddiao Thanks for quick reply
I am using densenet161, keras 2.1.2 and tf 1.4.0
And my input shape is 224,224,3
Following is the exact wording of the error
"ValueError: Dimension 1 in both shapes must be equal, but are 2 and 1000 for 'Assign_1126' (op: 'Assign') with input shapes: [2208,2], [2208,1000]."

@taoddiao
Copy link

@Rabia-Metis It is seems that you have changed the output shape classes=1000 to classes=2. In this case, you cannot load weights directly because the weights have the output shape classes=1000. One feasible solution is to assign weights layer by layer.

@Rabia-Metis
Copy link

Rabia-Metis commented Dec 30, 2017

@taoddiao Oh I forgot it. Thanks for pointing it out

@rahul-321
Copy link

@Rabia-Metis your observation is correct, but how do we do that?

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

7 participants