python-将字节对象转换为张量对象,以用于TORCH.LOAD()
我已经从我的Google Drive下载了张量
(.pt)对象进入我的python工作区,该python工作区当前是bytes
对象。它需要是张量
对象(x)在代码torch.load.load(x)
中使用:
从我的Google Drive下载TensorFlow对象的代码是:
file_id2 = 'XXXXXXXXXXXXXXXXXXXXXXXXX'
request = drive_service.files().get_media(fileId=file_id2)
gh = io.BytesIO()
downloader = MediaIoBaseDownload(gh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print ("Download %d%%." % int(status.progress() * 100))
X = gh.getvalue()
我试图找到一种将字节对象(x)放入张量对象的方法,但是我找不到任何有用的
方法吗?或一种从Google下载张量对象的方法,以.pt
文件而不是bytes
。
I have downloaded a tensor
(.pt) object from my Google drive into my Python workspace, which is currently a bytes
object. It needs to be a tensor
object (X) to be used in the code torch.load(X)
:
The code to download the tensorflow object from my Google Drive is:
file_id2 = 'XXXXXXXXXXXXXXXXXXXXXXXXX'
request = drive_service.files().get_media(fileId=file_id2)
gh = io.BytesIO()
downloader = MediaIoBaseDownload(gh, request)
done = False
while done is False:
status, done = downloader.next_chunk()
print ("Download %d%%." % int(status.progress() * 100))
X = gh.getvalue()
I have tried to find a way of getting the bytes object (X) into a tensor object, but I am not finding anything helpful
Is there a way of doing this? or a way of downloading the tensor object from google as a .pt
file and not bytes
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我设法解决了它,因此如果将来有人需要它,它将留在这里。
我必须将对象作为字节对象(我认为已经是),现在它有效:)
I managed to solve it, so will leave this here in case anyone needs it in the future.
I had to pass the object as a BytesIO object (I thought it already was), and now it works :)