[英]How to load tf.keras model directly from cloud bucket?
我尝试直接从云存储桶加载 tf.keras model 但我看不到这样做很容易。 我想加载整个 model 结构,而不仅仅是权重。
我看到了 3 个可能的方向:
是否可以直接从谷歌云存储桶加载 keras model ? 命令 tf.keras.model.load_model('gs://my_bucket/model.h5') 不起作用
我尝试使用 tensorflow.python.lib.ii.file_io 但我不知道如何将其加载为 model。
我通过 gsutil cp 命令将 model 复制到本地目录,但我不知道如何等到操作完成。 tf 尝试在下载操作完成之前加载 model 因此出现错误
我会感谢任何建议。
彼得
from tensorflow.python.lib.io import file_io
model_file = file_io.FileIO('gs://mybucket/model.h5', mode='rb')
temp_model_location = './temp_model.h5'
temp_model_file = open(temp_model_location, 'wb')
temp_model_file.write(model_file.read())
temp_model_file.close()
model_file.close()
model = tf.keras.models.load_model(temp_model_location)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.