我尝试过从Google合作实验室下载小文件。它们很容易下载,但是每当我尝试下载大文件时,都会显示错误?下载大文件的方式是什么?

最佳答案

这是我处理此问题的方式:

from google.colab import auth
from googleapiclient.http import MediaFileUpload
from googleapiclient.discovery import build

auth.authenticate_user()

然后点击链接,授权Google云端硬盘并将代码粘贴到笔记本中。
drive_service = build('drive', 'v3')

def save_file_to_drive(name, path):
    file_metadata = {
      'name': name,
      'mimeType': 'application/octet-stream'
     }

     media = MediaFileUpload(path,
                    mimetype='application/octet-stream',
                    resumable=True)

     created = drive_service.files().create(body=file_metadata,
                                   media_body=media,
                                   fields='id').execute()

     print('File ID: {}'.format(created.get('id')))

     return created

然后:
save_file_to_drive(destination_name, path_to_file)

这会将所有文件保存到您的Google云端硬盘中,您可以在其中下载或同步它们。

关于python-3.x - 如何从Colaboratory下载大文件(例如模型的权重)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49428332/

10-12 14:26
查看更多