Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

can't load pretrained model CheXNet_Keras_0.3.0_weights.h5 into Keras Densenet121 #52

Open
WrathofBhuvan11 opened this issue Oct 16, 2020 · 1 comment

Comments

@WrathofBhuvan11
Copy link

WrathofBhuvan11 commented Oct 16, 2020

Here I have asked the question
https://stackoverflow.com/questions/64390544/unable-to-load-chexnet-pre-trained-weight-file-to-densenet121
densenet = tf.keras.applications.DenseNet121( include_top=False, weights="CheXNet_Keras_0.3.0_weights.h5", input_shape=(224,224,3) )
ValueError: You are trying to load a weight file containing 242 layers into a model with 241 layers. if I Call densenet121
Please help...

@ddofer
Copy link

ddofer commented Dec 21, 2020

They saved the model without the correct output layer, here's the fix:

        base_model = densenet.DenseNet121(weights=None,
                                    include_top=False,
                                    input_shape=(224,224,3), pooling="avg")

        predictions = tf.keras.layers.Dense(14, activation='sigmoid', name='predictions')(base_model.output)
        base_model = tf.keras.Model(inputs=base_model.input, outputs=predictions)
        base_model.load_weights("./temp/CheXNet_Keras_0.3.0_weights.h5")
        base_model.layers.pop()
    print("CheXNet loaded")

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

No branches or pull requests

2 participants