Load a TensorFlow (.h5) model hosted online

Viewed 603

I am trying to load .h5 model using a link (https://<url>) stored online but I get this error from TensorFlow:

MODEL_PATH = 'http://<url>/<model_name>.h5'
# I have replace the <tags> with actual URL and file name
model = load_model(MODEL_PATH)
tensorflow.python.framework.errors_impl.UnimplementedError: File system scheme 'http' not implemented 

The link to the .h5 is perfectly fine so it's something to do with TensorFlow. Can someone please help with this

1 Answers

While I couldn't figure out a way to directly load a model from a URL, I used a trick to achieve something similar using the urllib.request package.

import urllib.request

urllib.request.urlretrieve(
        'http://<url>/model.h5', 'model.h5')

The above line will download the h5 model and store it in the root directory of your project. Python can then use the downloaded model:

MODEL_PATH = './model.h5'

Note: The above code is meant for Python 3. If you are using Python 2, use the following code:

import urllib
urllib.urlretrieve('http://<url>/model.h5', 'model.h5')
Related