【发布时间】:2018-07-13 14:13:57
【问题描述】:
我正在尝试找到将存储在 Google Drive 中的 Keras 模型以 .h5 格式保存的方法加载到 Colaboratory 工作表中以用作 Keras 模型(无需先下载到桌面,已经有方法)。
我已使用 Drive REST API 的 Colaboratory 教程成功加载 .h5 文件:
# Download the '.h5' file from google drive
file_id = '1uBtlaggVyWshwcyP6kEI-y_W3P8D26sz'
import io
from io import BytesIO
from googleapiclient.http import MediaIoBaseDownload
request = drive_service.files().get_media(fileId=file_id)
downloaded = io.BytesIO()
downloader = MediaIoBaseDownload(downloaded, request)
done = False
while done is False:
status, done = downloader.next_chunk()
if status:
print("Download %%%d%%." % int(status.progress() * 100))
print("Download Complete!")
downloaded.seek(0)
print('Downloaded file contents are: {}'.format(downloaded.read()))
哪些输出:
Download %100%.
Download Complete!
Downloaded file contents are: b'\x89HDF\r\n\x1a\n\x00\x00\x00...(etc)
而且下载的.read() 似乎给出了一种字节字符串。
我的问题是如何将此字节字符串转换为 .h5 形式,以便我可以从 Keras 调用 load_model?
【问题讨论】:
-
(此处提供授权 Google Drive 等完整方法的教程:colab.research.google.com/notebook#fileId=/v2/external/…
标签: python google-drive-api keras hdf5 google-colaboratory