简体   繁体   English

加载在线托管的 TensorFlow (.h5) 模型

[英]Load a TensorFlow (.h5) model hosted online

I am trying to load .h5 model using a link ( https://<url> ) stored online but I get this error from TensorFlow:我正在尝试使用在线存储的链接 ( https://<url> ) 加载 .h5 模型,但我从 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. .h5 的链接非常好,所以它与 TensorFlow 有关。 Can someone please help with this有人可以帮忙吗

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.虽然我无法找到直接从 URL 加载模型的方法,但我使用了一个技巧来使用urllib.request包实现类似的功能。

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.上面的行将下载 h5 模型并将其存储在项目的根目录中。 Python can then use the downloaded model:然后 Python 可以使用下载的模型:

MODEL_PATH = './model.h5'

Note : The above code is meant for Python 3. If you are using Python 2, use the following code:注意:以上代码适用于 Python 3。如果您使用的是 Python 2,请使用以下代码:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM