如何从Colaboratory下载大文件(例如模型的权重)? [英] How to download large files (like weights of a model) from Colaboratory?

查看:94
本文介绍了如何从Colaboratory下载大文件(例如模型的权重)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have tried downloading small files from google Colaboratory. They are easily downloaded but whenever I try to download files which have a large sizes it shows an error? What is the way to download large files?

推荐答案

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

This is how I handle this issue:

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

auth.authenticate_user()

然后单击链接,授权Google云端硬盘并将代码粘贴到笔记本中.

Then click on the link, authorize Google Drive and paste the code in the notebook.

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云端硬盘中,您可以在其中下载或同步它们.

This will save whatever files to your Google Drive, where you can download or sync them or whatever.

这篇关于如何从Colaboratory下载大文件(例如模型的权重)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆