python-将字节对象转换为张量对象,以用于TORCH.LOAD()

发布于 2025-01-24 21:27:12 字数 677 浏览 1 评论 0原文

我已经从我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷弦 2025-01-31 21:27:12

我设法解决了它,因此如果将来有人需要它,它将留在这里。

tensorObject = torch.load(io.BytesIO(X))

我必须将对象作为字节对象(我认为已经是),现在它有效:)

I managed to solve it, so will leave this here in case anyone needs it in the future.

tensorObject = torch.load(io.BytesIO(X))

I had to pass the object as a BytesIO object (I thought it already was), and now it works :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文