繁体   English   中英

如何从带有密码的 .zip 文件中使用 keras 加载 .h5 CNN 模型

[英]How to load .h5 CNN model with keras from .zip file with password

我想从带有密码的.zip文件加载.h5模型而不提取.h5文件。 我只能使用python==3.6, h5py==2.10, tensorflow==1.4.0 我的代码如下:

import h5py
import zipfile
import tensorflow as tf

archive = zipfile.ZipFile('test_zip.zip')
for file in archive.infolist():
   model_h5_file = archive.open(file, pwd=pwd)
   h5_file1 = h5py.File(model_h5_file, 'r')  # gives an error "io.UnsupportedOperation: seek"
   h5_file2 = tf.keras.models.load_model(model_h5_file, custom_objects={'auc_roc': auc_roc})  # gives an error "io.UnsupportedOperation: seek"

如何使用 keras 加载我的 .h5 文件?

这就是我过去使用具有多个文件的自定义模型的方式

import zipfile
import tensorflow as tf

with zipfile.ZipFile('test_zip.zip') as zip_file:
   model = tf.saved_model.load("model.h5")

我希望这是你要找的。

如果您想深入了解,这里有一些资源: https ://docs.python.org/3/library/zipfile.html#zipfile.ZipFile.open https://www.tensorflow.org/api_docs/python/ tf/saved_model/加载

暂无
暂无

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

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