tensorflowkerasdeep-learningtransfer-learningvgg-net

How to manually load pretrained model if I can't download it using TensorFlow


I am trying to download the VGG19 model via TensorFlow

base_model = VGG19(input_shape = [256,256,3],
                    include_top = False,
                    weights = 'imagenet')

However the download always gets stuck before it finishes downloading. I've tried with different models too like InceptionV3 and the same happens there.

Fortunately, the prompt makes the link available where the model can be downloaded manually

Downloading data from https://storage.googleapis.com/tensorflow/keras-applications/vgg19/vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5
19546112/80134624 [======>.......................] - ETA: 11s

After downloading the model from the given link I try to import the model using

base_model = load_model('vgg19_weights_tf_dim_ordering_tf_kernels_notop.h5')

but I get this error

ValueError: No model found in config file.

How do I load in the downloaded .h5 model manually?


Solution

  • You're using load_model on weights, instead of a model. You need to have a defined model first, then load the weights.

    weights = "path/to/weights"
    model = VGG19  # the defined model
    model.load_weights(weights)  # the weights