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

时间:2020-09-28 06:40:43

标签: python 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 

.h5的链接非常好,因此与TensorFlow有关。有人可以帮忙吗

1 个答案:

答案 0 :(得分:2)

虽然我无法找到一种直接从URL加载模型的方法,但我使用了一个技巧来使用urllib.request包来实现类似的目的。

import urllib.request

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

以上行将下载h5模型并将其存储在项目的根目录中。然后,Python可以使用下载的模型:

MODEL_PATH = './model.h5'

注意:以上代码适用于Python3。如果您使用的是Python 2,请使用以下代码:

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