DenseNet-Keras icon indicating copy to clipboard operation
DenseNet-Keras copied to clipboard

about the pre-train weight

Open Fahim-F opened this issue 7 years ago • 15 comments

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

Fahim-F avatar Jul 06 '17 19:07 Fahim-F

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

flyyufelix avatar Jul 10 '17 04:07 flyyufelix

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

Fahim-F avatar Jul 11 '17 20:07 Fahim-F

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

flyyufelix avatar Jul 12 '17 01:07 flyyufelix

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.

Fahim-F avatar Jul 12 '17 01:07 Fahim-F

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?

flyyufelix avatar Jul 12 '17 02:07 flyyufelix

My keras 2.0.5 and tensorflow 1.2.0

Fahim-F avatar Jul 12 '17 02:07 Fahim-F

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].

datlife avatar Jul 23 '17 00:07 datlife

same problems with tensorflow 1.2.1 and keras 2.0.6

Tangzy7 avatar Aug 27 '17 06:08 Tangzy7

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

taoddiao avatar Dec 09 '17 14:12 taoddiao

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'

Rabia-Metis avatar Dec 21 '17 13:12 Rabia-Metis

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

taoddiao avatar Dec 21 '17 13:12 taoddiao

@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]."

Rabia-Metis avatar Dec 21 '17 14:12 Rabia-Metis

@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.

taoddiao avatar Dec 26 '17 07:12 taoddiao

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

Rabia-Metis avatar Dec 30 '17 11:12 Rabia-Metis

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

rahul-321 avatar Apr 15 '18 09:04 rahul-321