首页 > 解决方案 > 将文件从 kaggle 上传到谷歌驱动器

问题描述

我正在使用 kaggle 训练模型,一旦训练完成,我想将训练后的模型上传到谷歌驱动器,因为我无法找到在本地下载模型的方法。在执行 pip install pydrive 之后,我研究了使用https://pythonhosted.org/PyDrive/我尝试进行身份验证

    import os
    from pydrive.auth import GoogleAuth
    from pydrive.drive import GoogleDrive
    from oauth2client.client import GoogleCredentials

然后

gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)

我收到此错误 ApplicationDefaultCredentialsError:应用程序默认凭据不可用。如果在 Google Compute Engine 中运行,它们就可用。否则,必须定义环境变量 GOOGLE_APPLICATION_CREDENTIALS 指向定义凭据的文件。有关详细信息,请参阅https://developers.google.com/accounts/docs/application-default-credentials

还有另一种方法可以做到这一点吗?

此外,当我手动停止训练时,我还没有在 kaggle 中提交我的文件,因此提交将永远持续下去,并且在我尝试提交并停止输出区域中的提交后,我得到了超过 6 个子目录的错误

标签: pythongoogle-drive-apikagglepydrive

解决方案


我遇到了同样的问题,并且能够从Kaggleto下载文件Colab然后移动到Google Drive. 例如,如果当前目录是/kaggle/working并且要移动的文件是processed_file.zipthen,

来自 Kaggle

from IPython.display import FileLink
FileLink(r'processed_file.zip')

这将生成一个链接,

https://....kaggle.net/...../processed_file.zip

来自 Colab

!wget "https://....kaggle.net/...../processed_file.zip"

挂载 Google 云端硬盘

from google.colab import drive
drive.mount('/content/drive')

将文件复制到 Google 云端硬盘

!cp "/content/processed_file.zip" "/content/drive/My Drive/workspace"

推荐阅读