如何从ZipFile对象向Keras模型加载权重

问题描述

我正在尝试直接从Internet加载Conv模型,而没有在磁盘上写入任何内容,而是试图将模型加载到内存中。在此过程中,我最终得到了一个包含zipfile.ZipFile文件.h5对象。

我已经有了模型架构,但是需要权重填写。

这是我尝试过的

from zipfile import ZipFile
import keras
#zip_file is the ZipFile object
#Model is the keras.model object with architecture predefined and same as the original keras model
zip_open = zip_file.open("Model_weights.txt")

Model.set_weights(zip_open.read())

这给了我ValueError

ValueError: You called `set_weights(weights)` on layer "sequential_1" with a weight list of length 0,but the layer was expecting 10 weights. Provided weights: b''...

有没有一种方法可以将数据作为模型的权重加载而无需向磁盘写入任何内容

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)