1

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?

Anwesh
  • 23
  • 4

2 Answers2

1

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
Djinn
  • 663
  • 5
  • 12
  • Okay makes sense. Do I have to manually code the VGG19 model or is there any way I can import it without using TensorFlow's download feature – Anwesh Nov 15 '21 at 16:47
  • Keras (tensorflow included) already has VGG19 in the `applications` library. `from tensorflow.keras.applications.vgg19 import VGG19`. When you initialize the model, it will be downloaded automatically. – Djinn Nov 15 '21 at 20:31
  • Yeah I know but the problem is the download gets stuck, which is why I have to download the model and load it in manually. – Anwesh Nov 16 '21 at 10:09
  • Download the model manually and load with `load_model` then load the weights. – Djinn Nov 16 '21 at 14:15
0

Got the same problem when learning on tensorflow tutorial, too.

Transfer learning and fine-tuning: Create the base model from the pre-trained convnets

# Create the base model from the pre-trained model MobileNet V2
IMG_SIZE = (160, 160)
IMG_SHAPE = IMG_SIZE + (3,)
base_model = tf.keras.applications.MobileNetV2(input_shape=IMG_SHAPE, include_top=False, weights=None)

# load model weights manually
weights = 'mobilenet_v2_weights_tf_dim_ordering_tf_kernels_1.0_160_no_top.h5'
base_model.load_weights(weights)

I tried download the model.h5, and load manually. It works.

`

Jimmy Wang
  • 67
  • 9