URL fetch failure on resnet50_weights_tf

Issue

I have to train a model from where I dont have access to Internet.

base_cnn = resnet.ResNet50(
    weights="imagenet", input_shape=target_shape + (3,), include_top=False
)

Subsequently, training is failing with:

Traceback (most recent call last):
    base_cnn = resnet.ResNet50(
      return ResNet(stack_fn, False, True, 'resnet50', include_top, weights,
      weights_path = data_utils.get_file(
      raise Exception(error_msg.format(origin, e.errno, e.reason))
Exception: URL fetch failure on https://storage.googleapis.com/tensorflow/keras-applications/resnet/resnet50_weights_tf_dim_ordering_tf_kernels_notop.h5: None -- [Errno 101] Network is unreachable

Is there a way I can load the weights from drive instead of fetching an URL?

Solution

Weights could be downloaded as:

from tensorflow.keras.applications import resnet

base_cnn = resnet.ResNet50(
    weights="imagenet", input_shape=target_shape + (3,), include_top=False
)

base_cnn.save("weights.h5")

Then load the saved weights:

from tensorflow.keras.models import load_model
base_cnn=load_model('weights.h5')

Answered By – Exploring

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published